stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



long long n, a[200005], pos[200005], it[800005], tmp;



void update(long long k, long long l, long long r, long long i){

    if(l > i || r < i) return;

    if(l == r){

        it[k] = min(it[k], a[i]);

        return;

    }

    long long m = (l + r) / 2;

    update(2 * k, l, m, i);

    update(2 * k + 1, m + 1, r, i);

    it[k] = min(it[2 * k], it[2 * k + 1]);

}



void get(long long k, long long l, long long r, long long u, long long v){

    if(l > v || r < u) return;

    if(u <= l && r <= v){

        tmp = min(tmp, it[k]);

        return;

    }

    long long m = (l + r) / 2;

    get(2 * k, l, m, u, v);

    get(2 * k + 1,m + 1, r, u, v);

}



long long tinh(long long x, long long y){

    if(x > y) return 0;

    if(x == y) return a[x];

    tmp = LONG_LONG_MAX;

    get(1, 1, n, x, y);

    long long vt = pos[tmp];

    long long kq = ((vt - x) * (y - vt) + (vt  - x) + (y - vt) + 1) * tmp;

    return kq + tinh(x, vt - 1) + tinh(vt + 1, y);

}



int main()

{

    cin >> n;

    for(long long i = 1; i <= 4 * n; i++) it[i] = LONG_LONG_MAX;

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

        cin >> a[i];

        pos[a[i]] = i;

        update(1, 1, n, i);

    }

    cout << tinh(1, n);

}


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

#include<cstring>

#include<algorithm>

#define MAXN 200000

typedef long long LL;

using namespace std;

int N;

int a[MAXN+5],que[MAXN+5];

int l[MAXN+5],r[MAXN+5];

int main()

{

	scanf("%d",&N);

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

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

	int t=0;

	que[t++]=0;

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

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		l[i]=que[t-1]+1;

		que[t++]=i;

	}

	t=0;

	que[t++]=N+1;

	for(int i=N;i>=1;i--)

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		r[i]=que[t-1]-1;

		que[t++]=i;

	}

	LL ans=0;

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

		ans+=1LL*a[i]*(i-l[i]+1LL)*(r[i]-i+1LL);

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

	return 0;

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



using namespace std;



const int NMAX = 200005;



long long n, a[NMAX], L[NMAX], R[NMAX], st[NMAX];



int main(){

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

    cin >> n;

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



    int top = 0;

    st[0] = 0;

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

        while(top > 0 && a[st[top]] >= a[i]) top--;

        L[i] = st[top] + 1;

        st[++top] = i;

    }



    top = 0, st[0] = n+1;

    for(int i = n; i >= 1; i--){

        while(top > 0 && a[st[top]] >= a[i]) top--;

        R[i] = st[top] - 1;

        st[++top] = i;

    }



    long long res = 0, t1, t2;

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

        t1 = i-L[i];

        t2 = R[i] - i;

        res += (t1 + t2 + 1 +t1*t2)*a[i];

    }

    cout << res;

}


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

#include<cstring>

#include<algorithm>

#define MAXN 200000

typedef long long LL;

using namespace std;

int N;

int a[MAXN+5],que[MAXN+5];

int l[MAXN+5],r[MAXN+5];

int main()

{

	scanf("%d",&N);

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

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

	int t=0;

	que[t++]=0;

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

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		l[i]=que[t-1]+1;

		que[t++]=i;

	}

	t=0;

	que[t++]=N+1;

	for(int i=N;i>=1;i--)

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		r[i]=que[t-1]-1;

		que[t++]=i;

	}

	LL ans=0;

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

		ans+=1LL*a[i]*(i-l[i]+1LL)*(r[i]-i+1LL);

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

	return 0;

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

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;



/*

<url:https://agc005.contest.atcoder.jp/tasks/agc005_b>

問題文============================================================

 すぬけ君はある日友人から長さ N の順列 a1,a2,…,aN を貰いました。

 

 Σ{l = 1..N}Σ{r = l..N} min(al,al+1,...,ar)

 

 を求めてください。

 

 制約

 1≦N≦200,000

 (a1,a2,…,aN) は (1,2,…,N) を並び替えたものである



=================================================================



解説=============================================================



 問題をそのまま計算すると O(N^2)となってTLE

 

 よって、別視点の考えをする。

 ある数値 a[i]に関して、その左右で a[i] が最小となるのがどの範囲であるか。

 この考えを行えば 左側に関して a[i] より小さいものの　位置を l, 右側に関して、a[i]よりも

 小さいものの　位置を r とすれば

 

 (i - l) * (r - l) 個分　a[i]が最小となる。

 

 よって各 a[i] に関して、その個数を 平衡木などを用いて数え上げてやれば良い

 

================================================================

*/

