QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393481#6837. AC AutomatonmarherTL 7752ms192544kbC++177.4kb2024-04-18 17:08:362024-04-18 17:08:37

Judging History

你现在查看的是最新测评结果

  • [2024-04-18 17:08:37]
  • 评测
  • 测评结果:TL
  • 用时:7752ms
  • 内存:192544kb
  • [2024-04-18 17:08:36]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=7e5+50;

namespace IO {
#define iL (1 << 20)
char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
template<class T> inline void read(T &x) {
  x = 0;int f = 0;char ch = gc();
  for (; !isdigit(ch); f |= ch == '-', ch = gc());
  for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
  x = (f == 1 ? ~ x + 1 : x);
}
template<class T, class... Args> inline void read(T &x, Args&... args) { read(x), read(args...); }
template<class T> inline void readch(T &x) { char ch = gc(); for (; ch!='A'&&ch!='C'&&ch!='?'; ch = gc()); x = ch; }
char Out[iL], *iter = Out;
#define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
template<class T> inline void write(T x, char ch = '\n') {
  T l, c[35];
  if (x < 0) *iter ++ = '-', x = ~ x + 1;
  for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
  for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
  flush();
}
template<class T, class... Args> inline void write(T x, Args... args) { write(x, ' '), write(args...); }
} // IO
using namespace IO;

int n,q,f[N],g[N],B,fa[N],ff[N],top[N],siz[N],son[N],dep[N],p[N],t[N],dfn[N],now[N],in[N];
vector<int>to[N],vt,tson[N];
char s[N],c[N];

int LCA(int u,int v)
{
    while(top[u]!=top[v])
    {
        if(dep[top[u]]<dep[top[v]])swap(u,v);
        u=fa[top[u]];
    }
    return dep[u]<dep[v]?u:v;
}

int st[N];

void ADD(int x,int y)
{
    to[x].push_back(y);ff[y]=x;in[x]=in[y]=1;
}

void add(int&top)
{
	ADD(st[top-1],st[top]);
	top--;
}

void rebuild(int k)
{
	int top=0;st[++top]=1;in[1]=t[0]=1;
	for(int i=1;i<=k;i++)if(t[i]!=t[i-1])
	{
		int lca=LCA(t[i],st[top]);
		while(dep[lca]<=dep[st[top-1]])add(top);
		if(lca!=st[top])ADD(lca,st[top]),st[top]=lca;
		if(t[i]!=lca)st[++top]=t[i];
	}
	while(top>1)add(top);
}

int cmp(int a,int b)
{
    return dfn[a]<dfn[b];
}

struct node
{
    int x,num;ll sum;
};

int tim,tt,dd;

struct block
{
    vector<int>p;
    node *a;
    int num,n;ll sum;// F
    int pos,ad;//G

    void clear()
    {
        vector<int>().swap(p);free(a);
        num=n=sum=pos=ad=0;
    }

    void init()
    {
        sort(p.begin(),p.end());
        a=new node[p.size()+4];
        a[0]=(node){-1000000000,0,0};
        for(auto x:p)
        {
            if(x!=a[n].x)a[++n]=(node){x,1,x};
            else a[n].num++,a[n].sum+=x;
        }
        a[++n]=(node){1000000000,0,0};
        for(int i=n-1;i>=0;i--)a[i].sum+=a[i+1].sum,a[i].num+=a[i+1].num;
        for(int i=1;i<=n;i++)if(a[i].x>0)
        {
            pos=i;
            break;
        }
    }

    void fad(int x)
    {
        sum+=x*num;
    }

    void gad(int x)
    {
        ad-=x;
        if(x>0&&a[pos-1].x>ad)pos--;
        if(x<0&&a[pos].x<=ad)pos++;
    }

    ll sol()
    {
        return sum+a[pos].sum-ad*a[pos].num;
    }

    void insert(char c,int x)
    {
        if(c=='?'&&g[x]+dd>0)p.push_back(g[x]);
        if(c=='A')sum+=f[x],num++;
    }
}d1[N],d2[N];

void clear(int x)
{
    in[x]=ff[x]=0;
    d1[x].clear();
    d2[x].clear();
    for(auto v:to[x])clear(v);
    vector<int>().swap(to[x]);
}

int dfs(int x,int r)
{
    if(in[x])r=x;
    int w=0;
    for(auto v:tson[x])w+=dfs(v,r);
    if(!in[x]&&s[x]!='C')
    {
        if(w)d1[w].insert(s[x],x);
        else d2[r].insert(s[x],x);
    }
    return in[x]?x:w;
}

void GAD(int x,int w)
{
    d1[x].gad(w);d2[x].gad(w);g[x]+=w;
    for(auto v:to[x])GAD(v,w);
}

void mk(int x,char c,int w)
{
    int rx=x;
    if(c!='A')
    {
        d1[x].fad(w),d1[x].gad(w),x=ff[x];
        while(x)d1[x].fad(w),d1[x].gad(w),f[x]+=w,g[x]+=w,x=ff[x];
    }
    if(c!='C')
    {
        d2[x=rx].gad(-w);
        for(auto v:to[x])GAD(v,-w);
    }
}

void rmk(int x,char s,char c)
{
    if(s==c)return;
    int rx=x;
    if(s=='A'||c=='A')
    {
        int w=(s=='A')?1:-1;
        d1[x].fad(w),d1[x].gad(w),x=ff[x];
        while(x)d1[x].fad(w),d1[x].gad(w),f[x]+=w,g[x]+=w,x=ff[x];
    }
    if(s=='C'||c=='C')
    {
        int w=(s=='C')?1:-1;
        d2[x=rx].gad(-w);
        for(auto v:to[x])GAD(v,-w);
    }
}

void sol()
{
    ll ans=0;
    for(auto x:vt)ans+=(s[x]=='A')*f[x]+(s[x]=='?')*max(0,g[x])+d1[x].sol()+d2[x].sol();
    cout<<ans<<'\n';
}

void solve(int q)
{
    vector<int>().swap(vt);dd=q;
    for(int i=1;i<=n;i++)f[i]=g[i]=0;
    for(int i=n;i>=1;i--)f[fa[i]]+=f[i]+(s[i]!='A');
    for(int i=2;i<=n;i++)g[i]=g[fa[i]]-(s[fa[i]]!='C');
    for(int i=1;i<=n;i++)g[i]+=f[i];
    for(int i=1;i<=q;i++)read(p[i]),readch(c[i]),t[i]=p[i];
    sort(t+1,t+1+q,cmp);rebuild(q);dfs(1,1);
    for(int i=1;i<=n;i++)if(in[i])vt.push_back(i),d1[i].init(),d2[i].init();
    for(int i=1;i<=q;i++)rmk(p[i],s[p[i]],c[i]),s[p[i]]=c[i],sol();
    clear(1);
}

int cc;

void dfs2(int x,int topp)
{
    top[x]=topp;dfn[x]=++cc;
    if(!son[x])return;dfs2(son[x],topp);
    for(auto v:tson[x])if(v!=son[x])dfs2(v,v);
}

char ss[5]={'A','?','C'};

