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

#define fi first

#define se second

#define all(v) begin(v), end(v)

using std::cin;

using std::cout;

using pii = std::pair<int, int>;

const int MAXN = 1e5 + 10;

int a[MAXN];



std::vector<int> G[MAXN];



void change(int L, int R, int v) {

    //cout << L << '-'<<R<<"\n";

    (a[L] += v) %= 26;

    (a[R + 1] -= v) %= 26;

}



void solve() {

    std::string s;

    cin >> s;

    int n = s.length();

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

        change(i + 1, i + 1, s[i] - s[n - i - 1]);

    }

    int m; cin >> m;

    std::vector<pii> ls;

    double mm = 0.5 * (n + 1);

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

        cin >> x >> y;

        if (x > mm  && y > mm) {

            x = n - x + 1;

            y = n - y + 1;

            std::swap(x, y);

        }

        if (x <=mm && y >mm) {

            y = n - y + 1;

            if (x == y) continue;

            if (x > y) std::swap(x, y);

            y--;

        }

        G[x].push_back(y);

    }

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

        if (!G[i].empty()) {

            std::sort(all(G[i]));

            G[i].erase(std::unique(all(G[i])), end(G[i]));

            int k = G[i].size();

            change(i, G[i][0], -a[i]);

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

                G[G[i][j - 1] + 1].push_back(G[i][j]);

            }

        }

        if (a[i] != 0) {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

}



int main() {

    solve();

    return 0;

}


// Optimized solution to the same problem (faster):
#include"bits/stdc++.h"

using namespace std;

typedef long long LL;

const int N=1e5+10;

char s[N];

int n,f[N],a[N],sum[N];

int find(int x){

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

}

int main()

{

	scanf("%s",s+1);

	scanf("%d",&n);

	int m=strlen(s+1);

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

		a[i]=s[i]-s[i-1];

		f[i]=i;

	}

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

		f[find(i)]=find(m+1-i+1);

	

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

		int l,r;

		scanf("%d%d",&l,&r);

		f[find(l)]=find(r+1);

	}

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

		sum[find(i)]=(sum[find(i)]+a[i]%26+26)%26;

	

	int flag=1;

	for(int i=1;i<=m+1&&flag;i++){

		if(sum[find(i)])flag=0;

	}

		

	if(flag)printf("YES\n");

	else printf("NO\n");

}

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

using namespace std;

int main()

{

	int n,x,g, h = 0, p = 1;

	int a[10000];

	cin >> n >> x;

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

		cin >> g;

		h += g;

		if (h > x) break;

		++p;

	}

	cout << p;

}	

// Optimized solution to the same problem (faster):
//答案错误 

#include<stdio.h>

int main()

{

	int n,m,i,cnt=0;

	int a[105]={0};

	int b[105]={0};

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

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

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

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

			b[i]=b[i-1]+a[i];

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

			if(b[i]<=m){

				cnt++;

			}

		}printf("%d\n",cnt);

		cnt=0;

	}

}

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



using namespace std;



int main()

{

#ifdef LOCAL

    freopen("input.txt", "r", stdin);

#endif // LOCAL

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int n;

    cin >> n;

    int x;

    cin >> x;

    vector <int> l(n + 1);

    vector <int> d(n + 2);

    for (int i = 1; i <= n; i++) cin >> l[i];

    d[1] = 0;

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

        d[i] = d[i - 1] + l[i - 1];

    }

    int ans = 0;

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

        if (d[i] <= x) {

            ans++;

//            return 0;

        }

    }

    cout << ans;

    return 0;

}


// Optimized solution to the same problem (faster):
//答案错误 

#include<stdio.h>

int main()

{

	int n,m,i,cnt=0;

	int a[105]={0};

	int b[105]={0};

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

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

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

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

			b[i]=b[i-1]+a[i];

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

			if(b[i]<=m){

				cnt++;

			}

		}printf("%d\n",cnt);

		cnt=0;

	}

}

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

using namespace std;

int a[1000005];

int b[10005];

