stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<stack>

#include<cstring>

#include<vector>

#include<queue>

#include<stack>

#define white 0

#define grey 1

#define nil -1

#define maxn 100000

using namespace std;



vector<int> g[maxn+5];

int color[maxn+5];

int n,m;



void dfs(int s,int t)

{

    stack<int>q;

    q.push(s);

    color[s]=t;

    while(!q.empty())

    {

        int v=q.top();

        q.pop();

        for(int j=0;j<g[v].size();j++)

        {

            int u=g[v][j];

            if(color[u]==nil)

            {

                q.push(u);

                color[u]=t;

            }

        }

    }

}



void work()

{

    int id=1;

    for(int i=0;i<n;i++)

        color[i]=nil;

    for(int i=0;i<n;i++)

        if(color[i]==nil)

           dfs(i,id++);

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=0;i<m;i++)

    {

        int x,y;

        scanf("%d%d",&x,&y);

        g[x].push_back(y);

        g[y].push_back(x);

    }

    work();



    int q;

    scanf("%d",&q);

    for(int i=1;i<=q;i++)

    {

        int s,t;

        scanf("%d%d",&s,&t);

        if(color[s]==color[t])

            printf("yes\n");

        else printf("no\n");

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#pragma GCC optimize("03")

#include <bits/stdc++.h>

#define endl '\n'

#define ll long long 

using namespace std;

int f[200000];

int find(int x){

	if(f[x]==x)

		return x;

	else

		return f[x]=find(f[x]);

}

void merge(int c,int d){

	f[d]=c;

}

int main()

{

    ios::sync_with_stdio(0);cin .tie(NULL);

    ll a,b,num;

   	cin >> a >> b;

   	for(int i=0;i<a;i++)

	f[i]=i;

    for(int i=0;i<b;i++)

    {

    	ll c,d;

    	cin >> c >> d;

    	c=find(c);

    	d=find(d);

   		merge(c,d);

	}

	cin >> num;

	for(int i=0;i<num;i++)

	{

		ll e,g;

		cin >> e >> g;

		if(find(e)==find(g))

			cout << "yes" << endl;

		else

			cout << "no" << endl;

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<queue>

using namespace std;



const int grey=1;

const int white=0;

const int black=-1;



const int maxn=100005;

int head[maxn+5],pos=0;

int color[maxn+5],id[maxn+5];

int n,m;



struct node

{

    int k;

    int next;

};

struct node G[2*maxn+5];



void add(int u,int v)

{

    G[++pos].k=v;

    G[pos].next=head[u];

    head[u]=pos;

}



void bfsvisit(int u,int k)

{

    color[u]=black;

    queue<int> q;

    q.push(u);

    id[u]=k;

    while(!q.empty())

    {

        int r=q.front();

        q.pop();

        for(int j=head[r];j;j=G[j].next)

        {

            int v=G[j].k;

            if(color[v]==white)

            {

                q.push(v);

                color[v]=black;

                id[v]=k;

            }

        }

    }

}



void bfs()

{

    memset(id,0,sizeof(id));

    memset(color,0,sizeof(color));

    int k=0;



    for(int i=0;i<n;i++)

    {

        if(color[i]==white)

        {

            bfsvisit(i,k++);

        }

    }

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)

    {

        int u,v;

        scanf("%d%d",&u,&v);

        add(u,v);

        add(v,u);

    }



    bfs();

    int q,s,t;

    scanf("%d",&q);

    while(q--)

    {

        scanf("%d%d",&s,&t);

        if(id[s]==id[t])

            printf("yes\n");

        else printf("no\n");

    }

}

// Optimized solution to the same problem (faster):
#pragma GCC optimize("03")

#include <bits/stdc++.h>

#define endl '\n'

#define ll long long 

using namespace std;

int f[200000];

int find(int x){

	if(f[x]==x)

		return x;

	else

		return f[x]=find(f[x]);

}

void merge(int c,int d){

	f[d]=c;

}

int main()

{

    ios::sync_with_stdio(0);cin .tie(NULL);

    ll a,b,num;

   	cin >> a >> b;

   	for(int i=0;i<a;i++)

	f[i]=i;

    for(int i=0;i<b;i++)

    {

    	ll c,d;

    	cin >> c >> d;

    	c=find(c);

    	d=find(d);

   		merge(c,d);

	}

	cin >> num;

	for(int i=0;i<num;i++)

	{

		ll e,g;

		cin >> e >> g;

		if(find(e)==find(g))

			cout << "yes" << endl;

		else

			cout << "no" << endl;

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<vector>

#include<stack>

#include<queue>

using namespace std;

#define maxn 100005

#define NIL -1



int n,m;

vector<int> G[maxn]; //邻接表

int color[maxn]; //编号（可以互相链接的两个节点编号相同）



void dfs(int r,int c) //给节点r分配编号c（深搜实现）（栈）

{

    stack<int> S;

    S.push(r);

    color[r]=c;

    while(!S.empty())

    {

        int u=S.top();S.pop(); //从栈顶取出

        for(int i=0;i<G[u].size();i++)

        {

            int v=G[u][i];

            if(color[v]==NIL) //如果该节点无编号

            {

                color[v]=c; //给其编号

                S.push(v); //压入栈

            }

        }

    }

}



void dfs_(int r,int c) //给节点r分配编号c（深搜实现）（递归）

{

    color[r]=c;

    for(int i=0;i<G[r].size();i++) //注意这里代码于上面的不同

    {

        int v=G[r][i];

        if(color[v]==NIL)

            {

                color[v]=c;

                dfs_(v,c);

            }

    }

}



void bfs(int r,int c) //给节点r分配编号c（广搜实现）

{

    queue<int> S;

    S.push(r);

    color[r]=c;

    while(!S.empty())

    {

        int u=S.front();S.pop(); //从队首取出

        for(int i=0;i<G[u].size();i++)

        {

            int v=G[u][i];

            if(color[v]==NIL)

            {

                color[v]=c;

                S.push(v); //加入队列中

            }

        }

    }

}



void assigncolor()

{

    int id=1;

    memset(color,NIL,sizeof(color)); //这里要记得初始化

    for(int u=0;u<n;u++)

        if(color[u]==NIL)

            dfs_(u,id++); //这里选取了广搜的方式给各个节点编号

}



int main()

{

    int s,t,q;

    cin>>n>>m;

    while(m--)

    {

        cin>>s>>t;

        G[s].push_back(t); //从顶点s向t画边

        G[t].push_back(s); //反过来连边

    }

    assigncolor();

    cin>>q;

    while(q--)

    {

        cin>>s>>t;

        if(color[s]==color[t]) cout<<"yes"<<endl;

        else cout<<"no"<<endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#pragma GCC optimize("03")

#include <bits/stdc++.h>

#define endl '\n'

#define ll long long 

using namespace std;

int f[200000];

int find(int x){

	if(f[x]==x)

		return x;

	else

		return f[x]=find(f[x]);

}

void merge(int c,int d){

	f[d]=c;

}

int main()

{

    ios::sync_with_stdio(0);cin .tie(NULL);

    ll a,b,num;

   	cin >> a >> b;

   	for(int i=0;i<a;i++)

	f[i]=i;

    for(int i=0;i<b;i++)

    {

    	ll c,d;

    	cin >> c >> d;

    	c=find(c);

    	d=find(d);

   		merge(c,d);

	}

	cin >> num;

	for(int i=0;i<num;i++)

	{

		ll e,g;

		cin >> e >> g;

		if(find(e)==find(g))

			cout << "yes" << endl;

		else

			cout << "no" << endl;

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <queue>



using namespace std;



struct Node {

    int color = 0;

    vector<int> next;

} node[100000];



int main() {

    int n, m, q, t1, t2;



    cin >> n >> m;

    for (int i = 0; i < m; i++) {

        cin >> t1 >> t2;

        node[t1].next.push_back(t2);

        node[t2].next.push_back(t1);

    }



    int color = 1;

    queue<int> que;

    while (1) {

        int start = -1;

        for (int i = 0; i < n; i++) {

            if (node[i].color == 0) {

                start = i;

                break;

            }

        }

        if (start == -1) {

            break;

        }

        

        node[start].color = color;

        que.push(start);

        while (!que.empty()) {

            int temp = que.front();

            int size = node[temp].next.size();

            for (int i = 0; i < size; i++) {

                if (node[node[temp].next[i]].color == 0) {

                    node[node[temp].next[i]].color = color;

                    que.push(node[temp].next[i]);

                }

            }

            que.pop();

        }

        color++;

    }



    cin >> q;

    for (int i = 0; i < q; i++) {

        cin >> t1 >> t2;

        if (node[t1].color == node[t2].color && node[t1].color > 0 && node[t2].color > 0) {

            cout << "yes" << endl;

        }

        else {

            cout << "no" << endl;

        }

    }



    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>



using namespace std;



int user[100000];



void init(int n) {

    fill_n(user, n, -1);

}



int root(int s) {

    if (user[s] < 0)

        return s;

    else

        return user[s] = root(user[s]);

}



void unite(int s, int t) {

    int rs = root(s);

    int rt = root(t);

    if (rs != rt) {

        if (user[rs] < user[rt])

            swap(rs, rt);

        user[rs] += user[rt];

        user[rt] = rs;

    }

}



bool same(int s, int t) {

    return root(s) == root(t);

}



int main() {

    int n, m, q, s, t, c = 1;

    cin >> n >> m;

    init(n);

    for (int i = 0; i < m; ++i) {

        cin >> s >> t;

        unite(s, t);

    }

    cin >> q;

    for (int i = 0; i < q; ++i) {

        cin >> s >> t;

        if (same(s, t))

            cout << "yes" << endl;

        else 

            cout << "no" << endl;

    }



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<iostream>

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



	cin >> n >> m;



	for (int i = 0; i < n; i++)table[i] = -1;

	for (int i = 0; i < m; i++) {

		int s, t;

		cin >> s >> t;

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	cin >> q;



	for (int i = 0; i < q; i++) {

		int s, t;

		cin >> s >> t;



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			cout << "yes" << endl;

		}

		else {

			cout << "no" << endl;

		}

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	if (table[child] == -1)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX];



	scanf("%d %d", &n, &m);



	for (int i = 0; i < n; i++)table[i] = -1;

	for (int i = 0; i < m; i++) {

		int s, t;

		scanf("%d %d", &s, &t);

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



	for (int i = 0; i < q; i++) {

		int s, t;

		

		scanf("%d %d", &s, &t);



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



	scanf("%d %d", &n, &m);



	for (int i = 0; i < n; i++)table[i] = -1;

	for (int i = 0; i < m; i++) {

		int s, t;

		scanf("%d %d", &s, &t);

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



	for (int i = 0; i < q; i++) {

		int s, t;

		

		scanf("%d %d", &s, &t);



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	if (table[child] == -1)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX];



	scanf("%d %d", &n, &m);



	for (int i = 0; i < n; i++)table[i] = -1;

	for (int i = 0; i < m; i++) {

		int s, t;

		scanf("%d %d", &s, &t);

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



	for (int i = 0; i < q; i++) {

		int s, t;

		

		scanf("%d %d", &s, &t);



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <stdio.h>

#include <vector>

#include <stack>

#include <queue>

#define N 100000

using namespace std;





int C[N];

queue<int> k;

vector<int> v[N];

void color(int);

bool search(int,int);



int main(){

	int n,m,a,b,q;

	cin >> n >>m;

	for(int i=0;i<m;i++){

		cin >> a >> b;

		v[a].push_back(b);

		v[b].push_back(a);

	}

	cin >> q;

	for(int i=0;i<n;i++){

		C[i]=-1; //?????????

	}

	for(int i=0;i<n;i++){

		if(C[i]==-1)color(i); //i????§??????¨????????±???

	}

	for(int i=0;i<q;i++){

		cin>>a>>b;

		if(search(a,b)) cout<<"yes"<<endl;

		else cout<<"no"<<endl;

	}

	return 0;

}



bool search(int a,int b){

	if(C[a]==C[b]) return true;

	else return false;

}



void color(int a){

	static int c=0;

	c++;

	C[a]=c;

	k.push(a);

	while(!k.empty()){

		int m = k.front();

		k.pop();

		for(int i=0;i<v[m].size();i++){

			int Z= v[m].at(i);

			if(C[Z]==-1){

				C[Z]=c;

				k.push(Z);

			}

		}

	}

}

// Optimized solution to the same problem (faster):
/*

	 AOJ DSL_1

	 ??????????´??????????

	 2??????????´????????????????????±??????????????????¶=2??????????´??????????????????§??????

	 ?????????????????¨???father[]?????´??\?????§???????????§????????????find??¢??°??§??¢?´¢??????????????????

	 ??????????????????????????¨?????¨??????????????????

	 */

#include<iostream>

#include <string>

#define maxn 100100

using namespace std;

int n,q,m;

int father[maxn];



void init(){

	for(int i=0;i<n;i++)father[i]=i;

}



int find(int x){ // x?????????????????¢??°

	if(father[x]==x)return x; // ?????????????????????????????´??????x???????????????

	return father[x]=find(father[x]); // ??????????????§????????°??????????????????????????????(????????§?????????)

}



void unite(int x,int y){

	father[find(x)]=find(y); // x????????¨y????????????????????????

}



string same(int x,int y){

	if(find(x)==find(y))return "yes"; // ????????????????????????

	else return "no";

}



int main(void){

	cin>>n>>m;

	init();

	while(m--){

		int x,y;

		cin>>x>>y;

		unite(x,y);

	}

	cin>>q;

	while(q--){

		int x,y;

		cin>>x>>y;

		cout<<same(x,y)<<endl;

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#define N_MAX 100000

using namespace std;



vector<int> sns[N_MAX];

int* group;

int g = 0;



void dfs(int s) {

  if (group[s] != 0) return;

  group[s] = g;

  

  int len = sns[s].size();

  for (int i = 0; i < len; i++) {

    dfs(sns[s][i]);

  }

}



int main() {

  int n,m,q,s,t;

  cin >> n >> m;



  for (int i = 0; i < m; i++) {

    cin >> s >> t;



    sns[s].push_back(t);

    sns[t].push_back(s);

  }



  // dfs

  group = new int[n];

  for (int i = 0; i < n; i++) {

    if (group[i] == 0) {

      g++;

      dfs(i);

    }

  }



  cin >> q;

  for (int i = 0; i < q; i++) {

    cin >> s >> t;

    if (group[s] == group[t]) {

      cout << "yes" << endl;

    } else {

      cout << "no" << endl;

    }

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#define eol '\n'

using namespace std;



vector< vector<int> > list;

vector<int> group;



void bfs(int v, int g) {

  if (group[v] != 0) {

    return;

  }

  group[v] = g;

  for (int i = 0; i < list[v].size(); i++) {

    bfs(list[v][i], g);

  }

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);



  int n,m,s,t,q;

  cin >> n >> m;



  list = vector< vector<int> >(n, vector<int>());

  group = vector<int>(n,0);

  

  for (int i = 0; i < m; i++) {

    cin >> s >> t;

    list[s].push_back(t);

    list[t].push_back(s);

  }



  int g = 1;

  for (int i = 0; i < n; i++) {

    if (group[i] == 0) {

      bfs(i, g);

      g++;

    }

  }



  cin >> q;

  for (int i = 0; i < q; i++) {

    cin >> s >> t;

    if (group[s] == group[t]) {

      cout << "yes" << eol;

    } else {

      cout << "no" << eol;

    }

  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <vector>

#include <cstring>

#include <cstdlib>



void numbering(int id, int *g, int num, std::vector<int> *a){

    int tmp;

    for(int i=0;i<a[id].size();i++){

        tmp = a[id][i];

        if(g[tmp])continue;

        g[tmp] = num;

        numbering(tmp, g, num, a);

    }

}



void grouping(std::vector<int> *a, int *g, int n){

    int num = 1;

    for(int i=0;i<n;i++){

        if(g[i])continue;

        g[i] = num;

        numbering(i,g,num,a);

        num++;

    }

}



int main(){

    int i, n, m, q, s, t;

    int *g;

    scanf("%d %d",&n,&m);

    g = (int *)malloc(sizeof(int)*n);

    memset(g, 0, sizeof(int)*n);

    std::vector<int> a[n];

    for(i=0;i<m;i++){

        scanf("%d %d",&s,&t);

        a[s].push_back(t);

        a[t].push_back(s);

    }

    scanf("%d",&q);

    grouping(a,g,n);

    for(i=0;i<q;i++){

        scanf("%d %d",&s,&t);

        if(g[s]==g[t])printf("yes\n");

        else printf("no\n");

    }

    return 0;

}




// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>



typedef struct{

    int height;

    int parent;

}node;



node* nd;



int top(int key){

    if(nd[key].parent == -1)return key;

    else return top(nd[key].parent);

}



void join(int s, int t){

    int a = top(s);

    int b = top(t);

    if(a==b)return;

    if(nd[a].height<nd[b].height){

        nd[a].parent = b;

    }else{

        nd[b].parent = a;

        if(nd[a].height==nd[b].height)nd[a].height++;

    }

    return;

}



bool isFriend(int s, int t){

    if(top(s)==top(t))return true;

    else return false;

}



int main(){

    int i, n, m, s, t, q;

    scanf("%d %d",&n,&m);



    nd = (node *)malloc(sizeof(node)*n);



    for(i=0;i<n;i++){

        nd[i].height = 1;

        nd[i].parent = -1;

    }



    for(i=0;i<m;i++){

        scanf("%d %d",&s,&t);

        join(s,t);

    }



    scanf("%d",&q);

    for(i=0;i<q;i++){

        scanf("%d %d",&s,&t);

        if(isFriend(s,t))printf("yes\n");

        else printf("no\n");

    }

    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <map>

#include <vector>

using namespace std;



int main(){

	int n,a,b;

	bool flag;

	string number;

	map<string,int> info;

	vector<string> seq;

	

	while(cin >> n && n){

		info.clear();

		seq.clear();

		while(n--){

			cin >> number >> a >> b;

			if(!info[number])seq.push_back(number);

			while(b-- && info[number]<1000000){

				info[number] += a;

			}

		}

		flag = true;

		for(int i=0;i<seq.size();i++){

			if(info[seq[i]]>=1000000){

				flag = false;

				cout << seq[i] << endl;

			}

		}

		if(flag)cout << "NA" << endl;

	}

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <map>

#include <vector>

using namespace std;



int main(){

	long long n,a,b;

	bool flag;

	int number;

	map<int,long long> info;

	vector<int> seq;

	

	while(cin >> n && n){

		info.clear();

		seq.clear();

		while(n--){

			cin >> number >> a >> b;

			if(!info[number])seq.push_back(number);

			info[number] += a*b;

		}

		flag = true;

		for(int i=0;i<seq.size();i++){

			if(info[seq[i]]>=1000000){

				flag = false;

				cout << seq[i] << endl;

			}

		}

		if(flag)cout << "NA" << endl;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

using namespace std;

typedef struct{

	string id;

	long long sales;

} staff;



int main(void)

{

	long long n;

	while(cin>>n){

		if(!n) break;

		staff staff1[4001];

		int pt = 0;

		for(int i=0; i< n; i++){

			string id;

			cin >> id;

			long long price;

			int bnum;

			cin >> price >> bnum;

			int m=-1;

			for(int j=0;j < i; j++){

				if(id==staff1[j].id){

					pt++;

					m=j;

					break;

				}

			}

			if(m==-1){

				staff1[i-pt].id = id;

				staff1[i-pt].sales = price * bnum;

			}else{

				staff1[m].sales += price * bnum;

			}

		}

		int count = 0;

		for(int i=0; i < n-pt; i++){

			if(staff1[i].sales >= 1000000){

				count++;

				cout << staff1[i].id << endl;

			}

		}

		if(!count) cout << "NA" << endl;

	}

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<map>

#include<vector>

#include<string>



using namespace std;

#define mp make_pair

int main(){

  int n;

  string a;

  long long b,c;

  map<string,long long> data;

  vector<string> id;

  while(true){

    id.clear();

    data.clear();

    cin>>n;

    if(!n)

      break;

    for(int i=0;i<n;i++){

      cin>>a>>b>>c;

      c*=b;

      if(data.find(a)==data.end()){

	data.insert(mp(a,c));

	id.push_back(a);

      }

      else{

	data[a]+=c;

      }

    }

    bool empty = true;

    for(int i=0;i<id.size();i++){

      if(data[id[i]]>=1000000){

	cout<<id[i]<<endl;

	empty = false;

      }

    }

    if (empty)

      cout<<"NA"<<endl;



  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<stack>

#include<vector>

#include<cctype>

#define szxb 200010

using namespace std;

int n;

long long a[szxb];

int main()

{

	memset(a,0,sizeof(a));

	scanf("%d",&n);

	int t;

	long long total=0;

	for(register int i=1;i<=n;i++)

	{

		scanf("%d",&t);

		total+=t,a[i]=(a[i-1]+t);

	}

	long long minn=1e17;

	for(register int i=2;i<=n;i++)

	{

		minn=(min(minn,abs(total-(a[i-1]*2))));

	}

	printf("%lld",minn);

	putchar(10);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

int n;

long long int sum,min,x;

int a[200000];

int main()

{

	scanf("%d",&n);

	for(int i=0;i<n;i++)

	  scanf("%d",&a[i]);

	for(int i=0;i<n;i++)

	  sum+=a[i];

	min=labs(sum-2*a[0]);

	for(int i=0;i<n-1;i++)

	{

		x+=a[i];

		if(labs(sum-2*x)<min)

		  min=abs(sum-2*x);

	}

	printf("%d\n",min);

	return 0;

}

// Fastest known solution for this problem: