Submission #882949

# Submission time Handle Problem Language Result Execution time Memory
882949 2023-12-04T08:25:51 Z tsumondai Real Mountains (CCO23_day1problem2) C++14
25 / 25
3619 ms 279816 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 1e6 + 5;

const int oo = 1e18, mod = 1e6 + 3;

int n, m, k, h[N];
map<int, vector<int>> add, del;
set<int> s;
int nodes[4*N];

void build(int id, int l, int r) {
	if (l == r) {
		nodes[id] = h[l];
		return;
	}

	int mid = (l + r) >> 1;

	build(id << 1, l, mid);
	build(id << 1 | 1, mid + 1, r);

	nodes[id] = min(nodes[id << 1], nodes[id << 1 | 1]);
}

void update(int id, int l, int r, int pos) {
	if (l == r) {
		nodes[id] = oo;
		return;
	}

	int mid = (l + r) >> 1;

	if (pos <= mid) update(id << 1, l, mid, pos);
	else update(id << 1 | 1, mid + 1, r, pos);

	nodes[id] = min(nodes[id << 1], nodes[id << 1 | 1]);
}

int get(int id, int l, int r, int u, int v) {
	if (u > r || v < l /*|| l>r || u>v*/) return oo;
	if (l >= u && r <= v) return nodes[id];
	int mid = (l + r) >> 1;
	return min(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
}

int calc(int l, int r) {
	if (s.empty()) return 0;
	int res = 0;
	int x = *s.begin(), y = *s.rbegin();
	int lx = get(1, 1, n, 1, x), ry = get(1, 1, n, y, n);
	int sum = ((r - l) * (l + r - 1) / 2) % mod;
	if (x == y) return ((lx + ry) * (r - l) + sum) % mod;
	int add = lx + ry + r;
	res = (res + add * (r - l)) % mod;
	int sz = (int)s.size();
	res = ((res + (3 * sum + 2 * (r - l)) * (sz - 1) - (r - l)) % mod + mod) % mod;
	return res;
}

void process() {
	cin >> n;
	foru(i, 1, n) {
		cin >> h[i];
		add[h[i]].pb(i);
	}
	build(1, 1, n);
	int p = max_element(h + 1, h + n + 1) - h;
	foru(i, 1, p) h[i] = max(h[i], h[i - 1]);
	ford(i, n, p) h[i] = max(h[i], h[i + 1]);
	foru(i, 1, n) del[h[i]].push_back(i);
	int pre = -1, ans = 0;
	for (auto &it : add) {
		if (pre != -1) ans = (ans + calc(pre, it.fi)) % mod;
		for (int x : it.se) {
			s.insert(x);
			update(1, 1, n, x);
		}
		for (int x : del[it.fi]) s.erase(x);
		pre = it.fi;
	}
	cout << ans << '\n';
	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 7 ms 5720 KB Output is correct
36 Correct 6 ms 5724 KB Output is correct
37 Correct 8 ms 5724 KB Output is correct
38 Correct 8 ms 5720 KB Output is correct
39 Correct 8 ms 5740 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 3 ms 4960 KB Output is correct
43 Correct 6 ms 5724 KB Output is correct
44 Correct 7 ms 5720 KB Output is correct
45 Correct 7 ms 5724 KB Output is correct
46 Correct 7 ms 5740 KB Output is correct
47 Correct 7 ms 5720 KB Output is correct
48 Correct 6 ms 5736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 7 ms 5720 KB Output is correct
36 Correct 6 ms 5724 KB Output is correct
37 Correct 8 ms 5724 KB Output is correct
38 Correct 8 ms 5720 KB Output is correct
39 Correct 8 ms 5740 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 3 ms 4960 KB Output is correct
43 Correct 6 ms 5724 KB Output is correct
44 Correct 7 ms 5720 KB Output is correct
45 Correct 7 ms 5724 KB Output is correct
46 Correct 7 ms 5740 KB Output is correct
47 Correct 7 ms 5720 KB Output is correct
48 Correct 6 ms 5736 KB Output is correct
49 Correct 5 ms 5724 KB Output is correct
50 Correct 5 ms 5724 KB Output is correct
51 Correct 5 ms 5724 KB Output is correct
52 Correct 5 ms 5764 KB Output is correct
53 Correct 5 ms 5724 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 6 ms 5936 KB Output is correct
58 Correct 5 ms 5724 KB Output is correct
59 Correct 5 ms 5728 KB Output is correct
60 Correct 5 ms 5728 KB Output is correct
61 Correct 7 ms 5724 KB Output is correct
62 Correct 5 ms 5924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 952 ms 93164 KB Output is correct
36 Correct 997 ms 93100 KB Output is correct
37 Correct 972 ms 93156 KB Output is correct
38 Correct 906 ms 93108 KB Output is correct
39 Correct 970 ms 93076 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 420 ms 90024 KB Output is correct
43 Correct 446 ms 90160 KB Output is correct
44 Correct 420 ms 89724 KB Output is correct
45 Correct 351 ms 93448 KB Output is correct
46 Correct 363 ms 93124 KB Output is correct
47 Correct 353 ms 93396 KB Output is correct
48 Correct 469 ms 93224 KB Output is correct
49 Correct 464 ms 93392 KB Output is correct
50 Correct 471 ms 93620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 7 ms 5720 KB Output is correct
36 Correct 6 ms 5724 KB Output is correct
37 Correct 8 ms 5724 KB Output is correct
38 Correct 8 ms 5720 KB Output is correct
39 Correct 8 ms 5740 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 3 ms 4960 KB Output is correct
43 Correct 6 ms 5724 KB Output is correct
44 Correct 7 ms 5720 KB Output is correct
45 Correct 7 ms 5724 KB Output is correct
46 Correct 7 ms 5740 KB Output is correct
47 Correct 7 ms 5720 KB Output is correct
48 Correct 6 ms 5736 KB Output is correct
49 Correct 952 ms 93164 KB Output is correct
50 Correct 997 ms 93100 KB Output is correct
51 Correct 972 ms 93156 KB Output is correct
52 Correct 906 ms 93108 KB Output is correct
53 Correct 970 ms 93076 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 420 ms 90024 KB Output is correct
57 Correct 446 ms 90160 KB Output is correct
58 Correct 420 ms 89724 KB Output is correct
59 Correct 351 ms 93448 KB Output is correct
60 Correct 363 ms 93124 KB Output is correct
61 Correct 353 ms 93396 KB Output is correct
62 Correct 469 ms 93224 KB Output is correct
63 Correct 464 ms 93392 KB Output is correct
64 Correct 471 ms 93620 KB Output is correct
65 Correct 3040 ms 208028 KB Output is correct
66 Correct 3303 ms 209056 KB Output is correct
67 Correct 3169 ms 207404 KB Output is correct
68 Correct 3221 ms 206800 KB Output is correct
69 Correct 3217 ms 207428 KB Output is correct
70 Correct 422 ms 89880 KB Output is correct
71 Correct 412 ms 89944 KB Output is correct
72 Correct 405 ms 89892 KB Output is correct
73 Correct 864 ms 207056 KB Output is correct
74 Correct 888 ms 207304 KB Output is correct
75 Correct 865 ms 206732 KB Output is correct
76 Correct 1501 ms 207536 KB Output is correct
77 Correct 1479 ms 208604 KB Output is correct
78 Correct 1426 ms 208264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4448 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4960 KB Output is correct
9 Correct 3 ms 4708 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 3 ms 4960 KB Output is correct
12 Correct 3 ms 4856 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4448 KB Output is correct
15 Correct 1 ms 4452 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 4960 KB Output is correct
18 Correct 3 ms 4964 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4856 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 3020 KB Output is correct
23 Correct 3 ms 864 KB Output is correct
24 Correct 3 ms 2912 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4964 KB Output is correct
27 Correct 4 ms 4960 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 7 ms 5720 KB Output is correct
36 Correct 6 ms 5724 KB Output is correct
37 Correct 8 ms 5724 KB Output is correct
38 Correct 8 ms 5720 KB Output is correct
39 Correct 8 ms 5740 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 3 ms 4960 KB Output is correct
43 Correct 6 ms 5724 KB Output is correct
44 Correct 7 ms 5720 KB Output is correct
45 Correct 7 ms 5724 KB Output is correct
46 Correct 7 ms 5740 KB Output is correct
47 Correct 7 ms 5720 KB Output is correct
48 Correct 6 ms 5736 KB Output is correct
49 Correct 5 ms 5724 KB Output is correct
50 Correct 5 ms 5724 KB Output is correct
51 Correct 5 ms 5724 KB Output is correct
52 Correct 5 ms 5764 KB Output is correct
53 Correct 5 ms 5724 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 6 ms 5936 KB Output is correct
58 Correct 5 ms 5724 KB Output is correct
59 Correct 5 ms 5728 KB Output is correct
60 Correct 5 ms 5728 KB Output is correct
61 Correct 7 ms 5724 KB Output is correct
62 Correct 5 ms 5924 KB Output is correct
63 Correct 952 ms 93164 KB Output is correct
64 Correct 997 ms 93100 KB Output is correct
65 Correct 972 ms 93156 KB Output is correct
66 Correct 906 ms 93108 KB Output is correct
67 Correct 970 ms 93076 KB Output is correct
68 Correct 1 ms 4444 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 420 ms 90024 KB Output is correct
71 Correct 446 ms 90160 KB Output is correct
72 Correct 420 ms 89724 KB Output is correct
73 Correct 351 ms 93448 KB Output is correct
74 Correct 363 ms 93124 KB Output is correct
75 Correct 353 ms 93396 KB Output is correct
76 Correct 469 ms 93224 KB Output is correct
77 Correct 464 ms 93392 KB Output is correct
78 Correct 471 ms 93620 KB Output is correct
79 Correct 3040 ms 208028 KB Output is correct
80 Correct 3303 ms 209056 KB Output is correct
81 Correct 3169 ms 207404 KB Output is correct
82 Correct 3221 ms 206800 KB Output is correct
83 Correct 3217 ms 207428 KB Output is correct
84 Correct 422 ms 89880 KB Output is correct
85 Correct 412 ms 89944 KB Output is correct
86 Correct 405 ms 89892 KB Output is correct
87 Correct 864 ms 207056 KB Output is correct
88 Correct 888 ms 207304 KB Output is correct
89 Correct 865 ms 206732 KB Output is correct
90 Correct 1501 ms 207536 KB Output is correct
91 Correct 1479 ms 208604 KB Output is correct
92 Correct 1426 ms 208264 KB Output is correct
93 Correct 414 ms 90108 KB Output is correct
94 Correct 1283 ms 277428 KB Output is correct
95 Correct 1208 ms 277696 KB Output is correct
96 Correct 1224 ms 277480 KB Output is correct
97 Correct 1738 ms 276984 KB Output is correct
98 Correct 1796 ms 278128 KB Output is correct
99 Correct 1747 ms 277316 KB Output is correct
100 Correct 3386 ms 279816 KB Output is correct
101 Correct 3506 ms 278316 KB Output is correct
102 Correct 3514 ms 278836 KB Output is correct
103 Correct 3619 ms 277512 KB Output is correct
104 Correct 3565 ms 278524 KB Output is correct
105 Correct 406 ms 89800 KB Output is correct
106 Correct 400 ms 89876 KB Output is correct