int main()

{

	int n,p;

	cin>>n>>p;

	int k=0;

	int sum=0;

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

	{

		cin>>a[i];

	}

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

	{

		b[i]=b[i-1]+a[i-1];

	}

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

	{

		if(b[i]<=p)sum++;

	}

	cout<<sum;

	return 0;

}

// Optimized solution to the same problem (faster):
//答案错误 

#include<stdio.h>

int main()

{

	int n,m,i,cnt=0;

	int a[105]={0};

	int b[105]={0};

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

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

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

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

			b[i]=b[i-1]+a[i];

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

			if(b[i]<=m){

				cnt++;

			}

		}printf("%d\n",cnt);

		cnt=0;

	}

}

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

using namespace std;



int main()

{

    int x,n,i,j,ara[111],ctn,d;

    cin>>n>>x;

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

        cin>>ara[i];

    ctn=1;

    d=0;

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

    {

        j=d+ara[i-1];

        d=j;

        ctn++;

        if (d>=x)

        {

            if(d>x)

                ctn--;

            break;

        }

    }

    cout<<ctn<<endl;



    return 0;

}


// Optimized solution to the same problem (faster):
//答案错误 

#include<stdio.h>

int main()

{

	int n,m,i,cnt=0;

	int a[105]={0};

	int b[105]={0};

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

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

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

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

			b[i]=b[i-1]+a[i];

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

			if(b[i]<=m){

				cnt++;

			}

		}printf("%d\n",cnt);

		cnt=0;

	}

}

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

#include <vector>

#include <algorithm>

#include <map>



using namespace std;



typedef long long ll;

typedef pair<ll, ll> P;

    

vector<int> L(100001);



int main() {



    int N , X;

    cin >> N >> X;

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

        cin >> L[i];

    }

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

        L[i] += L[i-1];

    }

    

    int ans = 1;



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

        if (L[i] <= X) ans++;

    }

    cout << ans << '\n';

}


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

using namespace std;

/* typedef */

typedef long long ll;

typedef pair<int, int> pii;

/* constant */

const int INF = 1 << 30;

const ll LINF = 1LL << 50;

const int NIL = -1;

const int MAX = 10000;

const int mod = 1000000007;

const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */

int main(){

    int N, X;

    cin >> N >> X;

    int ans = 1, sum = 0;

    int a;

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

        cin >> a;

        sum += a;

        if (sum <= X) ans++;

    }

    cout << ans << '\n';

}


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



using namespace std;



int main() {

	int res = 1;

	int n, x;

	cin >> n >> x;

	int l;

	int t = 0;

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

		cin >> l;

		t += l;

		if (t <= x) res++;

		else break;

	}

	cout << res;

}

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

int main()

{

	int a[200];

	int x,n;

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

	int i;

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

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

	int sum=0;

	int d=0;

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

	{

	d+=a[i];

	if(d<=x)

	{

		sum++;

	}

	}

	printf("%d",sum+1);

	

}

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



using namespace std;



const int INF = numeric_limits<int>::max();

const int MAXN = 3e5 + 1;

const int MOD = 1e9 + 7;

const double res = 1e-9;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main() {

#if(DEBUG_LEVEL > 0)

    freopen("../input.txt", "r", stdin);

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

#endif

    int n, x;

    cin >> n >> x;

    int now = 0, ans = 1;

    while(n--) {

        int k;

        cin >> k;

        now += k;

        ans += now <= x;

    }

    cout << ans;

    return 0;

}

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

int main()

{

	int a[200];

	int x,n;

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

	int i;

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

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

	int sum=0;

	int d=0;

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

	{

	d+=a[i];

	if(d<=x)

	{

		sum++;

	}

	}

	printf("%d",sum+1);

	

}

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

#include<list>

#include<queue>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

int l[1000005]={0};

int ans[1000005]={0};

int main()

{

   int n,x;

   cin>>n>>x;

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

   {

        cin>>l[i];

   }

   ans[0]++;int d=0;   

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

   {

        d+=l[i];

        ans[d]++;



   }

   int tot=0;

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

   {

    //cout<<ans[i]<<" ";

    tot+=ans[i];

    }

    cout<<tot;

return 0;

}

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

int main()

{

	int a[200];

	int x,n;

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

	int i;

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

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

	int sum=0;

	int d=0;

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

	{

	d+=a[i];

	if(d<=x)

	{

		sum++;

	}

	}

	printf("%d",sum+1);

	

}

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

#include<iostream>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

int n,x;

int l[1000001];

int s;

int k;

int main()

{

	cin>>n>>x;

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

	{

		cin>>l[i];

		s=s+l[i];

		if(s>x)

		{

			cout<<i;

			k++;

			break;

		}

		else k=0;

	}

	if(k==0) cout<<n+1;

}

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

int main()

{

	int a[200];

	int x,n;

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

	int i;

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

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

	int sum=0;

	int d=0;

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

	{

	d+=a[i];

	if(d<=x)

	{

		sum++;

	}

	}

	printf("%d",sum+1);

	

}

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

Md. Shahnewaz Siddique Labib

Dept. of CSE

IUT'19

*/

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);

using namespace std;



int main(){

    fastio;

    int n, b;

    cin >> n >> b;

    cout << floor((log(n)/log(b))) + 1;

}

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



int main()

{

    int     number,cnt,i,b;

    int     a[100000];



    scanf("%d",&number);

    scanf("%d",&b);



    cnt=0;

    while(number>0)

    {

        a[cnt]=number%b;

        number=number/b;

        cnt++;

    }

    printf("%d",cnt);

}

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

SHERAJUL ARIFIN

Dept. of CSE,

IUT.

*/



#include <bits/stdc++.h>

using namespace std;



int main()

{

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    long long int n,b,r;

    cin>>n>>b;

    vector<int>v;

    while(n!=0)

    {

        r=n%b;

        v.push_back(r);

        n/=b;

    }

    cout<<v.size();









    return 0;

}


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



int main()

{

    int     number,cnt,i,b;

    int     a[100000];



    scanf("%d",&number);

    scanf("%d",&b);



    cnt=0;

    while(number>0)

    {

        a[cnt]=number%b;

        number=number/b;

        cnt++;

    }

    printf("%d",cnt);

}

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

 * Created By: Anonyman637

 * Created On: 3/5/2020 9:00:33 PM

 */



/* =============================================================================

   ================================== HEADERS ==================================

   ========================================================================== */



#include <cstdio>

#include <string>

#include <cmath>



/* =============================================================================

   ================================= TYPEDEFS ==================================

   ========================================================================== */



typedef char i8;

typedef short i16;

typedef int i32;

typedef long long i64;



typedef unsigned char ui8;

typedef unsigned short ui16;

typedef unsigned int ui32;

typedef unsigned long long ui64;



using namespace std;



/* =============================================================================

   ================================== MACROS ===================================

   ========================================================================== */



#ifdef DEBUG

#define debug(format, ...) printf(format, __VA_ARGS__)

#else

#define debug(format, ...) 

#endif



#ifdef FILEIO

#define INFILE "fileio\\"__FILE__"In.txt"

#define OUTFILE "fileio\\"__FILE__"Out.txt"

#endif



/* =============================================================================

   ================================== GLOBALS ==================================

   ========================================================================== */





/* =============================================================================

   =================================== SETUP ===================================

   ========================================================================== */



i32 setup() {



#ifdef FILEIO

        if(freopen(INFILE, "r", stdin) == NULL) return 401;

        if(freopen(OUTFILE, "w", stdout) == NULL) return 402;

#endif



        return 0;

}





/* =============================================================================

   ================================= FUNCTIONS =================================

   ========================================================================== */



i32 main() {



        i32 errorInSetup = setup();

        if (errorInSetup) exit(errorInSetup);



        i32 i, t;

        i32 n, k;

        double digits;

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

        if (n == 0) {

                digits = 1;

        } else {

                digits = (i32) ((double) log2(n) / log2(k)) + 1;

        }

        printf("%.0lf", digits);

        

        return 0;

}


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