main()
{
    read(n,q);
    for(int i=1;i<=n;i++)readch(s[i]);
    B=1200;dep[1]=1;
    for(int i=2;i<=n;i++)read(fa[i]),dep[i]=dep[fa[i]]+1,tson[fa[i]].push_back(i);
    for(int i=n;i>=1;i--)siz[i]++,siz[fa[i]]+=siz[i];
    siz[0]=0;
    for(int i=2;i<=n;i++)if(siz[i]>siz[son[fa[i]]])son[fa[i]]=i;
    dfs2(1,1);
    while(q>0)solve(min(q,B)),q-=B;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 136388kb

input:

5 3
AC??C
1 2 2 1
1 ?
4 A
2 ?

output:

4
3
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 20ms
memory: 139000kb

input:

1000 1000
AC?ACCCCC?CCA??CCCCC?A?AC?C??C?ACCCACC?C?CCC?CACACA???????C?????CC?C?AAAAACCA??AAAACACACA???AACAC?CCC?CAC?AAAACCAC???ACAA??A??A?CA?A?ACACACCAA?ACACA?AC??AC??ACAAACCC??CAA?A???CC?AA??AC???A?CCCC??CACCAACC?AA?C?AAACCCA?AAA??C?CC??CACCACAACCA?AACCC?A?CCC?CC???AA?CACCCAAC??CAA??C?AA??CA???CAAA...

output:

2344
2345
2342
2342
2768
2768
2772
2772
2772
2772
2772
2772
2772
2767
2767
2767
2767
2764
2766
2766
2769
2765
2761
2764
2767
2772
2772
2772
2772
2772
2772
2777
2777
2777
2777
2774
2771
2774
2782
2778
2778
2772
2768
2772
2772
2772
2772
2772
2774
2774
2778
2781
2781
2779
2782
2784
2787
2782
2786
2788
...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 6700ms
memory: 179392kb

input:

300000 300000
AAA?CA?AA?AC?A?CCA?AACCAAA???CA?ACCAACCCCAACAAA?CCAAAC?A?C??CC?C?C?CCCA?CAA?ACA??C?C?AC??CA??ACA?AA???CACAAA?CACCCCCCC?A?AAAAAC?AACCA????CCC?C?AAACCCAA?C???CCCC?AAACAAA???A?CAAC??A??A??CCCC??AA?C??ACA?AACAAA????CAA???AAAAACC?C?CCA?CCAA?AAC?CC?CA?A??CC??CCAC??C??????AAC?AA?AA?AAC?C??AAC...

output:

14995917235
14995917235
14996064601
14996083631
14995980103
14995925797
14995925797
14995925797
14995967213
14995967213
14995967213
14995876211
14995774037
14995774037
14995774037
14995876791
14995866113
14995756158
14995647554
14995647554
14995560537
14995560537
14995583619
14995583619
14995583619
...

result:

ok 300000 lines

Test #4:

score: 0
Accepted
time: 3377ms
memory: 147444kb

input:

300000 300000
?ACA???CCCA?C???AA??CAAAAACCC??A?CAC??C???????CAA?C?C?A?C???A?CC?CCAC?C?ACC??C?CAACA??CA?CA?CAACA??AACCC?CCCACACC?AAC?CA??C?C?CCCA?ACAA??AA?CCAACACCA?AC?C?CCCCCCAAA?CC??A?CCC???A?CA?ACAC???C??CCA??CCAA?AAC???CCCC??AA?C?C?C?CACAC?C?CA??AACC?A????C??CACAAAAA?C?CAACACA?ACCAC?A?CCCACACA??A...

output:

200180
200181
200182
200182
200182
200182
200182
200182
200183
200183
200183
200182
200183
200183
200183
200183
200183
200182
200183
200183
200183
200183
200183
200183
200183
200183
200184
200183
200182
200181
200180
200180
200180
200181
200181
200182
200181
200180
200180
200181
200182
200181
200182...

result:

ok 300000 lines

Test #5:

score: 0
Accepted
time: 7752ms
memory: 192544kb

input:

300000 300000
A??CCAAACAC?A?CCACA?CA??ACC?CCA?CCAACACAC?A?CCC??ACC?ACC?CA?CA?C??A?CACCCC?C?AC?AAC??A???CA?C???AC?A?A?ACCCAACC?AA?CCACCCAAAA????C?ACC?????ACACA?C?A?CCC?A?AC????AC?C?A???ACA??CAACACC????CAA???ACCAC???CCCA?A?CAA?C??CCCCA?ACCA?A?CCC?ACA?C??AA?C??ACA?AAACC?CCAACCCAC?CAAA??ACC?ACCAA??????A...

output:

15015050020
15015050020
15015135045
15015202340
15015303448
15015303448
15015282042
15015282042
15015310379
15015329461
15015377957
15015514924
15015514924
15015613521
15015724614
15015640441
15015598420
15015635210
15015635210
15015544590
15015671373
15015653717
15015706346
15015805421
15015835446
...

result:

ok 300000 lines

Test #6:

score: 0
Accepted
time: 1120ms
memory: 164476kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
10018652160
...

result:

ok 300000 lines

Test #7:

score: 0
Accepted
time: 4523ms
memory: 152996kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891340
2619172
2891...

result:

ok 300000 lines

Test #8:

score: 0
Accepted
time: 4381ms
memory: 152056kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

2972868
3149825
2972868
2700372
2875914
2700372
2972868
2700372
2875914
3149825
2875914
3149825
2972868
2700372
2972868
2700372
2972868
2700372
2875914
2700372
2972868
2700372
2875914
3149825
2972868
3149825
2972868
3149825
2972868
3149825
2875914
2700372
2875914
3149825
2972868
3149825
2972868
2700...

result:

ok 300000 lines

Test #9:

score: 0
Accepted
time: 5205ms
memory: 159172kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

2733980
2504686
2733980
2504686
2733980
3006821
2775490
2504686
2733980
3006821
2733980
2504686
2775490
2504686
2733980
2504686
2733980
2504686
2775490
2504686
2775490
2504686
2775490
3006821
2733980
2504686
2775490
2504686
2775490
2504686
2733980
3006821
2775490
3006821
2775490
3006821
2775490
3006...

result:

ok 300000 lines

Test #10:

score: 0
Accepted
time: 3755ms
memory: 157444kb

input:

300000 300000
?C??C?C??C??C??CC???C???CCC?CCCCCC??C???C?CCCC????C??C????C???C???C????C?CC??CC?C???CC?C??C?C?CCC??C?CCCCC?C??C??C?CC?C?CC?CC?CCC??C?C???C??CC??CC???CC?C??CCC??C??C???C???C??C?C????CCCCCC????CC?CC?CCC?CCC?CCC?C???CC????CCC?CC??C?CC?C?C?C???CCC?CCCCC??C??C???CC??C??CCCCC?C??C?CCC???C???...

output:

2075827
1795155
1531311
1795155
2075827
1809426
2075827
1809426
1531311
1795155
1531311
1795155
1531311
1795155
1531311
1795155
2075827
1809426
2075827
1809426
2075827
1795155
1531311
1795155
2075827
1795155
2075827
1795155
2075827
1795155
2075827
1809426
2075827
1809426
2075827
1795155
2075827
1795...

result:

ok 300000 lines

Test #11:

score: 0
Accepted
time: 3994ms
memory: 151404kb

input:

300000 300000
?C??C???C?CC?C????CCCCC?C?CC?C??CC?CC?CC???C?????C????CC?C???C?CC?CCCCCC????C??CC??C?CC????????C?CC??C?C???CCC?C???CC??C????????C?C?C??C?C??CCC?C???CC???C???CC??CCCC?C????C?CCCCC???CC?CC?CCC?C??C??C??CC?C?C?C?CC??C????CCC?CC???C??CC??C?C?????CC?C??C?????????CC?CCCC??CCCC?CCCC?CC??CCC??...

output:

2157824
1877034
2157824
1896339
1617981
1896339
1617981
1896339
2157824
1896339
1617981
1896339
1617981
1896339
1617981
1896339
1617981
1896339
1617981
1896339
2157824
1896339
2157824
1896339
2157824
1877034
1617981
1877034
2157824
1877034
2157824
1896339
1617981
1896339
1617981
1896339
2157824
1877...

result:

ok 300000 lines

Test #12:

score: 0
Accepted
time: 4528ms
memory: 152068kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

2735497
2557038
2735497
2557038
2735497
2557038
2735497
2557038
2828577
2557038
2735497
3008607
2828577
3008607
2828577
3008607
2735497
3008607
2828577
2557038
2828577
2557038
2828577
2557038
2828577
2557038
2828577
2557038
2735497
3008607
2735497
3008607
2735497
2557038
2735497
3008607
2735497
2557...

result:

ok 300000 lines

Test #13:

score: 0
Accepted
time: 4216ms
memory: 154412kb

input:

300000 300000
??C?CC?CCCCC?CC?????C??C?CCCCC?CCC?C?CC????CC?CCCC?C??C?C??CC?CC??C?C?CC?C?C?C?C?????C?CCCCCCCCCC??CCCC?CC?CC?????CCC?C?CC??C??CC?????CC?C?C?CC?C?C????CCCC?C?????C????C?C???C?C????CC?C?C?C?CCC??C?CCCCCCCC????C?C??C?C?C??CCC?C???CC?CC?????CC?CC?????C??C???CCC????CCCCC??CCC???C??C??C?C??...

output:

1485826
1212139
1485826
1212139
1400502
1677115
1485826
1677115
1400502
1677115
1485826
1212139
1485826
1212139
1485826
1677115
1485826
1677115
1485826
1212139
1400502
1677115
1400502
1212139
1485826
1212139
1485826
1677115
1400502
1677115
1400502
1212139
1485826
1212139
1485826
1212139
1485826
1212...

result:

ok 300000 lines

Test #14:

score: 0
Accepted
time: 3773ms
memory: 148856kb

input:

300000 300000
C??CC?????CCC?CCCC????CC?C?C???CCC????C???CC?CC?C???CC?????????CCC?C?C????CC??C?????CC?CCC??C????CC?C???CC??CC??CCC??CCC?C??C?C?CC??CCCC???CC??C?CCC?CCCCCC??CCC?C????C?CCCC??CCC?C?CCCC?C?C???C????CCCCC???C?????CC??CC??CC?C?CCCC??C?CC????C?C??C??CC?C?C?CCCCC?C?CC?CCCC??C???C??C??C?CCCC?...

output:

1974842
1695078
1430018
1695078
1430018
1695078
1974842
1706826
1974842
1706826
1430018
1706826
1974842
1706826
1430018
1706826
1974842
1695078
1974842
1695078
1430018
1695078
1430018
1706826
1430018
1706826
1974842
1695078
1430018
1706826
1430018
1706826
1430018
1706826
1430018
1695078
1430018
1706...

result:

ok 300000 lines

Test #15:

score: 0
Accepted
time: 3616ms
memory: 156864kb

input:

300000 300000
CC?C?CC?CC?C?CC??C???CCCCC?C??C?CC????????CCCC????CC???C?CC?C???CCC??C?CC??C???C?C?CC??CC??C???CCCC???C?C?C?CC??CCC?CCC?CCCCC???????C?C???C?C?????CC?CCCC?C?C???C?????????CCC??CC?CCCC??C?C?CC???C??CC???CC?C?CC??C????CCCC???C?CC?C?CCCCCCCC?C?CCC???CCCCCC?C??C???????C??C????CC??C??C?C??CC...

output:

1728837
1451650
1663426
1942865
1728837
1942865
1663426
1942865
1663426
1942865
1663426
1942865
1663426
1942865
1728837
1451650
1663426
1451650
1663426
1942865
1663426
1451650
1728837
1942865
1663426
1942865
1728837
1942865
1728837
1451650
1728837
1942865
1663426
1451650
1728837
1451650
1663426
1942...

result:

ok 300000 lines

Test #16:

score: 0
Accepted
time: 4308ms
memory: 150868kb

input:

300000 300000
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

3019536
2746517
3019536
3285983
3010822
2746517
3010822
3285983
3010822
2746517
3010822
3285983
3019536
3285983
3010822
3285983
3019536
3285983
3019536
2746517
3019536
3285983
3019536
3285983
3010822
2746517
3010822
3285983
3010822
3285983
3019536
2746517
3019536
3285983
3010822
2746517
3019536
2746...

result:

ok 300000 lines

Test #17:

score: 0
Accepted
time: 3617ms
memory: 147740kb

input:

300000 300000
C???C?C?CCCC?C??C??CCC??CCC??C?CCC???C?C??CC?C?CC?CC??C?C????CCC??C??CC?????CC???C????CCCCC??CCCC?CC??CCC???CC?????CC????CCC???C??C?C?????C?CC?CC?CCCCCC???C?CCCC???C??????CC?C??C??C?C??C?C?????????C??CC?CC??C?????C??CC?C?CCCCCCC?C??C?C?C?C?CCC???CCC?CCC????C?C?CC?CC?CCC?C??CCC?????CCCC...

output:

1891146
1702030
1891146
1702030
1891146
1612503
1425186
1702030
1891146
1702030
1425186
1612503
1425186
1612503
1891146
1612503
1891146
1612503
1891146
1612503
1891146
1612503
1425186
1612503
1425186
1702030
1891146
1612503
1425186
1702030
1425186
1702030
1891146
1612503
1891146
1702030
1425186
1702...

result:

ok 300000 lines

Test #18:

score: 0
Accepted
time: 3618ms
memory: 151884kb

input:

300000 300000
??CC?????CCCCC?????C?C?C?C???CC???CC???C?C???C??????C?C?C????CC?CCCC?CC?CC?C??CCC???CC???????CC???CC?C?CC?CC?C?CC?C?C?????C????CC?C?CCC????CCC?????C??CCCCC??C?C?C?C???CCCCCC??CC?C????CCCCC?CC?CC?CC???C?CCC?CC?CC?C???C?C?C??C?C?C?C????C?CCC?CC??C?CC??C?C??CCCC??CCCCC?CC?CC????CCC????CCC...

output:

1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915088
1635795
1915...

result:

ok 300000 lines

Test #19:

score: 0
Accepted
time: 3610ms
memory: 155380kb

input:

300000 300000
?CCC?C??????CC?CCCCCCCC??C??CC???CC?CCCC?CC????CCC?C?C??CCC??C???CCC?CCCC?CCC?C?C??CC??CCCC?CCC?C???CC??CCC??C????C??C????C??C?C?CC??????CCC?CCCC????C?CC?C??CCCC????CCC??CC???C???C?CC??C?CC?C??C????CCC??C???C?CCC??C??????C???C?C????CC?C???C??C????C??CC???C?C?C?CCCCC?C?????CC?CCC??CC?CC...

output:

1446155
1708168
1987846
1722916
1446155
1722916
1987846
1708168
1987846
1722916
1987846
1708168
1987846
1722916
1446155
1722916
1446155
1722916
1987846
1722916
1987846
1722916
1987846
1708168
1987846
1722916
1446155
1708168
1987846
1708168
1987846
1722916
1987846
1708168
1987846
1708168
1987846
1708...

result:

ok 300000 lines

Test #20:

score: -100
Time Limit Exceeded

input:

300000 300000
C??AA??C?AACC?CC?CAA??AAAAACAA??CAAAACACCCCA?CC??C?CC?CCCAAA?ACC?ACA?AA??AC?CA??AAAC?AC?A?CA??ACC??ACACC??CCA??A?C?CCCA???A???A?ACCAAC?CA??C??AA?A?ACCACA???CCACCCACAACAA??C??C?CACA??AA?ACAA??A??CCAA?CAA?AC?AC?CCCA?C?C???C?CCCC??CCACAC??CC?CCACA?CCA?AACC?AC???ACAC?AA?ACAACA?ACAAACA?C??C...

output:

1446727
1446731
1446741
1446749
1446749
1446755
1446761
1446757
1446757
1446757
1446757
1446757
1446763
1446754
1446754
1446754
1446754
1446754
1446751
1446751
1446751
1446757
1446760
1446762
1446762
1446762
1446762
1446762
1446772
1446765
1446765
1446765
1446768
1446768
1446771
1446771
1446771
1446...

result: