QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165361#7111. Press the ButtonikunsomeAC ✓22ms11044kbC++2320.3kb2023-09-05 17:43:432023-09-05 17:43:44

Judging History

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

  • [2023-09-05 17:43:44]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:11044kb
  • [2023-09-05 17:43:43]
  • 提交

answer

#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#include <math.h>
#include <string>
#define bit(x) (1LL << (x))
#define lowbit(x) (x & (-x))
#define SQU(x) ((x) * (x))
#define ls id << 1
#define rs id << 1 | 1
#define int long long//////////////////////////////////////////
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=620;
const int INF=0x3f3f3f3f;
const int inf=0x3f3f3f3f;
#define ll long long
#define llu unsigned ll
using namespace std;
const int LINF=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
//const int inv2=(mod+1)/2;
// x3=x2-y2+y1,y3=y2+x2-x1;正方形对角,另外两点公式
// x4=x1-y2+y1,y4=y1+x2-x1;
int MaximumWeightedMatchingn,MaximumWeightedMatchingm;
struct MaximumWeightedMatching{
    struct node{
        int x,y,z;
        node(){}
        node(int a,int b,int c){
            x=a,y=b,z=c;
        }
    }g[maxn][maxn];
    int nx,t,lab[maxn],match[maxn],slack[maxn];
    int st[maxn],pa[maxn],flower_from[maxn][maxn],S[maxn],vis[maxn];
    vector<int>flower[maxn];
    deque<int>q;
    void Init(){
        for(int x=1;x<=MaximumWeightedMatchingn;x++)
            for(int y=1;y<=MaximumWeightedMatchingn;y++ )
                g[x][y]=node(x,y,0);
    }
    int dist(node e){
        return lab[e.x]+lab[e.y]-g[e.x][e.y].z*2;
    }
    void update_slack(int x,int y){
        if(!slack[y]||dist(g[x][y])<dist(g[slack[y]][y]))
            slack[y]=x;
    }
    void set_slack(int y){
        slack[y]=0;
        for(int x=1;x<=MaximumWeightedMatchingn;x++)
            if(g[x][y].z>0&&st[x]!=y&&S[st[x]]==0)
                update_slack(x,y);
    }
    void q_push(int x){
        if(x<=MaximumWeightedMatchingn) return q.push_back(x);
        for(int i=0;i<flower[x].size();i++) q_push(flower[x][i]);
    }
    void set_st(int x,int b){
        st[x]=b;
        if(x<=MaximumWeightedMatchingn) return;
        for(int i=0;i<flower[x].size();i++) set_st(flower[x][i],b);
    }
    int get_pr(int b,int xr){
        int pr=find(flower[b].begin(),flower[b].end(),xr)-flower[b].begin();
        if(pr%2==1){
            reverse(flower[b].begin()+1,flower[b].end());
            return flower[b].size()-pr;
        }
        else return pr;
    }
    void set_match(int x,int y){
        match[x]=g[x][y].y;
        if(x<=MaximumWeightedMatchingn) return;
        node e=g[x][y];
        int xr=flower_from[x][e.x],pr =get_pr(x,xr);
        for(int i=0;i<pr;i++)
            set_match(flower[x][i],flower[x][i^1]);

        set_match(xr,y);
        rotate(flower[x].begin(),flower[x].begin()+pr,flower[x].end());
    }
    void augment(int x,int y){
        int xnv=st[match[x]];
        set_match(x,y);
        if(!xnv) return;
        set_match(xnv,st[pa[xnv]]);
        augment(st[pa[xnv]],xnv);
    }
    int get_lca(int x,int y){
        for(++t;x||y;swap(x,y)){
            if(x==0) continue;
            if(vis[x]==t) return x;
            vis[x]=t;
            x=st[match[x]];
            if(x) x=st[pa[x]];
        }
        return 0;
    }
    void add_blossom(int x,int lca,int y){
        int b=MaximumWeightedMatchingn+1;
        while(b<=nx&&st[b]) b++;
        if(b>nx) nx++;
        lab[b]=0,S[b]=0;
        match[b]=match[lca];
        flower[b].clear();
        flower[b].push_back(lca);
        for(int xx=x,yy;xx!=lca;xx=st[pa[yy]])
            flower[b].push_back(xx),flower[b].push_back(yy=st[match[xx]]),q_push(yy);
        reverse(flower[b].begin()+1,flower[b].end());
        for(int xx=y,yy;xx!=lca;xx=st[pa[yy]])
            flower[b].push_back(xx),flower[b].push_back(yy=st[match[xx]]),q_push(yy);
        set_st(b,b);
        for(int xx=1;xx<=nx;xx++) g[b][xx].z=g[xx][b].z=0;
        for(int xx=1;xx<=MaximumWeightedMatchingn;xx++) flower_from[b][xx]=0;
        for(int i=0;i<flower[b].size();i++){
            int xs=flower[b][i];
            for(int xx=1;xx<=nx;xx++)
                if(g[b][xx].z==0||dist(g[xs][xx])<dist(g[b][xx]))
                    g[b][xx]=g[xs][xx],g[xx][b]=g[xx][xs];
            for(int xx=1;xx<=MaximumWeightedMatchingn;xx++)
                if(flower_from[xs][xx]) flower_from[b][xx]=xs;
        }
        set_slack(b);
    }
    void expand_blossom(int b){
        for(int i=0;i<flower[b].size();i++ )
            set_st(flower[b][i],flower[b][i]);
        int xr=flower_from[b][g[b][pa[b]].x],pr=get_pr(b,xr);
        for(int i=0;i<pr;i+=2){
            int xs=flower[b][i],xns=flower[b][i+1];
            pa[xs]=g[xns][xs].x;
            S[xs]=1,S[xns]=0;
            slack[xs]=0,set_slack(xns);
            q_push(xns);
        }
        S[xr]=1,pa[xr]=pa[b];
        for(int i=pr+1;i<flower[b].size();i++){
            int xs=flower[b][i];
            S[xs]=-1,set_slack(xs);
        }
        st[b] = 0;
    }
    bool on_found_edge(const node &e){
        int x=st[e.x],y=st[e.y];
        if(S[y]==-1){
            pa[y]=e.x,S[y]=1;
            int nu=st[match[y]];
            slack[y]=slack[nu]=0;
            S[nu]=0,q_push(nu);
        }
        else if(S[y]==0){
            int lca=get_lca(x,y);
            if (!lca) return augment(x,y),augment(y,x),true;
            else add_blossom(x,lca,y);
        }
        return false;
    }
    bool matching(void){
        memset(S,-1,sizeof(S));
        memset(slack,0,sizeof(slack));
        q.clear();
        for(int x=1;x<=nx;x++)
            if(st[x]==x&&!match[x]) pa[x]=0,S[x]=0,q_push(x);
        if(q.empty()) return false;
        while(1){
            while(q.size()){
                int x=q.front();
                q.pop_front();
                if(S[st[x]]==1) continue;
                for(int y=1;y<=MaximumWeightedMatchingn;y++)
                    if(g[x][y].z>0&&st[x]!=st[y]){
                        if(dist(g[x][y])==0){
                            if(on_found_edge(g[x][y])) return true;
                        }
                        else update_slack(x,st[y]);
                    }
            }
            int d=inf;
            for(int b=MaximumWeightedMatchingn+1;b<=nx;b++)
                if(st[b]==b&&S[b]==1) d=min(d,lab[b]/2);
            for(int x=1;x<=nx;x++)
                if(st[x]==x&&slack[x])
                {
                    if(S[x]==-1) d=min(d,dist(g[slack[x]][x]));
                    else if(S[x]==0) d=min(d,dist(g[slack[x]][x])/2);
                }
            for(int x=1;x<=MaximumWeightedMatchingn;x++){
                if(S[st[x]]==0){
                    if(lab[x]<=d) return false;
                    lab[x]-=d;
                }
                else if(S[st[x]]==1) lab[x]+=d;
            }
            for(int b=MaximumWeightedMatchingn+1;b<=nx;b++)
                if(st[b]==b){
                    if(S[st[b]]==0) lab[b]+=d*2;
                    else if (S[st[b]]==1) lab[b]-=d*2;
                }
            q.clear();
            for(int x=1;x<=nx;x++)
                if(st[x]==x&&slack[x]&&st[slack[x]]!=x&&dist(g[slack[x]][x])==0)
                    if(on_found_edge(g[slack[x]][x])) return true;
            for(int b=MaximumWeightedMatchingn+1;b<=nx;b++)
                if(st[b]==b&&S[b]==1&&lab[b]==0) expand_blossom(b);
        }
        return false;
    }
    pair<ll,int>weight_blossom(void){
        memset(match,0,sizeof(match));
        nx=MaximumWeightedMatchingn;
        int n_matches=0;
        ll tot_weight=0;
        for(int x=0;x<=MaximumWeightedMatchingn;x++)
            st[x]=x,flower[x].clear();
        int w_max=0;
        for(int x=1;x<=MaximumWeightedMatchingn;x++)
            for(int y=1;y<=MaximumWeightedMatchingn;y++)
            {
                flower_from[x][y]=(x==y?x:0);
                w_max=max(w_max,g[x][y].z);
            }
        for(int x=1;x<=MaximumWeightedMatchingn;x++) lab[x]=w_max;
        while(matching()) ++n_matches;
        for(int x=1;x<=MaximumWeightedMatchingn;x++)
            if(match[x]&&match[x]<x)
                tot_weight+=(ll)g[x][match[x]].z;
        return make_pair(tot_weight,n_matches);
    }
    void solve(){
        Init();
        for(int i=1;i<=MaximumWeightedMatchingm;i++){
            int t1,t2,t3;
            cin>>t1>>t2>>t3;
            g[t1][t2].z=g[t2][t1].z=t3;
        }
        cout<<weight_blossom().first<<'\n';
        for(int i=1;i<=MaximumWeightedMatchingn;i++) cout<<match[i]<<" \n"[i==MaximumWeightedMatchingn];
    }
};
const int bn=1e3+10;
struct Blossom{//add(u,v),blossom(now);
    int ans,cnt;
    Blossom(){
        ans=cnt=0;
    }
    queue<int>que;
    vector<vector<int>>adj=vector<vector<int>>(bn);
    vector<int>color=vector<int>(bn,0),match=vector<int>(bn,0),
            pre=vector<int>(bn,0),fa=vector<int>(bn),vis=vector<int>(bn,0);
    void add(int u,int v){
        if(!match[u]&&!match[v]){
            ans++;
            match[u]=v;
            match[v]=u;
        }
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int find(int a){
        if(fa[a]==a)return a;
        return fa[a]=find(fa[a]);
    }
    int lca(int u,int v){
        u=find(u);v=find(v);
        for(++cnt;vis[u]!=cnt;){
            vis[u]=cnt;
            u=find(pre[match[u]]);
            if(v)swap(u,v);
        }
        return u;
    }
    void shrink(int u,int v,int root){
        while(find(u)!=root){
            pre[u]=v;
            v=match[u];
            if(color[v]==2){
                color[v]=1;
                que.push(v);
            }
            if(find(u)==u)fa[u]=root;
            if(find(v)==v)fa[v]=root;
            u=pre[v];
        }
    }
    void init(){
        for(int i=1;i<=bn;i++){
            pre[i]=color[i]=0;
            fa[i]=i;
        }
    }
    bool update(int v){
        while(v){
            int temp=match[pre[v]];
            match[v]=pre[v];
            match[pre[v]]=v;
            v=temp;
        }
        return true;
    }
    bool blossom(int now){
        que=queue<int>();
        init();
        color[now]=1;
        que.push(now);
        while(que.size()){
            int u=que.front();
            que.pop();
            for(auto &v:adj[u]){
                if(find(u)==find(v)||color[v]==2)continue;
                if(color[v]){
                    int root=lca(u,v);
                    shrink(u,v,root);
                    shrink(v,u,root);
                }
                else{
                    color[v]=2;
                    pre[v]=u;
                    if(!match[v]){
                        return update(v);
                    }
                    else{
                        color[match[v]]=1;
                        que.push(match[v]);
                    }
                }
            }
        }
        return false;
    }
};
struct Edge{//MCF,MCMF
    int from,to,cap,flow,cost;
    Edge(int u,int v,int c,int f,int w):from(u),to(v),cap(c),flow(f),cost(w){}
};
const int MAXN=1000;//MCMF MCF
struct MCMF{//init(n) add(fr,to,cap,cost) MincostMaxflow(s,t,cost) MAXFLOW//zui xiao fei yong zui da liu
    int n,m,inq[MAXN],d[MAXN],p[MAXN],a[MAXN];
    vector<Edge> edges;
    vector<int> G[MAXN];
    void init(int n){
        this->n=n;
        for (int i=0;i<=n;i++)
            G[i].clear();
        edges.clear();
    }
    void AddEdge(int from,int to,int cap,int cost){
        edges.push_back(Edge(from,to,cap,0,cost));
        edges.push_back(Edge(to,from,0,0,-cost));
        m=edges.size();
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }
    bool BellmanFord(int s,int t,int&flow,long long&cost){
        for (int i=0;i<=n;i++)
            d[i]=INT_MAX;
        memset(inq,0,sizeof(inq));
        d[s]=0;
        inq[s]=1;
        p[s]=0;
        a[s]=INT_MAX;
        queue<int>Q;
        Q.push(s);
        while(!Q.empty()){
            int u=Q.front();
            Q.pop();
            inq[u]=0;
            for(int i=0;i<G[u].size();i++){
                Edge&e=edges[G[u][i]];
                if(e.cap>e.flow&&d[e.to]>d[u]+e.cost){
                    d[e.to]=d[u] + e.cost;
                    p[e.to]=G[u][i];
                    a[e.to]=min(a[u],e.cap-e.flow);
                    if(!inq[e.to]){
                        Q.push(e.to);
                        inq[e.to]=1;
                    }
                }
            }
        }
        if(d[t]==INT_MAX)return false;
        flow+=a[t];
        cost+=(long long)d[t]*(long long)a[t];
        for(int u=t;u!=s;u=edges[p[u]].from){
            edges[p[u]].flow+=a[t];
            edges[p[u]^1].flow-=a[t];
        }
        return true;
    }
    int MincostMaxflow(int s,int t,long long&cost){
        int flow=0;
        cost=0;
        while(BellmanFord(s,t,flow,cost));
        return flow;
    }
};
struct KM{//二分完全匹配最小权-最大权 km.add(fr,to,cost),km.init1(n),km.km() 最小权转负数
    int s[200],t[200],pii[200],slack[200],lx[200],ly[200],g[200][200],n;
    void add(int fr,int to,int cost){
        g[fr][to]=max(g[fr][to],cost);
    }
    void init1(int x){
        n=x;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                g[i][j]=-INF;//INF
    }
    void init2(){
        for(int i=1;i<=n;i++)slack[i]=INF;
    }
    void init3(){
        for(int i=1;i<=n;i++)
            s[i]=t[i]=0;
    }
    bool dfs(int u){
        s[u]=1;
        for(int v=1;v<=n;v++){
            if(!t[v]&&lx[u]+ly[v]==g[u][v]){
                t[v]=1;
                if(pii[v]==-1||dfs(pii[v])){
                    pii[v]=u;
                    return true;
                }
            }
            else slack[v]=min(lx[u]+ly[v]-g[u][v],slack[v]);
        }
        return false;
    }
    void update(){
        int ans=INF;
        for(int i=1;i<=n;i++){
            if(!t[i])ans=min(ans,slack[i]);
        }
        for(int i=1;i<=n;i++){
            if(s[i])lx[i]-=ans;
            if(t[i])ly[i]+=ans;
        }
    }
    void km(){
        for(int i=1;i<=n;i++){
            pii[i]=-1;
            lx[i]=-INF;ly[i]=0;//lx[i]=INF
            for(int j=1;j<=n;j++){
                lx[i]=max(lx[i],g[i][j]);//max->min
            }
        }
        for(int i=1;i<=n;i++){
            init2();
            while(true){
                init3();
                if(dfs(i))break;
                else update();
            }
        }
    }
};
const int SThashnum=1e3,SThashlength=1e3;
struct SThash{ // init() addstring(int now,string s) gethash(int now,int l,int r)//STHASH goto struct
    int f1[SThashnum][SThashlength],f2[SThashnum][SThashlength],f3[SThashnum][SThashlength];
    int pw1[SThashnum][SThashlength],pw2[SThashnum][SThashlength],pw3[SThashnum][SThashlength];
    const int mod1=998244353,mod2=1e9+7,mod3=1e9+9,bs=18492853;
    int v1,v2,v3;
    SThash(int v1=0,int v2=0,int v3=0):v1(v1),v2(v2),v3(v3){}
    bool operator<(const SThash&a)const{
        return v1<a.v1;
    }
    bool operator==(const SThash x) const{return v1==x.v1&&v2==x.v2&&v3==x.v3;}
    inline void init(){for(int i=1;i<=1000;i++)pw1[i][0]=pw2[i][0]=pw3[i][0]=1;}
    inline int addmod(int x,int mod){return x>=mod?x-mod:x;}
    inline int submod(int x,int mod){return x<0?x+mod:x;}
    SThash gethash(int now,int l,int r) {
        return SThash(submod(f1[now][r]-1ll*f1[now][l-1]*pw1[now][r-l+1]%mod1,mod1),
                      submod(f2[now][r]-1ll*f2[now][l-1]*pw2[now][r-l+1]%mod2,mod2),
                      submod(f3[now][r]-1ll*f3[now][l-1]*pw3[now][r-l+1]%mod3,mod3));
    }
    void addstring(int now,string s){
        for(int i=1;i<=s.length();i++){
            pw1[now][i]=1ll*pw1[now][i-1]*bs%mod1;
            pw2[now][i]=1ll*pw2[now][i-1]*bs%mod2;
            pw3[now][i]=1ll*pw3[now][i-1]*bs%mod3;
            f1[now][i]=addmod(1ll*f1[now][i-1]*bs%mod1+s[i],mod1);
            f2[now][i]=addmod(1ll*f2[now][i-1]*bs%mod2+s[i],mod2);
            f3[now][i]=addmod(1ll*f3[now][i-1]*bs%mod3+s[i],mod3);
        }
    }
};
const int MX=505;//Store_wagner MX
struct Stoer_Wagner{//init(n) add(fr,to,w) slove()
    int mp[MX][MX],s,t;
    int v[MX],d[MX];
    void init(int n){
        memset(mp,0,sizeof(mp));
    }
    void add(int u,int v,int w){
        mp[u][v]+=w;
        mp[v][u]+=w;
    }
    int solve(int n){
        int i,j,now,ret=inf;
        for(i=0; i<n;i++)v[i]=i;
        while(n>1){
            for(now=0,i=1;i<n;i++)d[v[i]]=0;
            for(i=1;i<n;i++){
                swap(v[now],v[i-1]);
                for(now=j=i; j<n ; j++){
                    d[v[j]] += mp[v[i-1]][v[j]];
                    if(d[v[now]]<d[v[j]]) now = j;
                }
            }
            if(ret>d[v[now]]){
                ret=d[v[now]];
                s=v[now-1];
                t=v[now];
            }
            for(j = 0; j<n; j++)
                mp[v[j]][v[now-1]]=mp[v[now-1]][v[j]]+=mp[v[j]][v[now]];
            v[now]=v[--n];
        }
        return ret;
    }
};
const int V = 1010;//FlowGraph F
const int E = 101000;//FlowGraph E
template<typename T>
struct FlowGraph{//init(s,t,n) add(fr,to,w) dinic() FLOWGragh<type>name
    int s,t,vtot;
    int head[V],etot;
    int dis[V],cur[V];
    struct edge{
        int v,nxt;
        T f;
    }e[E*2];
    void addedge(int u,int v, T f){
        e[etot]={v,head[u],f};head[u]=etot++;
        e[etot]={u,head[v],0};head[v]=etot++;
    }
    bool bfs(){
        for (int i=1;i<=vtot;i++){
            dis[i]=0;
            cur[i]=head[i];
        }
        queue<int> q;
        q.push(s);dis[s]=1;
        while(!q.empty()){
            int u=q.front();q.pop();
            for(int i=head[u];~i;i=e[i].nxt){
                if (e[i].f&&!dis[e[i].v]){
                    int v=e[i].v;
                    dis[v]=dis[u]+1;
                    if (v==t) return true;
                    q.push(v);
                }
            }
        }
        return false;
    }
    T dfs(int u,T m) {
        if(u==t)return m;
        T flow=0;
        for(int i=cur[u];~i;cur[u]=i=e[i].nxt)
            if (e[i].f&&dis[e[i].v]==dis[u]+1){
                T f=dfs(e[i].v,min(m,e[i].f));
                e[i].f-=f;
                e[i^1].f+=f;
                m-=f;
                flow+=f;
                if(!m)break;
            }
        if(!flow)dis[u]=-1;
        return flow;
    }
    T dinic(){
        T flow=0;
        while (bfs())flow+=dfs(s,numeric_limits<T>::max());
        return flow;
    }
    void init(int s_,int t_,int vtot_){
        s=s_;
        t=t_;
        vtot=vtot_;
        etot=0;
        for(int i=1;i<=vtot;i++)head[i]=-1;
    }
};
int gcd(int x, int y){
    x=labs(x);y=labs(y);
    while(y^=x^=y^=x%=y);
    return x;
}
ll qpow(ll x,ll y) {
    ll res = 1;
    while(y) {
        if(y&1)res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
void add(int &x,int y) {
    x+=y;
    if(x>=mod)x-=mod;
}
const int dx[]={1,0,-1,0};
const int dy[]={0,-1,0,1};


void solve() {
    int a,b,c,d,v,t;
    cin>>a>>b>>c>>d>>v>>t;
    if(a<=v||c<=v){
        cout<<t/a*b+t/c*d+b+d-1<<'\n';
        return;
    }
    int lcm=(a*c)/gcd(a,c);
    int cnt=0;
    while(t>=lcm){
        cnt++;
        t-=lcm;
    }
    auto getsum=[&](int x)->pair<int,int>{
        vector<pair<int,int>>ans;
        for(int i=0;a*i<=x;i++)ans.push_back(make_pair(a*i,b));
        for(int i=0;c*i<=x;i++)ans.push_back(make_pair(c*i,d));
        sort(ans.begin(),ans.end());
        int sum=0,now=0;
        for(auto &i:ans){
            if(!i.first){
                sum+=i.second;
                continue;
            }
            if(i.first>now+v)sum+=i.second-1;
            else sum+=i.second;
            now=i.first;
        }
        return ((ans[ans.size()-1].first+v>=(x+1))?make_pair(sum,1):make_pair(sum,0));
    };
    pair<int,int>sum1=getsum(lcm-1);
    pair<int,int>sum2=getsum(t);
    cout<<(sum1.second?(cnt*sum1.first+sum2.first-1):(cnt*sum1.first+sum2.first-(cnt+1)))<<'\n';
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed <<setprecision(20);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
/*
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3588kb

input:

2
8 2 5 1 2 18
10 2 5 1 2 10

output:

6
4

result:

ok 2 number(s): "6 4"

Test #2:

score: 0
Accepted
time: 3ms
memory: 3832kb

input:

1000
8 6 2 6 3 17
1 6 1 1 1 30
5 4 8 8 1 31
7 6 10 3 6 12
9 1 4 4 3 38
3 3 5 8 1 8
9 1 5 2 3 18
6 10 10 8 2 40
9 6 9 10 3 9
2 5 1 10 10 39
7 7 1 2 4 19
8 10 8 6 7 36
2 9 1 1 7 17
1 2 3 5 6 14
8 8 8 7 1 46
6 9 3 9 4 6
10 8 1 7 10 18
7 1 7 10 3 50
1 10 2 1 5 1
5 8 4 9 7 44
9 2 5 4 7 42
9 1 2 1 1 20
5 ...

output:

71
216
52
16
38
22
7
102
30
499
60
75
98
54
84
44
148
80
20
179
45
4
463
139
56
30
45
127
204
121
42
69
38
98
63
121
25
142
17
75
24
175
114
40
32
11
29
85
35
7
66
49
492
49
49
14
17
53
431
161
94
27
21
135
71
92
33
290
57
300
18
89
155
55
10
219
203
390
28
50
67
213
26
18
27
19
128
101
118
62
46
15...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 22ms
memory: 11044kb

input:

100
9 9 3 1 1 2
5 5 7 7 7 50
2 1 8 10 10 45
3 4 5 7 7 38
1 6 9 5 2 13
5 6 7 9 1 29
10 1 4 3 3 19
6 10 10 8 7 3
9 3 10 3 3 14
9 7 1 7 8 38
3 78 5 43 5 958
4 98 3 42 10 7
3 16 9 71 7 52
1 70 3 86 3 410
10 44 1 56 3 628
9 15 9 94 10 15
9 95 9 61 2 525
2 23 8 37 10 108
5 92 3 65 10 331
6 54 6 44 3 537
2...

output:

9
110
82
107
93
73
13
17
10
307
33215
321
713
40551
37995
217
9145
1782
13378
8730
270
2433
143
17
30
136
10
82
33
97
733
126
2917
623
364
1448
1212
872
268
1031
1601
3889
122
523
819
83
17513
277
2973
4651
202187
42602
17225
7881
32574
7087
4453
34029
20529
17520
58488
189327
14380
67133
90956
4328...

result:

ok 100 numbers

Extra Test:

score: 0
Extra Test Passed