B. Makes And The Product
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i,  j,  k)(i < j < k), such that ai·aj·ak is minimum possible, are there in the array? Help him with it!

Input

The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array.

Output

Print one number — the quantity of triples (i,  j,  k) such that i,  j and k are pairwise distinct and ai·aj·ak is minimum possible.

Examples
input
4
1 1 1 1
output
4
input
5
1 3 2 3 4
output
2
input
6
1 3 3 1 3 2
output
1
Note

In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.

In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.

In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices.

题意:

给一串数字,在其中选三个数字,使得这三个数字的乘积最小,问有多少个这样的组合

思路:

直接排序乘积最小那么这三个数字必定是最小的三个,又因为数字可能相同,会产成不同结果的情况一共有三种:

1.三个数字都相同 。

2.第一个和第二个不同,第二个与第三个相同。

3.第二个和第三个不同。

实现代码:

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
map<ll,ll>mp;
int main()
{
ll m,i,a[];
cin>>m;
for(i=;i<m;i++){
cin>>a[i];
mp[a[i]]++;}
sort(a,a+m);
ll sum = ;
if(a[]==a[]&&a[]==a[]){
ll num = mp[a[]];
sum = (num*(num-)*(num-))/;
}
if(a[]!=a[]){
ll num = mp[a[]];
sum = num;
}
if(a[]!=a[]&&a[]==a[]){
ll num = mp[a[]];
// num = 99999;
sum = (num*(num-))/;
} cout<<sum<<endl;
}

Educational Codeforces Round 23 B. Makes And The Product的更多相关文章

  1. Educational Codeforces Round 23 E. Choosing The Commander trie数

    E. Choosing The Commander time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Educational Codeforces Round 23.C

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. Educational Codeforces Round 23 F. MEX Queries 离散化+线段树

    F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Educational Codeforces Round 23 D. Imbalanced Array 单调栈

    D. Imbalanced Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 23 C. Really Big Numbers 暴力

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Educational Codeforces Round 23 补题小结

    昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...

  7. Educational Codeforces Round 23

    A题 分析:注意两个点之间的倍数差,若为偶数则为YES,否则为NO #include "iostream" #include "cstdio" #include ...

  8. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  9. Educational Codeforces Round 40千名记

    人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...

随机推荐

  1. oracle 记录被另一个用户锁住

    第一步:查询处用户,被锁表名,sessionID select b.owner,b.object_name,l.session_id,l.locked_modefrom v$locked_object ...

  2. I2S音频总线学习

    IIS音频总线学习(一)数字音频技术 一.声音的基本概念 声音是通过一定介质传播的连续的波. 图1 声波 重要指标: 振幅:音量的大小 周期:重复出现的时间间隔 频率:指信号每秒钟变化的次数 声音按频 ...

  3. CF888G Xor-MST 生成树、分治、Trie树合并

    传送门 第一次接触到Boruvka求最小生成树 它的原版本是:初始每一个点构成一个连通块,每一次找到每一个连通块到其他的连通块权值最短的边,然后合并这两个连通块.因为每一次连通块个数至少减半,所以复杂 ...

  4. 在angularjs实现一个时钟

    想在网页上,显示当前系统时钟. <body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind ...

  5. International Programming Retreat Day(2018.11.17)

    时间:2018.11.17地点:北京国华投资大厦

  6. WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法

    原文:WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法 WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法        最近在做 ...

  7. WPF 滚动文字控件MarqueeControl

    原文:WPF 滚动文字控件MarqueeControl WPF使用的滚动文字控件,支持上下左右滚动方式,支持设置滚动速度 XAML部分: <UserControl x:Class="U ...

  8. Python高级特性(切片,迭代,列表生成式,生成器,迭代器)

    掌握了Python的数据类型.语句和函数,基本上就可以编写出很多有用的程序了. 比如构造一个1, 3, 5, 7, ..., 99的列表,可以通过循环实现: L = [] n = 1 while n ...

  9. Docker系列学习

    一.Docker入门 1.Docker概述与安装 2.Docker镜像管理 3.Docker容器管理 4.Docker数据管理 5.Docker网络配置 6.Docker图形化管理 7.Docker监 ...

  10. 撰写POPUSH需求文档

    不当家不知柴米贵,撰写了正规的软件需求文档才知道软件工程的复杂性 感谢@洪宇@王需@江林楠下午的加班加点,五个人正闷在406B奋斗中,加油!