QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704393 | #212. Wyspa [A] | TheZone | 10 ✓ | 420ms | 113364kb | C++20 | 17.6kb | 2024-11-02 19:53:40 | 2024-11-02 19:53:53 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1000005
#define inf 0x3f3f3f3f
int n,m,n1,n2;
vi e[maxn];
int dfn[maxn],low[maxn],idx,scc,st[maxn],tp,bel[maxn];
vi p[maxn];
void tar(int u){
dfn[u]=low[u]=++idx;
st[++tp]=u;
for(int v:e[u]){
if(!dfn[v])tar(v),low[u]=min(low[u],low[v]);
else if(!bel[v])low[u]=min(low[u],dfn[v]);
}
if(dfn[u]!=low[u])return;
int v; ++scc; do{
v=st[tp--];
bel[v]=scc;
p[scc].pb(v);
}while(u!=v);
}
int id[maxn],cnt;
int l[maxn],r[maxn];
pii get(vector<pii>o){
if(!o.size()) return {-1,-1};
sort(o.begin(),o.end());
int l=-inf,r=-inf;
vector<pii>res;
for(auto [x,y]:o){
if(x>r+1){
if(l!=-inf)res.pb(mkp(l,r));
l=x,r=y;
}
else r=max(r,y);
}
res.pb(mkp(l,r));
if(res.size()==1) return res[0];
// cout<<"res "<<"\n";
// for(auto [x,y]:res)cout<<x<<" "<<y<<"\n";
// assert(res.size()==2);
if(res[0].fi==1 && res[1].se==cnt); else exit(3);
return mkp(res[1].fi,res[0].se);
}
bool vis[maxn];
int t[maxn],len;
int Len(int l,int r){
if(l<=r)return r-l+1;
return (cnt-l+1)+r;
}
modint f[maxn],sf[maxn],pw[maxn];
bool havp[maxn],ban[maxn];
int mx1[maxn],mx2[maxn];
signed main()
{
// freopen("wys2d.in","r",stdin);
// freopen("my.out","w",stdout);
n=read(),m=read(),n1=read(),n2=read();
For(i,1,m){
int u=read();
string w;cin>>w;
int v=read();
e[u].pb(v);
if(w=="--")e[v].pb(u);
}
For(i,1,n1) if(!dfn[i]) tar(i);
int pres=0;
For(i,n1+1,n1+n2)
if(dfn[i]) id[i]=++cnt;
else ++pres;
// [1,n1] --> [n1+1,n1+n2]
For(i,1,scc) {
vector<pii>o;
for(int u:p[i]){
if(u>n1 && u<=n1+n2) o.pb(mkp(id[u],id[u]));
for(int v:e[u]){
int x=bel[v];
if(vis[x] || x==i)continue;
vis[x]=1;
// cout<<"x: "<<x<<" "<<l[x]<<' '<<r[x]<<"\n";
if(l[x]==-1)continue;
if(l[x]<=r[x])o.pb(mkp(l[x],r[x]));
else o.pb(mkp(1,r[x])),o.pb(mkp(l[x],cnt));
}
}
pii t=get(o);
l[i]=t.fi,r[i]=t.se;
for(int u:p[i]) for(int v:e[u]) vis[bel[v]]=0;
}
int mn=inf,ml=0,mr=0;
For(i,1,n1) havp[bel[i]]=1;
For(i,1,scc) if(havp[i] && Len(l[i],r[i])<mn) mn=Len(l[i],r[i]),ml=l[i],mr=r[i];
vector< array<int,3> >vec;
// cout<<"cnt "<<cnt<<"\n";
// cout<<"pres "<<pres<<"\n";
int add=ml;
For(i,1,scc) if(havp[i]) {
l[i]=(l[i]-ml+cnt)%cnt+1;
r[i]=(r[i]-ml+cnt)%cnt+1;
if(l[i]<=r[i]) vec.pb({l[i],r[i],i}),vec.pb({l[i]+cnt,r[i]+cnt,i});
else vec.pb({l[i],r[i]+cnt,i});
// cout<<"i: "<<i<<" "<<l[i]<<" "<<r[i]<<"\n";
}
ml=(ml-add+cnt)%cnt+1;
mr=(mr-add+cnt)%cnt+1;
sort(vec.begin(),vec.end(),[&](auto x,auto y){
if(x[0]!=y[0]) return x[0]<y[0];
if(x[1]!=y[1]) return x[1]>y[1];
return x[2]<y[2]; // important
});
reverse(vec.begin(),vec.end());
mn=inf;
for(auto p:vec){
if(p[1]>=mn)ban[p[2]]=1;
mn=min(mn,p[1]);
}
t[++len]=0;
t[++len]=cnt;
For(i,1,scc) if(havp[i] && !ban[i]) t[++len]=l[i]-1,t[++len]=r[i];
sort(t+1,t+len+1),len=unique(t+1,t+len+1)-t-1;
#define V(x) lower_bound(t+1,t+len+1,x)-t
For(i,1,scc) if(havp[i] && !ban[i]) {
l[i]=V(l[i]-1),r[i]=V(r[i]);
if(l[i]<=r[i]) mx1[r[i]]=max(mx1[r[i]],l[i]);
else mx2[r[i]]=max(mx2[r[i]],l[i]);
}
mr=V(mr);
pw[0]=1;
For(i,1,n)pw[i]=pw[i-1]*2;
modint res=0;
For(i,2,mr){
For(j,0,len) f[j]=sf[j]=0;
f[i]=sf[i]=pw[t[i]-t[i-1]]-1;
int mx=1;
For(j,i+1,len){
f[j]=(sf[j-1]-sf[mx])*(pw[t[j]-t[j-1]]-1);
sf[j]=sf[j-1]+f[j];
mx=max(mx,mx1[j]);
}
res+=sf[len]-sf[mx];
mx1[len]=max(mx1[len],mx2[i]);
}
res*=qpow(2,pres);
cout<<res.x;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 23984kb
input:
2 1 1 1 1 -> 2
output:
1
result:
ok single line: '1'
Test #2:
score: 1
Accepted
time: 5ms
memory: 22044kb
input:
2 1 1 1 2 -- 1
output:
1
result:
ok single line: '1'
Test #3:
score: 1
Accepted
time: 0ms
memory: 24084kb
input:
5 4 1 4 1 -> 2 3 -> 1 1 -- 4 4 -- 5
output:
14
result:
ok single line: '14'
Test #4:
score: 1
Accepted
time: 3ms
memory: 24096kb
input:
15 4 4 4 1 -> 5 2 -> 6 3 -> 7 4 -> 8
output:
1
result:
ok single line: '1'
Test #5:
score: 1
Accepted
time: 5ms
memory: 26292kb
input:
9 10 3 3 1 -> 7 7 -> 2 2 -> 8 8 -> 3 3 -> 9 9 -> 6 1 -> 5 2 -> 5 2 -> 4 3 -> 4
output:
6
result:
ok single line: '6'
Test #6:
score: 1
Accepted
time: 5ms
memory: 22272kb
input:
20 22 6 12 8 -- 9 8 -- 10 13 -- 14 13 -- 15 7 -- 17 2 -> 19 19 -> 16 16 -> 7 4 -> 20 20 -> 8 6 -> 11 11 -> 12 12 -> 13 1 -> 11 4 -> 19 19 -> 12 5 -> 20 20 -> 16 16 -> 13 6 -> 8 8 -> 7 3 -> 19
output:
3948
result:
ok single line: '3948'
Test #7:
score: 1
Accepted
time: 5ms
memory: 22072kb
input:
20 30 5 5 2 -> 1 2 -> 3 4 -> 3 5 -> 4 1 -> 5 6 -> 7 8 -> 7 8 -> 9 9 -> 10 10 -> 6 11 -> 1 13 -> 2 3 -> 15 4 -> 17 5 -> 19 6 -> 12 7 -> 14 8 -> 16 18 -> 9 20 -> 10 12 -> 11 13 -> 12 14 -> 13 15 -> 14 15 -> 16 17 -> 16 17 -> 18 18 -> 19 20 -> 19 20 -> 11
output:
30
result:
ok single line: '30'
Test #8:
score: 1
Accepted
time: 4ms
memory: 21988kb
input:
20 30 5 5 2 -> 1 3 -> 2 4 -> 3 5 -> 4 1 -> 5 7 -> 6 8 -> 7 8 -> 9 10 -> 9 10 -> 6 11 -> 1 2 -> 13 15 -> 3 17 -> 4 5 -> 19 6 -> 12 14 -> 7 16 -> 8 9 -> 18 10 -> 20 11 -> 12 13 -> 12 13 -- 14 14 -> 15 16 -> 15 17 -- 16 18 -- 17 18 -> 19 20 -> 19 11 -> 20
output:
24
result:
ok single line: '24'
Test #9:
score: 1
Accepted
time: 2ms
memory: 26036kb
input:
20 8 1 19 1 -> 2 2 -> 6 6 -> 12 12 -> 19 19 -> 15 15 -> 13 19 -> 20 12 -> 9
output:
522240
result:
ok single line: '522240'
Test #10:
score: 1
Accepted
time: 4ms
memory: 22272kb
input:
20 20 19 1 2 -- 3 9 -- 10 7 -> 8 19 -> 1 13 -> 14 20 -> 6 6 -> 7 4 -> 5 11 -- 10 8 -> 9 14 -- 15 1 -> 2 12 -- 13 18 -- 19 3 -> 4 17 -> 18 16 -> 17 11 -> 12 5 -- 20 15 -> 16
output:
1
result:
ok single line: '1'
Test #11:
score: 1
Accepted
time: 5ms
memory: 24124kb
input:
20 24 10 8 13 -> 12 5 -> 17 6 -> 19 13 -> 14 5 -> 15 9 -> 19 19 -> 17 17 -> 18 19 -> 11 15 -> 16 10 -> 20 1 -> 20 17 -> 16 20 -> 13 2 -> 20 4 -> 15 7 -> 19 20 -> 11 3 -> 20 8 -> 19 11 -> 12 11 -> 18 4 -> 13 15 -> 14
output:
231
result:
ok single line: '231'
Test #12:
score: 1
Accepted
time: 4ms
memory: 20040kb
input:
12 30 3 3 2 -> 1 2 -> 3 1 -> 3 4 -> 5 5 -- 6 6 -> 4 1 -> 7 9 -> 1 1 -- 12 7 -- 2 8 -- 2 2 -> 10 8 -- 3 9 -> 3 11 -> 3 7 -> 4 10 -> 4 12 -- 4 9 -- 5 11 -> 5 5 -> 12 6 -> 8 10 -> 6 6 -> 11 7 -- 10 10 -> 8 11 -> 8 9 -> 11 12 -> 9 7 -> 12
output:
7
result:
ok single line: '7'
Test #13:
score: 1
Accepted
time: 0ms
memory: 24104kb
input:
20 31 5 5 16 -> 10 19 -> 5 5 -- 17 10 -> 6 9 -> 10 20 -> 5 20 -> 3 9 -> 8 4 -> 20 3 -- 11 5 -> 13 1 -- 17 17 -- 6 17 -> 13 18 -- 19 4 -> 3 18 -> 5 2 -> 3 11 -> 10 2 -> 1 11 -- 20 7 -> 8 5 -- 4 18 -> 16 11 -> 16 20 -- 16 6 -- 7 13 -> 19 5 -> 1 6 -- 13 20 -- 18
output:
30
result:
ok single line: '30'
Test #14:
score: 1
Accepted
time: 0ms
memory: 22068kb
input:
20 36 3 4 15 -> 7 8 -> 13 6 -- 5 17 -- 13 12 -> 11 16 -> 15 4 -- 7 2 -- 3 16 -> 1 15 -- 20 12 -> 1 20 -> 5 2 -- 1 8 -> 17 2 -- 11 5 -> 4 9 -> 13 7 -- 1 8 -> 9 12 -- 9 7 -> 16 4 -> 13 5 -> 11 8 -> 1 9 -- 4 1 -- 9 6 -- 20 7 -- 6 2 -- 20 2 -> 15 15 -> 6 3 -> 16 11 -> 20 17 -- 1 1 -- 3 16 -- 2
output:
15
result:
ok single line: '15'
Test #15:
score: 1
Accepted
time: 0ms
memory: 24124kb
input:
20 20 10 10 1 -> 11 1 -> 12 2 -> 12 2 -> 13 3 -> 13 3 -> 14 4 -> 14 4 -> 15 5 -> 15 5 -> 16 6 -> 16 6 -> 17 7 -> 17 7 -> 18 8 -> 18 8 -> 19 9 -> 19 9 -> 20 10 -> 20 10 -> 11
output:
123
result:
ok single line: '123'
Test #16:
score: 1
Accepted
time: 2ms
memory: 26076kb
input:
8 6 4 2 7 -- 2 7 -- 4 8 -> 7 3 -> 8 7 -> 5 1 -> 6
output:
1
result:
ok single line: '1'
Test #17:
score: 1
Accepted
time: 0ms
memory: 24036kb
input:
18 30 3 3 15 -> 16 9 -> 14 18 -> 6 2 -> 9 11 -> 15 13 -> 17 8 -> 11 7 -> 11 17 -> 18 1 -> 8 3 -> 9 14 -> 12 3 -> 7 17 -> 16 13 -> 15 9 -> 13 7 -> 14 12 -> 18 18 -> 5 14 -> 17 12 -> 10 1 -> 7 16 -> 5 16 -> 4 8 -> 13 10 -> 4 11 -> 12 10 -> 6 15 -> 10 2 -> 8
output:
7
result:
ok single line: '7'
Test #18:
score: 1
Accepted
time: 4ms
memory: 22068kb
input:
6 11 3 2 3 -> 2 5 -> 4 5 -> 3 5 -> 1 4 -> 1 6 -> 4 6 -> 2 2 -> 4 6 -> 5 2 -> 5 1 -> 2
output:
3
result:
ok single line: '3'
Test #19:
score: 1
Accepted
time: 4ms
memory: 22064kb
input:
9 12 3 4 5 -> 8 2 -> 5 1 -> 3 1 -> 5 6 -> 2 7 -> 9 4 -> 6 8 -> 3 6 -> 7 8 -> 1 3 -> 4 6 -> 9
output:
15
result:
ok single line: '15'
Test #20:
score: 1
Accepted
time: 4ms
memory: 24292kb
input:
10 6 3 7 5 -- 6 3 -- 10 1 -> 4 2 -> 5 2 -> 4 3 -> 5
output:
56
result:
ok single line: '56'
Test #21:
score: 1
Accepted
time: 3ms
memory: 26332kb
input:
5 5 2 3 1 -> 5 2 -> 5 3 -> 1 5 -> 4 2 -> 1
output:
6
result:
ok single line: '6'
Test #22:
score: 1
Accepted
time: 0ms
memory: 26168kb
input:
11 10 3 5 10 -> 5 3 -> 1 10 -> 4 2 -> 3 2 -> 7 10 -> 11 9 -> 10 1 -> 10 6 -> 7 3 -> 5
output:
24
result:
ok single line: '24'
Test #23:
score: 1
Accepted
time: 0ms
memory: 22056kb
input:
20 20 8 12 12 -- 13 16 -- 17 16 -- 18 19 -- 20 1 -> 11 11 -> 12 12 -> 14 14 -> 15 15 -> 16 16 -> 19 7 -> 9 8 -> 10 1 -> 10 10 -> 9 2 -> 11 3 -> 12 4 -> 14 5 -> 15 6 -> 16 7 -> 19
output:
2752
result:
ok single line: '2752'
Subtask #2:
score: 1
Accepted
Test #24:
score: 1
Accepted
time: 2ms
memory: 24124kb
input:
200 360 20 20 104 -> 180 182 -> 21 136 -> 115 159 -> 139 66 -> 26 153 -> 154 189 -> 79 187 -> 143 42 -> 161 144 -> 188 165 -> 61 144 -> 117 10 -> 173 48 -> 111 180 -> 166 191 -> 138 141 -> 108 84 -> 47 156 -> 66 116 -> 74 119 -> 123 200 -> 128 91 -> 154 83 -> 70 64 -> 50 82 -> 146 152 -> 91 45 -> 64...
output:
1038335
result:
ok single line: '1038335'
Test #25:
score: 1
Accepted
time: 3ms
memory: 24056kb
input:
200 300 50 50 42 -> 137 189 -> 63 198 -> 199 113 -> 122 152 -> 169 188 -> 195 168 -> 196 10 -> 116 120 -> 59 117 -> 164 149 -> 75 22 -> 113 102 -> 75 126 -> 161 14 -> 128 158 -> 133 11 -> 156 152 -> 127 26 -> 109 104 -> 100 29 -> 136 158 -> 141 137 -> 125 148 -> 88 128 -> 104 9 -> 180 156 -> 186 21 ...
output:
983378722
result:
ok single line: '983378722'
Test #26:
score: 1
Accepted
time: 5ms
memory: 22008kb
input:
200 499 51 49 198 -> 100 117 -> 122 86 -> 85 27 -> 28 117 -- 185 87 -> 86 120 -- 114 191 -> 167 59 -> 60 28 -> 189 139 -- 151 160 -> 113 170 -- 102 122 -> 85 175 -- 123 87 -> 88 132 -> 164 186 -> 97 100 -> 186 126 -- 142 174 -- 168 137 -> 154 98 -- 186 142 -> 68 168 -> 117 187 -> 152 87 -> 89 148 ->...
output:
949480667
result:
ok single line: '949480667'
Test #27:
score: 1
Accepted
time: 5ms
memory: 26104kb
input:
200 484 51 63 116 -> 161 21 -> 22 10 -> 192 42 -> 183 146 -> 86 185 -> 194 136 -> 1 145 -> 131 180 -> 58 89 -> 90 151 -> 84 128 -> 190 1 -> 152 92 -> 91 174 -> 135 156 -> 151 162 -> 115 197 -> 47 26 -> 25 50 -> 1 93 -> 94 71 -> 72 76 -> 77 16 -> 15 79 -> 80 4 -> 5 139 -> 141 29 -> 31 69 -- 144 49 ->...
output:
99548853
result:
ok single line: '99548853'
Test #28:
score: 1
Accepted
time: 5ms
memory: 20036kb
input:
200 142 69 131 152 -> 154 119 -> 121 24 -- 25 151 -- 10 35 -> 88 90 -> 93 87 -- 86 118 -- 117 29 -> 78 84 -- 85 13 -- 166 93 -- 40 77 -- 29 58 -- 57 48 -- 103 114 -- 60 66 -- 67 37 -> 38 42 -- 43 117 -- 60 171 -- 15 64 -- 63 38 -- 39 34 -- 33 40 -- 95 71 -> 73 107 -> 49 148 -> 151 139 -> 8 41 -> 42 ...
output:
102959076
result:
ok single line: '102959076'
Test #29:
score: 1
Accepted
time: 5ms
memory: 24132kb
input:
200 210 105 15 5 -- 121 4 -- 122 122 -> 121 8 -- 123 19 -- 123 23 -- 123 7 -- 124 6 -> 125 125 -> 124 124 -> 123 11 -- 126 10 -- 127 9 -> 128 128 -> 127 127 -> 126 13 -- 129 16 -- 129 12 -> 130 130 -> 129 14 -- 131 15 -- 132 132 -> 131 131 -> 129 17 -- 133 18 -> 134 134 -> 133 133 -> 129 129 -> 126 ...
output:
10584
result:
ok single line: '10584'
Test #30:
score: 1
Accepted
time: 0ms
memory: 24276kb
input:
199 318 50 28 62 -> 61 39 -> 80 143 -> 163 152 -> 184 5 -> 104 48 -> 153 178 -> 96 177 -> 144 85 -> 110 122 -> 158 121 -> 54 94 -> 98 132 -> 128 169 -> 190 102 -> 57 86 -> 58 176 -> 71 189 -> 197 68 -> 69 132 -> 113 29 -> 117 60 -> 59 161 -> 112 40 -> 80 74 -> 73 110 -> 102 135 -> 181 146 -> 136 79 ...
output:
259738311
result:
ok single line: '259738311'
Test #31:
score: 1
Accepted
time: 0ms
memory: 26056kb
input:
199 343 25 34 144 -> 186 16 -> 172 185 -> 119 55 -- 56 128 -> 96 184 -> 144 184 -> 111 197 -> 194 114 -> 185 190 -> 132 3 -> 176 199 -> 189 132 -> 152 138 -> 48 79 -> 165 127 -> 122 13 -> 98 115 -> 146 69 -> 136 189 -> 32 44 -> 42 117 -> 102 144 -> 123 61 -> 104 19 -> 193 76 -> 170 95 -> 121 176 -> ...
output:
177200520
result:
ok single line: '177200520'
Test #32:
score: 1
Accepted
time: 0ms
memory: 22232kb
input:
200 326 41 39 95 -> 127 193 -> 166 159 -> 97 14 -> 167 144 -> 90 41 -> 153 119 -> 111 77 -> 75 135 -> 189 116 -> 169 99 -> 162 192 -> 86 170 -> 160 10 -> 153 165 -> 87 126 -> 156 163 -> 83 72 -> 73 74 -> 75 195 -> 124 102 -> 123 104 -> 138 6 -> 153 135 -> 183 39 -> 130 51 -> 50 196 -> 164 21 -> 103 ...
output:
755794076
result:
ok single line: '755794076'
Test #33:
score: 1
Accepted
time: 3ms
memory: 24128kb
input:
196 308 42 47 142 -> 170 136 -> 177 44 -- 45 137 -> 151 83 -> 84 36 -> 127 168 -> 57 112 -> 128 187 -> 52 102 -> 155 147 -> 157 42 -> 186 96 -> 129 27 -> 110 112 -> 92 56 -- 54 70 -> 68 18 -> 194 195 -> 128 172 -> 140 8 -> 163 46 -- 47 172 -> 145 12 -> 180 186 -> 105 99 -> 151 149 -> 125 103 -> 95 1...
output:
486055864
result:
ok single line: '486055864'
Test #34:
score: 1
Accepted
time: 6ms
memory: 26192kb
input:
199 196 153 43 197 -> 186 64 -> 197 123 -> 198 117 -> 198 52 -> 197 199 -> 178 198 -> 161 199 -> 176 31 -> 199 59 -> 197 44 -> 197 21 -> 199 51 -> 197 121 -> 198 199 -> 183 2 -> 199 57 -> 197 197 -> 196 25 -> 199 8 -> 199 86 -> 198 36 -> 197 149 -> 199 66 -> 197 67 -> 197 142 -> 199 199 -> 182 82 ->...
output:
542926224
result:
ok single line: '542926224'
Test #35:
score: 1
Accepted
time: 5ms
memory: 22080kb
input:
194 250 55 61 61 -- 62 61 -- 63 64 -- 65 66 -- 67 71 -- 72 73 -- 74 76 -- 77 78 -- 79 78 -- 80 85 -- 86 85 -- 87 85 -- 88 89 -- 90 91 -- 92 93 -- 94 93 -- 95 102 -- 103 102 -- 104 102 -- 105 107 -- 108 107 -- 109 111 -- 112 111 -- 113 6 -> 121 121 -> 120 120 -> 119 119 -> 118 118 -> 117 117 -> 59 8 ...
output:
886436262
result:
ok single line: '886436262'
Test #36:
score: 1
Accepted
time: 5ms
memory: 24064kb
input:
195 235 60 80 62 -- 63 66 -- 67 71 -- 72 73 -- 76 79 -- 80 83 -- 84 85 -- 86 87 -- 88 87 -- 89 87 -- 90 87 -- 91 92 -- 93 92 -- 94 96 -- 97 96 -- 98 96 -- 99 100 -- 101 104 -- 105 104 -- 109 111 -- 112 117 -- 118 122 -- 123 125 -- 126 130 -- 131 130 -- 132 130 -- 133 130 -- 134 130 -- 135 137 -- 138...
output:
752176841
result:
ok single line: '752176841'
Test #37:
score: 1
Accepted
time: 5ms
memory: 26332kb
input:
200 240 100 60 195 -> 114 162 -> 116 15 -> 171 31 -> 130 90 -> 160 81 -> 160 102 -> 101 27 -> 127 177 -> 106 55 -> 172 132 -> 131 174 -> 179 128 -> 127 141 -> 140 196 -> 111 127 -> 126 53 -> 168 3 -> 163 183 -> 168 21 -> 181 176 -> 178 185 -> 199 158 -> 157 92 -> 160 67 -> 179 73 -> 153 70 -> 176 16...
output:
780652002
result:
ok single line: '780652002'
Test #38:
score: 1
Accepted
time: 0ms
memory: 26136kb
input:
200 592 4 4 193 -> 143 198 -> 46 14 -> 22 109 -> 47 120 -> 132 45 -> 155 33 -> 133 33 -> 114 74 -> 125 53 -> 160 121 -> 87 134 -> 168 13 -> 156 26 -> 104 145 -> 52 72 -> 35 178 -> 65 151 -> 190 171 -> 17 52 -> 12 184 -> 130 85 -> 200 176 -> 88 46 -> 91 56 -> 137 149 -> 187 13 -> 163 186 -> 105 65 ->...
output:
15
result:
ok single line: '15'
Test #39:
score: 1
Accepted
time: 3ms
memory: 22096kb
input:
200 200 7 193 8 -- 9 8 -- 10 8 -- 11 8 -- 12 8 -- 13 8 -- 14 8 -- 15 8 -- 16 8 -- 17 8 -- 18 8 -- 19 8 -- 20 8 -- 21 8 -- 22 8 -- 23 8 -- 24 8 -- 25 8 -- 26 8 -- 27 8 -- 28 8 -- 29 8 -- 30 8 -- 31 8 -- 32 8 -- 33 8 -- 34 8 -- 35 36 -- 37 36 -- 38 36 -- 39 36 -- 40 36 -- 41 36 -- 42 36 -- 43 36 -- 44...
output:
714723034
result:
ok single line: '714723034'
Subtask #3:
score: 1
Accepted
Test #40:
score: 1
Accepted
time: 3ms
memory: 22412kb
input:
3000 8028 401 433 1220 -- 1460 1170 -> 2617 975 -> 2172 2360 -> 2457 1940 -- 2222 1250 -> 2269 687 -> 686 198 -- 201 288 -> 1236 2899 -> 1548 1238 -- 2495 1585 -> 2511 2032 -- 1211 1229 -- 2232 1086 -- 2055 1270 -- 2827 1311 -> 792 385 -> 384 2933 -- 2598 2100 -> 962 2553 -> 1717 1217 -> 1516 1284 -...
output:
253229893
result:
ok single line: '253229893'
Test #41:
score: 1
Accepted
time: 3ms
memory: 26524kb
input:
2996 4194 1000 798 857 -> 2397 341 -> 2015 595 -> 2875 391 -> 2015 590 -> 2300 1860 -> 1862 2711 -> 2216 1905 -> 1155 2683 -> 2698 245 -> 2490 23 -> 2732 109 -> 2601 2598 -> 2379 441 -> 2693 2349 -> 1703 1825 -> 2009 1501 -> 1500 2727 -> 2119 654 -> 2664 640 -> 2258 2032 -> 2327 488 -> 2126 170 -> 1...
output:
130634365
result:
ok single line: '130634365'
Test #42:
score: 1
Accepted
time: 2ms
memory: 26984kb
input:
5000 6000 2000 2000 4677 -> 4960 2145 -> 2144 1216 -> 2785 4372 -> 2328 2825 -> 2824 2429 -> 2428 3549 -> 3548 4178 -> 4985 4723 -> 2187 4023 -> 4571 1864 -> 4226 2191 -> 2190 4888 -> 2093 4917 -> 3117 4400 -> 4044 3838 -> 3837 627 -> 4609 459 -> 3542 2586 -> 2585 1774 -> 4144 789 -> 4369 1058 -> 29...
output:
793410203
result:
ok single line: '793410203'
Test #43:
score: 1
Accepted
time: 3ms
memory: 22556kb
input:
4999 8475 2048 2333 4916 -> 4154 2007 -> 2008 4387 -> 4418 4651 -> 3420 4521 -> 4196 2812 -> 2810 1493 -> 1491 3658 -> 3659 3578 -> 3579 3718 -> 3720 2670 -> 2666 1199 -> 1200 2385 -> 2388 2410 -> 2406 1989 -> 1986 3403 -> 3402 2587 -> 2586 3108 -> 3107 3586 -> 3589 562 -> 563 1065 -> 1066 3734 -> 3...
output:
957931503
result:
ok single line: '957931503'
Test #44:
score: 1
Accepted
time: 4ms
memory: 24824kb
input:
5000 10000 2500 2500 4154 -> 4153 25 -> 4418 1643 -> 3536 4020 -> 4019 4991 -> 4992 1084 -> 2976 1717 -> 1718 1584 -> 3476 4752 -> 4753 4031 -> 4032 2389 -> 4282 630 -> 2522 3937 -> 3936 1612 -> 3504 4472 -> 4473 1520 -> 1519 4210 -> 4211 4617 -> 4616 1000 -> 2893 2107 -> 4000 348 -> 4741 1640 -> 35...
output:
917179159
result:
ok single line: '917179159'
Test #45:
score: 1
Accepted
time: 6ms
memory: 24620kb
input:
4973 6668 1500 1777 2922 -- 2910 3764 -> 3417 4949 -> 3975 4663 -> 1993 4182 -> 3418 3470 -> 4659 2124 -- 2130 2070 -- 2071 1355 -> 4407 4008 -> 4599 4356 -> 4425 4889 -> 4396 4707 -> 3717 3593 -> 1692 948 -> 4138 867 -> 3804 1297 -> 4853 4425 -> 3849 1742 -- 1741 3756 -> 4097 4895 -> 4263 3391 -> 4...
output:
239020875
result:
ok single line: '239020875'
Test #46:
score: 1
Accepted
time: 0ms
memory: 24800kb
input:
4923 5789 2137 1918 2188 -- 2192 3546 -- 3562 3525 -> 3533 3913 -> 3918 974 -> 4514 4730 -> 2511 399 -> 2143 1107 -> 4843 4285 -> 4073 4507 -> 2608 3796 -- 3797 1870 -> 4299 1214 -> 4519 1228 -> 4219 4127 -> 4597 3216 -- 3212 4681 -> 3563 4317 -> 4348 2033 -> 4818 1544 -> 4170 2301 -- 2294 955 -> 46...
output:
227337116
result:
ok single line: '227337116'
Test #47:
score: 1
Accepted
time: 6ms
memory: 23076kb
input:
5000 4664 2616 2384 4573 -> 4574 554 -> 555 1371 -> 1372 1620 -> 1621 2179 -> 2180 4486 -> 2090 577 -> 3096 529 -> 530 4841 -- 2508 1908 -> 1909 816 -> 817 1945 -> 1946 445 -> 446 2681 -> 2682 2390 -> 4732 3830 -> 3831 1246 -> 1247 2457 -> 2458 4740 -> 2401 3768 -- 1275 1180 -> 1181 1678 -> 1679 101...
output:
486858746
result:
ok single line: '486858746'
Test #48:
score: 1
Accepted
time: 4ms
memory: 22680kb
input:
4992 9280 360 394 1391 -> 3767 3968 -> 1840 4750 -> 684 4441 -> 2864 2607 -> 1395 2356 -> 4854 3967 -> 999 1988 -> 3005 1302 -> 407 1501 -> 4429 2829 -> 3882 4934 -> 4336 1898 -> 3784 3815 -> 1235 2646 -> 3847 4424 -> 2190 189 -> 4700 2250 -> 2659 3397 -> 3554 936 -> 2472 77 -> 3739 2797 -> 3414 229...
output:
464113563
result:
ok single line: '464113563'
Test #49:
score: 1
Accepted
time: 3ms
memory: 24284kb
input:
5000 9 2 4444 1 -> 5 7 -> 1 1 -- 9 1 -> 11 2 -> 11 2 -> 13 15 -> 2 17 -- 2 2 -> 5
output:
371505583
result:
ok single line: '371505583'
Test #50:
score: 1
Accepted
time: 8ms
memory: 24780kb
input:
4990 6830 1500 1802 3344 -> 1744 4947 -> 4431 1379 -> 4906 686 -> 4711 3593 -> 4742 3360 -> 2350 244 -> 3711 387 -> 4394 952 -> 3405 109 -> 4481 291 -> 3910 4682 -> 3087 1112 -> 3415 3810 -> 3512 1837 -> 1838 569 -> 3845 4856 -> 4121 3988 -> 4840 4656 -> 1738 4407 -> 2677 782 -> 3551 2407 -> 2408 39...
output:
53767981
result:
ok single line: '53767981'
Test #51:
score: 1
Accepted
time: 0ms
memory: 22412kb
input:
5000 5000 30 4970 31 -- 32 31 -- 33 31 -- 34 31 -- 35 31 -- 36 31 -- 37 31 -- 38 31 -- 39 31 -- 40 31 -- 41 31 -- 42 31 -- 43 31 -- 44 31 -- 45 31 -- 46 31 -- 47 31 -- 48 31 -- 49 31 -- 50 31 -- 51 31 -- 52 31 -- 53 31 -- 54 31 -- 55 31 -- 56 31 -- 57 31 -- 58 31 -- 59 31 -- 60 31 -- 61 31 -- 62 31 ...
output:
732610805
result:
ok single line: '732610805'
Subtask #4:
score: 1
Accepted
Test #52:
score: 1
Accepted
time: 393ms
memory: 89436kb
input:
482822 959624 2998 2999 295169 -> 25482 351106 -> 358911 94543 -> 291620 203491 -> 138533 455060 -> 118484 38644 -> 429232 271166 -> 408392 310839 -> 332732 308961 -> 448115 192668 -> 403132 367072 -> 390997 355638 -> 305571 478714 -> 426285 126806 -> 322693 471322 -> 163762 145598 -> 66308 348342 -...
output:
111100790
result:
ok single line: '111100790'
Test #53:
score: 1
Accepted
time: 389ms
memory: 87684kb
input:
484978 963974 3000 3000 141769 -> 234828 260927 -> 218970 236983 -> 433297 227234 -> 397153 309565 -> 366087 112150 -> 166912 227466 -> 413340 105904 -> 375216 124343 -> 451410 74400 -> 53240 100101 -> 190422 29034 -> 423832 362388 -> 28298 283096 -> 260332 360764 -> 317553 73503 -> 8849 430967 -> 1...
output:
17429083
result:
ok single line: '17429083'
Test #54:
score: 1
Accepted
time: 409ms
memory: 89636kb
input:
496288 986673 2919 2955 25981 -> 411032 366907 -> 157675 197876 -> 406441 186542 -> 386445 326871 -> 203549 482579 -> 307434 478390 -> 251919 6154 -> 162436 359832 -> 298179 131908 -> 203655 51902 -> 38641 59386 -> 130790 154499 -> 92834 183024 -> 30476 335018 -> 313082 493205 -> 123725 270035 -> 21...
output:
851532352
result:
ok single line: '851532352'
Test #55:
score: 1
Accepted
time: 295ms
memory: 83156kb
input:
417762 831185 2019 2222 296328 -> 10491 321848 -> 381425 203677 -> 48748 215429 -> 77495 242641 -> 89410 310711 -> 205583 42323 -> 143772 205756 -> 339510 39324 -> 94146 355268 -> 181378 387359 -> 48761 214253 -> 72846 154697 -> 352153 241830 -> 229117 107611 -> 321082 203017 -> 72495 172855 -> 2259...
output:
76363246
result:
ok single line: '76363246'
Test #56:
score: 1
Accepted
time: 379ms
memory: 89460kb
input:
498361 992121 2333 2149 4943 -> 440373 318575 -> 202142 74514 -> 75114 377318 -> 307815 151876 -> 447493 493771 -> 142033 309125 -> 269827 351821 -> 197691 179311 -> 237378 281334 -> 221469 82226 -> 437101 147759 -> 194431 92421 -> 155832 165541 -> 262685 61525 -> 421896 48523 -> 417068 241519 -> 28...
output:
543320499
result:
ok single line: '543320499'
Test #57:
score: 1
Accepted
time: 274ms
memory: 76096kb
input:
380185 755803 1693 3000 70077 -> 240501 280229 -> 378190 294133 -> 300954 326283 -> 197649 224178 -> 13718 128112 -> 168290 201313 -> 164129 275592 -> 173651 344857 -> 265347 356698 -> 202212 372595 -> 187684 69126 -> 231807 16764 -> 327246 52719 -> 96866 117914 -> 143661 238887 -> 286402 112814 -> ...
output:
678846323
result:
ok single line: '678846323'
Subtask #5:
score: 1
Accepted
Test #58:
score: 1
Accepted
time: 271ms
memory: 64932kb
input:
324219 964928 3000 2999 225338 -> 99336 238630 -> 81437 15635 -> 212723 28808 -> 66657 155734 -> 159393 21200 -> 169542 166398 -> 212810 49801 -> 59110 225342 -- 33239 103624 -> 282192 310894 -> 106042 82787 -> 45950 78852 -> 323358 110462 -> 271102 43363 -> 128811 288100 -> 96678 256048 -> 210282 1...
output:
961630822
result:
ok single line: '961630822'
Test #59:
score: 1
Accepted
time: 300ms
memory: 61996kb
input:
335915 999997 3000 3000 141647 -> 248728 312284 -> 164046 246489 -> 160827 176634 -> 61814 131672 -> 259268 99109 -> 202553 30505 -> 320311 88121 -> 143536 12020 -> 157399 285428 -> 51331 99433 -> 38255 316725 -> 281535 92861 -> 223126 176662 -> 333783 56322 -> 147032 9058 -> 217213 112326 -> 254017...
output:
89141898
result:
ok single line: '89141898'
Test #60:
score: 1
Accepted
time: 369ms
memory: 92020kb
input:
498000 990000 3000 3000 320086 -> 224040 221015 -> 423374 216797 -> 244608 116304 -> 267655 74252 -> 454775 251028 -> 486728 450965 -> 243202 186182 -> 306835 165303 -> 98355 338021 -> 336805 210191 -> 488691 112335 -> 218451 204782 -> 318328 350908 -> 85565 29841 -> 456370 411072 -> 30814 184962 ->...
output:
779066732
result:
ok single line: '779066732'
Test #61:
score: 1
Accepted
time: 287ms
memory: 65916kb
input:
335328 999996 2994 2994 287254 -> 328340 188470 -> 158916 300591 -> 223951 194093 -> 267531 268885 -> 286374 109976 -> 151609 71461 -> 266471 173387 -> 219819 61690 -> 60920 68864 -> 332899 72682 -> 204279 281472 -> 260132 169574 -> 69120 229040 -> 263364 245379 -> 21955 292360 -> 123203 269208 -> 1...
output:
445699418
result:
ok single line: '445699418'
Test #62:
score: 1
Accepted
time: 239ms
memory: 73312kb
input:
336724 667500 3000 2995 242196 -> 142725 12948 -> 18459 263335 -> 91844 284636 -> 259298 42235 -> 142504 1720 -> 282545 47603 -> 248538 22229 -> 231359 18117 -> 286187 71035 -> 312020 233316 -> 155140 58979 -> 150002 51072 -> 191933 235094 -> 66873 48438 -> 227929 31494 -> 163988 142900 -> 256484 18...
output:
859446722
result:
ok single line: '859446722'
Test #63:
score: 1
Accepted
time: 398ms
memory: 90728kb
input:
497315 989681 2998 2468 256141 -> 220726 442413 -> 384445 380176 -> 258002 323593 -> 286614 360478 -> 203175 382686 -> 184775 176310 -> 209687 84031 -> 409056 155136 -> 91889 370868 -> 256754 159592 -> 250915 67496 -> 181032 419043 -> 378501 189997 -> 362007 159897 -> 285667 357699 -> 91293 6866 -> ...
output:
99765246
result:
ok single line: '99765246'
Test #64:
score: 1
Accepted
time: 182ms
memory: 82336kb
input:
426235 846260 3000 2897 3006 -- 3007 3010 -- 3011 3026 -- 3027 3028 -- 3029 3032 -- 3033 3032 -- 3034 3035 -- 3036 3038 -- 3039 3038 -- 3040 3043 -- 3044 3046 -- 3047 3048 -- 3049 3052 -- 3053 3052 -- 3054 3052 -- 3055 3057 -- 3058 3063 -- 3064 3065 -- 3066 3065 -- 3067 3068 -- 3069 3068 -- 3070 306...
output:
632855874
result:
ok single line: '632855874'
Test #65:
score: 1
Accepted
time: 420ms
memory: 92680kb
input:
500000 994000 3000 3000 423863 -> 166344 345305 -> 168235 379618 -> 259302 147090 -> 137936 286046 -> 187488 442926 -> 291256 30938 -> 122467 313124 -> 197522 427910 -> 66884 202831 -> 481101 269202 -> 436363 220430 -> 405699 358256 -> 349844 54089 -> 363863 40418 -> 96892 113659 -> 449289 230667 ->...
output:
454492490
result:
ok single line: '454492490'
Test #66:
score: 1
Accepted
time: 0ms
memory: 22824kb
input:
4500 4500 1500 3000 1502 -- 1503 1502 -- 1504 1506 -- 1507 1509 -- 1510 1509 -- 1511 1509 -- 1512 1513 -- 1514 1513 -- 1515 1517 -- 1518 1520 -- 1521 1522 -- 1523 1524 -- 1525 1524 -- 1526 1527 -- 1528 1529 -- 1530 1529 -- 1531 1533 -- 1534 1533 -- 1535 1536 -- 1537 1536 -- 1538 1539 -- 1540 1541 --...
output:
254902877
result:
ok single line: '254902877'
Test #67:
score: 1
Accepted
time: 6ms
memory: 24516kb
input:
3000 3000 20 2980 21 -- 22 21 -- 23 21 -- 24 21 -- 25 21 -- 26 21 -- 27 21 -- 28 21 -- 29 21 -- 30 21 -- 31 21 -- 32 21 -- 33 21 -- 34 21 -- 35 21 -- 36 21 -- 37 21 -- 38 21 -- 39 21 -- 40 21 -- 41 21 -- 42 21 -- 43 21 -- 44 21 -- 45 21 -- 46 21 -- 47 21 -- 48 21 -- 49 21 -- 50 21 -- 51 21 -- 52 21 ...
output:
115775179
result:
ok single line: '115775179'
Subtask #6:
score: 1
Accepted
Test #68:
score: 1
Accepted
time: 32ms
memory: 44196kb
input:
100000 120000 40000 40000 64472 -> 64471 89344 -> 63610 47220 -> 47219 58030 -> 58029 8635 -> 98063 84959 -> 69963 81331 -> 69822 50779 -> 50778 10707 -> 50707 79454 -> 79453 89874 -> 44613 95442 -> 99600 1436 -> 87147 70359 -> 70358 83184 -> 95508 37154 -> 77154 83277 -> 42911 21371 -> 99760 50687 ...
output:
390851237
result:
ok single line: '390851237'
Test #69:
score: 1
Accepted
time: 50ms
memory: 41168kb
input:
100000 129998 40000 30000 87965 -> 89030 84339 -> 59102 25830 -> 96999 44772 -> 44771 79956 -> 69883 85188 -> 72355 67549 -> 67548 94900 -> 47080 1891 -> 70000 64126 -> 64125 89336 -> 83726 86298 -> 51667 25873 -> 72406 89560 -> 48041 72955 -> 80369 8727 -> 83118 49673 -> 49672 73465 -> 68293 44574 ...
output:
85201980
result:
ok single line: '85201980'
Test #70:
score: 1
Accepted
time: 70ms
memory: 44352kb
input:
99999 233331 33333 33333 86572 -> 83970 22577 -> 88395 31395 -> 31396 17804 -> 73548 26260 -> 76907 24871 -> 82282 87760 -> 45096 39940 -> 39939 15306 -> 15305 96508 -> 63213 9574 -> 9573 9969 -> 88462 15976 -> 87850 88318 -> 95886 76805 -> 95153 81936 -> 92928 37262 -> 37263 9960 -> 76381 43674 -> ...
output:
425200218
result:
ok single line: '425200218'
Test #71:
score: 1
Accepted
time: 37ms
memory: 36372kb
input:
99999 154599 44841 560 60511 -> 55307 53485 -> 68173 33079 -> 67957 19061 -> 76023 82802 -> 87612 65232 -> 59075 73350 -> 82750 80360 -> 50532 77036 -> 68053 78232 -> 55136 58301 -> 71355 38163 -> 78168 20776 -> 94296 82128 -> 48788 4325 -> 52963 52168 -> 61991 45865 -> 85434 34907 -> 52586 89475 ->...
output:
850170958
result:
ok single line: '850170958'
Test #72:
score: 1
Accepted
time: 51ms
memory: 38916kb
input:
99976 138415 40000 25626 13411 -> 95581 73011 -> 91658 78736 -> 91939 80810 -> 43499 70227 -> 78306 30183 -> 82183 66604 -> 40157 94452 -> 65770 72973 -> 69724 65251 -> 65252 95610 -> 48069 49699 -> 49700 7317 -> 76016 86626 -> 67042 89177 -> 98426 97591 -> 79940 25824 -> 92638 82687 -> 96207 92681 ...
output:
919815863
result:
ok single line: '919815863'
Test #73:
score: 1
Accepted
time: 27ms
memory: 34132kb
input:
99639 99839 58700 300 187 -- 59001 225 -- 59001 232 -- 59001 319 -- 59001 180 -- 59002 183 -- 59002 186 -- 59002 169 -- 59003 171 -- 59003 172 -- 59003 175 -- 59003 178 -- 59003 170 -> 59004 59004 -> 59003 174 -- 59005 173 -- 59006 59006 -> 59005 59005 -> 59003 177 -- 59007 176 -> 59008 59008 -> 590...
output:
291285700
result:
ok single line: '291285700'
Test #74:
score: 1
Accepted
time: 36ms
memory: 37824kb
input:
98917 191154 5000 1061 5002 -- 5003 5013 -- 5014 5013 -- 5015 5017 -- 5018 5025 -- 5026 5057 -- 5058 5073 -- 5074 5088 -- 5089 5096 -- 5097 5099 -- 5100 5109 -- 5110 5112 -- 5113 5119 -- 5120 5130 -- 5131 5146 -- 5147 5149 -- 5150 5155 -- 5156 5158 -- 5159 5169 -- 5170 5169 -- 5171 5182 -- 5183 5188...
output:
662800219
result:
ok single line: '662800219'
Test #75:
score: 1
Accepted
time: 46ms
memory: 37804kb
input:
99172 144578 25000 32166 96256 -> 48263 77488 -> 79613 24405 -> 71264 72873 -> 86353 88783 -> 51562 97415 -> 34584 21873 -> 96989 10368 -> 69641 6107 -> 80482 64529 -> 36275 74421 -> 36715 80739 -> 76266 15564 -> 80496 80461 -> 51839 6263 -> 63029 22496 -> 63733 78142 -> 73225 16201 -> 81930 53088 -...
output:
428108577
result:
ok single line: '428108577'
Test #76:
score: 1
Accepted
time: 15ms
memory: 32288kb
input:
100000 100000 300 99700 301 -- 302 301 -- 303 301 -- 304 301 -- 305 301 -- 306 301 -- 307 301 -- 308 301 -- 309 301 -- 310 301 -- 311 301 -- 312 301 -- 313 301 -- 314 301 -- 315 301 -- 316 301 -- 317 301 -- 318 301 -- 319 301 -- 320 301 -- 321 301 -- 322 301 -- 323 301 -- 324 301 -- 325 301 -- 326 3...
output:
473235705
result:
ok single line: '473235705'
Subtask #7:
score: 1
Accepted
Test #77:
score: 1
Accepted
time: 89ms
memory: 51656kb
input:
195000 240000 75000 75000 163326 -> 173398 177679 -> 167910 57236 -> 168189 108808 -> 108807 172327 -> 151104 185166 -> 177133 174476 -> 79690 153939 -> 94296 42741 -> 186113 48452 -> 154363 167925 -> 174849 53978 -> 182387 45368 -> 180772 17460 -> 187836 181176 -> 166147 132059 -> 132058 132006 -> ...
output:
422670064
result:
ok single line: '422670064'
Test #78:
score: 1
Accepted
time: 86ms
memory: 56940kb
input:
216414 282828 75000 75000 78048 -> 78047 203753 -> 119484 95024 -> 95023 150539 -> 153542 115725 -> 115724 80200 -> 80199 13599 -> 168633 65876 -> 208240 187436 -> 143513 135612 -> 135611 63145 -> 170913 113932 -> 113931 196413 -> 126872 30164 -> 215464 110884 -> 110883 68393 -> 153132 209480 -> 962...
output:
520667174
result:
ok single line: '520667174'
Test #79:
score: 1
Accepted
time: 148ms
memory: 72764kb
input:
274998 399996 75000 75000 174803 -> 95346 37543 -> 176190 137781 -> 137780 264648 -> 207656 188178 -> 263545 250371 -> 170251 264382 -> 239795 226461 -> 113490 117297 -> 117296 11750 -> 222383 158450 -> 274095 95847 -> 95846 185363 -> 110191 91468 -> 91467 16403 -> 250638 102797 -> 102796 48818 -> 2...
output:
495690226
result:
ok single line: '495690226'
Test #80:
score: 1
Accepted
time: 339ms
memory: 88240kb
input:
499996 857136 71428 71428 283356 -> 138641 183828 -> 344461 222272 -> 212366 293886 -> 472552 230836 -> 129808 18002 -> 466804 394165 -> 280521 349530 -> 109763 351442 -> 144054 339692 -> 378190 345610 -> 430486 215199 -> 486632 179854 -> 497041 44820 -> 407807 343987 -> 185277 179173 -> 409634 4751...
output:
817816516
result:
ok single line: '817816516'
Test #81:
score: 1
Accepted
time: 301ms
memory: 79636kb
input:
375000 975000 75000 75000 303139 -> 200471 345193 -> 105416 66048 -> 284058 198185 -> 180133 154480 -> 287812 231604 -> 141362 316289 -> 162982 310319 -> 146916 57410 -> 57409 157027 -> 370327 58412 -> 58411 261750 -> 336447 226662 -> 131180 238456 -> 226181 103975 -> 103974 267833 -> 174605 54607 -...
output:
482293884
result:
ok single line: '482293884'
Test #82:
score: 1
Accepted
time: 381ms
memory: 93976kb
input:
499903 897417 75000 30578 415581 -> 348575 490527 -> 342253 237685 -> 406602 393879 -> 179240 14785 -> 304482 129408 -> 197621 447042 -> 131957 205276 -> 347740 298672 -> 209960 74507 -> 215057 488440 -> 161707 381405 -> 218089 161101 -> 267700 342191 -> 90711 489575 -> 263088 490822 -> 122217 33058...
output:
861407009
result:
ok single line: '861407009'
Test #83:
score: 1
Accepted
time: 346ms
memory: 93792kb
input:
499916 887906 75000 43110 328269 -> 293403 438222 -> 317206 52157 -> 131628 329342 -> 137950 179641 -> 415616 216239 -> 230494 313782 -> 307492 242755 -> 330644 325894 -> 170339 445256 -> 436260 427290 -> 82721 466453 -> 290095 311389 -> 372912 84845 -> 84846 361150 -> 300259 254805 -> 121136 493328...
output:
669202168
result:
ok single line: '669202168'
Test #84:
score: 1
Accepted
time: 353ms
memory: 92620kb
input:
499270 862441 75000 54756 386858 -> 240291 263704 -> 482220 189495 -> 78062 346890 -> 295667 207090 -> 116080 6986 -> 139384 284241 -> 110451 486268 -> 355990 380628 -> 401915 41602 -> 353359 468348 -> 362313 311091 -> 370322 180684 -> 201200 205522 -> 126978 198234 -> 180574 466035 -> 173490 134782...
output:
928618818
result:
ok single line: '928618818'
Test #85:
score: 1
Accepted
time: 367ms
memory: 90440kb
input:
493940 970637 10000 6099 5282 -> 418389 387067 -> 358790 153325 -> 301770 235967 -> 102869 423459 -> 139191 430471 -> 121669 216144 -> 200731 402254 -> 477682 286386 -> 360681 386417 -> 391438 76994 -> 442301 11572 -> 11573 366644 -> 482239 397460 -> 63620 109352 -> 298323 202263 -> 81225 447808 -> ...
output:
262176563
result:
ok single line: '262176563'
Test #86:
score: 1
Accepted
time: 26ms
memory: 32460kb
input:
100000 100000 25000 75000 25001 -- 25002 25001 -- 25003 25004 -- 25005 25004 -- 25006 25004 -- 25007 25008 -- 25009 25010 -- 25011 25010 -- 25012 25010 -- 25013 25010 -- 25014 25015 -- 25016 25015 -- 25017 25018 -- 25019 25018 -- 25020 25018 -- 25021 25018 -- 25022 25023 -- 25024 25025 -- 25026 2502...
output:
440327864
result:
ok single line: '440327864'
Test #87:
score: 1
Accepted
time: 18ms
memory: 30392kb
input:
75000 75000 1000 74000 1001 -- 1002 1001 -- 1003 1001 -- 1004 1001 -- 1005 1001 -- 1006 1001 -- 1007 1001 -- 1008 1001 -- 1009 1001 -- 1010 1001 -- 1011 1001 -- 1012 1001 -- 1013 1001 -- 1014 1001 -- 1015 1001 -- 1016 1001 -- 1017 1001 -- 1018 1001 -- 1019 1001 -- 1020 1001 -- 1021 1001 -- 1022 1001...
output:
596675385
result:
ok single line: '596675385'
Subtask #8:
score: 1
Accepted
Test #88:
score: 1
Accepted
time: 391ms
memory: 87756kb
input:
480708 955454 2700 3000 388875 -> 70598 291012 -> 448536 286286 -> 309350 318088 -> 166350 282465 -> 24518 105434 -> 428582 311061 -> 54247 215036 -> 160493 466140 -> 380586 439211 -> 243679 62163 -> 4975 45626 -> 181790 193723 -> 291420 380938 -> 433052 175749 -> 245603 337566 -> 257546 215130 -> 1...
output:
494413606
result:
ok single line: '494413606'
Test #89:
score: 1
Accepted
time: 296ms
memory: 104580kb
input:
496008 644010 200000 148004 175624 -> 348004 378674 -> 441899 389873 -> 225480 342285 -> 342284 448597 -> 423730 322481 -> 322480 277684 -> 277683 77730 -> 274002 139051 -> 381500 322431 -> 322430 489893 -> 219415 112629 -> 486020 478810 -> 342275 321971 -> 321970 327088 -> 327087 363335 -> 270837 3...
output:
954229272
result:
ok single line: '954229272'
Test #90:
score: 1
Accepted
time: 286ms
memory: 108264kb
input:
498230 636232 222222 138004 480207 -> 453312 408631 -> 384309 485518 -> 308746 324825 -> 324824 388831 -> 358066 229161 -> 229160 385297 -> 397758 142702 -> 291224 297711 -> 297710 327537 -> 327536 397078 -> 274400 357082 -> 357081 77969 -> 364228 154283 -> 443734 310590 -> 310589 408847 -> 404403 4...
output:
258213809
result:
ok single line: '258213809'
Test #91:
score: 1
Accepted
time: 369ms
memory: 89944kb
input:
494975 949914 20000 20000 261730 -> 185565 254679 -> 172344 402359 -> 214906 373849 -> 428203 281645 -> 136091 125187 -> 341931 462640 -> 200091 142930 -> 365911 214071 -> 332071 82054 -> 244475 337852 -> 251558 410341 -> 407460 76984 -> 356551 160086 -> 256813 46085 -> 96998 145571 -> 388527 92468 ...
output:
301988351
result:
ok single line: '301988351'
Test #92:
score: 1
Accepted
time: 295ms
memory: 96500kb
input:
490490 703325 175132 102522 394663 -> 436412 314850 -> 309375 320686 -> 371482 488334 -> 328419 96749 -> 414442 94040 -> 404383 366135 -> 210530 136895 -> 476576 389095 -> 334418 438739 -> 448203 255070 -> 255071 159144 -> 435287 278187 -> 401207 451251 -> 442582 325692 -> 369099 380119 -> 461839 18...
output:
356999585
result:
ok single line: '356999585'
Test #93:
score: 1
Accepted
time: 299ms
memory: 96620kb
input:
489629 701603 175132 102522 290093 -> 390378 356326 -> 355703 375321 -> 392645 282398 -> 463683 357200 -> 337331 488131 -> 425351 21471 -> 280273 354128 -> 281531 241194 -- 241193 448565 -> 299914 424570 -> 454714 433928 -> 322270 132511 -> 310734 81945 -> 341620 397469 -> 329500 334702 -> 364841 23...
output:
281413111
result:
ok single line: '281413111'
Test #94:
score: 1
Accepted
time: 220ms
memory: 105460kb
input:
499666 499666 555 499111 453774 -> 453775 222037 -- 222038 137377 -> 137378 38271 -> 38272 17472 -> 17473 476139 -- 476138 169846 -> 169847 207291 -- 207292 154547 -> 154548 8870 -> 8871 30831 -> 30832 362516 -- 362517 338576 -> 338577 172299 -- 172300 120623 -> 120624 446255 -> 446256 174751 -> 174...
output:
839107374
result:
ok single line: '839107374'
Test #95:
score: 1
Accepted
time: 322ms
memory: 107428kb
input:
499998 725241 162132 112623 341397 -> 374082 124176 -> 281045 347309 -> 256265 175782 -> 175781 306343 -> 265795 484857 -> 349365 316079 -> 385399 437275 -> 344602 399491 -> 385783 107396 -> 297503 445444 -> 499594 279433 -> 403003 440757 -> 474391 382626 -> 171183 368658 -> 418373 422288 -> 337394 ...
output:
950977224
result:
ok single line: '950977224'
Subtask #9:
score: 1
Accepted
Test #96:
score: 1
Accepted
time: 205ms
memory: 94720kb
input:
400000 480000 160000 160000 199014 -> 199013 319909 -> 319908 76229 -> 399348 238306 -> 238305 8126 -> 311875 185637 -> 185636 126461 -> 392362 21942 -> 298059 370410 -> 272104 249737 -> 249736 318535 -> 318534 234868 -> 234867 325080 -> 349112 20659 -> 299342 97739 -> 222262 338648 -> 328963 140316...
output:
4265270
result:
ok single line: '4265270'
Test #97:
score: 1
Accepted
time: 197ms
memory: 93932kb
input:
400000 440000 200000 160000 213655 -> 213654 141244 -> 321244 34272 -> 234272 391609 -> 200628 104245 -> 395977 198826 -> 360000 2057 -> 392900 260177 -> 260176 89899 -> 280000 133322 -> 313322 56719 -> 256719 96221 -> 280000 186086 -> 360000 391991 -> 218045 163493 -> 343493 304605 -> 304604 4682 -...
output:
657564815
result:
ok single line: '657564815'
Test #98:
score: 1
Accepted
time: 236ms
memory: 89620kb
input:
399800 535200 160000 104400 11990 -> 347813 43117 -> 388588 18636 -> 389792 265659 -> 306852 26761 -> 331154 17056 -> 299531 376984 -> 253830 169502 -> 169501 97591 -> 331647 43086 -> 388588 32045 -> 280581 220537 -> 220536 343611 -> 230558 264727 -> 362930 398029 -> 360215 347175 -> 311219 179822 -...
output:
517228123
result:
ok single line: '517228123'
Test #99:
score: 1
Accepted
time: 142ms
memory: 72536kb
input:
351695 690082 10000 2033 10004 -- 10005 10004 -- 10006 10013 -- 10014 10020 -- 10021 10035 -- 10036 10051 -- 10052 10082 -- 10083 10108 -- 10109 10118 -- 10119 10130 -- 10131 10140 -- 10141 10143 -- 10144 10157 -- 10158 10162 -- 10163 10167 -- 10168 10177 -- 10178 10202 -- 10203 10219 -- 10220 10257...
output:
152169504
result:
ok single line: '152169504'
Test #100:
score: 1
Accepted
time: 143ms
memory: 75812kb
input:
400000 390000 200000 190000 397214 -> 321809 1775 -> 395712 391127 -> 340206 98658 -> 391031 32 -> 395653 124610 -> 391443 99658 -> 393513 36870 -> 395789 392209 -> 236442 190851 -> 396433 64890 -> 399931 58344 -> 391218 179191 -> 394322 396399 -> 335766 139821 -> 391380 74397 -> 391498 396514 -> 34...
output:
636653587
result:
ok single line: '636653587'
Test #101:
score: 1
Accepted
time: 238ms
memory: 80336kb
input:
398739 589694 101005 113657 221002 -> 218311 352101 -> 326228 354641 -> 247781 208866 -> 208868 107323 -> 107324 95463 -> 316173 370662 -> 345086 79339 -> 319336 278287 -> 273751 357843 -> 119724 211175 -> 211173 258599 -> 258631 275550 -> 366741 382366 -> 186180 262292 -> 141138 136592 -> 136590 34...
output:
544988618
result:
ok single line: '544988618'
Test #102:
score: 1
Accepted
time: 284ms
memory: 83712kb
input:
400000 800000 200000 200000 359851 -> 359852 372128 -> 372129 116523 -> 116524 45533 -> 45532 117553 -> 117552 393469 -> 393468 25021 -> 347834 88897 -> 211709 34060 -> 356872 154826 -> 277639 360611 -> 360610 85147 -> 207959 51939 -> 51938 299450 -> 299451 3388 -> 326201 190542 -> 313355 39778 -> 3...
output:
82670508
result:
ok single line: '82670508'
Test #103:
score: 1
Accepted
time: 310ms
memory: 75780kb
input:
400000 1000000 100000 100000 300216 -> 132051 206792 -> 137475 270981 -> 105536 246362 -> 329345 310023 -> 150748 74064 -> 74063 282562 -> 294000 324227 -> 119187 392908 -> 367647 388738 -> 110385 274556 -> 117511 288311 -> 392960 306262 -> 267516 75581 -> 75582 281193 -> 197754 322811 -> 161235 424...
output:
893358877
result:
ok single line: '893358877'
Test #104:
score: 1
Accepted
time: 271ms
memory: 77616kb
input:
333336 1000000 4 4 54584 -> 1908 254177 -> 151524 23413 -> 152185 73103 -> 189507 318163 -> 171383 316019 -> 251166 185330 -> 198652 207025 -> 157679 216474 -> 163209 7692 -> 207642 149446 -> 91364 246860 -> 207270 144017 -> 326578 16445 -> 115277 185377 -> 198013 4654 -> 314014 218151 -> 241357 331...
output:
15
result:
ok single line: '15'
Test #105:
score: 1
Accepted
time: 63ms
memory: 57176kb
input:
400000 400000 1000 399000 1001 -- 1002 1001 -- 1003 1001 -- 1004 1001 -- 1005 1001 -- 1006 1001 -- 1007 1001 -- 1008 1001 -- 1009 1001 -- 1010 1001 -- 1011 1001 -- 1012 1001 -- 1013 1001 -- 1014 1001 -- 1015 1001 -- 1016 1001 -- 1017 1001 -- 1018 1001 -- 1019 1001 -- 1020 1001 -- 1021 1001 -- 1022 1...
output:
584509931
result:
ok single line: '584509931'
Test #106:
score: 1
Accepted
time: 105ms
memory: 71944kb
input:
400000 400000 100000 300000 100001 -- 100002 100001 -- 100003 100004 -- 100005 100004 -- 100006 100007 -- 100008 100007 -- 100009 100007 -- 100010 100011 -- 100012 100011 -- 100013 100011 -- 100014 100011 -- 100015 100016 -- 100017 100016 -- 100018 100019 -- 100020 100019 -- 100021 100019 -- 100022 ...
output:
364667902
result:
ok single line: '364667902'
Subtask #10:
score: 1
Accepted
Test #107:
score: 1
Accepted
time: 266ms
memory: 105292kb
input:
500000 600000 200000 200000 490947 -> 451215 158625 -> 358625 4102 -> 441807 143729 -> 441350 467680 -> 337343 233111 -> 233110 389278 -> 389277 388075 -> 388074 245479 -> 245478 481355 -> 407929 100889 -> 488543 473277 -> 237338 133370 -> 459162 473784 -> 436652 320846 -> 320845 161395 -> 361395 42...
output:
340462744
result:
ok single line: '340462744'
Test #108:
score: 1
Accepted
time: 244ms
memory: 107348kb
input:
500000 567858 222222 209920 341288 -> 341287 399241 -> 399240 432431 -> 351525 407255 -> 407254 275923 -> 275922 13674 -> 450913 271189 -> 271188 461131 -> 497036 211113 -> 427184 194361 -> 410432 494008 -> 441531 440844 -> 482899 475944 -> 457798 444645 -> 463826 152684 -> 368755 148911 -> 364982 1...
output:
295693530
result:
ok single line: '295693530'
Test #109:
score: 1
Accepted
time: 275ms
memory: 113364kb
input:
499209 600492 198963 198963 427300 -> 462809 495566 -> 476874 426586 -> 463714 489550 -> 321501 464826 -> 441232 460972 -> 492665 241058 -> 241057 480311 -> 481893 77213 -> 448810 470253 -> 318403 102023 -> 295904 362798 -> 362797 108819 -> 289108 26483 -> 371444 185929 -> 431653 278786 -> 278785 36...
output:
27156851
result:
ok single line: '27156851'
Test #110:
score: 1
Accepted
time: 325ms
memory: 95808kb
input:
496840 742660 250000 1020 264920 -> 313092 231339 -> 306596 310244 -> 408000 400340 -> 455212 27053 -> 487331 291300 -> 280206 172713 -> 482531 26318 -> 276450 8422 -> 374144 17232 -> 307436 328041 -> 438123 217526 -> 455217 368261 -> 278888 441490 -> 404527 480297 -> 316397 461374 -> 310281 443898 ...
output:
229142308
result:
ok single line: '229142308'
Test #111:
score: 1
Accepted
time: 235ms
memory: 87892kb
input:
498585 666165 180000 151006 37061 -> 435056 358274 -> 396666 451153 -> 428256 167913 -> 456807 270877 -- 270950 293106 -- 293071 59018 -> 420164 399141 -> 398398 178678 -> 468990 205968 -- 205944 156980 -> 367491 446160 -> 413072 341017 -> 460452 463438 -> 398625 372636 -> 360334 472447 -> 387793 12...
output:
263470678
result:
ok single line: '263470678'
Test #112:
score: 1
Accepted
time: 215ms
memory: 91752kb
input:
498610 983676 10000 2238 10005 -- 10006 10011 -- 10012 10028 -- 10029 10031 -- 10032 10049 -- 10050 10059 -- 10060 10068 -- 10069 10075 -- 10076 10080 -- 10081 10105 -- 10106 10117 -- 10118 10119 -- 10120 10124 -- 10125 10129 -- 10130 10129 -- 10131 10133 -- 10134 10158 -- 10159 10191 -- 10192 10193...
output:
352087169
result:
ok single line: '352087169'
Test #113:
score: 1
Accepted
time: 176ms
memory: 105520kb
input:
500000 500000 1 499999 207717 -> 207718 479061 -> 479062 205174 -> 205175 489791 -> 489792 133413 -> 133414 419886 -> 419887 480214 -> 480215 86704 -- 86703 213375 -> 213376 101853 -> 101854 165466 -> 165467 393562 -> 393563 298592 -> 298593 340634 -> 340635 32536 -> 32537 233442 -> 233443 328155 ->...
output:
483815610
result:
ok single line: '483815610'
Test #114:
score: 1
Accepted
time: 379ms
memory: 91700kb
input:
498295 987924 4333 4333 65477 -> 397560 234456 -> 444087 336223 -> 461726 277289 -> 342287 477459 -> 355292 495663 -> 444091 361508 -> 470061 14364 -> 442921 28753 -> 306375 466300 -> 179218 282509 -> 94461 468703 -> 479055 377215 -> 130073 43390 -> 286528 423006 -> 351739 162845 -> 393997 458505 ->...
output:
581720061
result:
ok single line: '581720061'
Test #115:
score: 1
Accepted
time: 303ms
memory: 91252kb
input:
497286 725246 111717 192702 372291 -> 463758 15319 -> 331957 410429 -> 246825 359344 -> 319568 75481 -> 318124 23097 -> 387353 483774 -> 320048 46080 -> 429618 329285 -> 210098 72733 -> 411598 428938 -> 315224 124941 -> 124942 110646 -> 128574 57778 -> 444071 232020 -> 232019 399116 -> 359149 463313...
output:
258346896
result:
ok single line: '258346896'
Test #116:
score: 1
Accepted
time: 323ms
memory: 92928kb
input:
491159 764619 111717 105505 451524 -> 198253 250752 -> 434433 109799 -> 234176 297005 -> 290558 76851 -> 305542 277874 -> 358722 264288 -> 239921 295345 -> 460252 416821 -> 341684 290258 -> 392886 330962 -> 143914 320070 -> 224613 467749 -> 215292 487782 -> 202645 378695 -> 163595 65543 -> 311244 22...
output:
981886548
result:
ok single line: '981886548'
Test #117:
score: 1
Accepted
time: 97ms
memory: 65796kb
input:
500000 500000 5000 495000 5001 -- 5002 5001 -- 5003 5001 -- 5004 5001 -- 5005 5001 -- 5006 5001 -- 5007 5001 -- 5008 5001 -- 5009 5001 -- 5010 5001 -- 5011 5001 -- 5012 5001 -- 5013 5001 -- 5014 5001 -- 5015 5001 -- 5016 5001 -- 5017 5001 -- 5018 5001 -- 5019 5001 -- 5020 5001 -- 5021 5001 -- 5022 5...
output:
536327127
result:
ok single line: '536327127'
Test #118:
score: 1
Accepted
time: 109ms
memory: 64348kb
input:
500000 500000 5000 495000 5001 -- 5002 5001 -- 5003 5001 -- 5004 5001 -- 5005 5001 -- 5006 5001 -- 5007 5001 -- 5008 5001 -- 5009 5001 -- 5010 5001 -- 5011 5001 -- 5012 5001 -- 5013 5001 -- 5014 5001 -- 5015 5001 -- 5016 5001 -- 5017 5001 -- 5018 5001 -- 5019 5001 -- 5020 5001 -- 5021 5001 -- 5022 5...
output:
509835702
result:
ok single line: '509835702'
Extra Test:
score: 0
Extra Test Passed