stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <string>

#include <map>

#include <set>

using namespace std;

map <string,int> cost;

multimap <string,string>  rule;

set <string> his;

void update(string a){

  multimap<string,string>::iterator it=rule.find(a);

  while(it != rule.end() && it->first == a) {

    if(cost[it->second]>cost[a])cost[it->second]=cost[a], update(it->second);

    it++;

  }

}

int mk_rule(string a){

  if(his.count(a) == 0){

    his.insert(a);    

    multimap<string,string>::iterator it=rule.find(a);

    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;

    update(a);

  }

  return cost[a];

}

int main(){

  int n,m,b;

  cin >> n;

  string a,c,ls[5002];

  for(int i=0;i<n;i++) cin >> ls[i] >> b, cost[ls[i]] = b;



  cin >> m;

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

    cin >> a >> c;

    rule.insert(pair<string,string>(a,c));

    rule.insert(pair<string,string>(c,a));

  }

  int ans=0;

  for(int i=0;i<n;i++) ans += mk_rule(ls[i]);

  cout << ans <<endl;

  return 0;

}

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

#include <string>

#include <algorithm>

#include <map>

using namespace std;

map <string,string> mp;

map <string,int> in;



string find(string  x){

  if(mp[x] != x) mp[x] = find(mp[x]);

  return mp[x];

}



void unite(string x,string y){

  x=find(x),y=find(y);

  if(in[x]<in[y]) swap(x,y);

  mp[x] = mp[y];

}



int main() {

  int n,m,a;

  string str,str2;

  cin >> n;

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

    cin >> str >> a;

    in[str] = a;

    mp[str] = str;

  } 



  cin >> m;

  for(int i=0;i<m;i++)cin >> str >> str2,unite(str,str2);



  int ans =0;

  map<string,int> :: iterator it;

  for(it=in.begin();it!=in.end();it++) ans += in[find(it->first)];

  cout << ans <<endl;

  return 0;

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

using namespace std;



#define INF 2147483647

#define ASTART (1<<17)

int a[1<<18][2];

int ti=1;



int find(int i){

  int nv=INF,t=0;

  i+=ASTART-1;

  nv=a[i][0];

  t=a[i][1];

  while (i>0){

    i=(i-1)/2;

    if (t<a[i][1])nv=a[i][0],t=a[i][1];

    //cout << i << " = " << a[i][0]<< " = " << a[i][1]<< endl;

  }

  return nv;

}

void update(int s,int t,int x,int k,int l,int r){

  if (l>=s&&r<=t){

    a[k][0]=x;

    a[k][1]=ti;

    return;

  }

  if (r<=s||l>=t)return;

  int m=(l+r)/2;

  update(s,t,x,k*2+1,l,m);

  update(s,t,x,k*2+2,m,r);

}

int main(){

  int n,q,com,s,t,x;

  for (int i=0;i<(1<<18);i++)a[i][0]=INF,a[i][1]=0;

  cin >> n>>q;



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

    cin >> com;

    if (com==0) {

      cin >> s >> t >> x;

      update(s,t+1,x,0,0,ASTART);

      ti++;

    }else {

      cin >> s;

      cout << find(s)<< endl;

    }

    //for (int i=0;i<5;i++)cout << a[i] << endl;

    //cout << a[ASTART];

  }



  return 0;

}

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

using namespace std;



#define INF (1 << 30) - 1 + (1 << 30)



int a[262144], n2, lazy[262144];



void lazyeval(int i) {

  if (lazy[i] == INF) return;

  a[i] = lazy[i];

  if (i < n2 - 1) {

    lazy[2 * i + 1] = lazy[2 * i + 2] = lazy[i];

  }

  lazy[i] = INF;

}



int findsingle(int i) {

  int j = i + n2 - 1;

  int val = a[i + n2 - 1];

  if (lazy[j] != INF) val = lazy[j];

  while (j > 0) {

    j = (j - 1) / 2;

    if (lazy[j] != INF) val = lazy[j];

  }



  return val;

}



void updaterange(int s, int t, int i, int l, int r, int x) {

  lazyeval(i);

  // cout << s << " " << t << " " << i << " " << l << " " << r << endl;

  if (s <= l && r <= t) {

    a[i] = x;

    if (i < n2 - 1) {

      lazy[2 * i + 1] = lazy[2 * i + 2] = a[i];

    }

    return;

  }

  if (t <= l || r <= s) return;

  updaterange(s, t, i * 2 + 1, l, (l + r) / 2, x);

  updaterange(s, t, i * 2 + 2, (l + r) / 2, r, x);



  a[i] = min(a[i * 2 + 1], a[i * 2 + 2]);

}



