akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> s;
  n = s.size();
  vector<int> b;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    b.push_back(s[i] - '0');
    while (b.size() > 1 && b[b.size() - 1] != b[b.size() - 2]) {
      b.pop_back();
      b.pop_back();
      ans += 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 972
#include<iostream>
#include<cmath>
using namespace std;
int mypow(int a,int b)
{
	if(b==0)
	{
		return 1;
	}
	if(b==1)
	{
		return a;
	}
	if(b!=0&&b!=1)
	{
		return a*mypow(a,b-1);
	}
}
int main()
{
    int a=0,b=0,c=0,k=0,bigger=0,biggest=0;
	cin>>a>>b>>c>>k;
	int maxa=b+c+a*mypow(2,k);
	int maxb=a+c+b*mypow(2,k);
	int maxc=a+b+c*mypow(2,k);
	bigger=maxa > maxb ? maxa : maxb;
	biggest=bigger>maxc?bigger:maxc;
	cout<<biggest;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define pb push_back

#define INF int(1e9)
#define EPS 1e-9
#define MOD int(1e9 + 7)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	int arr[n + 1], hero[n];
	for(int i = 0; i <= n; i++)
		cin >> arr[i];
	for(int i = 0; i < n; i++)
		cin >> hero[i];
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		if(arr[i] > 0) {
			int rem = min(arr[i], hero[i]);
			arr[i] -= rem;
			hero[i] -= rem;
			ans += rem;
		}
		if(hero[i] > 0) {
			int rem = min(arr[i + 1], hero[i]);
			arr[i + 1] -= rem;
			hero[i] -= rem;
			ans += rem;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

pow2 = [1] * (N + 1)
for i in range(N):
    pow2[i + 1] = pow2[i] * 2 % MOD

order = []
parent = [-1] * N

stack = deque([0])
while stack:
    v = stack.pop()
    order.append(v)
    for nv in G[v]:
        if parent[v] != nv:
            parent[nv] = v
            stack.append(nv)

numer = 0
nums = [0] * N

for v in reversed(order):
    tmp = 1
    for nv in G[v]:
        if parent[v] != nv:
            c = nums[nv] + 1
            nums[v] += c
            tmp += pow2[c] - 1
    tmp += pow2[N - nums[v] - 1] - 1
    numer = (numer + pow2[N - 1] - tmp) % MOD

denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)


Measured memory_bytes: 58132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main(){
    ll a,b,x; cin >> a >> b >> x;
    ll ans = (b/x) - a/x;
    if(a % x == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    int ans = 0, r = 0;
    rep(i, 0, n){
        if(i != 0) ans += (a[i] > r ? t : t - (r - a[i]));
        r = a[i] + t;
    }
    ans += t;
    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    a, b = (int(x) for x in sys.stdin.readline().split())
    ans = math.ceil((a + b) / 2)
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
n,m=list(map(int,input().split()))
l_list=[]
r_list=[]
for i in range(m):
  l,r=list(map(int,input().split()))
  l_list.append(l)
  r_list.append(r)

ans_1=max(l_list)
ans_2=min(r_list)
print(max(ans_2-ans_1+1,0))


Measured memory_bytes: 16940
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	long long n;
	cin>>n;
	long long mi=n+1;
	for(long long i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			mi=min(mi,i+(n/i));
		}
	}
	cout<<mi-2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

int A,B,C,D; 

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>A>>B>>C>>D;
    int Ta=(C+B-1)/B;
    int Tb=(A+D-1)/D;
    if(Tb>=Ta) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int a, b;
    cin >> a >> b;
    int now = 1, cnt = 0;
    while(now < b){
        now += a - 1;
        cnt++;
    }
    cout << cnt<< endl;

    return 0;
}

Measured memory_bytes: 256
<?php
$n = explode(' ', trim(fgets(STDIN)));
$k = trim(fgets(STDIN));

$max = 0;
$maxi = 0;
for ($i = 0; $i < 3; $i++) {
    $n[$i] = (int)$n[$i];
    if ($n[$i] > $max) {
        $max = $n[$i];
        $maxi = $i;
    }
}

$sum = 0;
for ($i = 0; $i < 3; $i++) {
    if ($i != $maxi) {
        $sum += $n[$i];
    }
}

if ($k > 1) {
    $sum += $max * pow(2, $k);
} else {
    $sum += $max * 2;
}

echo $sum . PHP_EOL;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;

int main(){
  string S,T="";
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='1'){
      T.push_back('1');
    }
    else if(S.at(i)=='0'){
      T.push_back('0');
    }
    else if(T.size()!=0){
      T.pop_back();
    }
  }
  cout << T << endl;
}
  

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int k, t; cin >> k >> t;
    vector<int> a(t);
    rep(i, t) {
        cin >> a[i];
        if((k + 1) / 2 < a[i]) {
            cout << k - ((k - a[i]) * 2 + 1) << endl;
            return;
        }
    }
    cout << 0 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	int n = a.length(), m = b.length();
	if(n < m)
	{
		swap(n, m);
		swap(a, b);
	}

	int x[n+1][m+1];
	memset(x, 0, sizeof(x));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(a[i-1] == b[j-1])
				x[i][j] = x[i-1][j-1] + 1;
			else x[i][j] = max(x[i-1][j], x[i][j-1]);
	string ans = "";
	int c = n, d = m;
	while(c > 0 && d > 0)
	{
		if(x[c][d] == x[c-1][d])
			c--;
		else if(x[c][d-1] == x[c][d])
			d--;
		else
		{
			assert(a[c-1] == b[d-1]);
			ans += a[c-1];
			c--;
			d--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 35456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int X = in.nextInt();
			if(A + B >= X && A <= X) {
				out.println("YES");
			} else {
				out.println("NO");
			}
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>

using namespace std;

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

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	string S;
	cin >> S;

	int N = S.size();

	V u(N,1),d(N,0);

	REP(i,N-1){
		if(S[i]=='R'&&S[i+1]=='R'){
			u[i+1] += d[i];
			d[i+1] += u[i];
		}
	}

	for(int i=N-1;i>0;--i){
		if(S[i]=='L'&&S[i-1]=='L'){
			u[i-1] += d[i];
			d[i-1] += u[i];
		}
	}

	REP(i,N){
		if(S[i]=='R'&&S[i+1]=='L'){
			cout << (u[i]+d[i+1]) << " ";
			cout << (d[i]+u[i+1]) << " ";
			++i;
		}
		else cout << '0' << " ";
	}
	cout << endl;
	return 0;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    int k, s,z;
    cin >> k>>s;
    int ans = 0;
    for (int i = 0; i < k+1; i++)
    {
        for (int j = 0; j < k+1; j++)
        {
            z = s - i - j;
            if (z < 0 || z > k) {
                continue;
            }
            else {
                ans++;
            }

        }
    }
    cout << ans << endl;
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val Array(min, mid, max) = StdIn.readLine().trim.split(" ").map(_.toInt).sorted

  val x = if(((3*max) % 2) == (min + mid + max) % 2){
    max
  } else max + 1
  
  println((3*x - (min + mid + max)) / 2)
}

Measured memory_bytes: 27188
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=8e18;
const int32_t LOG=21;
const int MOD=MOD2;

int power(int x,int y)
{
     if(y==0)return 1;
     int temp=power(x,y/2);
     temp*=temp;
     if(y&1)temp*=x;
     return temp;
}

int func(int x)
{
    return 5*power(x,4)+10*power(x,3)+10*power(x,2)+5*x+1;
}

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
          int x;
          cin>>x;
          rep(i,0,130)
          {
              rep(j,-130,130)
              {
                   int temp=power(i,5)-power(j,5);
                   if(temp==x)
                   {
                      cout<<i<<" "<<j<<endl;
                      return 0;
                   }
              }
          }
      }
      

      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3640
#include<stdio.h>

int main() {
   int R[200000];
   int n, i;
   int maxv=-2000000000;
   int minv;

   scanf("%d", &n);

   for(i=0; i<n; i++) {
      scanf("%d", &R[i]);
   }
   minv=R[0];
   for (i=1; i<n; i++) {
      if (maxv<R[i]-minv) {
         maxv=R[i]-minv;
      }
      if (minv>R[i]) {
         minv=R[i];
      }
   }
   printf("%d\n",maxv);
   return 0;
   
}

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_io;
    string a,b;
    cin >> a >> b;
    int n1 = a.length();
    int n2 = b.length();

    if( n1 < n2)
    {
        cout << "LESS";
    }
    else if( n1 > n2)
    {
        cout << "GREATER";
    }
    else
    {
        if( a > b)
        {
            cout << "GREATER";
        }
        else if(a < b)
        {
            cout << "LESS";
        }
        else
        {
            cout << "EQUAL";
        }
    }
}


Measured memory_bytes: 3636
n = int(input())
gifts = []
for i in range(n):
    x, u = input().split()
    gifts.append([x, u])
sum =0
for gift in gifts:
    if gift[1] == 'JPY':
        sum += int(gift[0])
    else:
        sum += float(gift[0]) * 380000
print(sum)

Measured memory_bytes: 3060
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define REP(i,a,n) for(int i = (a); i < (n); i++)
#define ALL(v) v.begin(), v.end()
int V[20], C[20];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) sum += V[i] - C[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 200004
#define MOD 1000000007
int H, W;
int main()
{
    cin >> H >> W;
    char board[H][W];
    long long int dp[H][W];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> board[i][j];
        }
    }
    for (int i = 0; i < W; i++)
    {
        if (board[0][i] != '#')
        {
            dp[0][i] = 1;
        }
        else
        {
            break;
        }
    }
    for (int i = 1; i < H; i++)
    {
        if (board[i][0] != '#')
        {
            dp[i][0] = 1;
        }
        else
        {
            break;
        }
    }
    for (int i = 1; i < H; i++)
    {
        for (int j = 1; j < W; j++)
        {
            if (board[i][j] != '#')
            {
                if (board[i - 1][j] != '#')
                {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j] + MOD) % MOD;
                }
                if (board[i][j - 1] != '#')
                {
                    dp[i][j] = (dp[i][j - 1] + dp[i][j] + MOD) % MOD;
                }
            }
        }
    }
    cout << dp[H - 1][W - 1];
    return 0;
}

Measured memory_bytes: 12344
#include<iostream>
using namespace std;
int main(){
	long long a,b,c,d,dc,dd,e,GCM=1,i,ans;
	cin>>a>>b>>c>>d;
	dc=c;
	dd=d;
	for(i=10000;i!=1;i--){
		if(dc%i==0&&dd%i==0){
			dc/=i;
			dd/=i;
			GCM*=i;
		}
	}
	e=dc*dd*GCM;
	a--;
	ans=b-a;
	ans-=b/c+b/d-b/e;   
	ans+=a/c+a/d-a/e;
	cout<<ans;
	
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    multiset<int> ms;
    int N; cin >> N;
    int ans = 0;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        if(ms.empty()) {
            ans++;
            ms.insert(val);
        }
        else {
            // val 未満で最大の要素
            auto itr = ms.lower_bound(val);
            if(itr == ms.begin()) {
                ans++;
                ms.insert(val);
            }
            else {
                --itr;
                ms.erase(itr);
                ms.insert(val);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
const int mod = 1e9+7;
const int inf = 2e9+10;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int x, y; cin>>x>>y;
	long long ans1 = y>=x? y-x:inf, ans2 = -y>=x? -y-x+1:inf,
	ans3 = y>=-x? y+x+1:inf, ans4 = -y>=-x? -y+x+2:inf;

	cout << min(min(ans1, ans2), min(ans3, ans4)) <<'\n';
	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;

signed main(void){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	if (n & 1) cout << n/2;
	else cout << n/2 - 1;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){

  vector <string> a,b; 
  string tmp;
  int n,i;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>tmp;
    a.push_back(tmp);
  }
  b.assign(a.begin(),a.end());
  for(i=0;i<n-1;i++) for(int j=n-2;j!=i-1;j--) if(a[j][1]>a[j+1][1]) swap(a[j],a[j+1]);
  for(i=0;i<n-1;i++) cout<<a[i]<<" ";
  cout<<a[n-1]<<endl<<"Stable"<<endl;

  for(i=0;i<n-1;i++){
    int now,minnum=101;
    for(int j=i;j<n;j++) if(minnum>b[j].at(1)-'0'){
        now=j;
        minnum=b[j].at(1)-'0';
      }
    if(i!=now)  swap(b[i],b[now]);
  }

  for(i=0;i<n-1;i++) cout<<b[i]<<" ";
  cout<<b[n-1]<<endl;
  if(a==b) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  
  return 0;
  
}


Measured memory_bytes: 3200
MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self//value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())

class Combination:
    def __init__(self,max_n):
        self.max_n=0
        self.fact=[Fp(1)]
        self.ifact=[Fp(1)]
        self.make_fact_list(max_n)
    def C(self,n,k):return self.fact[n]*self.ifact[k]*self.ifact[n-k] if 0<=k<=n else 0
    def H(self,n,k):return self.C(n+k-1,k) if n or k else 1
    def P(self,n,k):return self.fact[n]*self.ifact[n-k] if 0<=k<=n else 0
    def make_fact_list(self,max_n):
        if max_n<=self.max_n: return
        self.fact+=[Fp(0)]*(max_n-self.max_n)
        self.ifact+=[Fp(0)]*(max_n-self.max_n)
        for i in range(self.max_n+1,max_n+1):
            self.fact[i]=self.fact[i-1]*i
            self.ifact[i]=self.ifact[i-1]//i
        self.max_n=max_n

N = int(input())
A = list(map(int, input().split()))
B = [-1] * (N + 1)
for i, a in enumerate(A):
    if B[a] >= 0:
        break
    B[a] = i

L = B[a]
R = N - i
M = i - B[a] - 2
print(N)
comb = Combination(N+1)
for k in range(2, N+2):
    print(comb.C(N+1, k) - comb.C(L + R, k-1))


Measured memory_bytes: 27552
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 3000

void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input_dp.txt", "r", stdin);
	freopen("output_dp.txt", "w", stdout);
#endif
}

int dp[MAX + 1][MAX + 1];

string getLCS(string& s, string& t, int len)
{
	string  LCS;
	int i = 0, j = 0;

	while (len > 0)
	{
		if (s[i] == t[j])
		{
			LCS.push_back(s[i]);
			i++;
			j++;
			len--;
		}
		else {
			if (dp[i][j + 1] > dp[i + 1][j])
				j++;
			else
				i++;
		}
	}

	return LCS;
}

int lenLCS(string& s, string& t, int i, int j)
{
	if (i >= s.length() || j >= t.length())
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];

	if (s[i] == t[j])
		return dp[i][j] = 1 + lenLCS(s, t, i + 1, j + 1);
	else {
		return dp[i][j] = max(lenLCS(s, t, i + 1, j), lenLCS(s, t, i, j + 1));
	}
}

