Pagini recente » Cod sursa (job #1079371) | Cod sursa (job #2100676) | Cod sursa (job #2036403) | Rating Dan Andrei (danu223) | Cod sursa (job #694427)
Cod sursa(job #694427)
#include<stdio.h>
#include<vector>
#include<algorithm>
#define MOD 999983
#define Nmax 1025
#define pb push_back
#define mp make_pair
#define s first
#define x1 second.first
#define x2 second.second
#define LL long long
using namespace std;
LL j,n,S,i,sol,a[Nmax];
vector<pair<LL,pair<LL,LL> > > H[MOD];
vector<pair<LL,pair<LL,LL> > >::iterator it;
void insert(LL x)
{
H[x%MOD].pb(mp(x,mp(i,j)));
}
int OK(pair<LL,pair<LL,LL> > X,LL i,LL j,LL x)
{
if (X.s!=x) return 0;
if (X.x1==i) return 0;
if (X.x2==i) return 0;
if (X.x1==j) return 0;
if (X.x2==j) return 0;
return 1;
}
void search(LL x)
{
for (it=H[x%MOD].begin();it!=H[x%MOD].end();it++)
if (OK(*it,i,j,x))
sol++;
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%lld%lld",&n,&S);
for (i=1;i<=n;i++)
scanf("%lld",&a[i]);
for (i=1;i<=n;i++)
for (j=i+1;j<=n;j++)
if (i!=j) insert(a[i]+a[j]);
for (i=1;i<=n;i++)
for (j=i+1;j<=n;j++)
if (i!=j) search(S-a[i]-a[j]);
printf("%lld\n",sol/6);
}