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

#include<cstdio>

#define int long long

using namespace std;

int n,top,minn;

const int N=1000010;

int a[N],zhan[N],r[N],l[N];

long long ans;

signed main()

{

	cin>>n;

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

	for(int i=1;i<=n;++i)r[i]=n+1,l[i]=0;

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

	{

		while(top&&a[zhan[top]]>a[i])r[zhan[top--]]=i;

		l[i]=zhan[top];

		zhan[++top]=i;

	}

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

	cout<<ans;

	return 0;

}

/*

8

5 4 8 1 2 6 7 3

*/

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

#include <string.h>

#define N 200002

typedef unsigned long long LL;



int a[N], lp[N], rp[N];

LL ans;



int main()

{	

	int n, i, tp, t;

	

	scanf("%d", &n);

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

	a[0] = a[n + 1] = 0;

	for(lp[1] = 0, i = 2; i <= n; i++){

		tp = i - 1, t = a[i];

		while(a[tp] > t) tp = lp[tp];

		lp[i] = tp;

	}

	

	ans = (LL)a[n] * (LL)(n - lp[n]); 

	for(rp[n] = n + 1, i = n - 1; i >= 1; i--){

		tp = i + 1, t = a[i];

		while(a[tp] > t) tp = rp[tp];

		rp[i] = tp;

		ans += (LL)t * (LL)(tp - i) * (LL)(i - lp[i]);

	}

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

	

	return 0;

}

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

}


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

}

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

}


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

}

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

}


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

}

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

}

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

}

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

}


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

}

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

}


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

}

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

}

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

}

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

}


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

}

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

}


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

}


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

}


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

	}

}

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

using namespace std;

int main(){

 int a,b;

 cin>>a>>b;

 if(b%a==0){

    cout<<a+b;

 }

 else{

    cout<<b-a;

 }

 return 0;

}


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

}

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

#include<bits/stdc++.h>

using namespace std;



int main(){







                    int n,m;

                    cin>>n>>m;

                    if(m%n==0){

                        cout<<n+m;

                    }

                    else{

                        cout<<m-n;

                    }





}

//Pavel


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

#include<string.h>

int main(){

    

    int A, B;

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

    

    if(B%A == 0){

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

	} else {

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

	}

    

    return 0;

}

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

using namespace std;



typedef long long ll;



main()

{

    int a, b;

    cin >> a >> b;

    if(b % a == 0){

        cout << a + b;

    }

    else{

        cout << b - a;

    }





}


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

#include<string.h>

int main(){

    

    int A, B;

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

    

    if(B%A == 0){

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

	} else {

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

	}

    

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/// --- In the name of ALLAH --- ///





#include <cmath>

#include<bits/stdc++.h>

using namespace std;





typedef long long              ll;

typedef vector<int>            vi;

typedef vector<ll>             vl;

typedef vector<vi>             vvi;

typedef vector<vl>             vvl;

typedef pair<int,int>          pii;

typedef pair<double, double>   pdd;

typedef pair<ll, ll>           pll;

typedef vector<pii>            vii;

typedef vector<pll>            vll;

typedef double                 dl;



#define endl                   '\n'

#define PB                     push_back

#define F                      first

#define S                      second

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

#define rall(a)                (a).rbegin(),(a).rend()

#define sz(x)                  (ll)x.size()

#define wt                     ll t; cin>>t; while(t--)

#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];



const double PI = acos(-1);

const double eps = 1e-9;

const int inf = 2000000000;

const ll infLL = 9000000000000000000;





#define mem(a,b) memset(a, b, sizeof(a) )

#define sqr(a) ((a) * (a))

#define mod 10000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);



#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {            cerr << endl;}

template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}



ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }

ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }





const ll mx=1e9;



















int main()

{

    optimize();



   int n,m,i,j,p=0;

   cin>>n>>m;

   if(m%n==0)

   cout<<m+n<<endl;

   else

    cout<<m-n<<endl;









    return 0;

}
















































































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

}

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

using namespace std;

int main ()

{

    int a,b;

    cin>>a>>b;

    if (b%a==0)

        cout<<a+b<<endl;

    else

        cout<<b-a<<endl;

    return 0;

}


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



int main() {

	int A,B;

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

	if(B%A==0){

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

		

	}else{

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

	}

	return 0;

}



	 

// Fastest known solution for this problem: