Submission #968204

# Submission time Handle Problem Language Result Execution time Memory
968204 2024-04-23T08:29:18 Z Darren0724 Real Mountains (CCO23_day1problem2) C++17
25 / 25
1954 ms 145692 KB
#pragma GCC optimize("Ofast","O3")
#pragma GCC target("avx","avx2")
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long 
#define ll long long 
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
const int N=1000005;
const int mod=1e6+3;
const int INF=2e9;
int n;
struct segtree{
    int v[N<<2];
    void pull(int id){
        v[id]=min(v[id<<1],v[id<<1|1]);
    }
    void add(int id,int l,int r,int p,int x){
        if(r-l==1){
            v[id]=x;
            return;
        }
        int m=(l+r)>>1;
        if(p<m)add(id<<1,l,m,p,x);
        else add(id<<1|1,m,r,p,x);
        pull(id);
    }
    int ask(int id,int l,int r,int a,int b){
        if(a<=l&&b>=r)return v[id];
        int m=(l+r)>>1;
        if(b<=m)return ask(id<<1,l,m,a,b);
        if(a>=m)return ask(id<<1|1,m,r,a,b);
        return min(ask(id<<1,l,m,a,b),ask(id<<1|1,m,r,a,b));
    }
    void add(int a,int b){
        add(1,1,n+1,a,b);
    }
    int ask(int a,int b){
        return ask(1,1,n+1,a,b);
    }
}st;
int32_t main(){
    LCBorz;
    cin>>n;
    vector<int> v(n+2),pre(n+2),suf(n+2);
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    for(int i=1;i<=n;i++){
        pre[i]=max(pre[i-1],v[i]);
    }
    for(int i=n;i>=1;i--){
        suf[i]=max(suf[i+1],v[i]);
    }
    for(int i=1;i<=n;i++){
        st.add(1,1,n+1,i,v[i]);
    }
    ll ans=0;
    vector<pair<int,int>> leave,join;
    vector<int> tim;
    for(int i=1;i<=n;i++){
        join.push_back({v[i],i});
        leave.push_back({min(pre[i],suf[i]),i});
        tim.push_back(v[i]);
        tim.push_back(min(pre[i],suf[i]));
    }
    sort(all(tim));
    tim.resize(unique(all(tim))-tim.begin());
    sort(all(join),greater<>());
    sort(all(leave),greater<>());
    set<int> t;
    for(int i=0;i<(int)tim.size()-1;i++){
        int val=tim[i],val1=tim[i+1];
        while(join.size()&&join.back().first<=val){
            auto [a,b]=join.back();
            join.pop_back();
            st.add(b,INF);
            t.insert(b);
        }
        while(leave.size()&&leave.back().first<=val){
            auto [a,b]=leave.back();
            leave.pop_back();
            t.erase(b);
        }
        int m=t.size();
        if(m==0){
            continue;
        }
        auto cal=[&]()->ll {
            return 1ll*(val+val1-1)*(val1-val)/2%mod;
        };
        if(m==1){
            int p=*t.begin();
            ans+=cal()+1ll*(val1-val)*(st.ask(1,p)+st.ask(p+1,n+1));
            ans%=mod;
            continue;
        }
        int p1=*t.begin();
        int p2=*(--t.end());
        int tmp=st.ask(1,p1)+st.ask(p1+1,n+1)+st.ask(p2+1,n+1);
        int tmp1=st.ask(1,p2)+st.ask(p2+1,n+1)+st.ask(1,p1);
        ans+=1ll*(val1-val)*(min(tmp,tmp1)+1)+cal()*3;
        ans+=1ll*(m-2)*(3*cal()+2*(val1-val));
        ans%=mod;
    }
    cout<<ans<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 8 ms 1240 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1116 KB Output is correct
41 Correct 3 ms 1116 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 4 ms 1116 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 4 ms 1256 KB Output is correct
46 Correct 4 ms 1232 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
48 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 8 ms 1240 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1116 KB Output is correct
41 Correct 3 ms 1116 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 4 ms 1116 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 4 ms 1256 KB Output is correct
46 Correct 4 ms 1232 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
48 Correct 4 ms 1116 KB Output is correct
49 Correct 5 ms 1116 KB Output is correct
50 Correct 5 ms 1116 KB Output is correct
51 Correct 4 ms 1144 KB Output is correct
52 Correct 4 ms 1116 KB Output is correct
53 Correct 5 ms 1144 KB Output is correct
54 Correct 3 ms 1116 KB Output is correct
55 Correct 4 ms 1116 KB Output is correct
56 Correct 3 ms 1116 KB Output is correct
57 Correct 5 ms 1272 KB Output is correct
58 Correct 4 ms 1248 KB Output is correct
59 Correct 4 ms 1116 KB Output is correct
60 Correct 4 ms 1196 KB Output is correct
61 Correct 6 ms 1368 KB Output is correct
62 Correct 4 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1081 ms 135848 KB Output is correct
36 Correct 1059 ms 135916 KB Output is correct
37 Correct 1098 ms 134516 KB Output is correct
38 Correct 1148 ms 134508 KB Output is correct
39 Correct 1035 ms 134072 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 615 ms 134560 KB Output is correct
43 Correct 605 ms 134920 KB Output is correct
44 Correct 612 ms 134240 KB Output is correct
45 Correct 478 ms 134008 KB Output is correct
46 Correct 465 ms 134664 KB Output is correct
47 Correct 474 ms 134524 KB Output is correct
48 Correct 671 ms 134672 KB Output is correct
49 Correct 678 ms 135616 KB Output is correct
50 Correct 672 ms 133752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 8 ms 1240 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1116 KB Output is correct
41 Correct 3 ms 1116 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 4 ms 1116 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 4 ms 1256 KB Output is correct
46 Correct 4 ms 1232 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
48 Correct 4 ms 1116 KB Output is correct
49 Correct 1081 ms 135848 KB Output is correct
50 Correct 1059 ms 135916 KB Output is correct
51 Correct 1098 ms 134516 KB Output is correct
52 Correct 1148 ms 134508 KB Output is correct
53 Correct 1035 ms 134072 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 615 ms 134560 KB Output is correct
57 Correct 605 ms 134920 KB Output is correct
58 Correct 612 ms 134240 KB Output is correct
59 Correct 478 ms 134008 KB Output is correct
60 Correct 465 ms 134664 KB Output is correct
61 Correct 474 ms 134524 KB Output is correct
62 Correct 671 ms 134672 KB Output is correct
63 Correct 678 ms 135616 KB Output is correct
64 Correct 672 ms 133752 KB Output is correct
65 Correct 1750 ms 134624 KB Output is correct
66 Correct 1705 ms 134544 KB Output is correct
67 Correct 1794 ms 134732 KB Output is correct
68 Correct 1740 ms 135840 KB Output is correct
69 Correct 1788 ms 134632 KB Output is correct
70 Correct 633 ms 134580 KB Output is correct
71 Correct 593 ms 135016 KB Output is correct
72 Correct 618 ms 136092 KB Output is correct
73 Correct 830 ms 135536 KB Output is correct
74 Correct 814 ms 135532 KB Output is correct
75 Correct 847 ms 134448 KB Output is correct
76 Correct 1060 ms 134092 KB Output is correct
77 Correct 1014 ms 135544 KB Output is correct
78 Correct 996 ms 134356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1144 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 3 ms 1112 KB Output is correct
21 Correct 3 ms 1188 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 8 ms 1240 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1116 KB Output is correct
41 Correct 3 ms 1116 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 4 ms 1116 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 4 ms 1256 KB Output is correct
46 Correct 4 ms 1232 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
48 Correct 4 ms 1116 KB Output is correct
49 Correct 5 ms 1116 KB Output is correct
50 Correct 5 ms 1116 KB Output is correct
51 Correct 4 ms 1144 KB Output is correct
52 Correct 4 ms 1116 KB Output is correct
53 Correct 5 ms 1144 KB Output is correct
54 Correct 3 ms 1116 KB Output is correct
55 Correct 4 ms 1116 KB Output is correct
56 Correct 3 ms 1116 KB Output is correct
57 Correct 5 ms 1272 KB Output is correct
58 Correct 4 ms 1248 KB Output is correct
59 Correct 4 ms 1116 KB Output is correct
60 Correct 4 ms 1196 KB Output is correct
61 Correct 6 ms 1368 KB Output is correct
62 Correct 4 ms 1112 KB Output is correct
63 Correct 1081 ms 135848 KB Output is correct
64 Correct 1059 ms 135916 KB Output is correct
65 Correct 1098 ms 134516 KB Output is correct
66 Correct 1148 ms 134508 KB Output is correct
67 Correct 1035 ms 134072 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 615 ms 134560 KB Output is correct
71 Correct 605 ms 134920 KB Output is correct
72 Correct 612 ms 134240 KB Output is correct
73 Correct 478 ms 134008 KB Output is correct
74 Correct 465 ms 134664 KB Output is correct
75 Correct 474 ms 134524 KB Output is correct
76 Correct 671 ms 134672 KB Output is correct
77 Correct 678 ms 135616 KB Output is correct
78 Correct 672 ms 133752 KB Output is correct
79 Correct 1750 ms 134624 KB Output is correct
80 Correct 1705 ms 134544 KB Output is correct
81 Correct 1794 ms 134732 KB Output is correct
82 Correct 1740 ms 135840 KB Output is correct
83 Correct 1788 ms 134632 KB Output is correct
84 Correct 633 ms 134580 KB Output is correct
85 Correct 593 ms 135016 KB Output is correct
86 Correct 618 ms 136092 KB Output is correct
87 Correct 830 ms 135536 KB Output is correct
88 Correct 814 ms 135532 KB Output is correct
89 Correct 847 ms 134448 KB Output is correct
90 Correct 1060 ms 134092 KB Output is correct
91 Correct 1014 ms 135544 KB Output is correct
92 Correct 996 ms 134356 KB Output is correct
93 Correct 621 ms 137388 KB Output is correct
94 Correct 1050 ms 143732 KB Output is correct
95 Correct 939 ms 144224 KB Output is correct
96 Correct 949 ms 144140 KB Output is correct
97 Correct 1127 ms 143472 KB Output is correct
98 Correct 1132 ms 143512 KB Output is correct
99 Correct 1137 ms 143696 KB Output is correct
100 Correct 1879 ms 143824 KB Output is correct
101 Correct 1954 ms 143948 KB Output is correct
102 Correct 1830 ms 144148 KB Output is correct
103 Correct 1800 ms 145692 KB Output is correct
104 Correct 1914 ms 145288 KB Output is correct
105 Correct 576 ms 136380 KB Output is correct
106 Correct 606 ms 137268 KB Output is correct