#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const int inf=1e9+7;
const double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
//const double pi=acos(-1);

const int maxn=45;
int vis[55][55][55][4][4][4];//æ è®°æ°ç»ï¼[Aåæ ][Båæ ][Cåæ ][Aæä½ç¶æ][Bæä½ç¶æ][Cæä½ç¶æ]
int a[4][4];
int ans=0;

int dfs(int x1,int x2,int x3,int A,int B,int C){
	//åæ°åvisï¼[Aåæ ][Båæ ][Cåæ ][Aæä½ç¶æ][Bæä½ç¶æ][Cæä½ç¶æ]
    if(vis[x1][x2][x3][A][B][C]) return 0;
    vis[x1][x2][x3][A][B][C]=1;
    int b[4]={x1,x2,x3};//è®°å½æ¯äººå½ååæ ï¼å¼ä¸ªæ°ç»ä¸»è¦æ¯å¥½éå
    int c[4]={A,B,C};//æ¯äººæä½ç¶æï¼åæ ·æ¯æ¹ä¾¿éå
    int g[50]={0};//åæ è½´ç¶æï¼g[x]=iè¡¨ç¤ºxä½ç½®ä¸ç«çç¬¬iä¸ªäºº
	//å¶å®å¯¹äºåæçç¶æåºè¯¥é¢å¤å¼ä¸ªæ°ç»ï¼ä½æ¯ææï¼æä»¥æç¨g[maxn+i]è¡¨ç¤ºç¬¬iä¸ªäººä¸¾èµ·çäºº
	//ä¹å°±æ¯g[maxn+i]=qè¡¨ç¤ºç¬¬iä¸ªäººæ£å«çç¬¬qä¸ªäºº
	//g[x]ä¸º0èªç¶æ¯æ²¡äººç«/ä¸ä¸¾
    for(int i=0;i<3;i++) g[b[i]]=i;
    for(int i=0;i<3;i++){
        int t=b[i];//æä¸¾å½ååæ
        if(t<maxn){//æè¿ä¸ªifå æå°±tåºå¤©éï¼æ¬ä»£ç å¯ä¸åªæ
            ans=max(ans,t);
            if(!(c[i]&1)&&!g[maxn+i]){//c[i]&1æ¯0ï¼åç¬¬iäººæ²¡ç§»å¨è¿ï¼g[maxn+i]ä¸º0è¡¨ç¤ºè¿äººæ²¡åå«äººï¼å¯ä»¥ç§»å¨
                for(int j=max(0,t-a[i][1]);j<=t+a[i][1];j++){
                    if(j>0&&!g[j]){
                        b[i]=j;c[i]^=1;
                        dfs(b[0],b[1],b[2],c[0],c[1],c[2]);
                        b[i]=t;c[i]^=1;
                    }
                }
            }
            if(!(c[i]&2)&&!g[maxn+i]){
                for(int j=0;j<3;j++){
                    int v=b[j];
                    if(abs(t-v)!=1) continue;
                    b[j]=maxn+i;c[i]^=2;
                    dfs(b[0],b[1],b[2],c[0],c[1],c[2]);
                    b[j]=v;c[i]^=2;
                }
            }
            if(g[maxn+i]){
                int k=g[maxn+i];
                for(int j=max(0,t-a[i][2]);j<=t+a[i][2];j++){
                    if(j>0&&!g[j]){
                        b[k]=j;
                        dfs(b[0],b[1],b[2],c[0],c[1],c[2]);
                        b[k]=maxn+i;
                    }
                }
            }
        }
    }
    return 0;
}

int main()
{
    fd(3)
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    dfs(a[0][0],a[1][0],a[2][0],0,0,0);
    cout<<ans<<'\n';
    return 0;
}

You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The distance between the positions is the absolute difference between the respective numbers. Laharl, Etna and Flonne occupy some positions on the half-line and they want to get to the position with the largest possible number. They are originally placed in different positions. Each of the characters can perform each of the following actions no more than once:   Move a certain distance.  Grab another character and lift him above the head.  Throw the lifted character a certain distance.  Each character has a movement range parameter. They can only move to free positions, assuming that distance between those positions doesn't exceed the movement range. One character can lift another character if the distance between the two characters equals 1, and no one already holds that another character. We can assume that the lifted character moves to the same position as the person who has lifted him, and the position in which he stood before becomes free. A lifted character cannot perform any actions and the character that holds him cannot walk. Also, each character has a throwing range parameter. It is the distance at which this character can throw the one lifted above his head. He can only throw a character to a free position, and only when there is a lifted character. We accept the situation when one person grabs another one who in his turn has the third character in his hands. This forms a "column" of three characters. For example, Laharl can hold Etna while Etna holds Flonne. In this case, Etna and the Flonne cannot perform any actions, and Laharl can only throw Etna (together with Flonne) at some distance. Laharl, Etna and Flonne perform actions in any order. They perform actions in turns, that is no two of them can do actions at the same time.Determine the maximum number of position at least one of the characters can reach. That is, such maximal number x so that one of the characters can reach position x.

The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between 1 and 10, inclusive.

Print a single number — the maximum ordinal number of position which either Laharl, Etna or Flonne can reach.

NoteLet us explain how to reach position 15 in the sample.Initially Laharl occupies position 9, Etna — position 4 and Flonne — position 2.First Laharl moves to position 6.Then Flonne moves to position 5 and grabs Etna.Laharl grabs Flonne and throws to position 9.Flonne throws Etna to position 12.Etna moves to position 15.

#include<cstdio>

#include<cstring>

#include<cmath>

#define check(i) i-p[0] && i-p[1] && i-p[2]

int p[3],m[3],t[3],ans,dep;

bool f[48][48][48][8][8];

void dfs(int *p,int x,int y)

{

	bool &res=f[p[0]][p[1]][p[2]][x][y]; if (res) return; res=1;

	int far=0,near=50;

	for (int i=0;i<3;i++){

		if (p[i]<45 && p[i]>far) far=p[i];

		if (p[i]<near) near=p[i];

		}

	if (far>ans) ans=far;

	for (int j=0;j<3;j++) {

		int q[3]={p[0],p[1],p[2]},z=1<<j;

		if (p[j]>=45){

			int T=p[j]-45;

			for (int i=p[T]+t[T];p[T]<45 && i>=p[T]-t[T] && i>near-2 && i;i--)

				if (check(i)) q[j]=i,dfs(q,x,y);

			}

		else if (check(j+45)){

			if (y&z) for (int i=0;i<3;i++) if (fabs(p[i]-p[j])==1)

				q[i]=45+j,dfs(q,x,y^z),q[i]=p[i];

			if (x&z) for (int i=p[j]+m[j];i>=p[j]-m[j] && i>near-2 && i;i--)

				if (check(i)) q[j]=i,dfs(q,x^z,y);

			}

		}

}

int main()

{

	for (int i=0;i<3;i++) scanf("%d%d%d",p+i,m+i,t+i);

	dfs(p,7,7); printf("%d\n",ans);	return 0;

}


//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e3 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

string s[Maxn], V[Maxn];
ll ans[5];

ll check ( char t )
{
    if ( t == 'u' || t == 'o' || t == 'a' || t == 'i' || t == 'e' )
        return true;
    return false;
}

void f ( ll a, ll b, ll c, ll d )
{
    if ( V[a] == V[b] && V[c] == V[d] );
    else    ans[1] = 0;
    if ( V[a] == V[c] && V[b] == V[d] );
    else    ans[2] = 0;
    if ( V[a] == V[d] && V[c] == V[b] );
    else    ans[3] = 0;
    if ( V[a] == V[b] && V[c] == V[d] && V[c] == V[b] );
    else    ans[4] = 0;
}

void print ( ll i )
{
    if ( i == 1 )
        cout << "aabb" << endl;
    if ( i == 2 )
        cout << "abab" << endl;
    if ( i == 3 )
        cout << "abba" << endl;
    if ( i == 4 )
        cout << "aaaa" << endl;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    for ( ll i = 1; i <= 4 * n; i++ )
    {
        cin >> s[i];
        ll K = k;
        for ( ll j = s[i].size() - 1; K && j >= 0; j-- )
        {
            if ( check ( s[i][j] ) )
                V[i] += s[i][j], K--;
        }
        if ( K )
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    ans[1] = ans[2] = ans[3] = ans[4] = 1;
    for ( ll i = 1; i <= n; i++ )
    {
        ll st = ( i - 1 ) * 4;
        f ( st + 1, st + 2, st + 3, st + 4 );
    }
    for ( ll i = 4; i >= 1; i-- )
    {
        if ( ans[i] )
        {
            print ( i );
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):   Clerihew (aabb);  Alternating (abab);  Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.

The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.

NoteIn the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".

2 1
day
may
sun
fun
test
hill
fest
thrill

//In The Name Of God ( Of programming )

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P_ll pair<ll, ll>
#define P_cl pair<char, ll>
#define P_lc pair<ll, char>
#define Sort( a ) sort ( a.begin(), a.end() )
#define help_me_God ios_base::sync_with_stdio ( false )

string s[Maxn], V[Maxn];
ll ans[5];

ll check ( char t )
{
    if ( t == 'u' || t == 'o' || t == 'a' || t == 'i' || t == 'e' )
        return true;
    return false;
}

void f ( ll a, ll b, ll c, ll d )
{
    if ( V[a] == V[b] && V[c] == V[d] );
    else    ans[1] = 0;
    if ( V[a] == V[c] && V[b] == V[d] );
    else    ans[2] = 0;
    if ( V[a] == V[d] && V[c] == V[b] );
    else    ans[3] = 0;
    if ( V[a] == V[b] && V[c] == V[d] && V[c] == V[b] );
    else    ans[4] = 0;
}

void print ( ll i )
{
    if ( i == 1 )
        cout << "aabb" << endl;
    if ( i == 2 )
        cout << "abab" << endl;
    if ( i == 3 )
        cout << "abba" << endl;
    if ( i == 4 )
        cout << "aaaa" << endl;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    for ( ll i = 1; i <= 4 * n; i++ )
    {
        cin >> s[i];
        ll K = k;
        for ( ll j = s[i].size() - 1; K && j >= 0; j-- )
        {
            V[i] += s[i][j];
            if ( check ( s[i][j] ) )
                 K--;
        }
        if ( K )
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    ans[1] = ans[2] = ans[3] = ans[4] = 1;
    for ( ll i = 1; i <= n; i++ )
    {
        ll st = ( i - 1 ) * 4;
        f ( st + 1, st + 2, st + 3, st + 4 );
    }
    for ( ll i = 4; i >= 1; i-- )
    {
        if ( ans[i] )
        {
            print ( i );
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

[{'input': '1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n', 'output': ['aabb\r\n']}, {'input': '1 1\r\nday\r\nmay\r\ngray\r\nway\r\n', 'output': ['aaaa\r\n']}, {'input': '2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n', 'output': ['aabb\r\n']}, {'input': '2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n', 'output': ['NO\r\n']}, {'input': '2 5\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\nrezwbgy\r\nxakgmv\r\njogezwbgy\r\napezwbgy\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\nnuqfxwrb\r\napqfkw\r\nuqfxwrb\r\nnhcuqfxwrb\r\nogkznwncmt\r\nevf\r\nogkznwncmt\r\nogkznwncmt\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\naawjvkxx\r\nawjvkxx\r\nxawjvkxx\r\nawjvkxx\r\n', 'output': ['aaaa\r\n']}, {'input': '2 2\r\nrhcujgxabk\r\nnjgdqpurul\r\nueoedt\r\ncpcfhbyvo\r\nzmfwnieog\r\npkpylassbf\r\nhrfeod\r\ncdwuil\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\nol\r\nol\r\nol\r\nzol\r\nek\r\nek\r\nek\r\nqek\r\n', 'output': ['aaaa\r\n']}, {'input': '3 2\r\nexdaoao\r\nrdwunurp\r\ndunurp\r\ntyqzuxao\r\ndupocgsps\r\nzsiravcm\r\nnqiravcm\r\nlnupocgsps\r\niwashk\r\neepkqcykbv\r\nyviwashk\r\neepkqcykbv\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\ndaihacbnhgfts\r\nsqihpntjvczkw\r\nmihpntjvczkw\r\nvyacbnhgfts\r\ntsvovdpqajmgvcj\r\ncexqkwrvctomb\r\njxbomb\r\ngnpajmgvcj\r\n', 'output': ['abba\r\n']}, {'input': '3 2\r\netba\r\ntfecetba\r\nzkitbgcuuy\r\nuuy\r\nbuxeoi\r\nmekxoi\r\nblviwoehy\r\niwoehy\r\njyfpaqntiz\r\nqvaqntiz\r\nhciak\r\niak\r\n', 'output': ['aabb\r\n']}, {'input': '4 3\r\niixxiojrrdytjcbkvymw\r\nbjqixxiojrrdytjcbkvymw\r\nogjixxiojrrdytjcbkvymw\r\nevixxpfxpgicpg\r\njkotitixiughfhphliuurx\r\ngyubkqtonejprfjzvqxbdpn\r\ndpudxfoqnhekjytbwiuurx\r\noubkqtonejprfjzvqxbdpn\r\npgzaendrxjhsfzjmijv\r\npomuaendrxjhsfzjmijv\r\nafyuyxueaendrxjhsfzjmijv\r\naendrxjhsfzjmijv\r\nyubweicj\r\ntbnsuxqigmxdfnmbipubweicj\r\nfuftydlmoo\r\nmdkuftydlmoo\r\n', 'output': ['NO\r\n']}, {'input': '5 2\r\nqurcmcbxyoddgyyccsmb\r\nlsdzsqoa\r\neurcmcbxyoddgyyccsmb\r\noa\r\nutyxmdhcvaclynmstwsx\r\nmkyycelbmkmdrilmbvr\r\nutyxmdhcvaclynmstwsx\r\nrduyelbmkmdrilmbvr\r\nhmguhvqswwciowwgu\r\nnoe\r\nzmyncuwrowwgu\r\nqrhymghavvbmigzsjoe\r\nbvofhknbzusykztlxwms\r\nbpbfmvjaimkdeddy\r\neofhknbzusykztlxwms\r\nmhivpkxkpazimkdeddy\r\negvywnhmfngllaknmn\r\nmblkvhenlggoftwjgk\r\nzegvywnhmfngllaknmn\r\ngrdenlggoftwjgk\r\n', 'output': ['abab\r\n']}, {'input': '7 3\r\nferwljzwakxedlgwl\r\noerwljzwakxedlgwl\r\nhyqombizhuhxedprb\r\netptjrizhuhxedprb\r\nurtuckar\r\ndkartmwramklcmi\r\nrurtuckar\r\nnurartmwramklcmi\r\niraziomsv\r\nsaziomsv\r\nbprapiqpayzurgij\r\nusyemayzurgij\r\nztstmeecvmkvuu\r\nquexlecvmkvuu\r\nrlhwecvmkvuu\r\nzecvmkvuu\r\niikymgbncljtub\r\nqiikymgbncljtub\r\nbcavhexqamyszgfya\r\nojexqamyszgfya\r\nieyxqinjinjv\r\nxtiudieyxqinjinjv\r\nthtceyxqinjinjv\r\nmuneyxqinjinjv\r\nwreae\r\nqylcjhjzfhteae\r\nozcjthgyuchqo\r\nfcjozcjthgyuchqo\r\n', 'output': ['NO\r\n']}, {'input': '16 1\r\ni\r\ni\r\ni\r\ni\r\ni\r\nu\r\ni\r\ni\r\no\r\na\r\na\r\no\r\na\r\ni\r\na\r\na\r\ni\r\ni\r\no\r\no\r\ni\r\ni\r\ni\r\ni\r\nu\r\nu\r\nu\r\nu\r\no\r\ne\r\ne\r\ne\r\no\r\ni\r\no\r\ni\r\na\r\na\r\na\r\na\r\nu\r\no\r\no\r\nu\r\ni\r\no\r\no\r\ni\r\na\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\na\r\no\r\na\r\na\r\nu\r\na\r\nu\r\nu\r\n', 'output': ['NO\r\n']}, {'input': '16 1\r\neb\r\neb\r\nfe\r\nce\r\ner\r\ner\r\new\r\new\r\nu\r\ncu\r\nu\r\nu\r\nud\r\nik\r\nud\r\nik\r\nve\r\niw\r\niw\r\nne\r\nel\r\nob\r\nel\r\nob\r\no\r\neo\r\no\r\nyo\r\nav\r\nav\r\nei\r\nmi\r\nu\r\noh\r\noh\r\nzu\r\niw\r\niw\r\na\r\nma\r\ni\r\nu\r\nku\r\ngi\r\nac\r\no\r\no\r\nac\r\ni\r\ner\r\nai\r\ner\r\nyu\r\nuf\r\nuf\r\nhu\r\nef\r\nef\r\nef\r\nef\r\nmu\r\nu\r\nqe\r\nie\r\n', 'output': ['NO\r\n']}, {'input': '25 1\r\nw\r\ni\r\nv\r\nx\r\nh\r\ns\r\nz\r\ny\r\no\r\nn\r\nh\r\ni\r\nf\r\nf\r\ny\r\nr\r\nb\r\nu\r\no\r\np\r\nz\r\nh\r\nt\r\no\r\nw\r\nx\r\nh\r\no\r\nj\r\ny\r\nw\r\nj\r\ny\r\nh\r\nh\r\nr\r\ns\r\nb\r\ny\r\nr\r\nw\r\no\r\nl\r\nl\r\nh\r\nh\r\nw\r\nu\r\na\r\nv\r\no\r\nx\r\nd\r\nw\r\nc\r\nf\r\ni\r\ne\r\nj\r\nq\r\nk\r\na\r\ne\r\nl\r\nw\r\nm\r\nf\r\na\r\nc\r\na\r\nb\r\nf\r\nj\r\nb\r\nx\r\ni\r\nx\r\ne\r\nu\r\nh\r\nm\r\no\r\ni\r\nq\r\nm\r\nk\r\nn\r\nd\r\nl\r\np\r\nc\r\nw\r\nu\r\nz\r\nc\r\nk\r\ng\r\ny\r\nj\r\ny\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\ne\r\ne\r\ne\r\ne\r\n', 'output': ['aaaa\r\n']}, {'input': '1 1\r\na\r\ne\r\ne\r\ne\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\ne\r\na\r\ne\r\ne\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\na\r\na\r\ne\r\ne\r\n', 'output': ['aabb\r\n']}, {'input': '1 1\r\ne\r\ne\r\na\r\ne\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\na\r\ne\r\na\r\ne\r\n', 'output': ['abab\r\n']}, {'input': '1 1\r\ne\r\na\r\na\r\ne\r\n', 'output': ['abba\r\n']}, {'input': '1 1\r\na\r\na\r\na\r\ne\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\ne\r\ne\r\ne\r\na\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\na\r\ne\r\ne\r\na\r\n', 'output': ['abba\r\n']}, {'input': '1 1\r\ne\r\na\r\ne\r\na\r\n', 'output': ['abab\r\n']}, {'input': '1 1\r\na\r\na\r\ne\r\na\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\ne\r\ne\r\na\r\na\r\n', 'output': ['aabb\r\n']}, {'input': '1 1\r\na\r\ne\r\na\r\na\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\ne\r\na\r\na\r\na\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\na\r\na\r\na\r\na\r\n', 'output': ['aaaa\r\n']}, {'input': '1 2\r\neraub\r\nbee\r\naab\r\nttbee\r\n', 'output': ['NO\r\n']}, {'input': '10 1\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\ny\r\n', 'output': ['NO\r\n']}, {'input': '1 2\r\neeereaatktb\r\nbee\r\niaattb\r\nottbee\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\nab\r\nac\r\nad\r\naf\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\nar\r\nat\r\nay\r\naw\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\na\r\ne\r\na\r\ne\r\na\r\na\r\na\r\na\r\n', 'output': ['abab\r\n']}, {'input': '1 1\r\na\r\ne\r\na\r\ni\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\na\r\ne\r\na\r\ne\r\n', 'output': ['abab\r\n']}, {'input': '1 1\r\nabbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbfbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbxbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbdbbbbbbbbbbbbbbbb\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\na\r\n', 'output': ['abba\r\n']}, {'input': '1 1\r\nbug\r\nsuy\r\nluh\r\ngut\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\nam\r\nat\r\nan\r\nag\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\na\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\n', 'output': ['aabb\r\n']}, {'input': '1 4\r\naieoabcd\r\naeioabcd\r\naoeiabcd\r\naoieabcd\r\n', 'output': ['NO\r\n']}, {'input': '1 2\r\naec\r\naed\r\naek\r\naem\r\n', 'output': ['NO\r\n']}, {'input': '1 1\r\nar\r\nab\r\nak\r\naz\r\n', 'output': ['NO\r\n']}, {'input': '2 1\r\na\r\na\r\na\r\na\r\na\r\nb\r\nb\r\nb\r\n', 'output': ['NO\r\n']}]


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

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int n,m;
	cin>>n>>m;
	unsigned long long int countInt=0, countIr=0;
	if(2*n-1>=m)
	{
		if(m%2==1)
		{
			countInt+=(m-1)/2+1;
			if((m-1)%4==0)
			{
				countInt+=(m-1)/4;
			}
			else
			{
				countInt+=((m-1)/2-1)/2;
			}
		}
		else
		{
			countInt+=m/2;
			if(m%4==0)
			{
				countInt+=m/4;
			}
			else
			{
				countInt+=(m/2-1)/2;
			}
		}
	}
	else
	{
		countInt+=n;
		if(m%2==1)
		{
			if(((m-1)/2)%2==1)
			{
				countInt+=n-max(1,(n-((m-1)/2-1)/2));
			}
			else
			{
				countInt+=n-max(1,n-(m-1)/4);
			}
		}
		else
		{
			if(m/2%2==1)
			{
				countInt+=n-max(1,n-(m/2-1)/2);
			}
			else
			{
				countInt+=n-max(1,n-m/4);
			}

		}
	}
	for(int b=1;b<=n;b++)
	{
		if(b*b<=m)
		{
			countIr+=b*b-b;
		}
		else
		{
			int countk=b-ceil(sqrt(b*b-m));
			countIr+=m-countk;

		}

	}
	countIr*=2;
	cout<<countIr+countInt<<endl;
	return 0;
}

A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple: x2 + 2bx + c = 0 where b, c are natural numbers.Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 ≤ b ≤ n, 1 ≤ c ≤ m. Help Petya find that number.

The single line contains two integers n and m. (1 ≤ n, m ≤ 5000000).

Print a single number which is the number of real roots of the described set of equations.

NoteIn the second test from the statement the following equations are analysed: b = 1, c = 1: x2 + 2x + 1 = 0; The root is x =  - 1 b = 1, c = 2: x2 + 2x + 2 = 0; No roots Overall there's one rootIn the second test the following equations are analysed: b = 1, c = 1: x2 + 2x + 1 = 0; The root is x =  - 1 b = 1, c = 2: x2 + 2x + 2 = 0; No roots b = 1, c = 3: x2 + 2x + 3 = 0; No roots b = 2, c = 1: x2 + 4x + 1 = 0; The roots are  b = 2, c = 2: x2 + 4x + 2 = 0; The roots are  b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 =  - 3, x2 =  - 1 b = 3, c = 1: x2 + 6x + 1 = 0; The roots are  b = 3, c = 2: x2 + 6x + 2 = 0; The roots are  b = 3, c = 3: x2 + 6x + 3 = 0; The roots are  Overall there are 13 roots and as the root  - 1 is repeated twice, that means there are 12 different roots.

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

#define problem "Khaustov"

typedef long long int64;
typedef unsigned char byte;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<int64, int64> pii64;
typedef pair<pii64, int> piii64;
typedef pair<double, int64> pdi;
typedef pair<double, double> pdd;
typedef pair<pdi, int> pdii;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef list<int> li;
typedef stringstream ss;

#define y1 _dsfdsfkn
#define left _dsfdsf
#define right _dfjdsj
#define link _tsu_sux
#define prime 1103
#define eps 1e-8
#define inf 123456789
#define toMod 1000000007LL

inline double sqr(double x)
{
    return x * x;
}

int n, m;
pii PREV, CUR;

int64 res;
int k;
pii a[15000000];

inline pii make(int x, int y)
{
    if (x > y) swap(x, y);
    return pii(x, y);
}

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    k = 0;
    scanf("%d%d", &n, &m);
    res = 0;
    for (int b = 1; b <= n; ++b)
    {
        int MAX = b - 1;
        int MIN = 1;

        int64 sb = b;
        sb *= (int64)b;

        if (sb > m)
        {
            double T = sqrt((double)(sb - m));
            if (T > 1e-9) T -= 1e-9;
            MIN = (int)ceil(T);
        } else a[k++] = make(-b, -b);

        if (MIN > MAX)
        {
            int64 lim = min((int64)m, sb - 1);
            res += 2 * lim;
            continue;
        }

        int64 lim = min((int64)m, sb - 1);
        lim -= (MAX - MIN + 1);
        res += 2 * lim;

        a[k++] = make(MAX - b, MIN - b);
        a[k++] = make(-MAX - b, -MIN - b);
    }

    sort(a, a + k);
    if (k) res += (a[0].second - a[0].first + 1);
    for (int i = 1; i < k; ++i)
    {
        a[i].first = max(a[i].first, a[i - 1].second + 1);
        if (a[i].second >= a[i].first)
            res += (a[i].second - a[i].first + 1);
        a[i].second = max(a[i].second, a[i - 1].second);
    }

    printf("%lld\n", res);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<algorithm>

using namespace std;

const double eps = 1e-8;
const int MaxN = 25, MaxSize = MaxN * MaxN;

int N, M, SA, SB, tot;
bool g[MaxN][MaxN];
int deg[MaxN];
double P[MaxN], ans[MaxSize];

int lab(int a, int b) {
    return (a - 1) * N + (b - 1);
}

struct Matrix {
    double a[MaxSize][MaxSize];
    void init() {
        for (int i = 0; i < tot; ++i)
            for (int j = 0; j <= tot; ++j)
                a[i][j] = 0;
        for (int i = 0; i < tot; ++i)
            a[i][i] = 1;
        a[lab(SA, SB)][tot] = 1;
        for (int i = 1; i <= N; ++i)
            for (int j = 1; j <= N; ++j)
                    for (int ii = 1; ii <= N; ++ii)
                        for (int jj = 1; jj <= N; ++jj) if (ii != jj && g[i][ii] && g[j][jj]) {
                            double pi = (i == ii) * P[ii] + (i != ii) * (1 - P[ii]) / deg[ii];
                            double pj = (j == jj) * P[jj] + (j != jj) * (1 - P[jj]) / deg[jj];
                            int t1 = lab(i, j), t2 = lab(ii, jj);
                            a[t1][t2] -= pi * pj;
                        }
    }
    void elimiate() {
        int i, j, k, p;
        for (i = 0, j = 0; i < tot; ++i, ++j) {
            for (k = i; k < tot; ++k) if (fabs(a[k][j]) > eps) break;
            for (p = i; p <= tot; ++p) swap(a[i][p], a[k][p]);
            for (k = i + 1; k < tot; ++k) if (fabs(a[k][j]) > eps) {
                double t = a[k][j] / a[i][j];
                for (p = j; p <= tot; ++p)
                    a[k][p] = a[k][p] - a[i][p] * t;
            }
        }
    }
    void solve() {
        for (int i = tot - 1; i >= 0; --i) {
            ans[i] = a[i][tot];
            for (int j = i + 1; j < tot; ++j)
                ans[i] -= ans[j] * a[i][j];
            ans[i] /= a[i][i];
        }
    }
}mat;

int main() {

    scanf("%d%d%d%d", &N, &M, &SA, &SB);
    tot = N * N;
    int x, y;
    memset(g, 0, sizeof(g));
    memset(deg, 0, sizeof(deg));
    for (int i = 1; i <= N; ++i) g[i][i] = true;
    for (int i = 0; i < M; ++i) {
        scanf("%d%d", &x, &y);
        g[x][y] = g[y][x] = true;
        deg[x]++; deg[y]++;
    }
    for (int i = 1; i <= N; ++i) scanf("%lf", P + i);
    mat.init();
    mat.elimiate();
    mat.solve();
    for (int i = 1; i < N; ++i) printf("%.8f ", ans[lab(i, i)]);
    printf("%.8f\n", ans[lab(N, N)]);

    return 0;

}

One day as Petya and his friend Vasya were having one of their numerous trips, they decided to visit a museum castle. The museum has a specific shape: it consists of n rooms connected with m corridors so that one can access any room from any other one.After the two friends had a little walk around the museum, they decided to split and watch the pieces of art each of them found interesting. They agreed to meet in one of the rooms at six p.m. However, they forgot one quite essential thing: they didn't specify the place to meet and when the time came, they started to rush about the museum looking for each other (they couldn't call each other as roaming made a call's cost skyrocket).Yet, even despite the whole rush, they couldn't get enough of the pieces of art, that's why each of them has the following strategy: each minute he make a decision where to go — with probability pi he doesn't move to any other place during this minute (i.e. he stays in the room). With probability 1 - pi he equiprobably choose one of the adjacent rooms and went there along the corridor. Here i is the ordinal number of the current room. Building was expensive in ancient times, that's why each corridor connected two different rooms, and any two rooms had no more than one corridor between them. The boys act simultaneously. As the corridors are dark, it is impossible to meet there; however, one can walk along the corridors in both directions (besides, the two boys can be going through the same corridor simultaneously without meeting). The boys act like that until they meet each other. More formally, the two friends meet when at some moment of time both of them decided to appear in the same room.For each room find the probability that the boys will meet there considering that at 6 p.m. they are positioned in rooms a and b correspondingly.

The first line contains four integers: n (1 ≤ n ≤ 22), representing the numbers of rooms; m , representing the number of corridors; a, b (1 ≤ a, b ≤ n), representing the numbers of Petya's and Vasya's starting rooms correspondingly. Next m lines contain pairs of numbers — the numbers of rooms connected by a corridor. Next n lines contain probabilities pi (0.01 ≤ pi ≤ 0.99) with the accuracy of up to four digits after the decimal point — the probability to stay in room i. It is guaranteed that every room can be reached from every other room by corridors.

In the only line print n space-separated numbers, the i-th number should represent the probability that the friends meet in the i-th room with absolute or relative error of no more than 10 - 6.

NoteIn the first sample the museum is symmetric. That means the probabilities to meet in rooms 1 and 2 are equal. And their sum equals to one. So, each probability equals 0.5.

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)      REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(C)   (C).begin(),(C).end()
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}
typedef complex<double>P;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 22;
const int M = N*N+10;
const double eps = 1e-10;
vector<int> edge[N];
bool e[N][N];
double ori[M][M];

//n matrix size  a00+x0+...=c0
//k current step
//mat Matrix
bool select_pivot(int n,int k,double mat[M][M]){
 int s=k;//selected pivot
 double val=fabs(mat[k][k]);
 REP(i,k+1,n)if (fabs(mat[i][k]) >val)val=fabs(mat[i][k]),s=i;
 if (val<eps)return false;//cannot solve this linear equations.
 REP(i,k,n+1)swap(mat[k][i],mat[s][i]);
 return true;//no problem for this pivot;
}

//n matrix size  x0,x1,...xn-1 =constant
//row n,column n+1
bool gauss(int n,double mat[M][M]){
 //step1
 rep(k,n){
   if (select_pivot(n,k,mat)==false)return false;
   REP(i,k+1,n+1)mat[k][i]/=mat[k][k];//devided by m[k][k];
   mat[k][k]=1;//for looking the equation
   REP(i,k+1,n){//
     REP(j,k+1,n+1)mat[i][j]+=-mat[i][k]*mat[k][j];
     mat[i][k]=0;//For looking the equation
   }
 }
 //step2
 for(int i=n-1;i>=0;i--){//solve ith row
   REP(j,i+1,n){
     mat[i][n]-=mat[i][j]*mat[j][n];
   }
 }
 return true;
}

main(){
  int n,m,a,b;
  double mat[M][M];
  while(cin>>n>>m>>a>>b){
    a--;b--;
    rep(i,n){
      rep(j,n)e[i][j]=false;
      e[i][i]=true;
      edge[i].clear();
    }
    rep(i,m){
      int f,t;cin>>f>>t;f--;t--;edge[f].pb(t);edge[t].pb(f);
      e[f][t]=e[t][f]=true;
    }
    double st[n],move[n];
    rep(i,n)cin>>st[i],move[i]=(1-st[i])/edge[i].size();
    int size=n*n;
    rep(i,size)rep(j,size)mat[i][j]=0;

    rep(i,n){//first player is on i,
      rep(j,n){//first player is on j
	//(i,j) -> (k,l)
	int pos1 = i*n+j;
	//if (i == j){continue;}
	mat[pos1][pos1]-=1;
	rep(k,n){
	  if (!e[i][k])continue;
	  double p1 = i==k ?st[k]:move[k];
	  rep(l,n){
	    if (!e[j][l])continue;
	    if (k == l)continue;
	    int pos2=k*n+l;
	    double p2 = j==l ?st[l]:move[l];
	    mat[pos1][pos2]+=p1*p2;
	  }
	}
      }
    }
    mat[a*n+b][size]=-1;
    //if (n <= 3)rep(i,size)rep(j,size+1)printf("%.5lf%c",mat[i][j],j==size?'\n':' ');
    gauss(size,mat);
    //if (n <= 3)rep(i,size)rep(j,size+1)printf("%.5lf%c",mat[i][j],j==size?'\n':' ');

    for(int i=0;i<n;i++){
      if (i)printf(" ");
      printf("%.10lf",mat[i*n+i][size]);
    }
    printf("\n");

#ifdef DEBUG
    cout <<"end " <<  endl;
#endif
  }
  return false;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileIO()    freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define F           first
#define S           second
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define SZ(x)       ((ll)x.size())
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,E,x) cerr<< #i << " = " << i << " / "; ddbg(E,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
typedef priority_queue<pll,vector<pll>,greater<pll>> dEq;
const ll maxn=1e3+10, inf=2e9, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
///**************************************
ll fac[maxn],inv[maxn];
ll mdc(ll n){
    while(n<0){n+=mod;}
    return n%mod;
}
ll pwm(ll a,ll b){
	if(b==0){return 1;}
	if(b%2){return mdc(a*pwm(a,b-1));}
	return pwm(mdc(a*a),b/2);
}
ll C(ll n,ll r){
    if(r>n){return 0;}
	return mdc(mdc(fac[n]*inv[r])*inv[n-r]);
}
///**************************************
ll n,m;
bool is[maxn];
ll revc[maxn];
ld dp[maxn][maxn],pd[maxn][maxn];
int main(){
    sync();
    ///**************************************
	fac[0]=inv[0]=1;
	for(int i=1;i<maxn;i++) fac[i]=mdc(i*fac[i-1]);
	for(int i=1;i<maxn;i++) inv[i]=mdc(inv[i-1]*pwm(i,mod-2));
    ///**************************************
    cin>>n>>m;
    vector<ll> g[maxn];
    ll kl[maxn],po=0;
    ll k,jens=0;
    for(int i=1;i<=m;i++){
        cin>>k; jens+=k;
        for(int j=0;j<k;j++){ cin>>kl[po++]; g[i].pb(kl[po-1]); }
    }
    sort(kl,kl+jens,greater<ll>());
    ll h=kl[n-1]; //dbg(h);

    ld fp=1; ll som=0,mos=0;
    for(int i=1;i<=m;i++){
        for(ll x:g[i]) is[i]|=(x==h), revc[i]+=(x>h);
        mos+=is[i];
        fp/=C(SZ(g[i]),revc[i]);
        som+=revc[i];
    }
    for(int i=0;i<=m;i++) dp[i][0]=pd[i][0]=fp;
    for(int i=1;i<=m;i++)for(int j=1;j<=n;j++){
        dp[i][j]=dp[i-1][j];
        if(is[i]) dp[i][j]+=dp[i-1][j-1]*(revc[i]+1)/(SZ(g[i])-revc[i]);
        tdbg(i,j,dp);
    }
    cout<<fixed<<setprecision(18)<<(dp[m][n-som]/C(mos,n-som);
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/

Once upon a time an old man and his wife lived by the great blue sea. One day the old man went fishing and caught a real live gold fish. The fish said: "Oh ye, old fisherman! Pray set me free to the ocean and I will grant you with n gifts, any gifts you wish!". Then the fish gave the old man a list of gifts and their prices. Some gifts on the list can have the same names but distinct prices. However, there can't be two gifts with the same names and the same prices. Also, there can be gifts with distinct names and the same prices. The old man can ask for n names of items from the list. If the fish's list has p occurrences of the given name, then the old man can't ask for this name of item more than p times.The old man knows that if he asks for s gifts of the same name, the fish will randomly (i.e. uniformly amongst all possible choices) choose s gifts of distinct prices with such name from the list. The old man wants to please his greedy wife, so he will choose the n names in such a way that he can get n gifts with the maximum price. Besides, he isn't the brightest of fishermen, so if there are several such ways, he chooses one of them uniformly.The old man wondered, what is the probability that he can get n most expensive gifts. As the old man isn't good at probability theory, he asks you to help him.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) — the number of the old man's wishes and the number of distinct names in the goldfish's list, correspondingly. Then m lines follow: the i-th line first contains integer ki (ki > 0) — the number of distinct prices of gifts with the i-th name, then ki distinct space-separated integers cij (1 ≤ cij ≤ 109), the gifts' prices.  It is guaranteed that the sum of all ki doesn't exceed 1000. It is guaranteed that n is not greater than the total number of the gifts.

On a single line print one real number — the probability of getting n most valuable gifts. The answer will be considered correct if its absolute or relative error does not exceed 10 - 9.


#include<bits/stdc++.h>

using namespace std;
using lint = long long int;

const int MAX_N = 2e5;
const int MAX_M =  3001;
const lint MOD = 998244353;

lint dp1[MAX_M][MAX_M];
lint dp2[MAX_M][MAX_M];
int state[MAX_N];
lint wi[MAX_N];
lint SA, SB;

lint pow(lint x, lint N) {
	lint ret = 1;

	while (N) {
		if (N & 1)
			(ret *= x) %= MOD;
		(x *= x) %= MOD;
		N >>= 1;
	}
	return ret;
}

lint inv(lint x) {
	return pow(x, MOD-2);
}

lint solve1(int i, int j, int M) {
	if (dp1[i][j] != -1)
		return dp1[i][j];

	lint &ret = dp1[i][j];
	ret = 0;

	if (i+j == M)
		return ret = 1;

	lint ri = SA + i, rj = SB - j;
	(ret += solve1(i+1, j, M) * (ri + 1) % MOD * inv(ri+rj) % MOD) %= MOD;
	if (SB-j-1 >= 0)
		(ret += solve1(i, j+1, M) * rj % MOD * inv(ri+rj) % MOD) %= MOD;

	return ret;
}

lint solve2(int i, int j, int M) {
	if (dp2[i][j] != -1)
		return dp2[i][j];

	lint &ret = dp2[i][j];
	ret = 0;

	if (i+j == M)
		return ret = 1;

	lint ri = SA + i, rj = SB - j;

	if (rj-1 >= 0)
		(ret += solve2(i, j+1, M) * (rj - 1) % MOD * inv(ri+rj) % MOD) %= MOD;
	(ret += solve2(i+1, j, M) * ri % MOD * inv(ri+rj) % MOD) %= MOD;

	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	memset(dp1, -1, sizeof dp1);
	memset(dp2, -1, sizeof dp2);

	int N, M;	cin >> N >> M;

	for (int i = 0; i < N; i ++)
		cin >> state[i];

	for (int i = 0; i < N; i ++) {
		cin >> wi[i];

		(state[i]?SA:SB) += wi[i];
	}

	for (int i = 0; i < N; i ++)
		cout << (wi[i]*(state[i]?solve1(0, 0, M):solve2(0, 0, M)))%MOD << '\n';
}

The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The $$$i$$$-th picture has a non-negative weight $$$w_i$$$, and the probability of the $$$i$$$-th picture being displayed is $$$\frac{w_i}{\sum_{j=1}^nw_j}$$$. That is to say, the probability of a picture to be displayed is proportional to its weight.However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add $$$1$$$ to its weight; otherwise, she would subtract $$$1$$$ from its weight.Nauuo will visit the website $$$m$$$ times. She wants to know the expected weight of each picture after all the $$$m$$$ visits modulo $$$998244353$$$. Can you help her?The expected weight of the $$$i$$$-th picture can be denoted by $$$\frac {q_i} {p_i}$$$ where $$$\gcd(p_i,q_i)=1$$$, you need to print an integer $$$r_i$$$ satisfying $$$0\le r_i<998244353$$$ and $$$r_i\cdot p_i\equiv q_i\pmod{998244353}$$$. It can be proved that such $$$r_i$$$ exists and is unique.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 2\cdot 10^5$$$, $$$1\le m\le 3000$$$) — the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) — if $$$a_i=0$$$ , Nauuo does not like the $$$i$$$-th picture; otherwise Nauuo likes the $$$i$$$-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains $$$n$$$ positive integers $$$w_1,w_2,\ldots,w_n$$$ ($$$w_i \geq 1$$$) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed $$$998244352-m$$$.

The output contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ — the expected weights modulo $$$998244353$$$.

NoteIn the first example, if the only visit shows the first picture with a probability of $$$\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$$$ .Because $$$332748119\cdot 3\equiv 4\pmod{998244353}$$$, you need to print $$$332748119$$$ instead of $$$\frac4 3$$$ or $$$1.3333333333$$$.In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $$$w_1$$$ will be increased by $$$1$$$.So, the expected weight is $$$1+2=3$$$.Nauuo is very naughty so she didn't give you any hint of the third example.

#include <bits/stdc++.h>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define CLEAR(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define REP(i, l, r) for (int i = (l); i <= (r); ++i)
using namespace std;

typedef long long li;
typedef unsigned long long lu;
typedef pair<int, int> pii;

const int mod = 998244353;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (lu)x * y % mod; }
inline int Mul(int x, int y, int z) { return Mul(Mul(x, y), z); }

inline void Max(int &x, int y) { if (y > x) x = y; }
inline void Min(int &x, int y) { if (y < x) x = y; }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

// ----------------------------------------

const int maxn = 2e5, maxm = 3000;

int n, m;
int type[maxn], wei[maxn];
// int n1, w1[maxn], s1;
// int n0, w0[maxn], s0;
int s0, s1;
int pro[maxm + 2][maxm + 2];

int _inv[4 * maxm + 1], *inv = _inv + 2 * maxm;

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", type + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", wei + i);
  }
  for (int i = 0; i < n; ++i) {
    if (type[i] == 0) {
      // w0[n0++] = wei[i];
      Add(s0, wei[i]);
    } else {
      // w1[n1++] = wei[i];
      Add(s1, wei[i]);
    }
  }

  for (int i = -2 * m; i <= 2 * m; ++i) {
    int x = Sub(Add(Add(s0 + s1) + i));
    inv[i] = Pow(x, mod - 2);
  }

  int ans0 = 0, ans1 = 0;

  pro[0][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; i + j < m; ++j) {
      int p = pro[i][j];
      // printf("pro[%d][%d] = %d\n", i, j, p);
      if (p == 0) continue;
      int ss0 = s0 - i;
      int ss1 = s1 + j;
      int pp0 = Mul(ss0, inv[j - i]);
      int pp1 = Mul(ss1, inv[j - i]);
      int p0 = Mul(p, pp0);
      int p1 = Mul(p, pp1);
      Add(pro[i + 1][j], p0);
      Add(pro[i][j + 1], p1);
      Add(ans0, p0);
      Add(ans1, p1);
    }
  }

  ans0 = Mul(ans0, Pow(s0, mod - 2));
  ans1 = Mul(ans1, Pow(s1, mod - 2));
  for (int i = 0; i < n; ++i) {
    int w = wei[i];
    if (type[i] == 0) {
      Sub(w, Mul(ans0, w));
    } else {
      Add(w, Mul(ans1, w));
    }
    printf("%d\n", w);
  }
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <ctime>

using namespace std;

typedef long long i64;

int main()
{
	int n,tr,lie;
	cin >> n >> tr;
	lie=n-tr;
	int kolp=0,kolz=0;
	char tmp,zn;
	int pip;
	vector< vector<int> > zash(n);
	vector< vector<int> > podozr(n);
	for (int i=0;i<n;i++)
	{
		scanf("%c%c%d",&tmp,&zn,&pip);
		pip--;
		if (zn=='-')
		{
			kolz++;
			zash[pip].push_back(i);
		}
		else
		{
			kolp++;
			podozr[pip].push_back(i);
		}
	}
	vector<int> saystrue(n,0);
	vector<int> isbad(n,0);
	int bad=-1;
	bool waschange=true;
	while (waschange)
	{
		waschange=false;
		if (kolz>tr)
		{
			for (int i=0;i<n;i++)
				if (zash[i].empty())
				{
					isbad[i]=-1;
					for (int j=0;j<podozr[i].size();j++)
					{
						saystrue[podozr[i][j]]=-1;
						waschange=true;
					}
					kolp-=podozr[i].size();
					podozr[i].clear();
				}
		}
		for (int i=0;i<n;i++)
		{
			if (zash[i].size()>tr || podozr[i].size()>lie)
			{
				bad=i;
				isbad[i]=1;
				/*for (int j=0;j<zash[i].size();j++)
					saystrue[zash[i][j]]=-1;
				for (int j=0;j<podozr[i].size();j++)
					saystrue[podozr[i][j]]=1;
				tr-=podozr[i].size();
				lie-=zash[i].size();
				waschange=true;
				*/
				break;
			}
			else
				if (podozr[i].size()>tr || zash[i].size()>lie)
				{
					isbad[i]=-1;
					for (int j=0;j<zash[i].size();j++)
					{
						saystrue[zash[i][j]]=1;
						waschange=true;
					}
					for (int j=0;j<podozr[i].size();j++)
					{
						saystrue[podozr[i][j]]=-1;
						waschange=true;
					}
					tr-=zash[i].size();
					kolz-=zash[i].size();
					lie-=podozr[i].size();
					kolp-=podozr[i].size();
					zash[i].clear();
					podozr[i].clear();
				}
		}
		if (bad!=-1)
		{
			for (int i=0;i<n;i++)
				if (isbad[i]==1)
				{
					for (int j=0;j<zash[i].size();j++)
						saystrue[zash[i][j]]=-1;
					for (int j=0;j<podozr[i].size();j++)
						saystrue[podozr[i][j]]=1;
				}
				else
				{
					for (int j=0;j<zash[i].size();j++)
						saystrue[zash[i][j]]=1;
					for (int j=0;j<podozr[i].size();j++)
						saystrue[podozr[i][j]]=-1;
				}
			break;
		}
	}
	for (int i=0;i<n;i++)
		if (saystrue[i]==1) printf("Truth\n");
		else
			if (saystrue[i]==-1) printf("Lie\n");
			else
				printf("Not defined\n");
	return 0;
}

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai = i).Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number ai didn't commit the crime (ai is an integer, 1 ≤ ai ≤ n). It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

NoteThe first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cctype>
#include <bitset>
#include <sstream>
#include <set>
#include <map>

using namespace std;
template <class T> T sqr(T a) { return a * a; }

int a[101000];
int murs[101000];
int b[101000][2];

int n, m;

int main()
{
#ifdef IMPETUS
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] > 0)
            b[a[i] - 1][0]++;
        else
            b[-a[i] - 1][1]++;
    }
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += b[i][1];
    int sols = 0;
    for (int i = 0; i < n; i++)
        if (sum - b[i][1] + b[i][0] == m)
        {
            sols++;
            murs[i] = 1;
        }
    string y = sols > 1 || sum == m ? "Not defined" : "Truth";
    string z = sols > 1 || sum == m ? "Not defined" : "Lie";
    for (int i = 0; i < n; i++)
        if (a[i] > 0)
        {
            if (murs[a[i] - 1])
                cout << y << endl;
            else
                cout << "Lie" << endl;
        }
        else
        {
            if (murs[-a[i] - 1])
                cout << z << endl;
            else
                cout << "Truth" << endl;
        }
    return 0;
}

[{'input': '1 1\r\n+1\r\n', 'output': ['Truth\r\n']}, {'input': '3 2\r\n-1\r\n-2\r\n-3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 1\r\n+2\r\n-3\r\n+4\r\n-1\r\n', 'output': ['Lie\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '1 0\r\n-1\r\n', 'output': ['Lie\r\n']}, {'input': '2 2\r\n+1\r\n+1\r\n', 'output': ['Truth\r\nTruth\r\n']}, {'input': '2 1\r\n+2\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\n']}, {'input': '2 0\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\n']}, {'input': '3 1\r\n+2\r\n+3\r\n+3\r\n', 'output': ['Truth\r\nLie\r\nLie\r\n']}, {'input': '6 3\r\n+5\r\n+5\r\n+5\r\n+1\r\n+1\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 3\r\n-4\r\n-3\r\n-1\r\n-3\r\n', 'output': ['Not defined\r\nTruth\r\nNot defined\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n+1\r\n-6\r\n-10\r\n+5\r\n-6\r\n-8\r\n-8\r\n-4\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-4\r\n+4\r\n+4\r\n-9\r\n-9\r\n-4\r\n-4\r\n+2\r\n-9\r\n-4\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '7 2\r\n+5\r\n+5\r\n+5\r\n-2\r\n+1\r\n-5\r\n-6\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nTruth\r\nNot defined\r\n']}, {'input': '7 4\r\n+7\r\n-3\r\n-3\r\n-4\r\n+3\r\n+3\r\n+3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '6 3\r\n-6\r\n-1\r\n+5\r\n+1\r\n+6\r\n+1\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '5 3\r\n-2\r\n+2\r\n+2\r\n-3\r\n+5\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\n']}, {'input': '3 0\r\n-2\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\n']}, {'input': '5 3\r\n-1\r\n-1\r\n-4\r\n+1\r\n-4\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '9 6\r\n+2\r\n+7\r\n+7\r\n-1\r\n-4\r\n+7\r\n-7\r\n+7\r\n+5\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '43 18\r\n-14\r\n-28\r\n+16\r\n+10\r\n+25\r\n-30\r\n+25\r\n+30\r\n+25\r\n+25\r\n+25\r\n+25\r\n-25\r\n+22\r\n+3\r\n-17\r\n+16\r\n-25\r\n+10\r\n+14\r\n+41\r\n+25\r\n-25\r\n+33\r\n+24\r\n-23\r\n-25\r\n+25\r\n-22\r\n+29\r\n+28\r\n-25\r\n-25\r\n-29\r\n+11\r\n+26\r\n-25\r\n+25\r\n+10\r\n+1\r\n-20\r\n-17\r\n+23\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '28 12\r\n+10\r\n-7\r\n+17\r\n-20\r\n+7\r\n-7\r\n+13\r\n-21\r\n-7\r\n-7\r\n-18\r\n+7\r\n+7\r\n+3\r\n+6\r\n+14\r\n+7\r\n-24\r\n-21\r\n-7\r\n-7\r\n+4\r\n+7\r\n-7\r\n+21\r\n-7\r\n-26\r\n+7\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '17 9\r\n-6\r\n+16\r\n+5\r\n+16\r\n-17\r\n+17\r\n-11\r\n+5\r\n+14\r\n+5\r\n-8\r\n-5\r\n+6\r\n-2\r\n-11\r\n+4\r\n+17\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '14 3\r\n+14\r\n+12\r\n-9\r\n+9\r\n-9\r\n-9\r\n+8\r\n+9\r\n+2\r\n+1\r\n-13\r\n-9\r\n+13\r\n+3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 4\r\n-9\r\n-8\r\n-5\r\n-9\r\n-7\r\n-9\r\n-9\r\n-9\r\n-4\r\n-9\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-10\r\n-10\r\n-10\r\n-5\r\n-1\r\n+10\r\n-3\r\n-10\r\n-9\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n-3\r\n-3\r\n-3\r\n-3\r\n-3\r\n-2\r\n-2\r\n-6\r\n-7\r\n-3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 6\r\n-9\r\n-7\r\n-5\r\n-5\r\n-4\r\n-2\r\n-8\r\n-5\r\n-5\r\n-9\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n-2\r\n-8\r\n+1\r\n-4\r\n-8\r\n-2\r\n-8\r\n-8\r\n-1\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 2\r\n-8\r\n+10\r\n+1\r\n+8\r\n+4\r\n+8\r\n+6\r\n-8\r\n+10\r\n+1\r\n', 'output': ['Not defined\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nLie\r\n']}, {'input': '10 3\r\n+9\r\n+3\r\n+8\r\n+3\r\n+6\r\n-3\r\n+6\r\n+8\r\n+3\r\n+7\r\n', 'output': ['Lie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\n']}, {'input': '10 8\r\n-2\r\n+9\r\n+9\r\n-4\r\n+9\r\n+9\r\n+4\r\n-9\r\n-3\r\n+9\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 7\r\n-4\r\n+6\r\n+4\r\n+9\r\n+6\r\n+6\r\n+6\r\n+6\r\n+6\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n+3\r\n+5\r\n+6\r\n+10\r\n+5\r\n+5\r\n+6\r\n+8\r\n+5\r\n+6\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 7\r\n-6\r\n-10\r\n-3\r\n-1\r\n-3\r\n-7\r\n-2\r\n-7\r\n-7\r\n-3\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '10 5\r\n-4\r\n-4\r\n-1\r\n-5\r\n-7\r\n-4\r\n-4\r\n-4\r\n-1\r\n-7\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 5\r\n-9\r\n-7\r\n-6\r\n-3\r\n-10\r\n-10\r\n-10\r\n-10\r\n-10\r\n-2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 3\r\n-10\r\n-10\r\n-10\r\n-3\r\n-10\r\n-10\r\n-10\r\n-8\r\n-4\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-8\r\n-8\r\n-4\r\n-9\r\n-10\r\n-2\r\n-9\r\n-8\r\n-8\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 5\r\n+7\r\n+8\r\n+9\r\n+1\r\n+7\r\n+7\r\n+7\r\n+6\r\n+6\r\n+7\r\n', 'output': ['Truth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 5\r\n+2\r\n+2\r\n+2\r\n+2\r\n+9\r\n+10\r\n+8\r\n+7\r\n+4\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 9\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+5\r\n+7\r\n+7\r\n+7\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '10 3\r\n+10\r\n+2\r\n+10\r\n+9\r\n+1\r\n+9\r\n+4\r\n+9\r\n+3\r\n+2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '10 6\r\n+10\r\n+10\r\n+10\r\n+3\r\n+10\r\n+10\r\n+6\r\n+6\r\n+10\r\n+8\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '3 2\r\n-1\r\n+2\r\n+3\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\n']}]


Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below://input: integers x, k, pa = x;for(step = 1; step <= k; step = step + 1){    rnd = [random integer from 1 to 100];    if(rnd <= p)        a = a * 2;    else        a = a + 1;}s = 0;while(remainder after dividing a by 2 equals 0){    a = a / 2;    s = s + 1;}Now Valera wonders: given the values x, k and p, what is the expected value of the resulting number s?

The first line of the input contains three integers x, k, p (1 ≤ x ≤ 109; 1 ≤ k ≤ 200; 0 ≤ p ≤ 100).

Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

NoteIf the concept of expected value is new to you, you can read about it by the link: http://en.wikipedia.org/wiki/Expected_value

#include <bits/stdc++.h>
#include <algorithm>
#define int long long
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,x,n) for(int i=x;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define itr_ iterator
#define p_b push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define m_p make_pair
#define debug(x) cout<<#x<<":"<<x<<endl;
#define lowbit(x) (x&(-x))
#define setp setprecision
#define over(x) {cout<<x<<endl; return ;}
using namespace std;
const int INF=0x3f3f3f3f;
const ll INFL=1e18;
const ll mod=1000000007;
const ld eps=1e-14;

const int N=305;
int x,k;
ld p,f[N][N];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin>>x>>k>>p;
	p/=100;
	for(int i=0;i<=k;i++){
		for(int j=x+i;!(j&1);j>>=1)
			f[0][i]++;
	}
	for(int i=0;i<k;i++){
		for(int j=0;j<=k;j++){
			if(j) f[i+1][j-1]+=(1-p)*f[i][j];
			if(j*2<=k) f[i+1][j*2]+=p*(f[i][j]+1);
		}
	}
	cout<<fixed<<setp(13)<<f[k][0]<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <queue>
#include <ctime>
#include <iomanip>

#define umap unordered_map
#define uset unordered_set

#define forn(i,n) for(int i=0;i<(int)n;i++)
#define rforn(i,n) for(int i=(int)n;i>=0;i--)
#define forin(i,x,y) for(ll i=x;i<=(ll)y;i++)
#define fora(itr,ctr) for(auto itr=ctr.begin();itr!=ctr.end();itr++)

using namespace std;
clock_t BT=clock();
stringstream ss;

#define ll long long
const ll MAX=1e5+1;

bool solve (ll u1,ll u2,ll u3,ll v1,ll v2,ll v3) {
	u2-=u1,v2-=v1;
	ll md=u3*u3+v3*v3;
	ll u4=u3,v4=-v3;

	ll x=u2*u4-v2*v4,y=u2*v4+v2*u4;
//	cout<<u2<<" "<<v2<<"     "<<u4<<" "<<v4<<"    "<<x<<" "<<y<<endl;
	if(md==0) {if(x==0 && y==0) return true;}
	else {
		if(x%md==0 && y%md==0) return true;
	}
	return false;
}

int main()
{
//	freopen("F:\\code\\competitive\\codelite\\cc\\cc++\\input.txt","r",stdin);
//	freopen("F:\\code\\competitive\\codelite\\cc\\cc++\\output.txt","w",stdout);

	ios_base::sync_with_stdio(false);
	ss<<setprecision(17);
	ll u1,u2,u3,v1,v2,v3;
	cin>>u1>>v1>>u2>>v2>>u3>>v3;
	bool b=solve(u1,u2,u3,v1,v2,v3);
//	cout<<b<<endl;
	forn(i,3) {
		swap(u1,v1),u1=-u1;
		b|=solve(u1,u2,u3,v1,v2,v3);
//		cout<<b<<endl;
	}
	if(b) ss<<"YES"<<endl;
	else ss<<"NO"<<endl;
	cout<<ss.str()<<endl;
	clock_t CT=clock()-BT;
//	cout<<((double)CT/CLOCKS_PER_SEC)<<endl;
	return 0;
}

At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А: Turn the vector by 90 degrees clockwise. Add to the vector a certain vector C.Operations could be performed in any order any number of times.Can Gerald cope with the task?

The first line contains integers x1 и y1 — the coordinates of the vector A ( - 108 ≤ x1, y1 ≤ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).

Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).

#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define eb emplace_back

#define f first

#define s second

#define deb(a) cerr << #a << " = " << a << "\n";

#define all(x) (x).begin(), (x).end()

#define file() { ifstream cin("input.txt"); ofstream cout("output.txt"); }

#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))

#define y1 y1212312

#define int long long

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

const ll INF = 2e18;

const ll mod = 1e9 + 7;

const int inf = 1e9;

const ld EPS = 1e-12;

const ld Pi = acosl(-1);

const int P = 31;

const int dx[2] = {0, 1};

const int dy[2] = {1, 0};

int qqq = 1;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int x1, y1, x2, y2, x3, y3;

void solve() {

    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    int leng = x3 * x3 + y3 * y3;

    for (int i = 0; i < 4; i++) {

        int x = x2 - x1;

        int y = y2 - y1;

        int dp = x * x3 + y * y3;

        int cp = x * y3 - y * x3;

        if (x == 0 && y == 0) {

            cout << "YES\n";

            return;

        }

        if (leng && dp % leng == 0 && cp % leng == 0) {

            cout << "YES\n";

            return;

        }

        x1 = -x1;

        swap(x1, y1);

    }

    cout << "NO\n";

}

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    clock_t tStart = clock();

    //cin >> qqq;

    while (qqq--) {

        solve();

    }

    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';

    return 0;

}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll n;
int k;
const int maxN = 105;
int a[maxN];
const int maxP = 6324554 + 100;
ll who[maxP];
int cnt[maxP];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        cin >> a[i];
        if (a[i] == 1) {
            cout << 0;
            return 0;
        }
    }
    sort(a + 1, a + k + 1);
    reverse(a + 1, a + k + 1);
    ll l = 1;
    int sz = 0;
    while (l <= n) {
        who[++sz] = n / l;
        l = (n / (n / l)) + 1;
    }
    reverse(who + 1, who + sz + 1);
    assert(sz < maxP);
    cnt[sz] = 1;
    // -=
    for (int i = 1; i <= k; i++) {
        int ptr = 1;
        for (int j = 1; j <= sz; j++) {
            if (cnt[j] == 0) continue;
            if (who[j] < a[i]) continue;
            while (who[ptr + 1] * a[i] <= who[j]) ptr++;
            cnt[ptr] -= cnt[j];
        }
    }
    ll ans = 0;
    for (int i = 1; i <= sz; i++) {
        ans += who[i] * cnt[i];
    }
    cout << ans;
    return 0;
}

Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good weapon and outfit as possible. One day, as he was reading the game's forum yet again, he discovered a very interesting fact. As it turns out, each weapon in the game is characterised with k different numbers: a1, ..., ak. They are called hit indicators and according to the game developers' plan they are pairwise coprime. The damage that is inflicted during a hit depends not only on the weapon's characteristics, but also on the hero's strength parameter. Thus, if the hero's strength equals n, than the inflicted damage will be calculated as the number of numbers on the segment , that aren't divisible by any hit indicator ai.Recently, having fulfilled another quest, Igor K. found a new Lostborn sword. He wants to know how much damage he will inflict upon his enemies if he uses it.

The first line contains two integers: n and k (1 ≤ n ≤ 1013, 1 ≤ k ≤ 100). They are the indicator of Igor K's hero's strength and the number of hit indicators. The next line contains space-separated k integers ai (1 ≤ ai ≤ 1000). They are Lostborn sword's hit indicators. The given k numbers are pairwise coprime.

Print the single number — the damage that will be inflicted by Igor K.'s hero when he uses his new weapon.  Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>

#define LL long long
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define size(S) S.size()
#define PII pair<int, int>
#define PID pair<int, double>

using namespace std;

const int MAX = 300000;
LL n, ans;
int k, a[110];
LL f[100][MAX];

LL dfs(int x, LL n){
	if (x == k) return n;
	if (n < MAX && f[x][n] >= 0) return f[x][n];
	LL ret = dfs(x + 1, n) - dfs(x + 1, n / a[x]);
	if (n < MAX) f[x][n] = ret;
	return ret;
}

int main(){
	cin >> n >> k;
	for (int i = 0; i < k; i++) cin >> a[i];
	memset(f, 255, sizeof(f));
	sort(a, a + k, greater<int>());
	ans = dfs(0, n);
	cout << ans << endl;
}


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

int main(){
    int l, r, x, y; cin >> l >> r >> x >> y;
    int n = x * y;
    int ans = 0;
    set <int> del;
    for (int i = 1; i < (int) sqrt(n) + 1; i++) {
        if (n % i == 0 and i * i != n) del.insert(i); del.insert(n / i);
        if (n % i == 0 and i * i == n) del.insert(i);
    }for (auto d : del) {
        if ( __gcd(d, n / d) == x and d * (n / d) / x == n and d >= l and d <= r and n / d >= l and n / d <= r) {
            ans++;
        }
    }cout << ans;
}

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisor of a and b, and LCM(a, b) denotes the least common multiple of a and b.You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b) and (b, a) are considered different if a ≠ b.

