Problem:
Coin Combination Problem
You have 4 bags A, B, C and D each of which includes
N
coins (there are totally
4N
coins). Values of the coins in each bag are
a
i
,
b
i
,
c
i
and
d
i
respectively.
Find the number of combinations that result when you choose one coin from each bag (totally
4
coins) in such a way that the total value of the coins is
V
. You should distinguish the coins in a bag.
Constraints
1 ≤
N
≤ 1000
1 ≤
a
i
,
b
i
,
c
i
,
d
i
≤ 10
16
1 ≤
V
≤ 10
16
All input values are given in integers
Input
The input is given in the following format.
N
V
a
1
a
2
...
a
N
b
1
b
2
...
b
N
c
1
c
2
...
c
N
d
1
d
2
...
d
N
Output
Print the number of combinations in a line.
Sample Input 1
3 14
3 1 2
4 8 2
1 2 3
7 3 2
Sample Output 1
9
Sample Input 2
5 4
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Sample Output 2
625

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ll N,V; cin>>N>>V;
    vector<ll> A(N),B(N),C(N),D(N);
    for(ll& a:A) cin>>a;
    for(ll& a:B) cin>>a;
    for(ll& a:C) cin>>a;
    for(ll& a:D) cin>>a;

    vector<ll> M1(N*N),M2(N*N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            M1[N*i+j]=A[i]+B[j];
            M2[N*i+j]=C[i]+D[j];
        }
    }
    sort(M2.begin(),M2.end());

    ll ans=0;
    for(int i=0;i<N*N;i++){
        ans+=upper_bound(M2.begin(),M2.end(),V-M1[i])-lower_bound(M2.begin(),M2.end(),V-M1[i]);
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 180
memory_kb: 18824
final_rank: 5

code_snippet: #include<bits/stdc++.h>

using namespace std;

typedef long long ll;
ll a[1005],b[1005],c[1005],d[1005];
map<ll,ll> m;
int main(){
    ll N,V;
    cin>>N>>V;
    for(int i=0;i<N;i++) cin>>a[i];
    for(int i=0;i<N;i++) cin>>b[i];
    for(int i=0;i<N;i++) cin>>c[i];
    for(int i=0;i<N;i++) cin>>d[i];
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            m[a[i]+b[j]]++;
    ll ans=0;
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            ans+=m[V-c[i]-d[j]];
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 1070
memory_kb: 128372
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

int main(){

    int N;
    ll res = 0, tmp, V;
    vector<ll> A, B, C, D, AB, CD;
    
    cin >> N >> V;
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        A.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        B.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        C.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        D.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        for( int j = 0 ; j < N ; j++ ){
            AB.push_back( A[i] + B[j] );
            CD.push_back( C[i] + D[j] );
        }
    }
    sort( CD.begin(), CD.end() );
    for( int i = 0 ; i < N * N ; i++ ){
        auto r = upper_bound( CD.begin(), CD.end(), V - AB[i] );
        auto l = lower_bound( CD.begin(), CD.end(), V - AB[i] );
        res += ( r - l );
    }
    cout << res << endl;

}
accuracy: 1
time_ms: 180
memory_kb: 19120
final_rank: 6

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

int main(){

    int N, res = 0;
    ll tmp, V;
    vector<ll> A, B, C, D, AB, CD;
    
    cin >> N >> V;
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        A.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        B.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        C.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        cin >> tmp;
        D.push_back( tmp );
    }
    for( int i = 0 ; i < N ; i++ ){
        for( int j = 0 ; j < N ; j++ ){
            AB.push_back( A[i] + B[j] );
            CD.push_back( C[i] + D[j] );
        }
    }
    sort( CD.begin(), CD.end() );
    for( int i = 0 ; i < N * N ; i++ ){
        auto r = upper_bound( CD.begin(), CD.end(), V - AB[i] );
        auto l = lower_bound( CD.begin(), CD.end(), V - AB[i] );
        res += ( r - l );
    }
    cout << res << endl;

}
accuracy: 0.6
time_ms: 40
memory_kb: 18796
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int N;
using ll=long long;
ll V,a[4][1<<10];
vector<ll>sum[2];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>N>>V;
  rep(i,4)rep(j,N)cin>>a[i][j];
  rep(i,2){
    rep(x,N)rep(y,N)sum[i].emplace_back(a[2*i][x]+a[2*i+1][y]);
  }
  sort(sum[1].begin(),sum[1].end());
  ll ans=0;
  for(const auto&s:sum[0]){
    ll t=V-s;
    ans+=distance(lower_bound(sum[1].begin(),sum[1].end(),t),upper_bound(sum[1].begin(),sum[1].end(),t));
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 170
memory_kb: 24732
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int N;
using ll=long long;
ll V,a[4][1<<10];
vector<int>sum[2];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>N>>V;
  rep(i,4)rep(j,N)cin>>a[i][j];
  rep(i,2){
    rep(x,N)rep(y,N)sum[i].emplace_back(a[2*i][x]+a[2*i+1][y]);
  }
  sort(sum[1].begin(),sum[1].end());
  ll ans=0;
  for(const auto&s:sum[0]){
    ll t=V-s;
    ans+=distance(lower_bound(sum[1].begin(),sum[1].end(),t),upper_bound(sum[1].begin(),sum[1].end(),t));
  }
  cout<<ans<<endl;
}
accuracy: 0.92
time_ms: 150
memory_kb: 14544
final_rank: 16

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


long long solve(vector<vector<long long> > coin, long long n, long long v) {
    vector<long long> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            long long cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    long long n, v;
    cin >> n >> v;
    vector<vector<long long> > coin(4, vector<long long>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 11020
final_rank: 1

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


long long solve(vector<vector<long long> > coin, long long n, long long v) {
    vector<long long> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    long long n, v;
    cin >> n >> v;
    vector<vector<long long> > coin(4, vector<long long>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 0.92
time_ms: 170
memory_kb: 11052
final_rank: 14

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


long long solve(vector<vector<long> > coin, long n, long v) {
    vector<long long> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    long n, v;
    cin >> n >> v;
    vector<vector<long> > coin(4, vector<long>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 0.92
time_ms: 170
memory_kb: 11084
final_rank: 15

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


long long solve(vector<vector<int> > coin, int n, int v) {
    vector<long long> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    int n, v;
    cin >> n >> v;
    vector<vector<int> > coin(4, vector<int>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 0.92
time_ms: 160
memory_kb: 11052
final_rank: 13

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


long long solve(vector<vector<int> > coin, int n, int v) {
    vector<int> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    int n, v;
    cin >> n >> v;
    vector<vector<int> > coin(4, vector<int>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 0.92
time_ms: 160
memory_kb: 6964
final_rank: 12

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;


int solve(vector<vector<int> > coin, int n, int v) {
    vector<int> CD(n*n);
    //CとDからの取り出し方を全列挙
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            CD[n*i+j] = coin[2][i] + coin[3][j];
        }
    }

    sort(CD.begin(), CD.end());

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int cd = v - (coin[0][i] + coin[1][j]);
            ans += upper_bound(CD.begin(), CD.end(), cd) - lower_bound(CD.begin(), CD.end(), cd);
        }
    }
    return ans;
}


int main(void) {
    //入力
    int n, v;
    cin >> n >> v;
    vector<vector<int> > coin(4, vector<int>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++) {
            cin >> coin[i][j];
        }
    }

    //出力
    cout << solve(coin, n, v) << endl;

    return 0;
}
accuracy: 0.6
time_ms: 30
memory_kb: 6760
final_rank: 17

code_snippet: #include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <concepts>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

constexpr int MOD{1'000'000'007};
constexpr int MOD2{998'244'353};
constexpr int INF{1'000'000'000}; //1e9
constexpr int NIL{-1};
constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18
constexpr long double EPS{1E-10L};
using namespace std::literals;
namespace ranges = std::ranges;
namespace views = ranges::views;

template<class T, class S> bool chmax(T &a, const S &b){
    if(a < b){a = b; return true;}
    return false;
}
template<class T, class S> bool chmin(T &a, const S &b){
    if(b < a){a = b; return true;}
    return false;
}
template<class T> bool inside(T x, T lx, T rx){ //semi-open
    return (ranges::clamp(x, lx, rx-1) == x);
}
template<class T> bool inside(T x, T y, T lx, T rx, T ly, T ry){
    return inside(x, lx, rx) && inside(y, ly, ry);
}
template<class T, class S> std::istream &operator>>(std::istream &is, std::pair<T, S> &p){
    return is >> p.first >> p.second;
}
template<class T, class S> std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &p){
    return os << p.first << " " << p.second;
}
template<class T> std::istream &operator>>(std::istream &is, std::vector<T> &v){
    {for(auto &e: v) is >> e;} return is;
}
template<class Container> void print_container(const Container &c, std::string sep = " "s, std::string end = "\n"s){
    for(int i{int(std::size(c))}; auto e: c) std::cout << e << (--i ? sep : end);
}
std::string yesno(bool x){return x ? "Yes"s : "No"s;}



int main(){
    int N; long long V; std::cin >> N >> V;
    auto ans{0LL};
    std::vector<long long> a(N), b(N), c(N), d(N), s;
    std::cin >> a >> b >> c >> d;
    for(auto e: a) for(auto f: b) s.push_back(e + f);
    ranges::sort(s);
    for(auto e: c) for(auto f: d){
        auto t{e + f};
        if(t > V) continue;
        ans += (long long)std::distance(ranges::lower_bound(s, V-t), ranges::upper_bound(s, V-t));
    }
    std::cout << ans << std::endl;
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 12800
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  long long v;
  cin>>n>>v;
  vector<long long>a(n),b(n),c(n),d(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++)cin>>c[i];
  for(int i=0;i<n;i++)cin>>d[i];
  auto calc=[](const vector<long long>&lhs,const vector<long long>&rhs)->vector<long long> {
    vector<long long>res;
    res.reserve(lhs.size()*rhs.size());
    for(int i=0;i<lhs.size();i++)for(int j=0;j<rhs.size();j++)res.push_back(lhs[i]+rhs[j]);
    return res;
  };
  auto f=calc(a,b);
  auto g=calc(c,d);
  sort(g.begin(),g.end());
  long long ans=0;
  for(int i=0;i<f.size();i++){
    long long t=v-f[i];
    ans+=upper_bound(g.begin(),g.end(),t)-lower_bound(g.begin(),g.end(),t);
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 170
memory_kb: 18948
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(n) for (int tjh = 0; tjh < (int)(n); tjh++)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int N;ll V;vector<ll>a;vector<ll>b;vector<ll>c;vector<ll>d;
unordered_map<ll,int>A;ll A0;
ll res;
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(16);
  cin>>N>>V;a.resize(N);b.resize(N);
  rep(i,N)cin>>a[i];
  rep(i,N)cin>>b[i];
  rep(i,N){
    rep(j,N){
      A0=a[i]+b[j];
      if(A0<=V-2)A[A0]++;
    }
  }
  c.resize(N);d.resize(N);
  rep(i,N)cin>>c[i];
  rep(i,N)cin>>d[i];
  rep(i,N){
    rep(j,N){
      A0=c[i]+d[j];
      if(A0<=V-2)res+=(int)A[V-A0];
    }
  }
  cout<<res<<'\n';
}
accuracy: 1
time_ms: 420
memory_kb: 88800
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <unordered_map>

int main() {
    int N;
    long long V;
    std::cin >> N >> V;

    std::vector<long long> A(N), B(N), C(N), D(N);
    for (int i = 0; i < N; i++) std::cin >> A[i];
    for (int i = 0; i < N; i++) std::cin >> B[i];
    for (int i = 0; i < N; i++) std::cin >> C[i];
    for (int i = 0; i < N; i++) std::cin >> D[i];

    std::unordered_map<long long, int> counts;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = A[i] + B[j];
            counts[total]++;
        }
    }

    long long combinations = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = C[i] + D[j];
            if (counts.find(V - total) != counts.end()) {
                combinations += counts[V - total];
            }
        }
    }

    std::cout << combinations << std::endl;

    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 52620
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <unordered_map>

int main() {
    int N;
    long long V;
    std::cin >> N >> V;

    std::vector<long long> A(N), B(N), C(N), D(N);
    for (int i = 0; i < N; i++) std::cin >> A[i];
    for (int i = 0; i < N; i++) std::cin >> B[i];
    for (int i = 0; i < N; i++) std::cin >> C[i];
    for (int i = 0; i < N; i++) std::cin >> D[i];

    std::unordered_map<long long, int> counts;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = A[i] + B[j];
            counts[total]++;
        }
    }

    int combinations = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = C[i] + D[j];
            if (counts.find(V - total) != counts.end()) {
                combinations += counts[V - total];
            }
        }
    }

    std::cout << combinations << std::endl;

    return 0;
}
accuracy: 0.6
time_ms: 10
memory_kb: 9876
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <map>

int main() {
    int N;
    long long V;
    std::cin >> N >> V;

    std::vector<long long> A(N), B(N), C(N), D(N);
    for (int i = 0; i < N; i++) std::cin >> A[i];
    for (int i = 0; i < N; i++) std::cin >> B[i];
    for (int i = 0; i < N; i++) std::cin >> C[i];
    for (int i = 0; i < N; i++) std::cin >> D[i];

    std::map<long long, int> counts;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = A[i] + B[j];
            counts[total]++;
        }
    }

    long long combinations = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = C[i] + D[j];
            if (counts.find(V - total) != counts.end()) {
                combinations += counts[V - total];
            }
        }
    }

    std::cout << combinations << std::endl;

    return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 65936
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <map>

int main() {
    int N;
    long long V;
    std::cin >> N >> V;

    std::vector<long long> A(N), B(N), C(N), D(N);
    for (int i = 0; i < N; i++) std::cin >> A[i];
    for (int i = 0; i < N; i++) std::cin >> B[i];
    for (int i = 0; i < N; i++) std::cin >> C[i];
    for (int i = 0; i < N; i++) std::cin >> D[i];

    std::map<long long, int> counts;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = A[i] + B[j];
            counts[total]++;
        }
    }

    int combinations = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long total = C[i] + D[j];
            if (counts.find(V - total) != counts.end()) {
                combinations += counts[V - total];
            }
        }
    }

    std::cout << combinations << std::endl;

    return 0;
}
accuracy: 0.6
time_ms: 60
memory_kb: 13272
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, i, j, count;
	long long V, ans = 0;
	cin >> N >> V;
	vector<long long> a(N), b(N), c(N), d(N), ab(N * N), cd(N * N);
	for (i = 0; i != N; ++i) cin >> a[i];
	for (i = 0; i != N; ++i) cin >> b[i];
	for (i = 0; i != N; ++i) cin >> c[i];
	for (i = 0; i != N; ++i) cin >> d[i];

	for (i = 0; i != N; ++i)
		for (j = 0; j != N; ++j)
			ab[i * N + j] = a[i] + b[j], cd[i * N + j] = c[i] + d[j];

	sort(cd.begin(), cd.end());
	for (i = 0; i != N * N; ++i)
		ans += upper_bound(cd.begin(), cd.end(), V - ab[i]) - lower_bound(cd.begin(), cd.end(), V - ab[i]);

	cout << ans << '\n';
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 18848
final_rank: 3