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



using namespace std;

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

#define REP(i,a,b) REPP(i,a,b,1)

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

#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) REP(i,0,(int)a-1)

#define FORD(i,a) REV(i,(int)a-1,0)

#define PB push_back

#define POB pop_back

#define MP make_pair

#define FI first

#define SE second

typedef long long ll;

typedef unsigned long long ull;

typedef pair < int , int > pii;

typedef vector < int > vi;

typedef vector < pii > vii;

typedef vector < ll > vl;



const double EPS = 1e-9;

const double PI = acos(-1);

const int INF = 1e9;

const ll MOD = 1e9 + 7;



ll addMod(ll a, ll b){

	return (a+b) % MOD;

}



ll mulMod(ll a, ll b){

	return (a*b) % MOD;

}



ll fast(ll a, ll b){

	if(b == 0) return 1;

	ll tmp = fast(a,b/2);

	tmp = mulMod(tmp, tmp);

	if(b & 1) tmp = mulMod(tmp, a);

	return tmp;

}



/////////////////////////////////////////////////////////



const int N = 1e5;



int n;

string str[N+5];





ll solve(){

	ll ret = 0, sz = 0;

	int bef = 0;

	FOR(i,n){

		if(str[i] != str[bef]){

			ret += sz * (sz - 1) / 2;

			bef = i;

			sz = 0;

		}

		sz++;

	}

	ret += sz * (sz - 1) / 2;

	return ret;

}



int main(){

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

	cin >> n;

	FOR(i,n){

		cin >> str[i];

		sort(str[i].begin(), str[i].end());

	}

	sort(str,str+n);

	cout << solve() << endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

int main(){

 long long int i,j,n,m,ans=0;

 map<string,int> p;

 string s;

 cin>>n;

 while(n--){

    cin>>s;

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

    ans+=p[s]++;

 }

 cout<<ans;

}


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

using namespace std;

#define ll unsigned long long int

ll ar[500009],br[500009],fr[500009];

string s1,s2,s3[200005];

map<string,int>mp;

int main()

{

    ll i,j,k,e,r,n,s,d,f,g,h,u,ck=0,ck1=0,t;

    cin >> n;

    g=0;

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

    {

        cin >> s3[i];

    sort(s3[i].begin(),s3[i].end());

    mp[s3[i]]++;

    if(mp[s3[i]]>1)

    {



        g+=mp[s3[i]]-1;

    }

    }

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

//    {

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

//        {

//            if(s3[i]==s3[j])

//            {

//                g++;

//            }

//        }

//    }

    cout << g << endl;

    return 0;

}

/*

2

greenbin

beginner

*/


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

#include <string>

#include <algorithm>

#include <map>



#define lli long long int



using namespace std;

string ordena(string s){

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

  return s;

}



int main() {



  lli n;

  cin >> n;

  map<string,lli> M;

  string s;

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

    cin >> s;

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

    M[s]++;



  }

  lli cont=0, aux, aux1;

  map<string,lli>::iterator it;

  for(it=M.begin(); it!=M.end(); it++){

    if(it->second>1)  {

      aux=it->second;

      aux1=aux*(aux-1);

      cont+=aux1/2;

    }

  }

  cout << cont;

}


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

#include<algorithm>

#include<cstring>

#include<string>

#include<cstdio>

using namespace std;

string a[100000];

int main(){

    long long n;

    cin>>n;

    long long ans=0;

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

        cin>>a[i];

        std::sort(a[i].begin(),a[i].end());

    }

    sort(a,a+n);

    long long z[100000]={0},cnt=0;

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

        if(i==0){

            z[cnt]=1;

            continue;

        }

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

            z[cnt]++;

        }

        else{

            cnt++;

            z[cnt]++;

        }

    }



    for(long long  i=0;i<=cnt;i++){

        ans+=((z[i]*(z[i]-1))/2);

    }

    cout<<ans;

}

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

#include <string>

#include <algorithm>

#include <map>



#define lli long long int



using namespace std;

string ordena(string s){

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

  return s;

}



int main() {



  lli n;

  cin >> n;

  map<string,lli> M;

  string s;

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

    cin >> s;

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

    M[s]++;



  }

  lli cont=0, aux, aux1;

  map<string,lli>::iterator it;

  for(it=M.begin(); it!=M.end(); it++){

    if(it->second>1)  {

      aux=it->second;

      aux1=aux*(aux-1);

      cont+=aux1/2;

    }

  }

  cout << cont;

}


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

#define int long long



using namespace std;



const int N = 1e5;



int readInt ()

{

    bool minus = false;

    int result = 0;

    char ch;

    ch = getchar();

    while (true)

    {

        if (ch == '-') break;

        if (ch >= '0' && ch <= '9') break;

        ch = getchar();

    }

    if (ch == '-') minus = true;

    else result = ch-'0';

    while (true)

    {

        ch = getchar();

        if (ch < '0' || ch > '9') break;

        result = result*10 + (ch - '0');

    }

    if (minus)

        return -result;

    else

        return result;

}

string s[N + 1];

main() {

    int n = readInt();

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

        cin >> s[i];

        sort(s[i].begin(), s[i].end());

    }

    sort(s + 1, s + n + 1);

    int ans = 0, cnt = 1;

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

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

            ++cnt;

        } else {

//            cout << s[i] << " " << cnt << " fuck \n";

            ans += cnt * (cnt - 1) / 2;

            cnt = 1;

        }

    }

    if (cnt) {

        ans += cnt * (cnt - 1) / 2;

    }

    cout << ans;

}


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



using namespace std;

const int N = 1e5 + 3;

map<string, int> freq;

char s[22];

int main() {

#ifndef ONLINE_JUDGE

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

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

#endif

	int n;

	scanf("%d", &n);

	long long res = 0;

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

		scanf("%s", s);

		sort(s, s + 10);

		res += freq[s]++;

	}

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

	return 0;

}


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

#include<algorithm>

using namespace std;

string s[200010];

long long x[200010]={0};

int main(){

	int n,i,j,m;

	long long ans=0,k=0;

	char t;

	cin >> n;

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

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

	}

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

		cin >> s[i];

	}

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

		for(i=0;i<s[m].size()-1;i++){

			for(j=i+1;j<s[m].size();j++){

				if(s[m][i]>s[m][j]){

					t=s[m][i];

					s[m][i]=s[m][j];

					s[m][j]=t;

				}

			}

		}

	}

	sort(s,s+n);

	ans=0;

	k=0;

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

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

			ans+=x[k];

			k=0;

		}

		else

			k++;

	}

	ans+=x[k];

	cout << ans << endl;

	return 0;

}


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

using namespace std;



int main()

{

	int n; 

	cin>>n;

	string s[n];

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

	{

		cin>>s[i];

		sort(s[i].begin(), s[i].end());

	}

	sort(s, s+n);

	long long cnt=0, ans=0;

	string last=s[0];

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

	{

		if(s[i]==last) cnt++;

		else ans+=(cnt+1)*cnt/2, last=s[i], cnt=0;

	}

	ans+=(cnt+1)*cnt/2;

	cout<<ans;

}


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

using namespace std;

#define ll long long

int a[100];

int main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);

    int i,j,k,m,n;

    int ans=2;

    cin>>n;

    if(n==1)

        cout<<1<<endl;

    else

    {

        while(ans<=n)

            ans*=2;

        cout<<ans/2<<endl;

    }

    return 0;

}


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

using namespace std; 

int main()

{

    int a;

    scanf("%d\n",&a);

    if(a<2)  {printf("1\n"); return 0;}

    if(a<4)  {printf("2\n"); return 0;}

    if(a<8)  {printf("4\n"); return 0;}

    if(a<16) {printf("8\n"); return 0;}

    if(a<32) {printf("16\n");return 0;}

    if(a<64) {printf("32\n");return 0;}

    if(a<128){printf("64\n");return 0;}

}

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

using namespace std;

long int a;

int main()