The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).

In the only line print the only integer — the answer for the problem.

NoteIn the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.

/*
 ID: osama2
 LANG: C++
 PROG: beads
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define imfaast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<typename T>using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);
int dx[]= {0,0,-1,1,1,-1,1,-1};
int dy[]= {1,-1,0,0,1,-1,-1,1};
#define f first
#define s second
int oo=1e3;
const int mod=1e9+7;
const int N=1;
const int N2=105;
#define endl '\n'
#define mem memset(dp,-1,sizeof(dp));
int gcd(int a,int b)
{
    // O(log(a*b)) GCD calculater
    if(b>a)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}
void doswaps(int& a,int&b,int q)
{
    int n=a-q*b;
    a=b;
    b=n;
}
int egcd(int a,int b,int& x0,int& y0)
{
    int x1,y1;
    x1=y0=0;
    x0=y1=1;
    int r0=a,r1=b;
    while(r1!=0)
    {
        int q=r0/r1;
        doswaps(x0,x1,q);
        doswaps(y0,y1,q);
        doswaps(r0,r1,q);
    }
    return r0;
}

ll fpow(int b,int p)// fast power
{
    if(p==1)return b;
    ll ret= fpow(b,p/2);
    ret*=ret;
    ret%=mod;
    if(p%2)ret= ret * b % mod;
    return ret%mod;
}
ll fact[N];
void pre(int n)
{
    fact[0]=1;
    for(int i=1; i<n; i++)
    {
        fact[i]= ( fact[i-1] * i);
    }
}
ll ncr(int n,int r)
{
    // n! / (n-r)! * r!
    if(r>n)return 0;
    ll ret= fact[n];
    ll d= fact[n-r];
    d*=fact[r];
    d%=mod;
    return (ret*fpow(d,mod-2))%mod;
}

signed main()
{
    imfaast
//      freopen("input.txt","r",stdin);
//      freopen("billboard.out","w",stdout);
    int l,r,x,y;cin>>l>>r>>x>>y;
    if(y%x)
    {
        cout << 0<<endl;return 0;
    }
    int ans=0;
    int z=y/x;
    for(int i=1;i*i<=z;i++)
    {
        if(z%i==0)
        {
            int j= z/i;
            if(i*x>=l&&i*x<=r&&j*x>=l&&j*x<=r&&gcd(i,j)==1)
            {
                ans++;
                if(i!=j)ans++;
            }
        }
    }
    cout << ans;

}


#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>

#define fii(x,y) for(int i=x;i<y;i++)
#define fjj(x,y) for(int j=x;j<y;j++)
#define fkk(x,y) for(int k=x;k<y;k++)
#define fi(x) fii(0,x)
#define fj(x) fjj(0,x)
#define fk(x) fkk(0,x)
#define eps 0.0000000001
#define inf 1<<28

using namespace std;

typedef long long ll;
typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <VVI> VVVI;
typedef vector <ll> VL;
typedef vector <VL> VVL;
typedef vector <double> VD;
typedef vector <VD> VVD;
typedef vector <bool> VB;
typedef vector <VB> VVB;
typedef queue <int> QI;
typedef pair<int,int> PI;
typedef pair<int,PI> PT;
typedef queue<PI> QPI;
typedef priority_queue<PT> QPT;
typedef pair<double,double> PD;

int main()
{
    int n;
    cin >> n;
    VL v (n);
    fi (n) cin >> v[i];
    sort(v.begin(),v.end());

    VL sum (n+1,0);
    fii (1,n+1) sum[i] = sum[i-1] + v[i-1];

    double ans = 0;
    int med = 0;
    int tam = 0;
    fi (n)
    {
        ll tmax = min(i, n-1-i);
        ll tmin = 0;
        while (tmax - tmin > 5)
        {
            ll v1 = (2 * tmin + tmax) / 3;
            ll v2 = (tmin + 2 * tmax) / 3;
            ll val1 = sum[i+1] - sum[i-v1] + sum[n] - sum[n-v1];
            ll val2 = sum[i+1] - sum[i-v2] + sum[n] - sum[n-v2];
            if (val1 > val2) tmax = v2;
            else tmin = v1;
        }
        fjj (tmin, tmax+1)
        {
            ll val = sum[i+1] - sum[i-j] + sum[n] - sum[n-j];
            double cand = double(val)/double(2*j+1) - v[i];
            if (cand > ans)
            {
                ans = cand;
                med = i;
                tam = j;
            }
        }
    }
    cout << 2 * tam + 1 << endl;
    bool prim = true;
    fi(tam)
    {
        if (prim)
            prim = false;
        else
            cout << " ";
        cout << v[med-tam+i];
    }

    if (prim)
        prim = false;
    else
        cout << " ";
    cout << v[med];
    fi(tam)
    {
        cout << " " << v[n-tam+i];
    }
    cout << endl;
}

Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.

NoteIn the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5 - 2 = 3.In the second case, the optimal subset is . Note that repetition is allowed.In the last case, any subset has the same median and mean, so all have simple skewness of 0.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 200010
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n,len;
int a[maxn];
LL sum[maxn];
int main()
{
	scanf("%d",&n);

	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	if(n==2)
	{
		printf("2\n");
		printf("%d %d",a[1],a[2]);
		return 0;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	int res,ans1=1,len=0;
	double ans=-INF;
	for(int i=1;i<=n;i++)
	{
		int l=1,r=min(i-1,n-i);
		res=0;
		while(l<=r)
		{
			int mid=(l+r)/2;
			double res1=1.0*(sum[i]-sum[i-mid-1]+sum[n]-sum[n-mid])/(2*mid+1);
			double res2=1.0*(sum[i]-sum[i-mid]+sum[n]-sum[n-mid+1])/(2*mid-1);
			if(res1>res2)
				{res=mid;l=mid+1;}
			else
				r=mid-1;

		}
		double tmp=1.0*(sum[i]-sum[i-res-1]+sum[n]-sum[n-res])/(2*res+1)-a[i];
		//printf("%.3lf %.3lf\n", tmp, ans);
		if(tmp>ans)
			{ans=tmp;ans1=i;len=res;}
	}
	printf("%d\n",2*len+1);
	for(int i=ans1-len;i<=ans1;i++)
	{
		printf("%d ",a[i]);
	}
	for(int i=n-len+1;i<=n;i++)
	{
		printf("%d",a[i]);
		if(i!=n)
		printf(" ");
	}
}