Problem:
完全平等二国間貿易
サイバースペースにあるアイヅ国はワカマツ国と情報貿易を行っています。２つの国はお互いに有用なデータを交換することで経済発展を遂げています。博愛と平等、そして何よりも会津地方の古い言葉である、「ならぬことはならぬものです」を国是とする両国は、定期的に貿易状況の調査を行っています。
調査では、バイト単位でアイヅ国から見たデータ流入量から流出量を引いた値を、１ナノ秒ごとに求めた表が与えられます。その表から、値の総和が０になる最長の区間を見つけます。この区間が長いほど、平等性が保たれていると判断します。
貿易状況が記録された表が与えられたとき、値の総和が０になる最長の区間の長さを求めるプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
N
d
1
d
2
:
d
N
１行目に、表に書かれた値の数
N
(1 ≤
N
≤ 200000) が与えられる。続く
N
行に、表の
i
行目に書かれた値を示す整数
d
i
(-10
9
≤
d
i
≤ 10
9
) が与えられる。
Output
表から得られる、総和が０になる最長の区間の長さを１行に出力する。そのような区間が存在しない場合、「0」を１行に出力する。
Sample Input 1
5
18
102
-155
53
32
Sample Output 1
3
入力例１では、２行目から４行目までの値の総和が０になるので、最長の区間の長さが3になる。
Sample Input 2
4
1
1
-1
-1
Sample Output 2
4
入力例２では、２行目から３行目の総和が０になるが、１行目から４行目までの値の総和も０になるので、最長の区間の長さが4になる。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<ll> d(N);
	rep(i, 0, N) cin >> d[i];
	
	rep(i, 1, N) d[i] += d[i - 1];
	
	map<ll, int> mini;
	mini[0] = -1;
	int ans = 0;
	rep(i, 0, N) {
		if (mini.count(d[i])) ans = max(ans, i - mini[d[i]]);
		else mini[d[i]] = i;
	}
	cout << ans << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 16948
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	map<ll, int> mp;
	vi v(n); cin >> v;
	vi s(n + 1);
	int ans = 0;
	mp[0] = 0;
	REP(i, n)
	{
		s[i + 1] = s[i] + v[i];
		if (mp.count(s[i + 1]) == 0) mp[s[i + 1]] = i + 1;
		else chmax(ans, i + 1 - mp[s[i + 1]]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 18564
final_rank: 6

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

// #include<atcoder/all>
// using namespace atcoder;
// using mint=atcoder::modint998244353;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

signed main(){
	int n;cin>>n;
	vector<int> d(n);
	for(auto&&e:d)cin>>e;

	map<int,vector<int>> vec;

	int sum=0;
	vec[sum].push_back(0);

	for(int i=0;i<n;i++){
		sum+=d[i];

		vec[sum].push_back(i+1);
	}

	int ans=0;

	for(auto&&[e,v]:vec){
		ans=max(ans,v.back()-v.front());
	}

	cout<<ans<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 26352
final_rank: 13

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

int main() {
    int n;
    cin >> n;
    long long d[n + 1];
    long long sum[n + 1] = {};
    vector<pair<long long, int>> data(n + 1);
    data[0] = {0, 0};
    for (int i = 1; i < n + 1; i++) {
        cin >> d[i];
        sum[i] = sum[i - 1] + d[i];
        data[i] = {sum[i], i};
    }
    sort(data.begin(), data.end());
    vector<long long> data2(n + 1);
    for (int i = 0; i <= n; i++) {
        data2[i] = data[i].first;
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        int pos = lower_bound(data2.begin(), data2.end(), sum[i]) - data2.begin();
        if (pos <= n) {
            ans = max(ans, i - data[pos].second);
        }
    }
    cout << ans << "\n";
    return(0);
}
accuracy: 1
time_ms: 50
memory_kb: 10964
final_rank: 3

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


using namespace std;
//make -f ../makefile SRC=
/*
https://stackoverflow.com/questions/5534063/maximum-subarray-whose-sum-equals-0
https://www.geeksforgeeks.org/find-the-largest-subarray-with-0-sum/
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 200000;
static int64_t vect[MAX_N];
static int64_t P[MAX_N];
//------------------------------------------------------------------------------
int solve(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    if (N == 1) return vect[0] == 0;
    //--------------------------------------------------------------------------
    // init:
    P[0] = vect[0];
    for (int i=1; i<N; ++i) P[i] = vect[i] + P[i-1];
    //printf("P: "); for (int i=0; i<N; ++i) printf("%d ",P[i]); printf("\n");
    //--------------------------------------------------------------------------
    // compute:
    unordered_map<int64_t,int> index;
    int res = 0;
    for (int i=0; i<N; ++i)
    {
        if (P[i] == 0) res = i+1;
        else if (index.find( P[i] ) == index.end())
        {
            index[ P[i] ] = i;
        }
        else
        {
            res = max(res, i - index[ P[i] ]);
        }
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%d\n", res);
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    num = scanf("%d ", &N);
    for (int i=0; i<N; ++i) num = scanf("%ld ", &vect[i]);
    int res = solve(N);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 30
memory_kb: 13992
final_rank: 1

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


using namespace std;
//make -f ../makefile SRC=
/*
https://stackoverflow.com/questions/5534063/maximum-subarray-whose-sum-equals-0
https://www.geeksforgeeks.org/find-the-largest-subarray-with-0-sum/
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 200000;
static int64_t vect[MAX_N];
static int64_t P[MAX_N];
//------------------------------------------------------------------------------
int solve(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    if (N == 1) return vect[0] == 0;
    //--------------------------------------------------------------------------
    // init:
    P[0] = vect[0];
    for (int i=1; i<N; ++i) P[i] = vect[i] + P[i-1];
    //printf("P: "); for (int i=0; i<N; ++i) printf("%d ",P[i]); printf("\n");
    //--------------------------------------------------------------------------
    // compute:
    unordered_map<int,int> index;
    int res = 0;
    for (int i=0; i<N; ++i)
    {
        if (P[i] == 0) res = i+1;
        else if (index.find( P[i] ) == index.end())
        {
            index[ P[i] ] = i;
        }
        else
        {
            res = max(res, i - index[ P[i] ]);
        }
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%d\n", res);
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    num = scanf("%d ", &N);
    for (int i=0; i<N; ++i) num = scanf("%ld ", &vect[i]);
    int res = solve(N);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 0.88
time_ms: 30
memory_kb: 13976
final_rank: 16

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


using namespace std;
//make -f ../makefile SRC=
/*
https://stackoverflow.com/questions/5534063/maximum-subarray-whose-sum-equals-0
https://www.geeksforgeeks.org/find-the-largest-subarray-with-0-sum/
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 200000;
static int vect[MAX_N];
static int P[MAX_N];
//------------------------------------------------------------------------------
int solve(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    if (N == 1) return vect[0] == 0;
    //--------------------------------------------------------------------------
    // init:
    P[0] = vect[0];
    for (int i=1; i<N; ++i) P[i] = vect[i] + P[i-1];
    //printf("P: "); for (int i=0; i<N; ++i) printf("%d ",P[i]); printf("\n");
    //--------------------------------------------------------------------------
    // compute:
    unordered_map<int,int> index;
    int res = 0;
    for (int i=0; i<N; ++i)
    {
        if (P[i] == 0) res = i+1;
        else if (index.find( P[i] ) == index.end())
        {
            index[ P[i] ] = i;
        }
        else
        {
            res = max(res, i - index[ P[i] ]);
        }
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%d\n", res);
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    num = scanf("%d ", &N);
    for (int i=0; i<N; ++i) num = scanf("%d ", &vect[i]);
    int res = solve(N);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 0.88
time_ms: 40
memory_kb: 12388
final_rank: 17

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<ll, int> mp;
    mp[0] = -1;
    ll sum = 0;
    int res = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        sum += a;
        if (mp.find(sum) != mp.end()) {
            res = max(res, i - mp[sum]);
        }
        else {
            mp[sum] = i;
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 15648
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    map<long,long> e;
    int a;
    cin>>a;
    long r=0;
    long f;
    long ans=0;
    e[0]=-1;
    for(int i=0;i<a;i+=1){
        cin>>f;
        r+=f;
        if(!e.count(r)){
            e[r]=i;
        }else{
            if(ans<i-e[r]){
                ans=i-e[r];
            }
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 15848
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    map<long,long> e;
    int a;
    cin>>a;
    int r=0;
    int f;
    int ans=0;
    e[0]=-1;
    for(int i=0;i<a;i+=1){
        cin>>f;
        r+=f;
        if(!e.count(r)){
            e[r]=i;
        }else{
            if(ans<i-e[r]){
                ans=i-e[r];
            }
        }
    }
    cout<<ans<<endl;
}
accuracy: 0.88
time_ms: 100
memory_kb: 15688
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) a.begin(),a.end()


void yn(bool n)
{
	if(n)
	{
		cout<<"yes"<<endl;
	}
	else
	{
		cout<<"no"<<endl;
	}
	return;
}


int main()
{
	int n;
	cin>>n;
	auto d=vector<ll>();
	for(int i=0; i<n; i++)
	{
		ll a;cin>>a;
		d.push_back(a);
	}

	auto dic=map<ll,int>();
	dic[0]=0;
	int ans=0;
	ll sum=0;
	for(int i=0; i<n; i++)
	{
		sum+=d[i];
		if(dic.find(sum)!=dic.end())
		{
			ans=max(ans,i+1-dic[sum]);
		}
		else
		{
			dic[sum]=i+1;
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 16892
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const int INF = ((1<<30)-1);
const long long LINF = (1LL<<60);
const double PI = 3.141592653589793238;
template<class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}
template<class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}



int solve(){
    int n; cin >> n;
    vl a(n);
    rep(i,0,n)cin >> a[i];
    vl rui(1,0);
    int ans = 0;
    rep(i,0,n){
        rui.push_back(rui.back()+a[i]);
        if(rui.back() == 0)ans = 1;
    }
    map<ll , vi> mp;
    rep(i,0,n+1)mp[rui[i]].push_back(i);
    for(auto c:mp){
        if(c.second.size() == 1)continue;
        chmax(ans , c.second.back()-c.second[0]);
    }
    cout << ans << endl;
    

    
    




    return 0;
}

int main(){
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1; 
    //cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 27984
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const int INF = ((1<<30)-1);
const long long LINF = (1LL<<60);
const double PI = 3.141592653589793238;
template<class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}
template<class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}



int solve(){
    int n; cin >> n;
    vl a(n);
    rep(i,0,n)cin >> a[i];
    vl rui(1,0);
    int ans = 0;
    rep(i,0,n){
        rui.push_back(rui.back()+a[i]);
        if(rui.back() == 0)ans = 1;
    }
    map<int , vi> mp;
    rep(i,0,n+1)mp[rui[i]].push_back(i);
    for(auto c:mp){
        if(c.second.size() == 1)continue;
        chmax(ans , c.second.back()-c.second[0]);
    }
    cout << ans << endl;
    

    
    




    return 0;
}

int main(){
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1; 
    //cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
	return 0;
}
accuracy: 0.88
time_ms: 90
memory_kb: 27984
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const int INF = ((1<<30)-1);
const long long LINF = (1LL<<60);
const double PI = 3.141592653589793238;
template<class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}
template<class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}



int solve(){
    int n; cin >> n;
    vl a(n);
    rep(i,0,n)cin >> a[i];
    vl rui(1,0);
    rep(i,0,n){
        rui.push_back(rui.back()+a[i]);
    }
    int ans = 0;
    map<int , vi> mp;
    rep(i,0,n+1)mp[rui[i]].push_back(i);
    for(auto c:mp){
        if(c.second.size() == 1)continue;
        chmax(ans , c.second.back()-c.second[0]);
    }
    cout << ans << endl;
    

    
    




    return 0;
}

int main(){
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1; 
    //cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
	return 0;
}
accuracy: 0.88
time_ms: 90
memory_kb: 27984
final_rank: 19

code_snippet: #include <iostream>
#include <map>
using namespace std;
map<long long int,int> ms;
map<long long int,int>::iterator it;
int main() {
	int n;
	long long int sum=0;
	cin>>n;
	ms[0]=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		long long int t;
		cin>>t;
		sum+=t;
		if(i>1){
			if(ms.find(sum)!=ms.end()){
				int t2=i-ms[sum];
				if(ans<t2)ans=t2;
			}
		}
		if(sum==0)ans=i;
		if(t==0&&ans==0)ans=1;
		if(ms.find(sum)==ms.end()){
			ms[sum]=i;
		}
	}
	//for(it=ms.begin();it!=ms.end();it++){
	//out<<(*it).first<<" "<<(*it).second<<endl;
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 15504
final_rank: 11

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0329.cc: 完全平等二国間貿易
 */

#include<cstdio>
#include<map>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;
typedef map<ll,int> mli;

/* global variables */

int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", ds + i);

  ll sum = 0;
  int maxl = 0;
  mli ps;
  ps[sum] = 0;
  
  for (int i = 0; i < n; i++) {
    sum += ds[i];
    mli::iterator mit = ps.lower_bound(sum);
    if (mit != ps.end() && mit->first == sum)
      maxl = max(maxl, i + 1 - mit->second);
    else
      ps[sum] = i + 1;
  }

  printf("%d\n", maxl);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 16272
final_rank: 2

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

int main(){
  int N;
  cin >> N;
  vector<long long int> d(N);
  for(int i=0;i<N;i++) cin >> d[i];
  int ans = 0;
  map<long long int,int> Map;
  Map[0] = N;
  long long int S = 0;
  for(int i=N-1;i>=0;i--){
    S += d[i];
    ans = max(ans,Map[S]-i);
    Map[S] = max(Map[S],i);
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 16948
final_rank: 9

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in();
	vll A=vecin(N),S(N+1,0);
	REP(i,N) S[i+1] = S[i]+A[i];

	map<ll,vector<ll>> M;
	REP(i,N+1){
		M[S[i]].push_back(i);
	}

	ll L=0;
	for(auto& x:M){
		chmax(L,x.second.back()-x.second.front());
	}
	out(L);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 28036
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
    int n; cin >> n;
    vector<ll> d(n);
    for(auto &it: d) cin >> it;
    vector<ll> tot(n+1, 0);
    for(int i = 0; i < n; i++) tot[i+1] = tot[i]+d[i];
    map<ll, vector<int>> mem;
    for(int i = 0; i <= n; i++) mem[tot[i]].emplace_back(i);
    int ans = 0;
    for(auto &it: mem){
        auto &vec = it.second;
        if(vec.size() > 1) ans = max(ans, vec.back()-vec.front());
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 28048
final_rank: 14

code_snippet: #include <iostream>
#include <unordered_set>
#include <map>
#include <cassert>
using namespace std;

long  max(unordered_set<long> *S);
long min(unordered_set<long> *S);

int main(void){
    long N;
    cin>>N;
    long long* d = new long long[N];
    for(long i=0;i<N;i++){
        cin>>d[i];
    }
    long long* accumurate = new long long[N+1];
    accumurate[0] = 0;
    for(long i=0;i<N;i++){
        accumurate[i+1] = accumurate[i] + d[i];
    }
    //accumurate[j+1]==accumurate[i] のときの j-iの最大値が知りたい

    map<long long, unordered_set<long> > count;
    assert(count.empty());
    for(long i=0;i<=N;i++){
        count[accumurate[i]].clear();
    }
    for(long i=0;i<=N;i++){
        count[accumurate[i]].insert(i);
    }

    long retval = 0;
    for(auto item : count){
        long long key = item.first;
        unordered_set<long> value = item.second;
        retval = max(retval, max(&value)-min(&value));
    }
    cout<<retval<<endl;
    return 0;
}


long max(unordered_set<long> *S){
    long M = -1000000010;
    for(long s:*S){
        if(M<s){
            M = s;
        }
    }
    return M;
}

long min(unordered_set<long> *S){
    long m = 1000000010;
    for(long s:*S){
        if(m>s){
            m = s;
        }
    }
    return m;
}
accuracy: 1
time_ms: 120
memory_kb: 40864
final_rank: 15