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

using namespace std;



int main(){

    int n;

    int out=1;

    string s;

    cin>>n>>s;

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

    {

        if(s[i]!=s[i-1])out++;

    }

    cout<<out<<endl;

	return 0;

}


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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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





#define ll long long



using namespace std;





int main()

{

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



    int n;

    cin >> n;



    string s;

    cin >> s;



    int res = 1;

    for(int i = 1 ; i < s.size(); ++i)

    {

        if(s[i] != s[i-1]) res++;

    }



    cout << res << endl;



    return 0;

}


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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

#include <iostream>

#include <string>

using namespace std;

int main()

{

    int number,counter=0;

    string name;

    cin >>number>> name;

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

    {

        if(name[i] != name[i+1] )

        {

            counter++;

        }

    }

    cout  << counter+1<<"\n";

}


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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

}

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



int main()

{

    ll n , x = 1;

    char a[100005];

    cin >> n;



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

        cin >> a[i];



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

        if(a[i] != a[i+1])

            x++;



    cout << x << "\n";



	return 0;

}


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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

set<char>st;

int main() {

    quick

int n; string s,ans; cin>>n>>s;  ans=s[0];

for(int i=1; i<s.size();i++){

    if(s[i]!=ans[ans.size()-1]){

        ans.push_back(s[i]); }

}

cout<<ans.size();

}

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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

using namespace std;

int main()

{



    int num;

    string word;

    cin>>num;cin>>word;

    for(int i=1;i<word.length();)

    {

        if(word[i]==word[i-1])

            word.erase(word.begin()+i-1,word.begin()+i);

        else

            i++;

    }

    cout<<word.length()<<endl;

    return 0;

}




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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

#include <algorithm>

using namespace std;



int main()

{

    int n;

    string s;

    cin >> n;

    cin >> s;

    char c = s[0];

    for(int i = 1; i < s.size(); i++)

    {

        if(c == s[i])

        {

            s[i] = '*';

        }else

        {

            c = s[i];

        }

    }

    s.erase(remove(s.begin(), s.end(), '*'), s.end());

    cout << s.size() << endl;

    return 0;

}


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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

using namespace std;

int main(){

        int n,c=1;



   string s;

   cin>>n;

    cin>>s;

    for (int i=0;i<s.length()-1;i++){

        if (s[i]==s[i+1])

            continue;

        else c++;

  }

  cout<<c<<endl;

  }

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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

KUET ECE 2K18*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define sc(a) scanf("%d",&a)

#define sc1(n) scanf("%lld",&n)

#define sc2(b,c) scanf("%lld%lld",&b,&c)

#define f(a,b) for(a=0;a<b;a++)

#define pb(a) push_back(a)

#define br break

int main()

{

    int n,i,j,c=1;

    cin>>n;

    char s[n];

    f(i,n)

    {

        cin>>s[i];

    }

    f(i,(n-1))

    {

        if(s[i]!=s[i+1])

        {

            c++;

        }

    }

    cout<<c<<endl;





    return 0;

}




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

#include <string.h>

int main ()

{

	long long int N,i,j,l;

	char S[1000000],a[1000000];

	scanf("%lld %s",&N,S);

	a[0]=S[0];

	for(i=1,j=1;S[j]!='\0';j++)

	{

		

		if(a[i-1]==S[j])

		{

			continue;

		}

		else

		{

			a[i]=S[j];

			i++;

		}

		

	}

	l=strlen(a);

	printf("%lld",l);

	

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

	{

		a[i]='\0';

	}

	return 0;

	

}

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

#include<map>

#include<string>

#include<string.h>

#include<utility>

#include<algorithm>

#include<vector>

#include<queue>

#include<iostream>

#include<math.h>

#include<stack>

#include<set>

#define INF 2147483647

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

#define mem(arr) memset(arr, 0, sizeof(arr));

using namespace std;

typedef long long lli;

typedef double llf;

typedef pair<int, int> P;

typedef vector<int> vec;

typedef priority_queue<int, vector<int>, greater<int> > pQ;

typedef queue<int> Q;

typedef set<int> S;

struct edge{

	int to, value;

};

void solve();

int main()

{

	int times = 1;

//	cin >> times;

	loop(i, 1, times)

	{

		solve();

		cout << '\n';

	}

	return 0;

}

const int n = 2e5;

vector<edge> tree[n + 50];

int a, b, c, d, e, f;

int arr[n + 50], arr1[n + 50], arr2[n + 50];

string str, str1, str2;



void solve()

{

	cin >> a;

	cin >> str;

	stack<char> S;

	S.push(str[0]);

	int cnt = 1;

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

	{

		if(str[i] == S.top()) continue;

		else

		{

			cnt ++;

			S.push(str[i]);

		}

	}

	cout << cnt << '\n';

}

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

using namespace std;



int main() {

  int n;

  string s;

  cin >> n >> s;

  s.resize(unique(s.begin(), s.end()) - s.begin());

  cout << s.size() << "\n";

  return 0;

}

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

using namespace std;

int n;

char a[100001];

int main(){

    int d=1;

    int res=1;

    cin>>n;

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

    if (a[i]!=a[d]) {res++;d=i;}

    }

    cout<<res;

}

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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

using namespace std;



typedef long long ll;



const int N = 50;

ll arr[N + 5];



int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;

	cin>>n;

	string s;

	cin>>s;

	char c = '@';

	int tot = 0;

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

		if(c != s[i]) tot++;

		c = s[i];

	}

	cout<<tot<<endl;

}

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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

#include <cstdio>

#include <cstring>

using namespace std;

int main() {

    int cnt = 0, n;

    char temp, old = '#';

    scanf("%d", &n);

    getchar();

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

        scanf("%c", &temp);

        if (temp != old) cnt++;

        old = temp;

    }

    printf("%d", cnt);

//return

    return 0;

}

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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

using namespace std;



int main()

{

    int n;

    char s[100001]={};

    cin>>n;

    int tag = 0;

    int ans = 0;

    cin>>s;

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

    {

        if(s[i]==s[i+1])

        {

            continue;

        }

        ans++;

    }

    cout <<ans;

    return 0;

}






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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

using namespace std; 

int main(){

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

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

	int n,o=0;

	cin>>n;

	char slimes[n+1],a[n+1];

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

	cin>>slimes;

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

			if(slimes[i]==a[o]) continue;

			if(slimes[i]==slimes[i+1]){

				a[o]=a[i];

			}

			else o++;

	}

	cout<<o+1;

    return 0;

}

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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define maxn 100010

char ss[maxn];

int main()

{

	int n;

	cin>>n;

	cin>>ss;

	int siz=sizeof(ss);

	char pre;

	pre=ss[0];

	int cnt=0;

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

	{

		if(pre!=ss[i])

		{

			cnt++;

			pre=ss[i];

		 } 

	}

	cout<<cnt;

	return 0;

 } 

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

int main()

{

	int a,n,cnt=1;

	char s[100000];

	scanf("%d",&n);

	getchar();

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

		scanf("%c",&s[a]);

	}

	for(a=0;a<n-1;a++){

		if(s[a]!=s[a+1]){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

using namespace std;



int main(){

	int n;

	scanf("%d",&n);

	string str;

	cin>>str;

	string s="";

	for(int i=0;i<str.length();i++){

		if(s=="") s+=str[i];

		else{

			if(s[s.length()-1]!=str[i]){

				s+=str[i];

			}

		}

	}

	cout<<s.size()<<endl;

}


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

int n,ans;

char ch1,ch2;

int main()

{

	scanf("%d",&n);

	ch1=getchar();

	ch1=getchar();

	ans=1;

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

	{

	    ch2=getchar();

	    if(ch2!=ch1) ans++;

	    ch1=ch2;

	}

	printf("%d",ans);

}

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

//P1T2

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e4;

int raw[maxn];

int main(){

	int n;

	cin >> n;

	string s;

	cin >> s;

	char pre = s[0];

	int ans = 1;

	for(int i = 1;i < s.size();i++){

		if(s[i] != pre){

			ans++;

			pre = s[i];

		}

	}

	printf("%d",ans);

	return 0;

}

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

int n,ans;

char ch1,ch2;

int main()

{

	scanf("%d",&n);

	ch1=getchar();

	ch1=getchar();

	ans=1;

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

	{

	    ch2=getchar();

	    if(ch2!=ch1) ans++;

	    ch1=ch2;

	}

	printf("%d",ans);

}

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

#include <stack>

using namespace std;



stack<char> s;



int main() {

    int n;

    cin >> n;

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

        char t;

        cin >> t;

        if (s.empty())

            s.push(t);

        else if (t == s.top())

            ;

        else

            s.push(t);

    }



    cout << s.size();



    return 0;

}

// Created by Kevin Weng on 2019/10/28.

//




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

int n,ans;

char ch1,ch2;

int main()

{

	scanf("%d",&n);

	ch1=getchar();

	ch1=getchar();

	ans=1;

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

	{

	    ch2=getchar();

	    if(ch2!=ch1) ans++;

	    ch1=ch2;

	}

	printf("%d",ans);

}

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

using namespace std;

int main(){

	int w;

	cin>>w;

	string s;

	cin>>s;

	int ans=1;

	int n=s.size();

	char q=s[0];

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

	{

		if(s[i]!=q)

		{

			ans++;

			q=s[i];

		}

	}

	cout<<ans;

	return 0;

}


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

const int maxn = 100010;

int main()

{

    int n;

    char p[maxn];

    scanf("%d", &n);

    scanf("%s", p);

    char c = p[0];

    int num = 1;

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

        if(p[i] != c){

            num++;

            c = p[i];

        }

    }

    printf("%d", num);

    return 0;

}


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

using namespace std;



int cut;

int n;

char s[100010];

int main(){

	scanf("%d",&n);

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

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

    	if(s[i]==s[i-1]){

    		cut++;

		}

	}

	printf("%d",n-cut);

	return 0;

}

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

const int maxn = 100010;

int main()

{

    int n;

    char p[maxn];

    scanf("%d", &n);

    scanf("%s", p);

    char c = p[0];

    int num = 1;

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

        if(p[i] != c){

            num++;

            c = p[i];

        }

    }

    printf("%d", num);

    return 0;

}


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

#include <cstdio>

#include <string>

using namespace std;

int main()

{

	int N;

	string s;

	int ans = 1;

	cin>>N;

	getchar();

	getline(cin, s);

	char f = s[0];

	for(int i =1;i<s.length();i++)

	{

		if(f==s[i])

			continue;

		else

		{

			ans++;

			f=s[i];

		}

	}

	cout<<ans<<endl;

	return 0;

}

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

const int maxn = 100010;

int main()

{

    int n;

    char p[maxn];

    scanf("%d", &n);

    scanf("%s", p);

    char c = p[0];

    int num = 1;

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

        if(p[i] != c){

            num++;

            c = p[i];

        }

    }

    printf("%d", num);

    return 0;

}


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

using namespace std;

char a , b;

int n, countor = 0;

int main(){

    cin >> n;

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

        cin >> b;

        if(b!=a){

            countor++;

            a = b;

        }

    }

    cout << countor;

    return 0;

}

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

const int maxn = 100010;

int main()

{

    int n;

    char p[maxn];

    scanf("%d", &n);

    scanf("%s", p);

    char c = p[0];

    int num = 1;

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

        if(p[i] != c){

            num++;

            c = p[i];

        }

    }

    printf("%d", num);

    return 0;

}


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

#include<string>

using namespace std;

int main()

{

	int n;

	char str[100005];

	int c[100005];

	cin>>n;

	cin>>str;

	int i,j,z=n;

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

	{

		c[i]=str[i]-'0';

	}

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

	{

		if(c[i]==c[i+1])

		{

			z--;

		}

	}

	cout<<z<<endl;

}

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

const int maxn = 100010;

int main()

{

    int n;

    char p[maxn];

    scanf("%d", &n);

    scanf("%s", p);

    char c = p[0];

    int num = 1;

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

        if(p[i] != c){

            num++;

            c = p[i];

        }

    }

    printf("%d", num);

    return 0;

}


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

#define ll long long

using namespace std;

ll n , x;

ll f(ll x , ll y)//x < y

{

	//cout << x << " " << y << endl;

	if(!(y % x))

	{

		ll step = y / x;

		return 2 * step * x - x;

	}



	if(x == y)

		return y;

	ll step = y / x;

	return 2 * step * x + f(min(x , y - step * x) , max(y - step * x , x));

}



int main()

{

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

	cin >> n >> x;

	ll ans = n;

	ans += f(min(x , n - x) , max(x, n - x));

	cout << ans;

}




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

#include <cstring>

#include <cstdio>



#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

#define CLOSEALL() fclose(stdin), fclose(stdout)



using namespace std;

typedef long long i64;



i64 N, K;



i64 simulate(i64 x, i64 y)

{

	if(y == 0)

		return (-x);

	return simulate(y, x % y) + 2 * (x / y) * y;

}



int main()

{

	//REDIRECT("light");



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

	printf("%lld\n", simulate(max(K, N - K), min(K, N - K)) + N);



	CLOSEALL();

	return 0;

}


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



using namespace std;



//#define _FILES

#define PB push_back

#define MP make_pair

#define X first

#define Y second



long long solve(long long n, long long x)

{

    if (((n % 2) == 0) && (x == n/2))

    {

        return 3 * (n / 2);

    }



    if (x <= n / 2)

    {

        return  3 * x + solve(n - x, n - 2 * x);

    }



    long long ans = x + 2 * (x / (n - x)) * (n - x);

    long long ost = x % (n - x);



    if (!ost)

    {

        return ans;

    }



    ans += solve(ost + n - x, ost) - ost;

    return ans;

}



int main()

{

    ios_base::sync_with_stdio(false);



    #ifdef _FILES

        freopen("","r",stdin);

        freopen("","w",stdout);

    #endif // _FILES

    long long n, x;

    cin >> n >> x;

    cout << solve(n , x) << endl;

    return 0;

}




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

#include <cstring>

#include <cstdio>



#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

#define CLOSEALL() fclose(stdin), fclose(stdout)



using namespace std;

typedef long long i64;



i64 N, K;



i64 simulate(i64 x, i64 y)

{

	if(y == 0)

		return (-x);

	return simulate(y, x % y) + 2 * (x / y) * y;

}



int main()

{

	//REDIRECT("light");



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

	printf("%lld\n", simulate(max(K, N - K), min(K, N - K)) + N);



	CLOSEALL();

	return 0;

}


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



#define endl '\n'



using namespace std;



typedef long long ll;



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	ll n, x;

	cin >> n >> x;

	cout << 3 * (n - __gcd(n, x)) << endl;

	return 0;

}

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

#include <cstring>

#include <cstdio>



#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

#define CLOSEALL() fclose(stdin), fclose(stdout)



using namespace std;

typedef long long i64;



i64 N, K;



i64 simulate(i64 x, i64 y)

{

	if(y == 0)

		return (-x);

	return simulate(y, x % y) + 2 * (x / y) * y;

}



int main()

{

	//REDIRECT("light");



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

	printf("%lld\n", simulate(max(K, N - K), min(K, N - K)) + N);



	CLOSEALL();

	return 0;

}


// Fastest known solution for this problem: