-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.cpp
More file actions
44 lines (32 loc) · 908 Bytes
/
rectangle.cpp
File metadata and controls
44 lines (32 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// uncomment the two following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int N;
cin >> N;
vector<long long> S(N);
for (int i = 0; i < N; ++i)
cin >> S[i];
long long A = 0;
// INSERT YOUR CODE HERE
sort (S.begin(), S.end());
reverse (S.begin(), S.end());
vector<long long> a(0);
for (int i=0; i<N; i++) {
if (i != N-1) if (S[i] == S[i+1]) {
a.push_back (S[i++]);
if (a.size() == 2) break;
}
}
if (a.size() == 2) A = a[0] * a[1];
else A = 0;
cout << A << endl;
return 0;
}