{

    cin>>a;

    if(a<2) cout<<1<<endl;

    else if(a<4)  cout<<2<<endl;

    else if(a<8)  cout<<4<<endl;

    else if(a<16) cout<<8<<endl;

    else if(a<32) cout<<16<<endl;

    else if(a<64) cout<<32<<endl;

    else cout<<64<<endl;

    return 0;

}

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

using namespace std; 

int main()

{

    int a;

    scanf("%d\n",&a);

    if(a<2)  {printf("1\n"); return 0;}

    if(a<4)  {printf("2\n"); return 0;}

    if(a<8)  {printf("4\n"); return 0;}

    if(a<16) {printf("8\n"); return 0;}

    if(a<32) {printf("16\n");return 0;}

    if(a<64) {printf("32\n");return 0;}

    if(a<128){printf("64\n");return 0;}

}

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

Character Drawing Adapted from FAKEUPDATE.NET

		   _    _____         _

		   \`,""   ,'7"r-..__/ \

		  ,'\ `, ,',','    _/   \

		 /   \, 7 / /     (   \ |

		J     \/ j  L______\  / |

		L   __JF"""/""\"\_,    /

		L,-"| O|  f O |  L_  _/

		F   \_ /  \__/   `-  j|

			.-'    `"""    ,' |          _..====.._

			\__/         r"_  A        ,' _..---.._`,

			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,

					  j   / / / 7"    `-<""=:'  '':. \ \

					 /   <,' /  F  . i , \   `,    :T W I

					 |    \,'  /    >X<  |     \   :| | L

					 |     `._/    ' ! ` |      I  :| |  G

					  \           \     /       |  :H T  |

					 __>-.__   __,-\   |        |  S P   |

					/     /|   | \  \  \_       | 'A R   |

				   /   __/ |   |  L  L   \      K./ /    L

				  /   |    |   4  I  I    |    E./ /   ,'

				 J    \    I    L F  I    |    // / _,'

		_________|     |   F    |J   F    |   //_/-'

		\   __   |    /   J     |/  J     |  /="

		\\  \_\  \__,' \  F     |   F     |

		\\\_____________\/      F__/      F

		 \\| 计算机编程 |_____/  (______/

		  \/从入门到入土/

*/

#include <iostream>

#include <cstdlib>

#include <iomanip>

#include <cmath>

#include <string>

#include <cstring>

#include <algorithm>

#include <vector>

#include <sstream>

#include <set>

#include <queue>

#include <stack>

#include <cctype>

#include <map>

#include <climits>

#include <bitset>

#include <functional>

using namespace std;

#define MATH_PI 3.14159265358979323846

int main(){

	ios::sync_with_stdio(false);

	int iNum;

	cin >> iNum;

	cout << ceil(pow(2, int(log2(iNum)))) << endl;

endapp:

	system("pause > nul");

	return 0;

}

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

using namespace std; 

int main()

{

    int a;

    scanf("%d\n",&a);

    if(a<2)  {printf("1\n"); return 0;}

    if(a<4)  {printf("2\n"); return 0;}

    if(a<8)  {printf("4\n"); return 0;}

    if(a<16) {printf("8\n"); return 0;}

    if(a<32) {printf("16\n");return 0;}

    if(a<64) {printf("32\n");return 0;}

    if(a<128){printf("64\n");return 0;}

}

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

using namespace std;

 

#define INF 1145141919

 

int main()

{

	int n;

	cin >> n;

	cout << pow(2,((int)log2(n))) << endl;

}

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

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	if(n<2)

	{

		printf("1\n");

		return 0;

	}

	if(n<4)

	{

		printf("2\n");

		return 0;

	}

	if(n<8)

	{

		printf("4\n");

		return 0;

	}

	if(n<16)

	{

		printf("8\n");

		return 0;

	}

	if(n<32)

	{

		printf("16\n");

		return 0;

	}

	if(n<64)

	{

		printf("32\n");

		return 0;

	}

	printf("64\n");

	return 0;

}

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

using namespace std;

int main(){

    int n,l=1;

    scanf("%d",&n);

    while(n>=l){

        l*=2;

    }

    printf("%d",l/2);

    return 0;

}

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

#include<cmath>

using namespace std;

int main()

{   int x,i;

    cin>>x;

    for(i=1;pow(2,i)<=x;i++);

    cout<<pow(2,i-1)<<endl;

    return 0;

}

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

using namespace std;

int main()

{

    int a,ans=1;

    cin>>a;

    while(ans<=a)

	ans*=2;

    cout<<ans/2<<endl;

    return 0;

}

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

using namespace std;

int n,ans;

int main(){

    cin>>n;

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

        if(pow(2,i)<=n){

        	ans=pow(2,i);

		}

    }

    cout<<ans<<endl;

    return 0;

} 

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

using namespace std;

int n,a[105]={0,2};

int main(void) {

    cin>>n;

    if(n==1) {

        cout<<1<<"\n";

        exit(0);

    }

    for(int i=2; i<=100; i++)  a[i]=a[i-1]*2;

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

        if(n>=a[i]&&n<a[i+1]) {

            cout<<a[i]<<endl;

            exit(0);

        }

    }

}

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

using namespace std;

int main()

{

	int n;

	cin>>n;

	if(n==1){cout<<1<<endl;return 0;}

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

		if(pow(2,i)<=n&&pow(2,i+1)>n)

		{

			cout<<pow(2,i)<<endl;

			return 0;

		}

    return 0;

}

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

using namespace std;

int n,sum[110];

int main(){

    scanf("%d",&n);

    if(n==1)

	{

        printf("1\n");

        return 0;

    }

    sum[1]=2;

    for(int i=2;i<=100;i++)

        sum[i]=sum[i-1]*2;

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

	{

        if(n<sum[i+1]&&n>=sum[i])

		{

        	printf("%d\n",sum[i]);

            break;

        }

    }

    return 0;

}

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

#include<cmath>

using namespace std;

int main()

{

	int a;

	cin>>a;

	int p=0;

	while(a=a/2)

	{

		p++;

	 } 

	cout<<pow(2,p);

 } 

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

int a[102],b[102];

int main()

{

	int N,i,j,max=0,k;

	scanf("%d",&N);

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

	{	

		k=i;

		for(j=0;k%2==0;j++)

			k=k/2;

			a[i-1]=j;

	}

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

	{

		if(a[j]<=a[max])

			max=max;

		else

			max=j;

	}

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

	{

		b[j]=j+1;

	}

	printf("%d",b[max]);				

	return 0;

}

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



using namespace std;



int main()

{

    int N;

    cin >> N;

    if(N>=64)

    {

        cout<<64<<endl;

    }

    else if(N>=32){

        cout<<32<<endl;

    }

    else if(N>=16)

    {

        cout<<16<<endl;

    }

    else if(N>=8)

    {

        cout<<8<<endl;

    }

    else if(N >= 4)

    {

        cout<<4<<endl;

    }

    else if(N >=2)

    {

        cout<<2<<endl;

    }

    else {

        cout<<N;

    }

    return 0;

}




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

int a[102],b[102];

int main()

{

	int N,i,j,max=0,k;

	scanf("%d",&N);

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

	{	

		k=i;

		for(j=0;k%2==0;j++)

			k=k/2;

			a[i-1]=j;

	}

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

	{

		if(a[j]<=a[max])

			max=max;

		else

			max=j;

	}

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

	{

		b[j]=j+1;

	}

	printf("%d",b[max]);				

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
using namespace std;

#include <iostream>

#include <cmath>

int main()

{

 	int n;cin>>n;

 	int sum=0;

 	int i=1;

 	while(pow(2,i)<=n) i++;

 	//cout<<pow(2,3)<<endl;

 	cout<<pow(2,i-1);

} 

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

int a[102],b[102];

int main()

{

	int N,i,j,max=0,k;

	scanf("%d",&N);

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

	{	

		k=i;

		for(j=0;k%2==0;j++)

			k=k/2;

			a[i-1]=j;

	}

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

	{

		if(a[j]<=a[max])

			max=max;

		else

			max=j;

	}

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

	{

		b[j]=j+1;

	}

	printf("%d",b[max]);				

	return 0;

}

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

#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	cin>>n;

	int i;

	while(n/2)

	{

		n/=2;

		i++;	

	}	

	i=pow(2,i);

	cout<<i<<endl;

	return 0;

}

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

int main()

{

	int N;

	scanf("%d",&N);

	int t=1;

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

	{

		if(t*2>N)

			break;

		t*=2;

	}

	printf("%d",t);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define taskname ""

#include <bits/stdc++.h>



using namespace std;



const int maxN = 1e5;



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(nullptr);

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << min(a, b) + min(c, d);

    return 0;

}


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

#include <algorithm>

using namespace std;

int main() {

    int a, b, c, d;

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

    printf("%d", min(a, b) + min(c, d));

    return 0;

}


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

using namespace std;

int main()

{

	int a,b,c,d;

	cin>>a>>b>>c>>d;

	int sum=0;

	if(a>b) sum+=b;

	else sum+=a;

	if(c>d) sum+=d;

	else sum+=c;

	cout<<sum<<endl;

}

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

int main()

{

    int a,b,c,d,s,s1;

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

    if(a<b)

        s=a;

    else

        s=b;

        if(c<d)

            s1=c;

            else

            s1=d;

        printf("%d\n",(s+s1));



}

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

#include <algorithm>

#include <string>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

const int MAX=1e3+5;

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

{

	int a,b,c,d;

	cin>>a>>b>>c>>d;

	printf("%d\n",min(a,b)+min(c,d));

	return 0;

}

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

int main()

{

    int a,b,c,d,s,s1;

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

    if(a<b)

        s=a;

    else

        s=b;

        if(c<d)

            s1=c;

            else

            s1=d;

        printf("%d\n",(s+s1));



}

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


#include<bits/stdc++.h>

using namespace std;

main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



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

    while(cin>>m>>n>>o>>p)



    {

        if(m>n)

            m=n;

        if(p>o)

            p=o;

        cout<<m+p<<endl;

    }

    return 0;

}


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

int main()

{

    int a,b,c,d,s,s1;

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

    if(a<b)

        s=a;

    else

        s=b;

        if(c<d)

            s1=c;

            else

            s1=d;

        printf("%d\n",(s+s1));



}

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

#include<vector>

#include<algorithm>

#include<functional>

using namespace std;

	bool is(int x){

		for(int i=2;i*i<=x;i++)if(x%i==0)return false;

		return true;

	}

int main(){

	int n,p;



	while(cin>>n>>p,n!=-1||p!=-1){

		int cnt=0;

		n++;

		if(n==1)n++;

		vector<int>primes;

		vector<int>sums;

		while(true){

			if(is(n)){

				cnt++;

				primes.push_back(n);

			}

			if(cnt==78)break;

			n++;

		}

		//for(int i=0;i<primes.size();i++)cout<<primes[i]<<endl;

		for(int i=0;i<primes.size();i++){

			for(int j=0;j<primes.size();j++){

				if(j>primes.size())break;

				if(i<j)break;

				sums.push_back(primes[i]+primes[j]);

			}

		}

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

		cout<<sums[p-1]<<endl;

	}

	return 0;

}

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

#include<vector>

#include<algorithm>

#include<functional>

using namespace std;

	bool is(int x){

		for(int i=2;i*i<=x;i++)if(x%i==0)return false;

		return true;

	}

int main(){

	int n,p;



	while(cin>>n>>p,n!=-1||p!=-1){

		int cnt=0;

		n++;

		if(n==1)n++;

		vector<int>primes;

		vector<int>sums;

		while(true){

			if(is(n)){

				cnt++;

				primes.push_back(n);

			}

			if(cnt==22)break;

			n++;

		}

		//for(int i=0;i<primes.size();i++)cout<<primes[i]<<endl;

		for(int i=0;i<primes.size();i++){

			for(int j=0;j<primes.size();j++){

				if(j>primes.size())break;

				if(i<j)break;

				sums.push_back(primes[i]+primes[j]);

			}

		}

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

		cout<<sums[p-1]<<endl;

	}

	return 0;

}

// Fastest known solution for this problem: