stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



int main() {

    using namespace std;

    constexpr unsigned long maxN = 200010;

    unsigned long N;

    scanf("%lu", &N);

    array<unsigned long, maxN> perm;

    {

        array<pair<long, long>, maxN> p;

        for(unsigned long i = 0; i < N; ++i)scanf("%lu%lu", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(unsigned long i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;

    array<unsigned long, maxN> binary;

    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});



    array<unsigned long, maxN> fenwick_tree{};

    auto que = [&fenwick_tree, &N](unsigned long i){

        unsigned long s{0}, j{i};

        while (i) { s += fenwick_tree[i]; i -= i & -i; }

        while (j <= N) { ++fenwick_tree[j]; j += j & -j; }

        return s;

    };



    array<unsigned long, maxN> coef{};

    coef[N] = N + MOD - 4;

    for(unsigned long i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8483159807321006x):
#include <array>

#include <cstdio>

#include <utility>

#include <algorithm>

#include <numeric>



using namespace std;



constexpr unsigned long maxN = 200010;



array<unsigned long, maxN> perm;

    array<unsigned long, maxN> binary;

    array<unsigned long, maxN> coef;

    array<unsigned long, maxN> fenwick_tree;



    unsigned long que(unsigned long i){

        unsigned long s{0}, j{i};

        while (i) { s += fenwick_tree[i]; i -= i & -i; }

        while (j < maxN) { ++fenwick_tree[j]; j += j & -j; }

        return s;

    };





int main() {

    //using namespace std;

   

    unsigned long N;

    scanf("%lu", &N);

   

    {

        array<pair<long, long>, maxN> p;

        for(unsigned long i = 0; i < N; ++i)scanf("%lu%lu", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(unsigned long i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;



    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});









    coef[N] = N + MOD - 4;

    for(unsigned long i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    printf("%lu", inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD);

    return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.1120612194190518x):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;



#define pb push_back

#define F first

#define S second

#define fo(i,a,b)  for(int i = a; i < b; i++)



using ll = long long;

using ld = long double;

using ul = unsigned long long;

using ii = pair<int, int>;

#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ReadFile            freopen("input.in","r",stdin)

#define WriteFile           freopen("output.txt","w",stdout)

const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;

const ld EPS = 1e-7;

double Pi=acos(-1);

const ld rad=Pi/180.0;

ll power(ll x, ll y, ll p)

{

    ll res = 1;

    while (y > 0)

    {

        if (y & 1)

            res = (res*x) % p;

        y = y>>1;

        x = (x*x) % p;

    }

    return res;

}

ll nCr (ll n,ll m)

{

    return(m == 0)?1:n*nCr(n-1,m-1)/m;

}

/*****************************************************/



const int N = 103;



int n , a[N] , ans = INT_MAX;



int main()

{

    cin >> n;



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

        cin >> a[i];



    for(int i = 1; i <= 101; ++i){

        int x = 0;

        for(int j = 1; j <= n; ++j){

            x += (a[j] - i) * (a[j] - i);

        }

    ans = min(ans , x);

    }



    cout << ans << "\n";



    return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.0967722437355043x):
#include <bits/stdc++.h>

using namespace std;

#define ll	    long long

#define vi      vector <int>

#define vii     vector <pair<int,int>>

#define ii      pair<int,int>

#define loop(n)	for(int i=0;i<n;i++)

ll mod=1e9+7;

bool is_prime(int n)

{

    if(n==2)

        return true;

    if(n%2==0||n<2)

        return false;

    for(int i=3; i<=sqrt(n); i+=2)

    {

        if(n%i==0)

            return false;

    }

    return true;

}

long long power(ll n, ll k){

    if(k==0) return 1;

    ll sq=(power(n,k/2))%mod;

    sq=(sq*sq)%mod;

    if(k%2==1)

        sq=(sq*n)%mod;

    return sq%mod;

}

void low(char &c){

c=tolower(c);

}

void primeFactors(int n)

{

    while (n % 2 == 0)

    {

        cout << 2 << " ";

        n = n/2;

    }



    for (int i = 3; i <= sqrt(n); i = i + 2)

    {

        while (n % i == 0)

        {

            cout << i << " ";

            n = n/i;

        }

    }



    if (n > 2)

        cout << n << " ";

}



#include <iostream>

using namespace std;

void fast();

int arr[105];

map <int,int> M;

int main() {

//fast();

int n;

cin >> n;

loop(n){

    cin >> arr[i];

}

int mn=99999999;

int sm=0;

loop(101){

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

    sm+=power(abs(arr[j]-i),2);

  }

  mn=min(sm,mn);

  sm=0;

}

cout << mn;

}











void fast(){

std::ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);



}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.112031699050598x):
#include<cstdio>

#include<cstring>

#include<iostream>



using namespace std;



int main()

{

	int n;

	int x[105],p[110] = {0};

	int num1;

	int num = 0;

	cin >> n;

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

		cin >> x[i];

	}

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

//

//		if(x[i] >= num)		num = x[i];

//	}

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

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

			if(x[j] > i){

				p[i] += (x[j] - i) * (x[j] - i);

			}

			else{

				p[i] += (i - x[j]) * (i - x[j]);

			}

		}

	}

	num1 = p[0];

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

		if(p[i] < num1){

			num1 = p[i];

		}

	}

	cout << num1 << endl;

	return 0;

	

		

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.1132303452993797x):
#include <cstdio>