int main(void) {

	cin.tie(0); ios::sync_with_stdio(false);

    ll N; cin >> N;

    vector<ll> b(N+1,0);

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

        ll a; cin >> a;

        b[a] = i;

    }

    set<ll> s; s.insert(0); s.insert(N+1);

    ll ans = 0;

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

        auto it = s.lower_bound(b[i]);

        ans += i * (*it - b[i]) * (b[i] - *(--it));

        s.insert(b[i]);

    }

    cout << ans << endl;

	return 0;

}


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

#include<cstring>

#include<algorithm>

#define MAXN 200000

typedef long long LL;

using namespace std;

int N;

int a[MAXN+5],que[MAXN+5];

int l[MAXN+5],r[MAXN+5];

int main()

{

	scanf("%d",&N);

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

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

	int t=0;

	que[t++]=0;

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

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		l[i]=que[t-1]+1;

		que[t++]=i;

	}

	t=0;

	que[t++]=N+1;

	for(int i=N;i>=1;i--)

	{

		while(t>0&&a[que[t-1]]>=a[i])

			t--;

		r[i]=que[t-1]-1;

		que[t++]=i;

	}

	LL ans=0;

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

		ans+=1LL*a[i]*(i-l[i]+1LL)*(r[i]-i+1LL);

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

	return 0;

}
// Slower C++ solution:
//Be Name Khoda

//me and who? :|

/*

ID: aminra81

PROG: gift1

LANG: C++11

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

const ll MOD = 1e9 + 7;

const ll inf = (ll)1e18;

const int infint = (int)2e9;

const int MAXN = (int)3e5 + 10;

ll a[MAXN], pre[MAXN], nxt[MAXN];

int main()

{

	ll sum = 0, n;

	cin >> n;

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

		cin >> a[i];

	stack<int> T;

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

	{

		while(T.size() > 0 and a[i] <= a[T.top()])

			T.pop();

		if(T.size() == 0)

			pre[i] = -1;

		else

			pre[i] = T.top();

		T.push(i);

	}

	while(T.size())

		T.pop();

	for (int i = n - 1; i >= 0; i--)

	{

		while(T.size() > 0 and a[i] < a[T.top()])

			T.pop();

		if(T.size() == 0)

			nxt[i] = n;

		else

			nxt[i] = T.top();

		T.push(i);

	}

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

	{

		sum += (i - pre[i]) * (nxt[i] - i) * a[i];

	}

	cout << sum;

}

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

#define maxn 200005

#define LL long long

int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;

LL ans;

int main()

{

	scanf("%d",&n);

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

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

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		l[i]=st[tp]; st[++tp]=i;

	}

	tp=0; st[0]=n+1;

	for(int i=n;i;i--)

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		r[i]=st[tp]; st[++tp]=i;

	}

	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);

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

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

#include <set>

#include <vector>



using namespace std;



int main(){

    long  sum = 0;

    int n;

    int a[200001];

    int pos[200001];

    set<int> data;



    cin >> n;

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

    {

        cin >> a[i];

        pos[a[i]] = i;

    }



    data.insert(0);

    data.insert(n + 1);



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

    {

        int l, r;

        data.insert(pos[i]);

        set<int>::iterator it = data.find(pos[i]);

        r = *(++it) - pos[i];

        --it;

        l = pos[i] - *(--it);

        sum += (long)i * r * l;

    }

    cout << sum << endl;

}


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

#define maxn 200005

#define LL long long

int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;

LL ans;

int main()

{

	scanf("%d",&n);

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

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

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		l[i]=st[tp]; st[++tp]=i;

	}

	tp=0; st[0]=n+1;

	for(int i=n;i;i--)

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		r[i]=st[tp]; st[++tp]=i;

	}

	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);

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

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



using namespace std;

stack <long long int> t,t2;

long long int n,o=0,u=0,k=0,sum=0,a[300000],sa[300000],ta[300000],x=0;

int main()

{

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

        cin >> n;

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

        {

                cin >> a[i];

                if(!t.empty())

                {

                        x=a[i];

                        k=0;

                        while(!t.empty() && t.top()>x)

                        {

                                o=t.top();

                                u=t2.top();

                                ta[u]=k+1;

                                k+=sa[u];

                                t.pop();

                                t2.pop();

                        }

                        sa[i]=k+1;

                        t.push(a[i]);

                        t2.push(i);

                }

                else

                {

                        sa[i]=1;

                        t.push(a[i]);

                        t2.push(i);

                }

        }

        k=0;

        while(!t.empty())

        {

                o=t.top();

                u=t2.top();

                ta[u]=k+1;

                k+=sa[u];

                t.pop();

                t2.pop();

        }

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

        {

                sum+=sa[i]*ta[i]*a[i];

        }

        cout << sum;

}


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

#define maxn 200005

#define LL long long

int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;

LL ans;

int main()

{

	scanf("%d",&n);

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

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

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		l[i]=st[tp]; st[++tp]=i;

	}

	tp=0; st[0]=n+1;

	for(int i=n;i;i--)

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		r[i]=st[tp]; st[++tp]=i;

	}

	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);

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

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

#include <set>

using namespace std;

const long long MAXN=(1e5)*3;

long long a[MAXN],p[MAXN],l,r,n;

long long i;

unsigned long long sums=0;

set <long long > mset;

	set <long long> :: iterator it;

int main() {

	cin>>n;

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

	{

		cin>>a[i];

		p[a[i]]=i;

	}

	mset.clear();

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

	{

		mset.insert(p[i]);

			it=mset.find(p[i]);

		if(mset.size()>1 && *it!=*mset.begin())

		{

			*it--;

			l=*mset.find(*it);l++;

		}

		else l=0;

		it=mset.find(p[i]);

		if(mset.size()>1 && it!=--mset.end())

		{

			*it++;

			r=*mset.find(*it);r--;

		}

		else r=n-1;

		sums+=((p[i]-l+1)*(r-p[i]+1)*i);

	}

	cout<<sums;

	return 0;

}

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

#define maxn 200005

#define LL long long

int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;

LL ans;

int main()

{

	scanf("%d",&n);

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

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

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		l[i]=st[tp]; st[++tp]=i;

	}

	tp=0; st[0]=n+1;

	for(int i=n;i;i--)

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		r[i]=st[tp]; st[++tp]=i;

	}

	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);

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

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;

 

typedef long long ll ;

typedef long double ld ;





#define int long long

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



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



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



int n , ar [ N ] , seg [ N << 2 ] ;



void build ( int id = 1 , int l = 1 , int r = n + 1 ) {

	if ( r - l < 2 ) {

		seg [ id ] = ar [ l ] ;

		return ; 

	}

	int mid = ( r + l ) >> 1 , lc = id << 1 , rc = lc | 1 ;

	build ( lc , l , mid ) ;

	build ( rc , mid , r ) ;

	seg [ id ] = min ( seg [ lc ] , seg [ rc ] ) ; 

}



int get ( int x , int y , int id = 1 , int l = 1 , int r = n + 1 ) {

	if ( r <= x || l >= y ) return n + 1 ;

	if ( l >= x && r <= y ) return seg [ id ] ;

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

	return min ( get ( x , y , id << 1 , l , mid )

		     , get ( x , y , id << 1 | 1 , mid , r ) ) ; 

}



int32_t main()                     

{

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

	cin >> n ;

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

		cin >> ar [ i ] ;

	build ( ) ;

	int res = 0 ; 

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

		int bl = i , br = i ; 

		int lo = 0 , hi = i + 1 ;

		while ( hi - lo > 1 ) {

			int mid = ( hi + lo ) >> 1 ;

			if ( get ( mid , i ) > ar [ i ] )

				hi = mid ;

			else

				lo = mid ; 

		}

		smin ( bl , hi ) ;

		lo = i , hi = n + 1 ;

		while ( hi - lo > 1 ) {

			int mid = hi + lo >> 1 ;

			if ( get ( i + 1 , mid + 1 ) > ar [ i ] )

				lo = mid ;

			else

				hi = mid ; 

		}

		br = lo ;

		res += ( br - i + 1 ) * ( i - bl + 1 ) * ar [ i ] ;

	}

	cout << res << endl ; 

}


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

#define maxn 200005

#define LL long long

int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;

LL ans;

int main()

{

	scanf("%d",&n);

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

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

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		l[i]=st[tp]; st[++tp]=i;

	}

	tp=0; st[0]=n+1;

	for(int i=n;i;i--)

	{

		while(tp&&a[st[tp]]>=a[i]) tp--;

		r[i]=st[tp]; st[++tp]=i;

	}

	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);

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

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

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define fi first

#define se second

#define mp make_pair

#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)

template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

typedef long long llong;

char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};

#define Sort(a) sort(a.begin(),a.end());

#define Reverse(a) reverse(a.begin(),a.end());

#define print(a) cout << a << endl;

#define MOD llong(1e9+7)

#define MAX int(2 * 1e5 +5)

#define debug(x)  cout << #x << " = " << (x) << endl;

#define pi acos(-1.0)

#define int llong

#define INF llong(1e17)



signed main(){

    int n;

    cin >> n;

    int id[MAX] = {};

    REP(i,n){

        int tmp; cin >> tmp;

        id[tmp] = i+1;

    }

    set<int> S;

    S.insert(0);

    S.insert(n+1);

    int res = 0;

    FOR(i,1,n+1){

        S.insert(id[i]);

        auto itr = S.find(id[i]);

        auto itr1 = next(itr);

        auto itr2 = prev(itr);

        res += i * (*itr - *(itr1) ) * ( *(itr2) - *(itr)  );



    }



    cout << res << endl;

}


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

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define fi first

#define se second

#define mp make_pair

#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)

template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

typedef long long llong;

char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};

#define Sort(a) sort(a.begin(),a.end());

#define Reverse(a) reverse(a.begin(),a.end());

#define print(a) cout << a << endl;

#define MOD llong(1e9+7)

#define MAX int(2 * 1e5 +5)

#define debug(x)  cout << #x << " = " << (x) << endl;

#define pi acos(-1.0)

#define int llong

#define INF llong(1e17)



signed main(){

    int n;

    cin >> n;

    int id[n] = {};

    REP(i,n){

        int tmp; cin >> tmp;

        id[tmp] = i+1;

    }

    set<int> S;

    S.insert(0);

    S.insert(n+1);

    int res = 0;

    FOR(i,1,n+1){

        S.insert(id[i]);

        auto itr = S.find(id[i]);

        auto itr1 = next(itr);

        auto itr2 = prev(itr);

        res += i * (*itr - *(itr1) ) * ( *(itr2) - *(itr)  );



    }



    cout << res << endl;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main()

{

	int n, m;

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

	if(m % n == 0){

		printf("%d\n", m + n);

	}else{

		printf("%d\n", m - n);

	}

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main() {

	int a, b;

	

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

	

	int c;

	c = b%a;

	

	if(c == 0) {

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

	}

	else {

		printf("%d\n", b-a);

	}



	return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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

#include<string.h>



int main(){

    

	int a, b;

	

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

	

	if(b%a == 0){

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

	}else{

		printf("%d", b-a);

	}

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main (){

	int a,b;

	

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

	

	if (b%a==0){

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

	}

	else if (a==1 && b==1){

		printf ("1");

	}

	else {

		printf ("%d",b-a);

	}

	return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main() {

	

	int A, B;

	scanf("%d %d", &A, &B);

	

	if (B%A==0){

		printf("%d\n", A+B);

	}

	else {

		printf("%d\n", B-A);

	}





    return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main(){

	

	int a, b;

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

	

	if(b%a == 0){

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

	}

	else if(a == b){

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

	}

	else if(b%a != 0){

		printf("%d\n", b-a);

	}

	

	

	return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main(){

    int a,b;

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



    if (b%a==0){

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

    } else {

        printf("%d\n", b-a);

    }

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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

int main (){

	int a,b; 

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

	if (b%a ==0){

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

	}else {

		printf ("%d",b-a);

	}



	return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main ()

{

	int A;

	int B;

	

	scanf("%d %d", &A, &B);

	

	B%A==0? printf("%d", A+B): printf("%d", B-A);

	

	return 0;

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

using namespace std;

int main()

{

    /*vector <int> v(3);

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

    {

        cin>>v[i];

    }

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

    double a=(v[0]*v[1])/2;

    cout<<(int)a<<endl;*/

    int a,b;

    cin>>a>>b;

    if(b%a==0)

    {

        cout<<a+b<<endl;

        return 0;

    }

    else cout<<b-a<<endl;

    return 0;

}


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



int main (){



    int G, N;

    scanf("%d %d", &G, &N);



    if(N % G == 0){

        printf("%d", G+N);

    } else {printf("%d", N - G);

    }







    return 0;

}