1
+ #include < bits/stdc++.h>
2
+
3
+ #define fast ios_base::sync_with_stdio (0 );cin.tie(NULL );cout.tie(NULL )
4
+ #define f (i,a,b ) for (auto i=a;i<b;i++)
5
+ #define fi (i,a,b,x ) for (auto i=a;i<b;i=i+x)
6
+ #define fe (i,a,b ) for (auto i=a;i<=b;i++)
7
+ #define fr (i,a,b ) for (auto i=a;i>=b;i--)
8
+ #define loop (i, a ) for (auto i=a.begin();i!=a.end();i++)
9
+ #define endl ' \n '
10
+ #define sp ' \t '
11
+ #define ll long long int
12
+ #define ff first
13
+ #define ss second
14
+ #define pb push_back
15
+ #define mp make_pair
16
+ #define all (x ) x.begin(), x.end()
17
+ #define clr (x ) memset(x, 0 , sizeof (x))
18
+ #define sortall (x ) sort(all(x))
19
+ #define mod 1000000007
20
+ #define PI 3.1415926535897932384626
21
+ #define deb (x ) cout<<#x<<" =" <<x<<endl
22
+ #define deb2 (x, y ) cout<<#x<<" = " <<x<<" ," <<#y<<" = " <<y<<endl
23
+
24
+ using namespace std ;
25
+
26
+ template <typename T>
27
+ void print (vector<T>& a, char sep)
28
+ {
29
+ for (auto i : a) { cout<<i<<sep; }
30
+ }
31
+
32
+ ll mod_opr (ll num)
33
+ {
34
+ return (num + mod) % mod;
35
+ }
36
+
37
+ template <typename T>
38
+ bool compare (T x, T y)
39
+ {
40
+ return x > y ? true : false ;
41
+ }
42
+
43
+ bool pair_Compare (const pair<int , int >&a, const pair<int , int >&b)
44
+ {
45
+ return a.second < b.second ;
46
+ }
47
+
48
+ int main ()
49
+ {
50
+
51
+ // ONLINE_JUDGE
52
+ #ifndef rahulbordoloi
53
+ freopen (" input.txt" , " r" , stdin);
54
+ // freopen("output.txt", "w", stdin);
55
+ #endif
56
+
57
+ // Code
58
+ fast;
59
+ ll n;
60
+ cin>>n;
61
+ vector<ll> array (n); // {1,2,3,4,1,2,3,1,2,1,1,1,9}
62
+ for (auto & i : array){
63
+ cin>>i;
64
+ }
65
+ map<ll, ll> freq;
66
+ for (auto i : array){
67
+ freq[i]++;
68
+ }
69
+
70
+ for (auto i : freq){
71
+ cout<<i.ff <<sp<<i.ss <<endl;
72
+ }
73
+
74
+ ll max = INT_MIN;
75
+ for (auto i : freq){
76
+ if (i.ss > max) max = i.ss ;
77
+ }
78
+
79
+ cout<<" Max Value : " <<max<<endl;
80
+ cout<<" First : " <<max_element (freq.begin (), freq.end (), pair_Compare)->first <<endl;
81
+
82
+ cerr<<" TIME : " <<(float )clock ()<<" ms" <<endl;
83
+ return 0 ;
84
+
85
+ }
0 commit comments