string solve(string s, string t)
{
	memset(dp, -1, sizeof dp);
	int len = lenLCS(s, t, 0, 0);
	return getLCS(s, t, len);
}


int32_t main()
{
	//d_m_c();

	string s, t;
	cin >> s >> t;

	cout << solve(s, t) << endl;


	return 0;
}

Measured memory_bytes: 70912
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXS (5000 + 5)
#define MAXN (25000000 + 5)
#define MAXC (26)
#define cint const int 
#define rint register int
#define LL long long
#define pii pair<int, int>
#define pci pair<char, int>
using namespace std;
cint root = 0;
struct cmp
{
	string s;
	int bh;
};
struct node
{
    int sum, next[MAXC], is_end, fa;
    node(): sum(0), is_end(0)
    { memset(next, -1, sizeof(next)); }
    node(int dqs, int dqi): sum(dqs), is_end(dqi)
    {
        memset(next, -1, sizeof(next));
    }
};
vector<node> b;
void ins(char* s, int n)
{
    static int cnt = 0;
    int dq = root;
    for (int i = 0; i < n; i++)
    {
        if (b[dq].next[s[i] - 'a'] == -1)
        {
            b.push_back(node());
            b[dq].next[s[i] - 'a'] = ++cnt;
        }
        b[b[dq].next[s[i] - 'a']].fa = dq;
        dq = b[dq].next[s[i] - 'a'];
    }
    int zh = 1 - b[dq].is_end;
    b[dq].is_end = 1;
    for (; dq != root; dq = b[dq].fa)
        b[dq].sum += zh;
    b[root].sum += zh;
}
void solve(int dq, int k)
{
    if (b[dq].is_end == 1 && k == 1)
        return ;
    int dqs = b[dq].is_end;
    for (int i = 0; i < MAXC; i++)
    {
        if (b[dq].next[i] != -1 && dqs + b[b[dq].next[i]].sum >= k)
        {
            printf("%c", 'a' + i);
            solve(b[dq].next[i], k - dqs);
            return ;
        }
        if (b[dq].next[i] != -1)
            dqs += b[b[dq].next[i]].sum;
    }
}
bool comp(cmp x, cmp y)
{
	return x.s < y.s;
}
int main()
{
	char s[MAXS];
	b.push_back(node());
	cmp sors[MAXS];
	int k, n;
	scanf("%s%d", s, &k);
	n = strlen(s);
	for (int i = 0; i < n; i++)
	{
		sors[i].bh = i;
		for (int j = i; j < n; j++)
			sors[i].s += s[j];
	}
	sort(sors, sors + n, comp);
	for (int i = 0; i < n; i++)
		for (int j = sors[i].bh; j < n; j++)
		{
			if (b[root].sum >= k)
			{
				solve(root, k);
				return 0;
			}
			ins(s + sors[i].bh, j - sors[i].bh + 1);
		}
	solve(root, k);
	return 0;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=0;
    for(int i=0;i<s.size();i++)
    {
        if((i+1)&1)
        {
            if(s[i]=='L')
            {
                flag++;
                break;
            }
        }
        else
        {
            if(s[i]=='R')
            {
                flag++;
                break;
            }
        }
    }
    if(flag==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3628
A, B, C, D, E, F = map(int, input().split())
perc = 0.0
ans = [0, 0]
op = [0, 0, 0, 0]
a = 0
while 100 * a <= F:
  b = 0
  while 100 * (a + b) <= F:
    c = 0
    while 100 * (a + b) + c <= F:
      if c > (a + b) * E:
        break
      d = 0
      while 100 * (a + b) + c + d <= F:
        if c + d > (a + b) * E:
          break
        if a == b == c == d == 0:
          break
        p = (c + d) * 1.0 / (100 * (a + b) + c + d)
        if p >= perc:
          perc = p
          ans = [100 * (a + b) + c + d, c + d]
          op = [a, b, c, d]
        d += D
      c += C
    b += B
  a += A
print(str(ans[0]) + " " + str(ans[1]))

Measured memory_bytes: 73660
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;
#define LL unsigned long long
#define MOD 1000000007
#define inf 1999999999


int main() {
	int n;
	cin >> n;
	cout << (n-1)/2 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const int N = 1e7 + 42;
const int m = 1e9 + 7;
int add(int x, int y) {
  x += y;
  while(x >= m) x -= m;
  while(x < 0) x += m;
  return x;
}
int mul(int x, int y) {
  return (x * 1ll * y) % m;
}
int binpow(int x, int y) {
  int z = 1;
  while(y) {
    if(y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
int inv(int x) {
  return binpow(x, m - 2);
}
int divide(int x, int y) {
  return mul(x, inv(y));
}
int fact[N];
void precalc() {
  fact[0] = 1;
  for(int i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k) {
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
int A(int n, int m) {
  return divide(fact[n], fact[n - m]);
}
int main() {

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

  precalc();

  int n, m;

  cin >> n >> m;

  int cur = 1, ans = 0;

  for(int i = 0; i < n + 1; i++) {
    ans = add(ans, mul(mul(mul(cur, C(n, i)), C(m - i, n - i)), fact[n - i]));
    cur *= -1;
  }

  cout << mul(mul(ans, C(m, n)), fact[n]);

  return 0;
}
/*

*/


Measured memory_bytes: 42712
import copy

n, m, x = map(int, input().split())
a = [0] * n
ans = 10 ** 7
c1 = [0] * m


def dfs(s, d, c):
    global ans
    c3=c.copy()
    if s == n:
        #print(d,c)
        for u in range(m):
            if c[u] < x:
                return
        ans = min(d, ans)
        #print(d,c,ans)
        return
    dfs(s + 1, d, c3)
    for k in range(m):
        c3[k] += a[s][k + 1]
    dfs(s + 1, d + a[s][0], c3)


for i in range(n):
    a[i] = list(map(int, input().split()))

c2 = [0] * m
for i in range(n):
    for j in range(m):
        c2[j] += a[i][j + 1]
for i in range(m):
    if c2[i] < x:
        print(-1)
        exit(0)

dfs(0, 0, c1)
print(ans)


Measured memory_bytes: 9352
#include<iostream>
#include<string>

using namespace std;

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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int a[q];
    rep(i, q) cin >> a[i];
    int ans[n];
    rep(i, n) ans[i] = 0;
    rep(i, q) ans[a[i]-1]++;
    rep(i, n){
        if (k - q + ans[i] > 0) {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }
}

Measured memory_bytes: 1408
import java.util.Scanner;
import java.util.Arrays;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        int[] times = new int[5];
        for(int i = 0; i < 5; i++){
            times[i] = scan.nextInt();
        }

        // search
        int min = Integer.MAX_VALUE;
        for(int a = 0; a < 5; a++){
            int sum = times[a];
            if(sum % 10 != 0){
                sum +=10 - sum % 10;
            }
            for(int b = 0; b < 5; b++){
                if(b == a){
                    continue;
                }
                sum += times[b];
                int tempB = 0;
                if(sum % 10 != 0){
                    tempB = 10 - sum % 10;
                    sum += tempB;
                }
                for(int c = 0; c < 5; c++){
                    if(c == a || c == b){
                        continue;
                    }
                    sum += times[c];
                    int tempC = 0;
                    if(sum % 10 != 0){
                        tempC = 10 - sum % 10;
                        sum += tempC;
                    }
                    for(int d = 0; d < 5; d++){
                        if(d == a || d == b || d == c){
                            continue;
                        }
                        sum += times[d];
                        int tempD = 0;
                        if(sum % 10 != 0){
                            tempD = 10 - sum % 10;
                            sum += tempD;
                        }
                        for(int e = 0; e < 5; e++){
                            if(e == a || e == b || e == c || e == d){
                                continue;
                            }
                            sum += times[e];
                            if(sum < min){
                                min = sum;
                            }
                            sum -= times[e];
                        }
                        sum -= (times[d] + tempD);
                    }
                    sum -= (times[c] + tempC);
                }
                sum -= (times[b] + tempB);
            }
        }


        // answer
        System.out.println(min);

    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define f first
#define s second

int fj[8][8] = {4, 1, 4, 1, 2, 1, 2, 1};

int main(){
  for(int i = 1 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      int t = j+1;
      if(t == 8) t = 0;
      fj[i][j] = fj[i-1][t];
    }
  }
  
  int p[8], tmp[8];
  int Count[8];
  while(cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7]){
    for(int i = 0 ; i < 8 ; i++){
      for(int j = 0 ; j < 8 ; j++) tmp[j] = p[j];
      int cnt = 0;
      bool flag = false;
      for(int j = 0 ; j < 8 ; j++){
	tmp[j] -= fj[i][j];
	tmp[j] = max(0, tmp[j]);
	cnt += tmp[j];
      }
      Count[i] = cnt;
    }
    
    pair<int, string> check[8];
    for(int i = 0 ; i < 8 ; i++){
      string tmp = "";
      for(int j = 0 ; j < 8 ; j++){
	tmp += fj[i][j]+'0';
      }
      check[i].f = Count[i];
      check[i].s = tmp;
    }
    sort(check, check+8);
    /*
    for(int i = 0 ; i < 8 ; i++){
      cout << "cnt = " << check[i].f << ", V = " << check[i].s << endl;
    }*/
    
    for(int i = 0 ; i < 8 ; i++){
      if(i != 7) cout <<check[0].s[i] << ' ';
      else cout << check[0].s[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
int main(){
  char s[101];
  int i,j,n;
  while(scanf("%s",s) != EOF){
    for(i=0;s[i]!='\0';i++){
      if(s[i] == '@'){
	for(j=0;j<s[i+1]-'0';j++){
	  printf("%c",s[i+2]);
	}
	i+=2;
      }
      else{
	printf("%c",s[i]);
      }
    }
    printf("\n");
  }
  return (0);
}

Measured memory_bytes: 524
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=1;i<=n;i++) a[i] = sc.nextLong();
        long[] left = new long[n+1];
        for(int i=1;i<=n;i++) left[i] = Math.max(left[i-1],a[i]);
        PriorityQueue<Long> pq = new PriorityQueue<>(10,Collections.reverseOrder());
        long[] ans = new long[n+1];
        long hi = left[n];
        long cnt = 0;
        for(int i=n;i>0;i--){
            if(a[i]<=left[i-1]){
                pq.add(a[i]);
                continue;
            }
            long lo = left[i-1];
            cnt++;
            ans[i] += cnt*(hi-lo);
            while(pq.size()>0&&pq.peek()>lo){
                ans[i] += pq.poll()-lo;
                cnt++;
            }
            hi = lo;
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=1;i<=n;i++) out.println(ans[i]);
        out.flush();
    }
}


Measured memory_bytes: 62968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CDifferentStrokes solver = new CDifferentStrokes();
        solver.solve(1, in, out);
        out.close();
    }

    static class CDifferentStrokes {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.NextInt();
            long[] dif = new long[n];
            long totalDif = 0;
            for (int i = 0; i < n; i++) {
                long a = in.NextInt();
                long b = in.NextInt();
                totalDif += a - b;
                dif[i] = -a - b;
            }
            Arrays.sort(dif);
            int x = -1;
            for (long i : dif) {
                totalDif += x * i;
                x *= -1;
            }
            out.println(totalDif / 2);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(Writer out) {
            super(out);
        }

        public OutputWriter(File file) throws FileNotFoundException {
            super(file);
        }

        public OutputWriter(OutputStream out) {
            super(out);
        }

    }
}



Measured memory_bytes: 46620
def main(argv)
  n = gets.chomp.to_i
  a = gets.chomp.split(' ').map(&:to_i).sort
  
  s = a.reduce(:+)
  
  q = a.bsearch_index{|x| x >= 0}
  # p q # <-- debug
  
  if q == nil then # a is all negative
    q = n - 1
  elsif q == 0  then # a is all positive
    q = 1
  end
  
  m = a[q..n].reduce(:+) - a[0..q-1].reduce(:+)
  puts m.to_s
  
  a[q..n-2].each do |y|
    puts [a[0], y].map(&:to_s).join(' ')
    a[0] -= y
  end
  
  a[0..q-1].each do |y|
    puts [a[n-1], y].map(&:to_s).join(' ')
    a[n-1] -= y
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 15464
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b;cin>>a>>b;

    if(b%a == 0){
        cout<<a+b<<endl;
    }
    else{
        cout<<b-a<<endl;
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3632
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . B.words <$> B.getLine
    let printn i = do
            B.putStr $ as V.! i
            B.putStr " "
    mapM_ printn [(n - 1), (n - 3) .. 0]
    mapM_ printn $ if odd $ length as then [1, 3 .. (n - 1)] else [0, 2 .. (n - 1)]


Measured memory_bytes: 24956
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000;

int main()
{
    int n;
    cin >> n;
    int a[300005];
    for(int i = 0; i < n * 3; i++) cin >> a[i];
    priority_queue<ll, vector<ll>, greater<ll>> quel;
    ll l[100005];
    for(int i = 0; i < n; i++){
        quel.push(a[i]);
        l[0] += a[i];
    }
    for(int i = 1; i <= n; i++){
        l[i] = l[i - 1] + a[n - 1 + i];
        quel.push(a[n - 1 + i]);
        l[i] -= quel.top();
        quel.pop();
    }
    priority_queue<ll> quer;
    ll r[100005];
    for(int i = 0; i < n; i++){
        quer.push(a[n * 3 - 1 - i]);
        r[0] += a[n * 3 - 1 - i];
    }
    for(int i = 1; i <= n; i++){
        r[i] = r[i - 1] + a[n * 2 - i];
        quer.push(a[n * 2 - i]);
        r[i] -= quer.top();
        quer.pop();
    }
    ll ans = -INF;
    for(int i = 0; i <= n; i++) ans = max(ans, l[i] - r[n - i]);
    cout << ans << endl;
}


Measured memory_bytes: 7592
use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        k: usize,
        a: [i64; n],
    }
    let mut x = vec![];
    let mut y = vec![];
    let mut z = 0;
    for a in a {
        if a == 0 {
            z += 1;
        } else if a > 0 {
            x.push(a);
        } else {
            y.push(a);
        }
    }
    if k > n - z {
        println!("0");
        return;
    }
    const MOD: i64 = 1_000_000_007;
    if k == n - z {
        if y.len() % 2 == 1 && z > 0 {
            println!("0");
            return;
        }
        let mut ans = 1;
        for x in x.iter().chain(y.iter()) {
            ans = ans * (*x + MOD) % MOD;
        }
        println!("{}", ans);
        return;
    }
    x.sort();
    y.sort();
    if k % 2 == 1 && x.is_empty() {
        if z > 0 {
            println!("0");
            return;
        }
        let mut ans = 1;
        for y in y.iter().rev().take(k) {
            ans = ans * (*y + MOD) % MOD;
        }
        println!("{}", ans);
        return;
    }
    // +
    let (mul, k) = if k % 2 == 1 {
        (x.pop().unwrap(), (k - 1) / 2)
    } else {
        (1, k / 2)
    };
    x.reverse();
    let mut x = x.chunks_exact(2).map(|x| x[1] * x[0]).collect::<Vec<_>>();
    let mut y = y.chunks_exact(2).map(|y| y[1] * y[0]).collect::<Vec<_>>();
    while x.len() < k {
        x.push(0);
    }
    while y.len() < k {
        y.push(0);
    }
    let mut i = 0;
    let mut j = 0;
    let mut ans = mul;
    while i + j < k {
        if x[i] > y[j] {
            ans = ans * (x[i] % MOD) % MOD;
            i += 1;
        } else {
            ans = ans * (y[j] % MOD) % MOD;
            j += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8204
#include <bits/stdc++.h>

using namespace std;

int main() {

	string s;
	cin >> s ;

	for (long i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
		if (i % 2 == 1) {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes"  << endl;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
S = [input() for i in range(H)]

S_h1 = [[0]*(W+1) for i in range(H)]
S_w1 = [[0]*(H+1) for i in range(W)]
S_h2 = [[0]*(W+1) for i in range(H)]
S_w2 = [[0]*(H+1) for i in range(W)]

for x in range(W):
    for y in range(H):
        if S[y][x] == '#':
            S_h1[y][x] = 0
            S_w1[x][y] = 0
        else:
            S_h1[y][x] += S_h1[y][x-1]+1
            S_w1[x][y] += S_w1[x][y-1]+1

for x in range(W-1,-1,-1):
    for y in range(H-1,-1,-1):
        if S[y][x] == '#':
            S_h2[y][x] = 0
            S_w2[x][y] = 0
        else:
            S_h2[y][x] += S_h2[y][x+1]+1
            S_w2[x][y] += S_w2[x][y+1]+1

ans = 0
for x in range(W):
    for y in range(H):
        if S[y][x] == '.':
            ans = max(ans,S_h1[y][x]+S_h2[y][x]+S_w1[x][y]+S_w2[x][y]-3)
 
print(ans)

Measured memory_bytes: 178692
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == b % 2) cout << (a + b) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
def pyramid(N: int, info: list) -> tuple:
    """
    """
    _info = sorted(info, key=lambda x: x[2], reverse=True)
    x, y, h = _info[0]
    candidtes = [
        (cx, cy, h + abs(cx - x) + abs(cy - y))
        for cx in range(100+1)
        for cy in range(100+1)]

    for x, y, h in _info[1:]:
        temp = []
        for cx, cy, H in candidtes:
            th = max(H - abs(cx - x)-abs(cy - y), 0)
            if th == h:
                temp.append((cx, cy, H))

        candidtes = temp

    return candidtes[0]

if __name__ == "__main__":
    N = int(input())
    info = [
        tuple(int(s) for s in input().split())
        for _ in range(N)]
    cx, cy, h = pyramid(N, info)
    print(cx, cy, h)


Measured memory_bytes: 4852
x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
# print("x = ", x)
# print("a = ", a)
# print("b = ", b)

if x < a:
    distance_xa = a - x
else:
    distance_xa = x - a
# print("distance_xa = ", distance_xa)

if x < b:
    distance_xb = b - x
else:
    distance_xb = x - b
# print("distance_xb = ", distance_xb)

if distance_xa < distance_xb:
    print("A")
else:
    print("B")

Measured memory_bytes: 3060