stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

      }

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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);

}


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



#define ll long long



using namespace std;



const int inf = 1e9 + 7;





ll ans = inf, cur;



main()

{

    int n;

    cin >> n;



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

    {

        int a, b;

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



        cur += a;



        if (a > b)

            ans = min(ans, b * 1LL);

    }



    if (ans == inf)

    {

        cout << 0;

        return 0;

    }

    cout << cur - ans;

}






// Optimized solution to the same problem (faster):
#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);

}


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



#define fr first

#define sc second

#define mk make_pair

#define pb push_back

#define ok puts("OK");

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

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

#define int long long



using namespace std;



const int N = 2e5 + 5;



int n, a[N], b[N], ans, sum = 1e9 + 7;



bool fl = 0;



vector <int> vec;



main()

{

    cin >> n;

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

        scanf("%lld%lld", &a[i], &b[i]), fl |= (a[i] != b[i]), ans += a[i];



    if (!fl)

    {

        puts("0");

        return 0;

    }

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

    {

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

            sum = min(sum, b[i]);

    }

    cout << ans - sum << endl;

}


// Optimized solution to the same problem (faster):
#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);

}


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

using namespace std;

typedef long long ll;

const int maxn=2e5+5;

ll sum,ans;

ll a[maxn],b[maxn],n;

int main()

{

    ll min1=1e9+5;

    scanf("%lld",&n);

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

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

    bool flag=true;

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

        if(a[i]!=b[i])

        {

            flag=false;

            break;

        }

    if(flag)

        printf("0\n");

    else

    {

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

        {

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

                min1=min(b[i],min1);

            sum+=b[i];

        }

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

    }

}

// Optimized solution to the same problem (faster):
#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);

}


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

#include<cstdio>

#include<algorithm>

using namespace std;

const int N=2*1e5+5;

long long n,a[N],b[N];

long long ans=0;

int main()

{

    cin>>n;

    int f=0;

    ans=0;

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

        {

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

            ans+=a[i];

            if(a[i]!=b[i])

                f=1;

        }

    if(!f)

    {

        cout<<0<<endl;

    }

    else

    {

        //sort(a,a+n);

        //sort(b,b+n);

        long long p=2000000000+7;

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

        {

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

                p=min(p,b[i]);

        }

        cout<<ans-p<<endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem: