akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int g_bm = 998244353;

#define _LL long long

int modl(_LL a)
{
    a %= g_bm;
    if( a < 0 ) a += g_bm * ( 1 - (a + 1) / g_bm );
    return a;
}

int modadd(_LL a, _LL b)
{
    return modl(a + b);
}


template <class T> class MultiArray3
{
    public:
        T** _a2;
        T* _a;
        int _d1;
        int _d2;
        int _d3;
        MultiArray3(int d1, int d2, int d3, bool clr = true)
        {
            _d1 = d1; _d2 = d2; _d3 = d3;
            _a = new T[_d1 * _d2 * _d3];
            _a2 = new T*[_d1 * d2];
            for(int i = 0; i < d1 * d2; i++ ) _a2[i] = _a + (i * _d3);
            if(clr) memzero();
        }

        void memzero()
        {
            memset(_a, 0, _d1 * _d2 * _d3 * sizeof(T));
        }

        ~MultiArray3()
        {
            delete _a;
            delete _a2;
        }

        T** operator[](int i)
        {
            return _a2 + (i * _d2);
        }
};

int onecount[304];

int main()
{
    string s;
    int k;
    cin >> s;
    cin >> k;

    int n0 = 0;
    int n1 = 0;
    int c = 0;
    for( int i = 0; i < (int)s.length(); i++ )
    {
        if( s[i] == '1' )
        {
            c++;
            n1++;
        }
        else
        {
            onecount[n0] = c;
            n0++;
            c = 0;
        }
    }
    if( c > 0)
    {
        onecount[n0] = c;
        n0++;
    }


    MultiArray3<int> dp(n0, n1 + 1, n1 + 1);
    int total1 = onecount[0];
    for(int j = total1; j <= n1; j++)
    {
        dp[0][j][onecount[0]] = 1;
    }

    for(int i = 1; i < n0; i++ )
    {
        total1 += onecount[i];
        for( int u = 0; u <= total1; u++ )
        {
            // i番目にonecount[i]以下しか残さないケース
            for( int j = total1; j <= n1; j++ )
            {
                for(int m = 0; m <= onecount[i] && j - m >= 0 && u - m >= 0; m++)
                {
                    // ここはトータルでn1回しか通らないはず
                    dp[i][j][u] = modadd(dp[i][j][u], dp[i-1][j-m][u-m]);
                }
            }

            // i番目にonecount[i]+1以上置く
            if( u < onecount[i] ) continue;
            int dpsum = 0;
            for( int jm = 0; jm < total1 - onecount[i] - 1; jm++) dpsum = modadd(dpsum, dp[i - 1][jm][u - onecount[i]]);
            for( int j = total1 + 1; j <= n1; j++ )
            {
                dpsum = modadd(dpsum, dp[i - 1][j - onecount[i] - 1][u - onecount[i]]);
                dp[i][j][u] = modadd(dp[i][j][u], dpsum);
            }
        }                  
    }

    int ans = 0;

    for( int u = max(0, n1 - k); u <= n1; u++ )
    {
        ans = modadd(ans, dp[n0-1][n1][u]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 18716
import numpy as np
n=int(input())
x=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
    if i%2==1:
        b.append(x.pop())
    if i%2==0:
        a.append(x.pop())
b=b[::-1]
print(*(a+b))
        

Measured memory_bytes: 34216
#include <iostream>
using namespace std;

int main() {
    int a, b, c, x;
    long long n;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    n = 0;

    if ((500 * a + 100 * b + 50 * c) < x) {
        cout << 0 << endl;
    } else {
        for (int i = x / 500; i >= 0; i--) {
            if ((i <= a) && ((x - 500 * i) <= (100 * b + 50 * c))) {
                for (int j = (x - 500 * i) / 100; j >= 0; j--) {
                    if ((j <= b) && ((x - 500 * i - 100 * j) <= 50 * c)) n++;
                }
            }
        }
        cout << n << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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 long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int dp[301][301][302] = {};
int main() {
	string s; cin >> s; int n = s.length();
	int c; cin >> c;
	rep(i, n) {
		rep(k, c+1) {
			rep(j, n+1) {
				if (j < n) {
					if (s[i] == s[n - 1 - j]) {
						dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
					}
					if (k < c) {
						dp[i + 1][j + 1][k + 1] = max(dp[i + 1][j + 1][k + 1], dp[i][j][k] + 1);
					}
					dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
				}
				dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}
	int out = 0;
	rep(i, n + 1) {
		rep(j, n + 1) {
			rep(k, c+1) {
				if (i + j == n) {
					out = max(out, 2*dp[i][j][k]);
				}
				else if (i + j == n - 1) {
					out = max(out, 1 + 2 * dp[i][j][k]);
				}
			}
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 107136
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2]:
        count +=1
    elif p[i]>p[i+1]>p[i+2]:
        count +=1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int a,b,temp;
  int i,num;

  while(scanf("%d%d",&a,&b)!=EOF){
    temp=a+b;  num=0;
    while(temp!=0){
      temp=temp/10;  num++;
    }
    printf("%d\n",num);
  }

  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k; cin >> k; int n;
	string s; cin >> s;
	n = s.size();
	if(n <= k) {
		cout << s;
	}else {
		string ans = "";
		for(int i = 0; i < k; ++i) {
			ans += s[i];
		}
		cout << ans + "...";
	}
	return 0;
}

Measured memory_bytes: 3644
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = -1

not_enough = []
enough = []

for i in range(N):
    if A[i] - B[i] < 0:
        not_enough.append(abs(A[i] - B[i]))
    else:
        enough.append(A[i] - B[i])

enough.sort()
enough.reverse()

#print(enough)
#print(not_enough)

count = 0
whre = 0
res_eno = 0
res_not_eno = 0

if len(not_enough) == 0:
    print('0')
elif len(enough) == 0:
    print('-1')
else:
    for i in enough:

        res_eno = i
        count += 1

        while res_eno > 0:
            #print("count" + (str)(count))
            #print("whre" + (str)(whre))
            #print("res_eno" + (str)(res_eno))
            #print("res_not_eno" + (str)(res_not_eno))

            if res_not_eno == 0:
                if res_eno >= not_enough[whre]:
                    #print('A')
                    res_eno -= not_enough[whre]
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('B')
                    res_not_eno = not_enough[whre] - res_eno
                    res_eno = 0
            else:
                if res_eno >= res_not_eno:
                    #print('C')

                    res_eno -= res_not_eno
                    res_not_eno = 0
                    count += 1
                    whre += 1
                    if whre == len(not_enough):
                        break
                else:
                    #print('D')

                    res_not_eno = res_not_eno - res_eno
                    res_eno = 0
        if whre == len(not_enough):
            break

    if res_not_eno == 0 and whre == len(not_enough):
        print(count)
    else:
        print('-1')

Measured memory_bytes: 18360
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int x;
    cin >> x;
    for(int i = 1; i < 10000000; i++){
        x-=i;
        if(x<=0){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}


int main() {
    ll k;
    cin>>k;
    vector<ll> v(k);
    ll sum = 0;
    rep(i,k){
        cin>>v[i];
        v[i]-=(1+i);
        //        sum+=v[i];
    }
    //    sum/=k;
    ll case1=0,case2=0,case3=0;
    //    sum--;
    sort(alll(v));
    rep(j,k){
        case1 += abs(v[0] - v[j]);
    }
//    ll l =0, r = v.size()-1;
    ll tmp =case1;
    rep(i,k-1){
        ll j = i+1;
//        ll tmp =case1;
        auto diff = v[j]-v[i];
        tmp -= diff * (v.size() - j);
        tmp += diff * j;
        case1=min(tmp,case1);
    }
    pr(case1);
    
}



Measured memory_bytes: 1792
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

//素因数分解
vector<int64> prime_factorization(int64 n){
    int64 copy = n;
    vector<int64> res;
    for(int64 i=2;i*i<=copy;i++){
        if(n%i==0){
            res.push_back(i);
        }
        while(n%i==0){
            n/=i;
        }
    }
    if(n!=1) res.push_back(n);
    return res;
}

int64 Phi(int64 N){
    int64 res = N;
    for(auto p:prime_factorization(N)) res-=res/p;
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 N; cin >> N;
    cout << Phi(N) << bn;
}


Measured memory_bytes: 3172
#include<stdio.h>
#define Max 500000
#define term 1000000000

int Left[(Max/2)+2], Right[(Max/2)+2];
int c=0;


void merge(int e[], int n, int left, int mid, int right){
  int i,j,k;

  int x = (mid-left);
  int y = (right-mid);

  for ( i=0; i<x; i++ )
   Left[i] = e[left+i];
  for ( i=0; i<y; i++ )
   Right[i] = e[mid+i];

  Left[x]= Right[y] = term;
  i = j = 0;
  for ( k=left; k<right; k++){
    c++;
    if ( Left[i]<=Right[j] ){
      e[k] = Left[i++];
    } else {
      e[k] = Right[j++];
    }
  }
}

void mergeSort(int e[], int n, int left, int right ){
  int mid;
  if ( left+1<right ){
    mid=(left + right)/2;
    mergeSort(e, n, left, mid);
    mergeSort(e, n, mid, right);
    merge(e, n, left, mid, right);
  }
}

int main(){
  int e[Max], n, i;
  scanf("%d", &n);
  for ( i=0; i<n; i++) {
    scanf("%d", &e[i]);
    if (e[i]>=term ){
      return 1;
    }
  }
  mergeSort(e,n,0,n);

  for ( i=0; i<n; i++) {
    if ( i !=0 ) 
    printf(" ");

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

  printf("%d\n", c);


  return 0;
}




Measured memory_bytes: 5704
listt = input().split()

doubutsu = int(listt[0])
ashi = int(listt[1])

kame = (ashi-2*doubutsu)/2
tsuru = doubutsu - kame

if ashi%2 == 0 and kame >= 0 and tsuru >= 0:
    print('Yes')
else:
    print("No")




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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string bit(unsigned int x) {
    string ret = "";
    while (ret.size() < 32) {
        ret.push_back('0' + (x & 1));
        x /= 2;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned int a, b;
    cin >> a >> b;
    cout << bit(a & b) << endl;
    cout << bit(a | b) << endl;
    cout << bit(a ^ b) << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

// refer:
// http://dai1741.github.io/maximum-algo-2012/docs/shortest-path/
typedef vector<vector<int> > Metrics;
Metrics d;

void warshall_floyd(int n) { // n:頂点数
	REP(i, n) {	// 経由する頂点
		REP(j, n) {	// 開始頂点
			REP(k, n) {	// 終端
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}

void debugprint(int n) {
	REP(i, n) {
		REP(j, n) {
			if (i != j && d[i][j] != INF) {
				cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.precision(16);

    int h, w;
    cin >> h >> w;

    const int cmax = 10;
	d = Metrics(cmax, vector<int>(cmax, INF));
	REP(i, cmax) d[i][i] = 0;

	REP(i, cmax) {
        REP(j, cmax) {
            int from, to, cost;
            cin >> cost;
            from = i, to = j;
            d[from][to] = cost;
        }
    }

    warshall_floyd(cmax);

    // Aの読み込み始めますよお
    ll ans = 0;
    REP(i, h) {
        REP(j, w) {
            int t;
            cin >> t;
            if(t == -1 || t == 1) continue;
            ans += d[t][1];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S == "Sunny") cout << "Cloudy" << endl;
  if (S == "Cloudy") cout << "Rainy" << endl;
  if (S == "Rainy") cout << "Sunny" << endl;
}

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

using namespace std;

int main()
{
    long long a, b, cmmdc, r, rez = 1, d = 3;
    cin >> a >> b;
    while (b != 0)
    {
        r = a % b;
        a = b;
        b = r;
    }
    cmmdc = a;
    if (cmmdc % 2 == 0)
    {
        rez++; while (cmmdc % 2 == 0) cmmdc /= 2;
    }
    for (; d * d <= cmmdc; d += 2)
    {
        if (cmmdc % d == 0)
        {
            rez++; while (cmmdc % d == 0) cmmdc /= d;
        }
    }
    if (cmmdc > 1) rez++;
    cout << rez;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

s = 1
if n == 0:
    if a[0] != 1:
        print(-1)
        quit()
    else:
        print(1)
        quit()
elif a[0] > 0:
    print(-1)
    quit()
memo = [[0,0] for _ in range(n+1)]
memo[0] = [0,1]
for i in range(1,n+1):
    if s == 0:
        print(-1)
        quit()
    s = memo[i-1][1]*2
    if s > 10**15:
        s = 10**15
    memo[i][0] = a[i]
    memo[i][1] = s-a[i]
    if s-a[i] < 0:
        print(-1)
        quit()
ans = [[a[i],0] for i in range(n+1)]
for i in range(n-1,-1,-1):
    if (ans[i+1][0]+ans[i+1][1]) > memo[i][1]*2:
        print(-1)
        quit()
    else:
        ans[i][1] = min(memo[i][1],ans[i+1][0]+ans[i+1][1])
s = 0
for i in range(n+1):
    s += sum(ans[i])
print(s)


Measured memory_bytes: 38400
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
bool comp(p2 a,p2 b){
	return a.second<b.second;
}
void solve(){
	ll n;
	cin>>n;
	vector<p2> v(n);
	for(ll i=0;i<n;i++)
	cin>>v[i].first>>v[i].second;
	sort(v.begin(),v.end());
	ll a,b;
	if(n%2)
	a=v[n/2].first;
	else
	a=v[n/2-1].first+v[n/2].first;
	sort(v.begin(),v.end(),comp);
	if(n%2)
	b=v[n/2].second;
	else
	b=v[n/2-1].second+v[n/2].second;
	cout<<b-a+1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 6356
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };


int main() {
	int N;
	cin >> N;
	int any = 0;
	set<int>rate;
	REP(i, N) {
		int a;
		cin >> a;
		if (a >= 3200) {
			any++;
		}
		else if (1 <= a&&a <= 399)rate.insert(1);
		else if (400 <= a&&a <= 799)rate.insert(2);
		else if (800 <= a&&a <= 1199)rate.insert(3);
		else if (1200 <= a&&a <= 1599)rate.insert(4);
		else if (1600 <= a&&a <= 1999)rate.insert(5);
		else if (2000 <= a&&a <= 2399)rate.insert(6);
		else if (2400 <= a&&a <= 2799)rate.insert(7);
		else if (2800 <= a&&a <= 3199)rate.insert(8);
	}
	int color = rate.size();
	int mini, max;
	if (color == 0) {
		mini = 1;
		max = any;
	}
	else {
		if (color == 8) {
			mini = 8; max = 8+any;
		}
		else {
			if (any > 0) {
				mini = color;
				max = color + any;
			}
			else {
				mini = color;
				max = color;
			}
		}
	}

	cout << mini << " " << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1LL<<62;
const int MAX = 1e5;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int s = max(a,c);
    int g = min(b,d);
    cout << max(0,g-s) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
 
typedef long long ll;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
    VI v(5);
    int k;
    cin >>v[0]>>v[1]>>v[2]>>v[3]>>v[4]>>k;
    
    string ans="Yay!";
    REP(i,v.size()-1){
        for(int j=i+1;j<v.size();j++){
            if(v[j]-v[i]>k) ans=":(";
        }
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
int T,a,b,c,d,x,len;
int L,R,mid,A,B,border;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
void work()
{
	a=read();b=read();len=a+b;
	c=read();d=read();
	if(a==b)
	{
		for(int i=c;i<=d;i++)
			if(i&1)putchar('A');
			else putchar('B');
		putchar('\n');return;
	}
	x=(max(a,b)-1)/(min(a,b)+1)+1;
	L=0;R=a;border=0;
	while(L<=R)
	{
		mid=(L+R)>>1;
		A=a-mid;B=b-mid/x;
		if(1ll*(A+1)*x-1>=B)border=mid,L=mid+1;
		else R=mid-1;
	}
	border+=border/x;
//	printf("bor %d\n",border);
	for(int i=c;i<=min(border,d);i++)
		if(i%(x+1)==0)putchar('B');
		else putchar('A');
	for(int i=max(c-1,border)+1;i<=d;i++)
		if((len-i+1)%(x+1)==0)putchar('A');
		else putchar('B');
	putchar('\n');
}
int main()
{
	T=read();
	while(T--)work();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int N;
    cin >> N;
    char S[2][N+10];
    cin >> S[0] >> S[1];
    for(int i = 0; i < 2*N; ++i) cout << S[i%2][i/2];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 2000000

void CountingSort( int A[] , int B[] , int k , int n ){
	
	int i , j;
	int C[MAX];
	
	for( i = 0; i <= k + 1; i++ ){
		C[i] = 0;
	}
	
	for( j = 1; j <= n; j++ ){
		C[A[j]]++;
	}
	
	for( i = 1; i <= k + 1; i++ ){
		C[i] = C[i] + C[i - 1 ];
	}
	
	for( j = n; j >= 1; j-- ){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
}

int max( int A[] , int n ){
	
	int max = -1;
	
	for( int i = 0; i < n; i++ ){
		if( A[i] > max ){
			max = A[i];
		}
	}
	
	return max;
}

int main( void ){
	
	int n;
	int A[MAX] , B[MAX];
	
	scanf( "%d" , &n );
	
	for( int i = 1; i <= n; i++ ){
		scanf( "%d" , &A[i] );
	}
	
	CountingSort( A , B , max( A , n ) , n );
	
	for( int i = 1; i <= n; i++ ){
		
		if( i > 1 ){ printf( " " ); }
		printf( "%d" , B[i] );
			
	}
	printf( "\n" );
}




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

int main(){
  string A,B;
  cin >> A >> B;
  if(A.size()>B.size()){
    cout << "GREATER" << endl;
  }else if(A.size()<B.size()){
    cout << "LESS" << endl;
  }else{
    bool b = 1;
    rep(i,A.size()){
      if(A.at(i)>B.at(i)){
        cout << "GREATER" << endl;
        b = 0; break;
      }else if(A.at(i)<B.at(i)){
        cout << "LESS" << endl;
        b = 0; break;
      }
    }
    if(b){
      cout << "EQUAL" << endl;
    }
  }
}


Measured memory_bytes: 256
H = int(input())
ans = 0
count2 = 0
while H/2 == H//2:
    count2 += 1
    H //= 2
    
ans += 2**count2 - 1

###################

countOdd = 0
while H > 1:
    countOdd += 1
    H //= 2
   
ans += (2**count2) * (2**(countOdd+1) -1)

print(ans)

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	string s; cin >> s;
	bool ok(false);
	if (s.size() >= 4) {
		if (s.substr(0, 4) == "YAKI") ok = true;
	}
	puts(ok ? "Yes" : "No");

	return 0;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

string Backsubstr(string str, size_t pos, size_t len){
	const size_t strLen = str.length();

	return str.substr(strLen - pos, len);
}

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	string S;
	cin >> S;

	vector<ll> mod(2019, 0);
	ll mod_temp = 0;
	ll tenfactor = 1; 
	rep(i,S.size()){
		mod_temp = (mod_temp + (S[(S.size()-1)-i] - '0') * tenfactor) % 2019;
		tenfactor = (tenfactor * 10) % 2019;
		// cout << mod_temp << endl;
		mod[mod_temp]++;
	}

	ll ans = 0;
	rep(i,2019){
		if(i == 0){
			mod[i]++;
		}
		/*
		if(mod[i] != 0){
			cout << i << " : " << mod[i] << endl;
		}
		*/
		ll temp = mod[i] * (mod[i] - 1) / 2;
		ans += temp;
	}

	cout << ans << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3740
#include<stdio.h>
#include<string.h>
int main(void){
  char str[99];
  scanf("%s",str);
  int i,j,l;
  l=strlen(str);
  for(i=0;i<l/2;i++){
    if(str[i]!=str[l-(i+1)]){
      printf("No");
      return 0;
    }
  }
  l/=2;
  for(i=0;i<l/2;i++){
    if(str[i]!=str[l-(i+1)]){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}
    
  


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) begin(c), end(c)

using ll = long long;
using namespace std;

int main() {
	int N;
	cin >> N;

	bool ans = false;
	REP(i, 100) {
		REP(j, 100) {
			if (4 * i + j * 7 == N) {
				ans = true;
				break;
			}
		}
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int D[10]={0,2,5,5,4,5,6,3,7,6};
int C[10];

int num[101010];
int nex[101010];

int hoge(int L) {
	if(L==0) return 0;
	if(num[L]!=-1) return num[L];
	
	num[L]=-101010;
	int i;
	
	int ma=-101010,best=-1;
	FOR(i,10) if(L>=i && C[i]) {
		int cand=hoge(L-i);
		if(cand+1>num[L]) {
			num[L]=cand+1;
			best=C[i];
		}
		else if(cand+1==num[L] && best<C[i]) {
			best=C[i];
		}
	}
	nex[L]=best;
	return num[L];
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x;
		C[D[x]]=max(C[D[x]],x);
	}
	MINUS(num);
	
	string S;
	hoge(N);
	while(N) {
		x=nex[N];
		S.push_back('0'+x);
		N-=D[nex[N]];
	}
	sort(ALL(S));
	reverse(ALL(S));
	cout<<S<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 896
from collections import deque

H,W=map(int,input().split())
d=[]
for i in range(H):    
    d.append([0 if c=='#' else -1 for c in input()])
#print(d)
q=deque()
for i in range(H):
    for j in range(W):
        if not d[i][j]:
            q.append((i,j))
#print(q)
while q:
    u=q.popleft()
    ui,uj=u
    for v in [(ui-1,uj),(ui+1,uj),(ui,uj-1),(ui,uj+1)]:
        vi,vj=v
        if 0<=vi<=H-1 and 0<=vj<=W-1 and d[vi][vj]==-1:
            d[vi][vj]=d[ui][uj]+1
            q.append(v)
#print(d)
print(max(max(di) for di in d))

Measured memory_bytes: 84700
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()

gcd_cnt = [0]*(K+1)

for i in range(K, 0, -1):
	cnt = pow(K//i, N, mod)
	for j in range(2, K//i+1):
		cnt -= gcd_cnt[j*i]
		cnt %= mod
	gcd_cnt[i] = cnt

ans = 0
for i, x in enumerate(gcd_cnt):
	ans += i*x
	ans %= mod

print(ans)


Measured memory_bytes: 12048
import bisect
a,b,q = list(map(int, input().split()))
shine = []
temple = []
inf = 10**11
x = []
for i in range(a):
    shine.append(int(input()))
shine.append(inf)
for i in range(b):
    temple.append(int(input()))
temple.append(inf)
s2t = [0 for i in range(a+1)]
t2s = [0 for i in range(b+1)]
for i in range(a+1):
    index = bisect.bisect_left(temple, shine[i])
    if index >= 1:
        s2t[i] = min(abs(shine[i] - temple[index]), abs(shine[i] - temple[index - 1]))
    else:
        s2t[i] = abs(shine[i] - temple[index])
for i in range(b+1):
    index = bisect.bisect_left(shine, temple[i])
    if index >= 1:
        t2s[i] = min(abs(temple[i] - shine[index]), abs(temple[i] - shine[index - 1]))
    else:
        t2s[i] = abs(temple[i] - shine[index])
ans = [] 
for i in range(q):
    x = int(input())
    shine_index = bisect.bisect_left(shine, x)
    temple_index = bisect.bisect_left(temple, x)
    #shine_index -> 一番近い神社に行く
    if shine_index >= 1:
        B = abs(shine[shine_index-1] - x) + s2t[shine_index-1]
    else:
        B = inf
    A = abs(shine[shine_index] - x) + s2t[shine_index]
    C = abs(temple[temple_index] - x) + t2s[temple_index]
    if temple_index >= 1:
        D = abs(temple[temple_index-1] - x) + t2s[temple_index-1]
    else:
        D = inf
    print(min([A,B,C,D]))
    


Measured memory_bytes: 83032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=300001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;
   ll ans=0 ;

   for(ll i=1;i<=n;i++)
   {
       if(i%5==0&&i%3==0)
       {

       }
       else if(i%3==0)
       {

       }
       else if(i%5==0)
       {

       }
       else
       {
           ans+=i ;
       }
   }
   cout<<ans ;


}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    rep(i, A, B + 1) {
        if (i % K == 0) {
            write("OK");
            return 0;
        }
    }
    write("NG");
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define N 110
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)  for(int i = n - 1; i >= 0; --i)
#define forr1(i, n) for(int i = n; i >= 1; --i)
#define form(l, r, i)   for(int i = l; i <= r; ++i)
#define forv(r, l, i)   for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
  
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 9;
  
using namespace std;



int main()
{
    barnarnar
    ll n, k;
    cin >> n >> k;
    cout << min(n, min(n % k, k - n % k));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define debug(x) cout << x << endl;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 1010;

int main()
{


ll n,m;
cin>>n>>m;
cout<<(n*(n-1))/2+(m*(m-1)/2);










}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, C = 0;

  std::cin >> N;

  for (int i = 1; i <= N; i += 2) {
    int c = 0;
    
    for (int j = 1; j <= i; j ++)
      if (i % j == 0)
        c ++;

    if (c == 8)
      C ++;
  }

  std::cout << C << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200+2;
int tmp,cnt;
string str[maxn];
int main(){
	for (char ch='a';ch<='c';ch++){
		cin>>tmp;
		while (tmp--) str[cnt++]+=ch;
	}
	while (cnt>1){
		sort(str,str+cnt);
		str[0]+=str[--cnt];
	}
	cout<<str[0];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define num  50111

using namespace std;




int main(void){
 
int innum;

int  su,tan,ssu=0,skin=0,cnt=0;
char k;
	while(cin >> tan >> k >> su){
		ssu += su;
		skin += tan * su;
		cnt++;
	}
	cout << skin << endl;
	cout << (int)(ssu*1.0l/cnt + 0.5) << endl;
	
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){

    int N; cin >> N;
    vector<int> X(N);
    rep(i,N) cin >> X[i];

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

    int sum = 0;
    rep(i,N){
        sum += X[i];
    }

    int ans = 100000000;
    for(int i = 0; i <= 100; i++){
        int tmp = 0;
        rep(j,N){
            tmp += (X[j]-i)*(X[j]-i);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}

    

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    long long n, k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n) << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc129/tasks/abc129_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

string s[2001];
int numh[2001][2001], numw[2001][2001];
int h, w;

// 縦方向に連続する空白を探す
int seqh(int _h, int _w) {
    if (s[_h][_w] == '#') {
        return 0;
    }
    if (numh[_h][_w] != -1) {
        return numh[_h][_w];
    }
    //上方向に空白を探す
    int posMin = _h, posMax = _h;
    while (posMin >= 0 && s[posMin][_w] == '.') {
        posMin--;
    }
    posMin++;
    // 下方向に空白を探す
    while (posMax <= h - 1 && s[posMax][_w] == '.') {
        posMax++;
    }
    posMax--;
    int ans = posMax - posMin + 1;
    for (int i = posMin; i <= posMax; i++) {
        numh[i][_w] = ans;
    }
    return ans;
}

// 横方向に連続する空白を探す
int seqw(int _h, int _w) {
    if (s[_h][_w] == '#') {
        return 0;
    }
    if (numw[_h][_w] != -1) {
        return numw[_h][_w];
    }
    // 左方向に空白を探す
    int posMin = _w, posMax = _w;
    while (posMin >= 0 && s[_h][posMin] == '.') {
        posMin--;
    }
    posMin++;
    // 右方向に空白を探す
    while (posMax < w && s[_h][posMax] == '.') {
        posMax++;
    }
    posMax--;
    int ans = posMax - posMin + 1;
    for (int i = posMin; i <= posMax; i++) {
        numw[_h][i] = ans;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int ans = 0;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    fill((int *)numh, (int *)(numh + lengthof(numh)), -1);
    fill((int *)numw, (int *)(numw + lengthof(numw)), -1);

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            // 縦横の交点は重複してカウントしないため-1
            ans = max(ans, seqh(i, j) + seqw(i, j) - 1);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
	long long N;
	cin >> N;
	map<long long,long long> pr;
	vector<long long> prs;
	int loop, prsn=0;
	long long prsh=2;
	while(prsh*prsh<=N){
		if(!(N%prsh)){
			N/=prsh;
			pr[prsh]=1;
			prs.push_back(prsh);
			prsn++;
			while(!(N%prsh)){
				N/=prsh;
				pr[prsh]++;
			}
		}
		prsh++;
	}
	if(N!=1){
		pr[N]=1;
		prs.push_back(N);
		prsn++;
	}
	long long ps,ans=0;
	for(loop=0;loop<prsn;loop++){
		ps=1;
		while(ps*(ps+1)/2<=pr[prs[loop]]){
			ans++;
			ps++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int a,b,c,d;
int main(){
	cin >> a >> b >> c >> d;

	if(b<c || d<a) puts("0");
	else pout(min(b,d)-max(a,c));

	return 0;
}


Measured memory_bytes: 256
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = lines[0].split(" ")[0];
    lines.shift();
    var s = lines.map(i => i.split(""));

    var ans = 0;
    for (var i = 0; i < N; i++) {
        for (var j = 0; j < s[i].length - 1; j++) {
            if (s[i][j] === "A" && s[i][j + 1] === "B") { ans++; }
        }
    }

    var a = 0, b = 0, z = 0;
    for (var i = 0; i < N; i++) {
        if (s[i][0] === "B" && s[i][s[i].length - 1] !== "A") { b++; }
        if (s[i][0] !== "B" && s[i][s[i].length - 1] === "A") { a++; }
        if (s[i][0] === "B" && s[i][s[i].length - 1] === "A") { z++; }
    }
    if (a === 0 && b === 0 && z !== 0) { ans += z - 1 }
    else { ans += Math.min(a + z, b + z) }

    console.log(ans);
});

Measured memory_bytes: 24052
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 地点数の入力
		int n = sc.nextInt();

		int result = 0;

		for (int i = 1; i <= n; i++) {
			String[] iStr = String.valueOf(i).split("");

			if (iStr.length%2==1) result++;
		}

		System.out.println(result);

	}}

Measured memory_bytes: 62524
#include <iostream>
using namespace std;
int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  x/=50;
  int r = 0;
  for(;a>=0;a--){
     if(x < 10*a) continue;
     for(int b_=b;b_>=0;b_--){
        if(x < 10*a + 2*b_ ) continue;
        if(x > 10*a + 2*b_ + c) continue;
        r++;
     }
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

Memory = {}

# ひとつひとつの要素を見て、+1~-1の範囲の値を確定させる
for i in a:
  p = i + 1
  q = i
  r = -1
  if i >= 0: 
    r = i-1 
  
  # 確定した範囲の値を+1する
  if p in Memory:
    Memory[p] += 1
  else:
    Memory[p] = 1
  if q in Memory:
    Memory[q] += 1
  else:
    Memory[q] = 1
  if r != -1:
    if r in Memory:
      Memory[r] += 1
    else:
      Memory[r] = 1
  
#print(Memory)
  # 最後にキャッシュの中で一番数が多いのが正解
max = 0
maxVal = 0
for k,i in Memory.items():
  if max < i:
    max = i
    maxVal = k

print(max)


Measured memory_bytes: 18800
N=int(input())
L=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i+1,N):
     for k in range(j+1,N):
        ##print(str(i)+" "+str(j)+" "+str(k))
        if (L[i]+L[j])>L[k] and abs(L[i]-L[j])<L[k] and L[i]!=L[j] and L[j]!=L[k] and L[i]!=L[k]:
          ##print(str(L[i])+" "+str(L[j])+" "+str(L[k]))
          count+=1

print(str(count))    

Measured memory_bytes: 68696
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


dicti = {
    'hon':[2,4,5,7,9],
    'pon':[0,1,6,8],
    'bon':[3]
}

n = int_input()

d = n%10

for key in dicti:
    if d in dicti[key]:
        print(key)
        break

Measured memory_bytes: 9608
H=1
W=1
while H!=0 or W!=0:
	H,W = [int(i) for i in input().split()]
	if H!=0 or W!=0:
		for i in range(W):
			print('#',end='')
		print()
		for i in range(H-2):
			print('#',end='')
			for j in range(W-2):
				print('.',end='')
			print('#',end='\n')
		for i in range(W):
			print('#',end='')
		print('\n')

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

int a[101];

map<int,bool>m;

int main (){

    int x , n ;
    cin >> x >> n ;

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

    for (int i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]=true ;
    }

    int y,z ;

    for (int i=x;i>=-100;i--)
        if (m[i]==false) {
            y=i ;
            break ;
        }

    for (int i=x+1;i<=101;i++)
        if (m[i]==false) {
            z=i ;
            break ;
        }

     if (x-y<=z-x)
        cout << y ;

     else
        cout << z ;

return 0 ;
}


Measured memory_bytes: 3644