#include <queue>

#include <cmath>

#include <algorithm>

#include <iostream>

#include <set>

#include <map>

#include <string>

#include <algorithm>

using namespace std;

#include <string>

#include <cstdio>

#define ll long long

#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef pair<int,int> pii;

const ll mod = 1000000007 ;

const int INF=0x3f3f3f3f;

#define test(n) cout<<"Test "<<n<<endl;

#define pb push_back

#define rp(n) for(int i=1;i<=n;i++)

#define rep(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)

ll ksm(ll x,ll n){ll ans=1;while (n){if (n&1)ans=(ans*x)%mod;x=x*x%mod;n>>=1;}return ans;}

using namespace std;

double pi = atan(1.0)*4 ;

const int mxn = 1e3+7 ;

int n,t,m,k,l,r;

/// ll mat[mxn][mxn], prime[mxn], isprime[mxn];

ll phi[mxn];

string str,s;char ch[27][27] ;

ll exgcd(ll a,ll b, ll &x ,ll &y){    if(!a&&!b) return -1;    if(!b) {x=1,y=0;return a;}    ll d=exgcd(b,a%b,y,x);    y-=a/b*x ;    return d;}

int vis[mxn][mxn];

int a[mxn];

int check(int x)

{

    int ans = 0 ;

    rp(n) ans+=(x-a[i])*(x-a[i]);

    return ans;

}

int main()

{

    cin>>n;

    int l = 1e3 ,r = -1;

    rp(n) {cin>>a[i];l = min(a[i],l) , r = max(a[i],r) ;}

    int mx = INF;

    for(int k=l;k<=r;k++)

    {

            int ans = check(k) ;

            if(ans < mx )

                m = k , mx = ans ;



    }

    cout<<mx<<endl;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.113316159336413x):
#include<bits/stdc++.h>

using namespace std;

main(){

long long i,j,k,l,m,n,p;

while(cin>>p){

long long x[p];

for(i=0;i<p;i++)cin>>x[i];

sort(x,x+p);m=10000000000000000;

for(j=x[0];j<=x[p-1];j++)

{ k=0;

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

l=abs(x[i]-j);

k+=(l*l);

}

    if(k<m) m=k;

}

cout<<m<<endl;

}

 return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.1023731694164802x):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main()

{

    ll x,y,i,m,s=0,d,c=0,n,c1=0;

    vector<ll>a;

    cin>>n;

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

    {

        cin>>m;

        a.push_back(m);

        s+=m;

    }

    m=(s/n);

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

    {

        c+=((m-a[i])*(m-a[i]));

    }

    m++;

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

    {

        c1+=((m-a[i])*(m-a[i]));

    }

    cout<<min(c,c1)<<endl;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

int arr[100];

int main() {

    quick

int n; cin>>n; long long ans=LONG_LONG_MAX;

for(int i=0;i<n;i++){cin>>arr[i];}

for(int i=0;i<=1e4;i++){

    long long sum=0;

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

    sum+=(arr[j]-i)*(arr[j]-i);

}

if(sum<ans){ans=sum;}

}

cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.1149701426069423x):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()

{

    ll n,c=0,t=0,b,s=0,f,g,d=0,x=0;

    cin>>n;

    ll a[n+10];

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

    {

        cin>>a[i];

        s += a[i];

    }



    f = ceil(s*1.0/n);

    //cout<<f<<endl;

    g = (s/n);

    //cout<<g<<endl;





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

    {

        t = abs(f-a[i]);

        t = t*t;

        c += t;

        //cout<<c<<endl;

    }

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

    {

        d = abs(g-a[i]);

        d = d*d;

        x += d;

        //cout<<c<<endl;

    }

    cout<<min(c,x)<<endl;

}
// Slower C++ solution:
#include <queue>

#include <vector>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

const int INF=0x3f3f3f3f;

using namespace std;

struct edge{

    int to,cost,w;

};

int V,d[10005],dis[10005];

vector<edge> G[20005];

typedef pair<int,int> P;

void dijkstra(int s){

    int i,v;

	priority_queue<P,vector<P>,greater<P> >que;

	fill(d,d+V+1,INF);

	fill(dis,dis+V+1,INF);

	d[s]=dis[s]=0;

	que.push(P(0,s));

	while(!que.empty()){

		P p=que.top(); que.pop();

		v=p.second;

		if(d[v]<p.first)

        continue;

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

			edge e=G[v][i];

			if(d[e.to]>d[v]+e.cost){

				d[e.to]=d[v]+e.cost;

                dis[e.to]=e.w;

				que.push(P(d[e.to],e.to));

			}

			else if(d[e.to]==d[v]+e.cost)

            dis[e.to]=min(dis[e.to],e.w);

		}

	}

}

int main(){

    int m,st,en,i,j,x,y,z,q,ans;

    edge temp;

    while(scanf("%d%d",&V,&m)!=EOF&&(V||m)){

        for(i=0;i<=V;i++)

        G[i].clear();

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

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

            temp.to=y;temp.cost=z;temp.w=q;

            G[x].push_back(temp);

            temp.to=x;

            G[y].push_back(temp);

        }

        dijkstra(1);

        ans=0;

        for(i=1;i<=V;i++)

        ans+=dis[i];

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1687536358939137x):
#include <iostream>

#include <queue>

#include <functional>

#include <cstring>

using namespace std;

#define MAX_V 10240

 

// 从?点from指向?点to的???cost的?

typedef struct edge

{

	int to, distance, cost;

	edge(){}

	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}

	bool operator > (const edge & b) const

	{

		return distance != b.distance  ? distance > b.distance : cost > b.cost;

	}

} P;

 

// first 最短路径，second?点?号

 

// ?

vector<edge> G[MAX_V];

 

// V是?点数

int V;

bool visited[MAX_V];

 

// 求解从?点s出?到所有点的最短花?

int dijkstra(int s)

{

	int result = 0;

	priority_queue<P, vector<P>, greater<P> > que;

	memset(visited, 0, V * sizeof(bool));

	que.push(P(0, 0, 0));

 

	while (!que.empty())

	{

		P p = que.top(); que.pop();

		int v = p.to;

		if (visited[v]) continue;

		visited[v] = true;

		result += p.cost;

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

		{

			edge e = G[v][i];

			que.push(P(G[v][i].to, p.distance + G[v][i].distance, G[v][i].cost));

		}

	}

 

	return result;

}

 

///////////////////////////SubMain//////////////////////////////////

int main(int argc, char *argv[])

{

	int /*N = V,*/ M;

	while (cin >> V >> M && V)

	{

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

		{

			G[i].clear();

		}

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

		{

			int u, v, d, c;

			cin >> u >> v >> d >> c;

			--u, --v;

			G[u].push_back(edge(v, d, c));

			G[v].push_back(edge(u, d, c));

		}

 

		cout << dijkstra(0) << endl;

	}

	return 0;

}
// Slower C++ solution:
#include <queue>

#include <vector>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

const int INF=0x3f3f3f3f;

using namespace std;

struct edge{

    int to,cost,w;

};

int V,d[10005],dis[10005];

vector<edge> G[20005];

typedef pair<int,int> P;

void dijkstra(int s){

    int i,v;

	priority_queue<P,vector<P>,greater<P> >que;

	fill(d,d+V+1,INF);

	fill(dis,dis+V+1,INF);

	d[s]=dis[s]=0;

	que.push(P(0,s));

	while(!que.empty()){

		P p=que.top(); que.pop();

		v=p.second;

		if(d[v]<p.first)

        continue;

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

			edge e=G[v][i];

			if(d[e.to]>d[v]+e.cost){

				d[e.to]=d[v]+e.cost;

                dis[e.to]=e.w;

				que.push(P(d[e.to],e.to));

			}

			else if(d[e.to]==d[v]+e.cost)

            dis[e.to]=min(dis[e.to],e.w);

		}

	}

}

int main(){

    int m,st,en,i,j,x,y,z,q,ans;

    edge temp;

    while(scanf("%d%d",&V,&m)!=EOF&&(V||m)){

        for(i=0;i<=V;i++)

        G[i].clear();

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

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

            temp.to=y;temp.cost=z;temp.w=q;

            G[x].push_back(temp);

            temp.to=x;

            G[y].push_back(temp);

        }

        dijkstra(1);

        ans=0;

        for(i=1;i<=V;i++)

        ans+=dis[i];

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4116814108482028x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <queue>

using namespace std;

const int inf =0x3f3f3f3f;

const int MAXN=10005;

struct node

{

    int next, to, d, c;

} G[2000005];

int cur, n;

bool vis[MAXN];

int cost[MAXN];

int dist[MAXN];

int head[MAXN];

void add(int u, int v, int d, int c)

{

    G[cur].to=v;

    G[cur].c=c;

    G[cur].d=d;

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

    head[u]=cur++;

}

queue<int>q;

void spfa(int s)

{



    while(!q.empty()) q.pop();

    memset(vis, false, sizeof(vis));

    fill(cost+1,cost+n+1,inf);

    fill(dist+1,dist+n+1,inf);

    q.push(s);

    dist[s]=0;

    cost[s]=0;

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

        for(int i=head[u]; ~i; i=G[i].next)

        {

            int v=G[i].to;

            if(dist[v]>dist[u]+G[i].d||(dist[v]==dist[u]+G[i].d&&cost[v]>G[i].c))

            {

                dist[v]=dist[u]+G[i].d;

                cost[v]=G[i].c;

                if(!vis[v])

                {

                    vis[v]=true;

                    q.push(v);

                }

            }

        }

    }

}

int main()

{

    int m;

    int u, v, d, c;

    while(~scanf("%d %d", &n, &m))

    {

        if(n==0&&m==0)break;

        memset(head, -1, sizeof(head));

        cur=0;

        while(m--)

        {

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

            add(u, v, d, c);

            add(v, u, d, c);

        }

        spfa(1);

        int ans=0;

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

            ans+=cost[i];

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

    }

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int N = 10005;

const int M = 1000000007;



int n, m;

typedef int wtype;

struct Edge { int v; wtype d, c; };

vector<Edge> e[N];

wtype dist[N], cost[N];

int pre[N];

bool vis[N];

int SPFA(int src) {

  memset(dist, 0x3f, sizeof(dist)); dist[src] = 0;

  memset(cost, 0x3f, sizeof(cost)); cost[src] = 0;

  memset(vis, 0, sizeof(vis)); vis[src] = true;

  stack<int> que; que.push(src);

  while (!que.empty()) {

    int u = que.top(); que.pop();

    vis[u] = false;

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

      int v = e[u][i].v; wtype d = e[u][i].d, c = e[u][i].c;

      if (dist[v] > dist[u] + d || (dist[v] == dist[u] + d && cost[v] != 0x3f3f3f3f && cost[v] > c)) {

        dist[v] = dist[u] + d; cost[v] = c;

        if (!vis[v]) { vis[v] = true; que.push(v); }

      }

    }

  }

  int ret = 0;

  for (int i = 1; i <= n; i++) { ret += cost[i]; }

  return ret;

}



int main() {

  while (scanf("%d%d", &n, &m), n) {

    for (int i = 1; i <= n; i++) { e[i].clear(); }

    for (int i = 0, u, v, d, c; i < m; i++) {

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

      e[u].push_back((Edge) {v, d, c});

      e[v].push_back((Edge) {u, d, c});

    }

    printf("%d\n", SPFA(1));

  }

}

// Faster C++ solution for the same problem (measured speedup: 1.2916032602530445x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <queue>

using namespace std;

const int inf =0x3f3f3f3f;

const int MAXN=10005;

struct node

{

    int next, to, d, c;

} G[2000005];

int cur, n;

bool vis[MAXN];

int cost[MAXN];

int dist[MAXN];

int head[MAXN];

void add(int u, int v, int d, int c)

{

    G[cur].to=v;

    G[cur].c=c;

    G[cur].d=d;

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

    head[u]=cur++;

}

queue<int>q;

void spfa(int s)

{



    while(!q.empty()) q.pop();

    memset(vis, false, sizeof(vis));

    fill(cost+1,cost+n+1,inf);

    fill(dist+1,dist+n+1,inf);

    q.push(s);

    dist[s]=0;

    cost[s]=0;

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

        for(int i=head[u]; ~i; i=G[i].next)

        {

            int v=G[i].to;

            if(dist[v]>dist[u]+G[i].d||(dist[v]==dist[u]+G[i].d&&cost[v]>G[i].c))

            {

                dist[v]=dist[u]+G[i].d;

                cost[v]=G[i].c;

                if(!vis[v])

                {

                    vis[v]=true;

                    q.push(v);

                }

            }

        }

    }

}

int main()

{

    int m;

    int u, v, d, c;

    while(~scanf("%d %d", &n, &m))

    {

        if(n==0&&m==0)break;

        memset(head, -1, sizeof(head));

        cur=0;

        while(m--)

        {

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

            add(u, v, d, c);

            add(v, u, d, c);

        }

        spfa(1);

        int ans=0;

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

            ans+=cost[i];

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

    }

    return 0;

}