int main() {

  int n, q, com, s, t, x;



  cin >> n >> q;

  n2 = 1;

  while (n > n2) n2 *= 2;

  for (int i = 0; i < n2 * 2; i++) a[i] = lazy[i] = INF;



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

    cin >> com >> s;

    if (com == 0) {

      cin >> t >> x;

      updaterange(s, t + 1, 0, 0, n2, x);

    } else

      cout << findsingle(s) << endl;

  }

  return 0;

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

using namespace std;



const int N = 55;



string s[N];

int cnt[26];



int main() {

  ios::sync_with_stdio(false);

  cin.tie(nullptr);

  int n; cin >> n;

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

    cin >> s[i];

  }

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

    cnt[s[0][i] - 'a']++;

  }

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

    int curcnt[26];

    for (int j = 0; j < 26; j++) curcnt[j] = 0;

    for (int j = 0; j < (int)s[i].size(); j++) {

      curcnt[s[i][j] - 'a']++;

    }

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

      cnt[j] = min(cnt[j], curcnt[j]);

    }

  }

  vector<char> v;

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

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

      v.push_back(i + 'a');

    }

  }

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

  for (char c : v) cout << c;

  cout << endl;

  return 0;

}


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

#include       <map>

#include     <queue>

#include     <cmath>

#include    <cstdio>

#include    <cctype>

#include    <vector>

#include   <cstring>

#include <algorithm>

using namespace std;



typedef long long ll;

const ll mod = 1e9+7;

const double eps = 1e-7;

const int maxn = 1e5+5;



ll fast_pow(ll a,ll b,ll mod){

    ll ans = 1;

    while(b){

        if(b&1)

            ans = ans*a%mod;

        a = a*a%mod;

        b>>=1;

    }

    return ans;

}

int a[127];

int c[127];

int main(){

    int n;

    char str[55];

    scanf("%d",&n);

    memset(c,0x3f,sizeof(c));

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

        scanf("%s",str);

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

        for(int j=0;str[j];j++)

            a[str[j]]++;

        for(int j='a';j<='z';j++)

            c[j] = min(c[j],a[j]);

    }

    for(int j='a';j<='z';j++)

        while(c[j])putchar(j),c[j]--;

}



/*



1592794101

989097785





232162543



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

#define   ll  long long int

#define   sz  100100



using namespace std;



string ss[sz];





string tani(ll n,char ch)

{

    ll i;

    string s="";



    for(i=1;i<=n;i++)s+=ch;



    return s;



}

int main()

{



    string s="abcdefghijklmnopqrstuvwxyz";



    ll i,j,k,p,x,d,c,a,b,n;



    string an="";



    cin>>n;



    ll mn=10000000;





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

    {

        cin>>ss[i];

    }



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

    {

        mn=10000000;



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

        {

            c=0;



            for(k=0;k<ss[j].size();k++)

            {

                if(ss[j][k]==s[i])c++;

            }

            mn=min(mn,c);

        }



        string xx=tani(mn,s[i]);



        an+=xx;

    }



    cout<<an<<endl;



    return 0;

}




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

using namespace std;

string s;

struct node

{

    int a[26];

    node()

    {

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

    }

};

node d[52];

int main()

{

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int t,i,j,n,m,l,r;

    cin>>n;

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

    {

        cin>>s;

        m=s.size();

        for(char c:s)

        {

            l=c-97;

            d[i].a[l]++;

        }

    }

    s.clear();

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

    {

        l=INT_MAX;

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

        {

            l=min(l,d[j].a[i]);

        }

        for(j=0;j<l;j++)

        {

            s+=(char)(i+97);

        }

    }

    cout<<s<<"\n";

    return 0;

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

#include<cstdio>

#include<algorithm>

#include<cmath>

const double EPS=1e-8;

const double PI=acos(-1);

const int N=105;

int n;double x[N],y[N],z[N];

bool vis[N];

struct Node {

    double x,y;int id;

    Node(double x=0,double y=0,int id=0):x(x),y(y),id(id){}

    bool operator < (const Node &b) const {

        if(x!=b.x) return x<b.x;

        return y<b.y;

    }

    Node operator - (const Node &b) {

        return Node(x-b.x,y-b.y);

    }

    double det(const Node &b) {

        return x*b.y-y*b.x;

    }

    double dot(const Node &b) {

        return x*b.x+y*b.y;

    }

    double dis() {

        return sqrt(x*x+y*y);

    }

}point[N],ans[N];

int solve(int num) {

    std::sort(point,point+num);

    int k=0;

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

        while(k>1&&(ans[k-1]-ans[k-2]).det(point[i]-ans[k-1])<EPS) k--;

        ans[k++]=point[i];

    }

    for(int i=num-2,t=k;~i;i--) {

        while(k>t&&(ans[k-1]-ans[k-2]).det(point[i]-ans[k-1])<EPS) k--;

        ans[k++]=point[i];

    }

    return k;

}

double res[N];

int main() {

    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%lf%lf",&point[i].x,&point[i].y),point[i].id=i;

    int num=solve(n)-1;

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

    if(num==2) res[ans[0].id]=res[ans[1].id]=0.5;

    else {

        double tmp;

        tmp=(ans[0]-ans[num-1]).dot(ans[0]-ans[1]);

        tmp=acos(tmp/(ans[0]-ans[num-1]).dis()/(ans[0]-ans[1]).dis());

        res[ans[0].id]=(PI-tmp)/PI/2;

        tmp=(ans[num-1]-ans[0]).dot(ans[num-1]-ans[num-2]);

        tmp=acos(tmp/(ans[num-1]-ans[num-2]).dis()/(ans[num-1]-ans[0]).dis());

        res[ans[num-1].id]=(PI-tmp)/PI/2;

        for(int i=1;i<num-1;i++) {

            tmp=(ans[i]-ans[i-1]).dot(ans[i]-ans[i+1]);

            tmp=acos(tmp/(ans[i]-ans[i-1]).dis()/(ans[i]-ans[i+1]).dis());

            res[ans[i].id]=(PI-tmp)/PI/2;

        }

    }

    for(int i=0;i<n;i++) printf("%.12f\n",res[i]);

    return 0;

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const double pi=acos(-1);

int n,x[101],y[101];

double p[201];

int pp;

double Max(double a,double b){return a>b?a:b;}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);

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

		for(int j=1;j<=n;j++)if(i!=j) p[++pp]=atan2(y[j]-y[i],x[j]-x[i]);

		sort(p+1,p+pp+1);

		for(int j=1;j<=pp;j++) p[pp+j]=p[j]+pi+pi;

		double mx=0;

		for(int j=1;j<=pp;j++) mx=max(mx,pi-p[j+pp-1]+p[j]);

		printf("%.8lf\n",mx/pi/2);

		pp=0;

	}

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

using namespace std;

const double pi=acos(-1.);

const int N=105;

int n,x[N],y[N];

double p[N+N];

signed main()

{

    cin>>n;

    for(int i=0; i<n; i++)cin>>x[i]>>y[i];

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

    {

        int tot=0;

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

            if(i!=j)p[tot++]=atan2(y[j]-y[i],x[j]-x[i]);

        sort(p,p+tot);

        for(int j=0; j<tot; j++)p[j+tot]=p[j]+2*pi;

        double ans=0;

        for(int j=0; j<tot; j++)ans=max(ans,pi-p[j+tot-1]+p[j]);

        printf("%.8f\n",ans/2/pi);

    }

    return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const double pi=acos(-1);

int n,x[101],y[101];

double p[201];

int pp;

double Max(double a,double b){return a>b?a:b;}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);

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

		for(int j=1;j<=n;j++)if(i!=j) p[++pp]=atan2(y[j]-y[i],x[j]-x[i]);

		sort(p+1,p+pp+1);

		for(int j=1;j<=pp;j++) p[pp+j]=p[j]+pi+pi;

		double mx=0;

		for(int j=1;j<=pp;j++) mx=max(mx,pi-p[j+pp-1]+p[j]);

		printf("%.8lf\n",mx/pi/2);

		pp=0;

	}

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

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

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

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



int n,x[101],y[101];

const double PI=acos(-1);

double k[101];



int main(){

	scanf("%d",&n);

	if(n==2){puts("0.5\n0.5");return 0;}

	F(i,1,n) scanf("%d%d",x+i,y+i);

	F(i,1,n){

		int cnt=0;

		F(j,1,n) if(j!=i){

			k[++cnt]=atan2(x[j]-x[i],y[j]-y[i]);

		}

		sort(k+1,k+cnt+1);

		double t;

		t=k[1]-k[cnt]+PI+PI;

		if(t>=PI-1e-9) {printf("%.15lf\n",(t-PI)/(PI+PI)); continue;}

		bool ok=0;

		F(j,1,cnt-1){

			t=k[j+1]-k[j];

			if(t>=PI-1e-9) {printf("%.15lf\n",(t-PI)/(PI+PI)); ok=1; break;}

		} if(!ok) printf("%.15lf\n",i,0.);

	}

	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const double pi=acos(-1);

int n,x[101],y[101];

double p[201];

int pp;

double Max(double a,double b){return a>b?a:b;}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);

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

		for(int j=1;j<=n;j++)if(i!=j) p[++pp]=atan2(y[j]-y[i],x[j]-x[i]);

		sort(p+1,p+pp+1);

		for(int j=1;j<=pp;j++) p[pp+j]=p[j]+pi+pi;

		double mx=0;

		for(int j=1;j<=pp;j++) mx=max(mx,pi-p[j+pp-1]+p[j]);

		printf("%.8lf\n",mx/pi/2);

		pp=0;

	}

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

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



int n,x[101],y[101];

const double PI=acos(-1);

double k[101];



int main(){

	scanf("%d",&n);

	if(n==2){puts("0.5\n0.5");return 0;}

	F(i,1,n) scanf("%d%d",x+i,y+i);

	F(i,1,n){

		int cnt=0;

		F(j,1,n) if(j!=i){

			k[++cnt]=atan2(x[j]-x[i],y[j]-y[i]);

		}

		std::sort(k+1,k+cnt+1);

		double t;

		t=k[1]-k[cnt]+PI+PI;

		if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); continue;}

		bool ok=0;

		F(j,1,cnt-1){

			t=k[j+1]-k[j];

			if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); ok=1; break;}

		} if(!ok) printf("%.15lf\n",0.);

	}

	return 0;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>

#define ld long double

#define MN 205

#define eps 1e-9

using namespace std;

const ld pi=acos(-1);

struct vec

{

	ld x,y; int pos;

	friend vec operator-(const vec& a,const vec& b) {return (vec){a.x-b.x,a.y-b.y};}

	friend ld operator/(const vec& a,const vec& b) {return a.x*b.y-a.y*b.x;}

	friend ld operator*(const vec& a,const vec& b) {return a.x*b.x+a.y*b.y;}

	friend ld abs(const vec& a) {return sqrt(a.x*a.x+a.y*a.y);}

}a[MN];

ld ans[MN];

int q[MN];

int n,tp;



inline int read()

{

	int n=0,f=1; char c=getchar();

	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}

	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}

	return n*f;

}



bool cmp1(const vec& a,const vec& b) {return a.x<b.x || a.x==b.x && a.y<b.y;}

bool cmp2(const vec& A,const vec& B)

{

	ld lt=(A-a[1])/(B-a[1]);

	if (fabs(lt)>eps) return lt>0;

	else return abs(A-a[1])<abs(B-a[1]);

}



int main()

{

//	freopen("data.in","r",stdin);

//	freopen("data.out","w",stdout);

	register int i;

	n=read();

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

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

		a[i].x=read(),a[i].y=read(),a[i].pos=i;

	if (n==1) return 0*printf("1");

	else if (n==2) return 0*printf("0.5000000\n0.5000000");

	sort(a+1,a+n+1,cmp1);

	sort(a+2,a+n+1,cmp2);

	q[tp=1]=1;

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

	{

		while (tp>1&&(a[q[tp]]-a[q[tp-1]])/(a[i]-a[q[tp-1]])<eps) --tp;

		q[++tp]=i;

	}

	q[tp+1]=q[1]; q[0]=q[tp];

//	for (i=1;i<=tp;++i) printf("%lld,%lld\n",a[q[i]].x,a[q[i]].y);	

//	for (i=1;i<=tp;++i) printf("%d ",a[q[i]].pos); puts("");

//	printf("%d\n",tp);

//	printf("%d %d\n",n,tp);

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

	

	{

	

		ans[a[q[i]].pos]=

		(pi-acos((double)(

		((a[q[i-1]]-a[q[i]])*

		(a[q[i+1]]-a[q[i]]))

		/(abs(a[q[i-1]]-a[q[i]])*

		  abs(a[q[i+1]]-a[q[i]])))))/(pi*2);

//	printf("%.5lf\n",acos(

//		((a[q[i-1]]-a[q[i]])*

//		(a[q[i+1]]-a[q[i]]))

//		/(abs(a[q[i-1]]-a[q[i]])*

//		  abs(a[q[i+1]]-a[q[i]]))));

	}

	

	for (i=1;i<=n;++i) printf("%.10lf\n",(double)ans[i]);

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

#include<iostream>

using namespace std;

int q;long long sum,a,b,m=100000000000;bool flag;

int main()

{

    cin>>q;

    while(q--)

    {

        cin>>a>>b;

        sum+=b;

        if(m>b&&b<a)

            m=b;

        if(a!=b)

            flag=1;

    }

    if(flag)

        cout<<sum-m;

    else cout<<0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define INF 0x7fffffff

#define N 200005

int n;

long long cnt,a,b,minb=INF;

bool f=0;

int main()

{

	scanf("%d",&n);

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

	{

		scanf("%lld %lld",&a,&b);

		cnt+=b;

		if(b<a&&minb>b)

		minb=b;

		if(b!=a) f=1; 

	}

	if(f)printf("%lld\n",cnt-minb);

	else printf("0\n");

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

#include<iostream>

using namespace std;

int q;long long sum,a,b,m=100000000000;bool flag;

int main()

{

    cin>>q;

    while(q--)

    {

        cin>>a>>b;

        sum+=b;

        if(m>b&&b<a)

            m=b;

        if(a!=b)

            flag=1;

    }

    if(flag)

        cout<<sum-m;

    else cout<<0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define INF 0x7fffffff

#define N 200007

int n;

long long cnt,a,b,minb=INF;

bool f=0;

int main()

{

	scanf("%d",&n);

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

	{

		scanf("%lld %lld",&a,&b);

		cnt+=b;

		if(b<a&&minb>b)

		minb=b;

		if(b!=a) f=1; 

	}

	if(f)printf("%lld\n",cnt-minb);

	else printf("0\n");

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

#include<iostream>

using namespace std;

int q;long long sum,a,b,m=100000000000;bool flag;

int main()

{

    cin>>q;

    while(q--)

    {

        cin>>a>>b;

        sum+=b;

        if(m>b&&b<a)

            m=b;

        if(a!=b)

            flag=1;

    }

    if(flag)

        cout<<sum-m;

    else cout<<0;

}

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

#include<algorithm>

#include<cmath>

#include<cstring>

using namespace std;

#define MAXN 200005

#define INF 0x3f3f3f3f

#define LL long long

int n,m=INF;

LL ans;

int a[MAXN],b[MAXN];

int main()

{

	scanf("%lld",&n);

	bool f=0;

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

	{

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

		if(a[i]!=b[i]) f=1;

		ans+=a[i];

		if(a[i]>b[i]) m=min(m,b[i]);

	}

	if(f==0) 

	{

		printf("0\n");

		return 0;

	}

	printf("%lld\n",ans-m);

    return 0;

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

#include <iostream>

#define f first

#define s second

using namespace std;

typedef long long LL;

const int MAXN = 1e6+66;

int main()

{

    LL n,a,b;

    cin>>n;

    int vis = n;

    LL ans = 0;

    LL bb = 1e9+99;

    while(n--)

    {

        cin>>a>>b;

        ans += a;

        if(a == b) vis--;

        if(a > b) bb = min(bb,b);

    }

    if(vis) cout<<(ans-bb);

    else cout<<0;

    return 0;

}

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

#include<algorithm>

#include<cmath>

#include<cstring>

using namespace std;

#define MAXN 200005

#define INF 0x3f3f3f3f

#define LL long long

int n,m=INF;

LL ans;

int a[MAXN],b[MAXN];

int main()

{

	scanf("%lld",&n);

	bool f=0;

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

	{

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

		if(a[i]!=b[i]) f=1;

		ans+=a[i];

		if(a[i]>b[i]) m=min(m,b[i]);

	}

	if(f==0) 

	{

		printf("0\n");

		return 0;

	}

	printf("%lld\n",ans-m);

    return 0;

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

#include<map> 

#include<ctime> 

#include<cmath> 

#include<cstdio> 

#include<queue> 

#include<vector> 

#include<cstring> 

#include<climits> 

#include<iostream> 

#include<algorithm> 

using namespace std; 

int read(){ 

    int f=1,x=0; 

    char c=getchar(); 

    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 

    while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar(); 

    return f*x; 

} 

#define MOD 100003 

#define MAXN 100000 

#define LL long long

#define INF 0x3f3f3f3f

int main(){

	bool flag=0;

	LL a,b,n=read(),s1=0,s2=INF;

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

	{

		a=read(),b=read(),s1+=a;

		if(a>b&&s2>b) s2=b;

		if(a!=b) flag=1;

	}

	printf("%lld\n",flag?(s1-s2):0);

    return 0; 

}

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

#include<algorithm>



const int N=2e5,inf=1<<30;



int a,b;

int mini=inf;

long long sum;



int main()

{

	int n;

	scanf("%d",&n);

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

	{

		scanf("%d %d",&a,&b);

		sum+=a;

		if(a>b)

			mini = std::min(mini,b);

	}

	if(mini == inf)

		printf("0\n");

	else

		printf("%lld\n",sum-mini);

	return 0;

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



#define fr first

#define sc second

#define OK puts("OK");

#define pb push_back

#define mk make_pair

#define int long long



using namespace std;



typedef long long ll;



const int inf = (int)1e9 + 7;

const int N = (int)2e5 + 7;



int n;

int a[N],b[N],mn = inf;

int ind,ans;

int sum;



 main () {

      cin >> n;



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

            cin >> a[i] >> b[i];

            sum += a[i];

            if (a[i] > b[i]) {

                  if (a[i] - b[i] < mn)

                        mn = a[i] - b[i],ind = i;



            }

      }

      if (mn == inf) {

            cout << 0 << endl;

      }

      else {

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

                  if (a[i] > b[i]) {

                        ans = max(ans,sum - a[i] + (a[i] - b[i]));

                  }

            }

            cout << ans << endl;

      }

}


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

#include<algorithm>

using namespace std;

const int MAXN = 2 * int(1E5);

struct node{

	int A, B;

}a[MAXN + 5];

int main() {

	int N;

	scanf("%d", &N);

	bool flag = true;

	long long Sum = 0, Min = (1ll << 60);

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

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

		if( a[i].A > a[i].B )

			Min = min(Min, 1ll*a[i].B);

		if( a[i].A != a[i].B )

			flag = false;

		Sum += a[i].A;

	}

	if( flag ) {

		printf("0\n");

		return 0;

	}

	printf("%lld", Sum - Min);

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



using namespace std;



#define pb push_back

#define eb emplace_back

#define ll long long

#define pii pair < int, int >

#define fr first

#define sc second

#define mk make_pair

#define sz(s) (int)s.size()

#define all(s) s.begin(), s.end()

#define ok puts("ok");

#define whatis(x) cerr << #x << " = " << x << endl;

#define pause system("pause");



const int N = (int)2e5 + 7;

const int inf = (int)1e9 + 7;



int n;

int a[N], b[N], c[N];

ll sum, sum1, ans;

bool fl;

int cc;



void putans(ll asd) {

  cout << asd;

  exit(0);

}



main() {

  scanf("%d", &n);

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

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

    c[i] = a[i] - b[i];

    sum += a[i];

    if (c[i] <= 0) {

      sum1 -= c[i];

      ans += a[i];

    }

  }

  fl = 1;

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

    fl &= (a[i] == b[i]);

  if (fl) {

    putans(0);

  }

  int mn = inf;

  int mx = -1;

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

    if (c[i] > 0) {

      if (b[i] < mn) {

        mn = b[i];

        mx = a[i];

      }

    }

  }

  putans(sum - mn);

}


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

#include<algorithm>

using namespace std;

const int MAXN = 2 * int(1E5);

struct node{

	int A, B;

}a[MAXN + 5];

int main() {

	int N;

	scanf("%d", &N);

	bool flag = true;

	long long Sum = 0, Min = (1ll << 60);

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

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

		if( a[i].A > a[i].B )

			Min = min(Min, 1ll*a[i].B);

		if( a[i].A != a[i].B )

			flag = false;

		Sum += a[i].A;

	}

	if( flag ) {

		printf("0\n");

		return 0;

	}

	printf("%lld", Sum - Min);

}