int main()

{

    int     number,cnt,i,b;

    int     a[100000];



    scanf("%d",&number);

    scanf("%d",&b);



    cnt=0;

    while(number>0)

    {

        a[cnt]=number%b;

        number=number/b;

        cnt++;

    }

    printf("%d",cnt);

}

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

using namespace std;

long long int ar[1000000];

int main()

{

  long long  int x, y,rem,temp,i,j,total,f=0;

   cin >> x >> y;

    temp=x;

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

    ar[i]=-1;

     i=0;

    while(temp>=1)

    {

        rem=temp%y;

        temp=temp/y;

        ar[i]=rem;

        i++;



    }

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

    {

         total=ar[j]%10;

            f++;

    }

    cout<<f<<endl;

}


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

using namespace std;



#define ll long long



int main() {

    ll n,count=0,k;

    cin>>n>>k;

    while(n!=0)

    {

        count++;

        n=n/k;

    }

    cout<<count;

    return 0;

}

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

using namespace std;

int main()

{

	long int n,k;

	cin>>n>>k;

	long int t=0;

	if(k==10)

	{

		while(n!=0)

		{

			n=n/10;

			t++;

		}

	}

	else{

		t=1;

		while(n>=k)

		{

			n=n/k;

			t++;

		}

	}

	cout<<t<<endl;

	return 0;

}

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

int main()

{

	long long int N,K,count=0,a;

	scanf("%lld %lld",&N,&K);

	if(N==0){

		printf("1");

		return 0;

	}

	else{

	while(1){

			a=N/K;

			N=a;

			count++;

			if(N==0) break;

	}

	}

	printf("%lld",count);

	return 0;

		

}

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

using namespace std;



int base_conversion(int number, int base)

{

    int t = 1, out = 0, r, a, count = 0;

    a = number;

    while (a != 0)

    {

        r = a % base;

        a = a / base;

        out = out + r * t;

        t = t * 10;

        count++;

    }

    return count;

}



int main()

{

    int n, k;

    cin >> n >> k;

    cout << base_conversion(n, k);

    return 0;

}

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

#include <math.h>

#include <stdlib.h>

long long int myfun(long long int a,long long int x);

int main()

{

    long long int n,k,ans;

    scanf("%lld %lld", &n,&k);

    ans=ceil(myfun(n,k));

    printf("%lld", ans+1);

    return 0;

}

long long int myfun(long long int n,long long int k)

{

    return log(n)/log(k);

}


// 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)1e5 + 7;

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



ll a, b, sq, mx, aa;

ll ans;



ll sqr(ll x) {

  ll l = 1;

  ll r = 1e9;

  while (r - l > 1) {

    ll mid = (l + r) >> 1;

    if (mid * mid <= x) {

      l = mid;

    } else {

      r = mid;

    }

  }

  return l;

}



void solve() {

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

  if (a > b) swap(a, b);

  sq = sqr(a * b - 1);

  ans = sq;

  if (a <= sq) {

    ans--;

  }

  mx = (a * b - 1) / (sq + 1);

  if (b <= mx) {

    ans--;

  }

  ans += mx;

  cout << ans << endl;

}



main() {

  int test;

  scanf("%d", &test);

  while (test--) {

    solve();

  }

}


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

#include<cstdio>

using namespace std;

int main() {

	int Q;

	scanf("%d",&Q);

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

		long long a,b;

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

		long long pr=a*b;

		long long t=sqrt(pr),ans;

		if(t*(t+1)<pr)

			ans=t*2-1;

		else if(t*t==pr) {

			ans=(t-1)*2;

			if(a!=b) ans--;

		} else

			ans=(t-1)*2;

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

	}

}

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

using namespace std;

typedef long long ll;



int main()

{

    int n;

    scanf("%d",&n);

    ll a, b, pr ,sqq;

    ll ans;

    while(n--)

    {

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

        pr=a*b;

        sqq=sqrt(pr);

        //printf("%lld\n",sqq);

        ans=sqq*2;

        if(sqq*sqq==pr){

            if(a==sqq&&b==a){

                ans-=2;

            }

            else{

                ans-=3;

            }

        }

        else{

            if((pr-1)/sqq==sqq){

                ans--;

            }

            ans--;

        }

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

    }

    return 0;

}


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

#include<cstdio>

using namespace std;

int main() {

	int Q;

	scanf("%d",&Q);

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

		long long a,b;

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

		long long pr=a*b;

		long long t=sqrt(pr),ans;

		if(t*(t+1)<pr)

			ans=t*2-1;

		else if(t*t==pr) {

			ans=(t-1)*2;

			if(a!=b) ans--;

		} else

			ans=(t-1)*2;

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

	}

	return 0;

}

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

#include<cmath>

#include<cstdio>

using namespace std;

int q;

typedef long long LL;

LL LLsqrt(LL x){

    LL L=0,R=1e9,mid,ans=-1;

    while (L<=R){

        mid=(L+R)>>1;

        if (mid*mid<=x)

            L=mid+1,ans=mid;

        else

            R=mid-1;

    }

    return ans;

}

int main()

{

    long long a,b;

    scanf("%d",&q);

    while(q--)

    {

        long long ans=0;

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

        long long c=a*b-1;

        long long p=LLsqrt(c);

        ans+=2*p;

        if(a!=b)

            ans--;

            if(p)

        if(p==c/p)

            ans--;

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

    }

}


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

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int main() {

    #ifdef LOACL

    freopen("in.txt","r",stdin);

    freopen("out.txt","w",stdout);

    #endif

    int t;

    scanf("%d",&t);

    while(t--) {

    	ll a,b,ans;

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

    	if(a>b)swap(a,b);

    	if(a==b) {

    		ans=2*(a-1);

		} else if(a+1==b) {

			ans=2*(a-1);

		} else {

			ll c=sqrt(a*b);

			if(c*c==a*b)c--;

			if(c*(c+1)>=a*b) {

				ans=2*c-2;

			} else {

				ans=2*c-1;

			}

		}

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

	}

    return 0;

}

// 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;



int tests, a, b;



int check (int x)

{

    int l = 1, r = x;

    while (r - l > 2)

    {

        int md1 = l + (r - l + 1) / 3, md2 = r - (r - l + 1) / 3;

        if ( md1 * (b + x - md1 + 1) > md2 * (b + x - md2 + 1) )

            r = md2;

        else

            l = md1;

    }

    int ans = l * (b + x - l + 1);



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

        ans = max(ans, i * (b + x - i + 1) );



    return ans;

}



main()

{

    cin >> tests;

    while (tests--)

    {

        cin >> a >> b;

        if (a < b)

            swap(a, b);

        int l = 1, r = b;



        while (r - l > 1)

        {

            int md = (l + r) >> 1;

            if ( (a + 1) * md < a * b )

                l = md;

            else

                r = md;

        }

        int left = b - l - 1;



        l = 0, r = a - left;



        while (r - l > 1)

        {

            int md = (l + r) >> 1;

            if ( check(md) < a * b )

                l = md;

            else

                r = md;

        }

        cout << l + b - 1<< endl;

    }

}


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

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int main() {

    #ifdef LOACL

    freopen("in.txt","r",stdin);

    freopen("out.txt","w",stdout);

    #endif

    int t;

    scanf("%d",&t);

    while(t--) {

    	ll a,b,ans;

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

    	if(a>b)swap(a,b);

    	if(a==b) {

    		ans=2*(a-1);

		} else if(a+1==b) {

			ans=2*(a-1);

		} else {

			ll c=sqrt(a*b);

			if(c*c==a*b)c--;

			if(c*(c+1)>=a*b) {

				ans=2*c-2;

			} else {

				ans=2*c-1;

			}

		}

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

	}

    return 0;

}

// Fastest known solution for this problem: