akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
  int main()
{	
    int n;
    cin>>n;
    int a[n],b[n+1],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    b[1]=abs(a[0]-a[1]);
    b[2]=min(abs(a[0]-a[1])+abs(a[2]-a[1]),abs(a[0]-a[2]));
    for(int i=3;i<n;i++) 
    {
        b[i]=min(abs(a[i-1]-a[i])+b[i-1],min(b[i-2]+abs(a[i-2]-a[i-1])+abs(a[i]-a[i-1]),b[i-2]+abs(a[i-2]-a[i])));
    }   
    cout<<b[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int  main()

{
    int a,b,res=0,p=1,q=0;
    float t;
    cin>>a>>b>>t;
    while(a*p<=(t+0.5))
    {
        p++;
        res+=b;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;

    int arr[n];

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

    sort(arr,arr+n);

    double d=0;

    d+= (arr[0]+arr[1]);
    d/=2.0;

    for(int i=2;i<n;i++){
        d+=arr[i];
        d/=2.0;
    }

    cout<<d<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
typedef long long ll;
int main(void) {
    bool ok = true;
    map<string,int> used;
    int n; cin >> n;
    string x; cin >> x;
    used[x] = 1;
    char end = x.back();
    rep(i, n-1) {
        string s; cin >> s;
        if(end != s[0] || used[s]) ok = false;
        used[s] = 1;
        end = s.back();
    }
    if(ok) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    int a, p;
    cin >> a >> p;
    p += a * 3;

    int ans = p / 2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint  = long long;
const lint INF= 1e16;

signed main(){
  lint N, K; cin >> N >> K;
  vector<lint> x(N);
  lint ans = INF;
  for(lint i = 0; i < N; i++) cin >> x[i];
  for(lint i = 0; i + K <= N; i++){
    lint ans1;
    if(x[i] * x[i + K - 1] >= 0) ans1 = max(abs(x[i]), abs(x[i + K - 1]));
    else ans1 = min(2 * abs(x[i]) + (x[i + K - 1]), abs(x[i]) + 2 * x[i + K - 1]);
    ans = min(ans, ans1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=500005,mod=998244353;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n,m;
int Fac[N],Inv[N];
void prework(){
	int n=N-1;
	Fac[0]=1;
	For(i,1,n)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
}
int C(int n,int m){
	if (m<0||m>n)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int main(){
	prework();
	n=read(),m=read();
	if (n>m)
		swap(n,m);
	int ans=0;
	For(i,0,n){
		int v=(LL)Pow(m+1,n-i)*Pow(n+1,m-i)%mod;
		v=(LL)v*C(n,i)%mod*C(m,i)%mod;
		v=(LL)v*Fac[i]%mod;
		if (i&1)
			Del(ans,v);
		else
			Add(ans,v);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(const string &a,const string &b){
	int i = 0;
	while(a[i] == b[i]){
		i++;
	}
	if(i == a.length()) return 0;
	return a[i] < b[i];
}
bool isvalidnum(const int money, vector<bool> hatenum){
	int m = money;
	int nownum;
	while(m>0){
		nownum = m%10;
		if (hatenum[nownum]) return false;
		m = (m-nownum)/10;
	}
	return true;
}

int main () {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << (X-Z)/(Y+Z);

	return 0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = [int(s) for s in input().split()]
ans = 0
for i in range(n):
    check = c
    a = [int(s) for s in input().split()]
    for j in range(m):
        check = check + a[j] * b[j]
    if check > 0:
        ans += 1
print(ans)

Measured memory_bytes: 9184
#include<stdio.h>

int main(void){
    unsigned long long int m,n,i,s,t = 108839116800000000;
    while(scanf("%llu",&m) , m != 0){
        scanf("%llu",&n);
        s = 0;
        for(i = m;i <= n;i++){
            if(!(t % i)){
                s++;
            }
        }
        printf("%llu\n",s);
    }
    return 0;
}

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

//#undef HOME

ll pw = (ll)1e9;

ll g(ll x) {
    return x * pw + pw - 1;
}

ll secret;

string str(ll x) {
    return to_string(x);
}

int cnt = 0;
bool ask(ll x) {
    //cerr << x << endl;
    assert(x > 0 && x <= (ll)1e18);
    cnt++;
    assert(cnt <= 64);
#ifdef HOME
    bool f1 = x <= secret;
    bool f2 = str(x) <= str(secret);
    return f1 == f2;
#else
    cout << "? " << x << endl;
    string s;
    cin >> s;
    return s == "Y";
#endif
}

void answer(ll x) {
#ifdef HOME
    cerr << x << endl;
    assert(x == secret);
#else
    cout << "! " << x << endl;
    exit(0);
#endif
}

int main() {
#ifdef HOME
    //assert(freopen("in", "r", stdin));
#endif
    secret = pw;

    ll cur = 0;
    int it = 0;
    while (it < 9) {

        int mn = it ? 0 : 1;

        int l = mn - 1;
        int r = 10;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (ask(g(cur * 10 + m))) r = m;
            else l = m;
        }
        /*if (r == mn) {
            cur = 10 * cur + r;
            break;
        }*/
        cur = 10 * cur + r;
        it++;
    }
    if (cur > pw) {
        assert(cur % 10 == 0);
        cur /= 10;
    }
    while (cur % 10 == 0) cur /= 10;
    assert(ask(cur));

    if (cur == 1) {
        cur = 9;
        while (cur < pw && !ask(cur)) cur = 10 * cur + 9;
        cur = (cur + 1) / 10;
        answer(cur);
        return 0;
    }

    while (cur <= pw && ask(cur - 1)) cur *= 10;
    cur /= 10;
    answer(cur);


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 708
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void convert(int x, vector<int> *v) {
  if(x == 0) return;
  convert(x / 8, v);
  v->push_back(x % 8);
}

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    vector<int> v;
    convert(n, &v);
    for(int i = 0; i < v.size(); i++) {
      int temp = v[i];
      if(temp >= 4) temp++;
      if(temp >= 6) temp++;
      cout << temp;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
//#include <tuple>
#include <set>
#include <string.h>
#include <functional>

#define X first
#define Y second
#define MP make_pair
//#define MT make_tuple
#define REP(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
#define FOR(i, n) REP(i, 0, n)
typedef long long ll;
using namespace std;
const int MAX = 500;
const double eps = 0.0000001;

template<class T, class U>
void convert(T &t, U &u)
{
	stringstream ss;
	ss << t;
	ss >> u;
}

int main()
{
	int n, m;
	while( cin >> n >> m && n | m ){
		vector<int> tb(n, 0);
		FOR(i, n){ tb[i] = i; }

		int index = n - 1;
		int ans = -1;
		bool b = false;
		while( !b ){
			FOR(j, m){
				while(1){
					index = ( index + 1 ) % n;
					if( tb[index] != -1 ) break;
				}
			}

			ans = index + 1;
			tb[index] = -1;

			b = true;
			FOR(i, n){ 
				b &= ( tb[i] == -1 ); 
			}
		}

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c))
#define     M             32000
int main()
{
    string s;
    bool b = false;
    cin>>s;
    int i=0;
    while(s[i]!='\0')
    {
        if(s[i]=='7')
        {
             b = true;
             break;
        }
        i++;

    }
    if(b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

return 0;

}


Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a=[lmis() for i in range(3)]
    n=ii()
    b=[ii() for i in range(n)]
    for s in b:
        for i in range(3):
            for j in range(3):
                if a[i][j]==s: a[i][j]=0
    flag=0
    for i in range(3):
        if sum(a[i])==0 or a[0][i]+a[1][i]+a[2][i]==0: flag=1
    if a[1][1]==0:
        if a[0][0]+a[2][2]==0 or a[0][2]+a[2][0]==0: flag=1
    print('Yes' if flag==1 else 'No')
    





if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool hash[100010] = {};
    REP(i, n){
        int l, r;
        cin >> l >> r;
        FOR(j, l, r) hash[j] = true;
    }

    int ans = 0;
    FOR(i, 1, 100000){
        if(hash[i] == true) ans++;
    }
    cout << ans << "\n";
    return 0;
}


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

int main()
{
	int n, k, count = 0;
	int s[1005] = { 0 };

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> s[i];

	sort(s, s + n);
	for (int i = 0; i < k; i++)
		count += s[i];

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpp make_pair
using namespace std;

int main()
{
	ll n,i,j;
	cin>>n;

	map<ll,ll>mp;

	for(i=1;i<=9;i++)
	{
		for(j=i;j<=9;j++)
			mp[i*j]++;
	}

	if(mp[n]>0)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = INT_MAX / 2;

vector<int> prices;
vector<vector<int>> unds;

int ans = INF;

// return INF if the condition is not satisfied
int calc(const vector<int> &books, const int M, const int X) {
    int acc_price = 0;
    vector<int> acc_unds(M, 0);
    for (auto b : books) {
        acc_price += prices[b];
        for (int i = 0; i < M; i++) {
            acc_unds[i] += unds[b][i];
        }
    }

    bool ok = true;
    for (int i = 0; i < M; i++) {
        if (acc_unds[i] < X) {
            ok = false;
        }
    }

    if (ok) {
        return acc_price;
    } else {
        return INF;
    }
}

void solve(int cur, vector<int> &books, const int N, const int M, const int X) {
    if (cur == N) {
        chmin(ans, calc(books, M, X));
        return;
    }

    // not use book
    solve(cur + 1, books, N, M, X);

    // use book
    books.push_back(cur);
    solve(cur + 1, books, N, M, X);
    books.pop_back();
}

int main(void) {
    int N, M, X;
    cin >> N >> M >> X;

    prices.resize(N, 0);
    unds.resize(N, vector<int>(M, 0));
    for (int i = 0; i < N; i++) {
        cin >> prices[i];
        for (int j = 0; j < M; j++) {
            cin >> unds[i][j];
        }
    }

    {
        vector<int> books;
        solve(0, books, N, M, X);
    }

    if (ans == INF) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int N; cin >> N;
    int arr[N];
    int alice_point = 0;
    int bob_point = 0;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    int n = sizeof(arr) / sizeof(arr[0]);
    sort(arr, arr + n, greater<int>());
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            alice_point += arr[i];
        } else {
            bob_point += arr[i];
        }
    }
    cout << alice_point - bob_point << endl;
}


Measured memory_bytes: 3632
def main():
    from collections import deque
    n,x,y=map(int,input().split())
    e=[[]for _ in range(n)]
    for i in range(n-1):
        e[i]+=i+1,
        e[i+1]+=i,
    e[x-1]+=y-1,
    e[y-1]+=x-1,
    a=[0]*n
    for s in range(n):
        d=[-1]*n
        d[s]=0
        q=deque([s])
        add,pop=q.append,q.popleft
        while q:
            v=pop()
            for w in e[v]:
                if d[w]<0:
                    d[w]=d[v]+1
                    add(w)
        for i in d:a[i]+=1
    print(' '.join(str(i//2)for i in a[1:]))
main()

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main() { 
    ll N, X;
    cin >> N >> X;
    vector<ll> x(N+1);
    for (int i = 0; i<N; ++i)cin >> x[i];
    x[N] = X;
    sort(x.begin(), x.end());
    vector<ll> dif(N);
    for (int i = 0; i < N; i++) dif[i] = x[i + 1] - x[i];
    ll g = *min_element(dif.begin(), dif.end());
    for (int i = 0; i < N; i++){
      g = gcd(g, dif[i]);
    }
      cout << g << endl;
    return 0;
}

Measured memory_bytes: 4720
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list()
for i in range(N):
  B.append(A[i]//2)

def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x
      
def lcm(x, y):
  return x * y // gcd(x, y)

def divide2(p):
  if(p % 2 == 1):
    return 0
  else:
    return divide2(p//2)+1

X = 1
for i in range(N):
  X = lcm(X, B[i])
  if(X > M):
    print(0)
    exit()

for i in range(1, N):
  if(divide2(A[0]) != divide2(A[i])):
    print(0)
    exit()
    
print((M-X)//(2*X) + 1)

Measured memory_bytes: 92432
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        char c[] = str.toCharArray();
        
        // char c[] = new char[4000];
        // for (int i = 0; i < 4000; i++) {
        //     if (i % 3 == 0) {
        //         c[i] = 'R';
        //     } else if (i % 3 == 1) {
        //         c[i] = 'G';
        //     } else {
        //         c[i] = 'B';
        //     }
        // }
        
        
        List<Integer>[] list = new List[3];
        for (int i = 0; i < 3; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n; i++) {
            if (c[i] == 'R') {
                list[0].add(i);
            } else if (c[i] == 'G') {
                list[1].add(i);
            } else {
                list[2].add(i);
            }
        }
        long sum = list[0].size() * list[1].size();
        sum *= list[2].size();
        
        long minus = 0;
        for (int offset = 1; offset < n; offset++) {
            for (int i = 0; i < n; i++) {
                int j = i + offset;
                int k = j + offset;
                if (k >= n) continue;
                if (c[i] != c[j] && c[j] != c[k] && c[k] != c[i]) minus++;
            }
        }
        System.out.println(sum - minus);
    }
}


Measured memory_bytes: 36344
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    vector<vector<int>> cnt(10, vector<int>(10));
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        cnt[s.front() - '0'][s.back() - '0']++;
    }

    ll ans = 0;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            ans += (ll)cnt[i][j] * cnt[j][i];
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  string a="pphbhhphph";
  string ans;ans+=a[n%10];ans+="on";
  print(ans);
  return 0;
}

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

using namespace std;
using ll = long long int;

int main() {
    ll N, t;
    cin >> N;
    vector<ll> monster = vector<ll>();
    vector<ll> original = vector<ll>();
    vector<ll> person = vector<ll>();
    vector<ll> remaining = vector<ll>();
    for (int i = 0; i < N+1; i++){
        cin >> t;
        monster.emplace_back(t);
        original.emplace_back(t);
    }
    for (int i = 0; i < N; i++){
        cin >> t;
        person.emplace_back(t);
    }
    for (int i = 0; i < N; i++) {
        ll K = monster[i] - person[i];
        if (K < 0){
            monster[i+1] = max(0LL, monster[i+1] + K);
            K = 0;
        }
        monster[i] = K;
    }
    ll ans = 0;
    for (int i = 0; i < N+1; i++) {
        ans += original[i] - monster[i];
    }
    cout << ans << endl;
    return 0;

}

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

int main(){
  string S;
  cin >> S;
  bool flg=true;
  if(S.size()%2!=0){
    flg=false;
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<S.size();i++){
    if(i%2==0){
      if(S[i]!='h')flg=false;
    }else{
      if(S[i]!='i')flg=false;
    }
  }
  if(flg)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(void){
	int alice,bob;
	cin >> alice >> bob;
	if(alice==1) alice = 14;
	if(bob==1) bob=14;
	
	if(alice>bob) cout << "Alice" << endl;
	else if(alice<bob) cout << "Bob" << endl;
	else cout << "Draw" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main() {
  int64_t N,K;
  cin>>N>>K;
  cout<<min(N%K,abs(N%K-K))<<endl;
  return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str;
		String[] arrStr;
		StringBuilder sb = new StringBuilder();
		try {

			while (true) {
				str = br.readLine();
				arrStr = str.split(" ");

				int h = Integer.parseInt(arrStr[0]);
				int w = Integer.parseInt(arrStr[1]);
				if (h == 0 && w == 0) {
					break;
				}

				boolean iKisu = false;
				for (int i = 0; i < h; i++) {
					iKisu = (i%2==0);
					for (int j = 0; j < w; j++) {
						if ( iKisu ){
							sb.append( j%2==0 ? "#":".");
						}else{
							sb.append( j%2==0 ? ".":"#");
						}
					}
					sb.append("\n");
				}
				System.out.println(sb.toString());
				sb.setLength(0);
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 20960
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#define int long long
using namespace std;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

signed main() {

    string s;
    map<char,bool> mp;

    cin >> s;

    for(int i = 0; i < 26; i ++){
        mp[(char)('a' +i)] = false;
    }

    for(int i = 0; i < s.length(); i ++){
        mp[s[i]] = true;
    }
    for(int i = 0; i < 26; i ++) {
        if(mp[(char)('a' +i)] == false){
            cout << (char)('a' +i);
            break;
        }
        if(i == 25) cout << "None";
    }

    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

vector<int> vx[N], vy[N];

struct UnionFind
{
   vector<int> parent, size;

   void init(int n){
      parent.resize(n+1);
      size.resize(n+1);
         
      for (int i = 1; i <= n; ++i)
      {
         parent[i] = i;
         size[i] = 1;
      }

   }

   int find(int x){

      while(x != parent[x]){
         parent[x] = parent[parent[x]];
         x = parent[x];
      }

      return x;
   }

   bool unite(int x, int y){//merges indexes
      x = find(x);
      y = find(y);
      if(x == y)
         return false;
      if(size[x] < size[y])
         swap(x, y);
      parent[y] = x;
      size[x] += size[y];

      for(auto it: vx[y])
         vx[x].push_back(it);

      for(auto it: vy[y])
         vy[x].push_back(it);

      return true;
   }

   int getSize(int x){
      x = find(x);
      return size[x];
   }

};

vector<int> X[2*N], Y[2*N];

const int maxn = 1e5;
vector<pair<P, int>> edges;
vector<pair<P, int>> edges2;

int n;
int32_t main(){_

   cin>>n;

   for (int i = 0; i < n; ++i)
   {
      int a, b;
      cin >> a >> b;
      X[a].push_back(b);
      X[b].push_back(a);
      vx[i].push_back(a);
      vy[i].push_back(b);
      edges.push_back({{a, b}, i});
      edges2.push_back({{b, a}, i});
   }

   UnionFind uf;
   uf.init(N);

   int ans = -n;

   #define F first
   #define S second
   
   sort(edges.begin(), edges.end());
   sort(edges2.begin(), edges2.end());

   // cout<<edges<<endl;

   for (int i = 0; i+1 < sz(edges); ++i)
   {
      int x = edges[i].F.F, y = edges[i].F.S, idx = edges[i].S;
      int x2 = edges[i+1].F.F, y2 = edges[i+1].F.S, idx2 = edges[i+1].S;
      if(x == x2){
         uf.unite(idx, idx2);
      }
   }

   #define edges edges2

   // cout<<edges<<endl;

   for (int i = 0; i+1 < sz(edges); ++i)
   {
      int x = edges[i].F.F, y = edges[i].F.S, idx = edges[i].S;
      int x2 = edges[i+1].F.F, y2 = edges[i+1].F.S, idx2 = edges[i+1].S;
      if(x == x2){
         uf.unite(idx, idx2);
      }
   }
   #undef edges

   for (int i = 0; i < n; ++i)
   {
      if(uf.find(i) == i){
         sort(vx[i].begin(), vx[i].end());
         ((vx[i]).erase(unique((vx[i]).begin(), (vx[i]).end()), (vx[i]).end()));
         sort(vy[i].begin(), vy[i].end());
         ((vy[i]).erase(unique((vy[i]).begin(), (vy[i]).end()), (vy[i]).end()));
         ans += sz(vx[i]) * sz(vy[i]);
      }  
   }

   cout<<ans;

   return 0;
}

Measured memory_bytes: 44256
#include <iostream>
#include<math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


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

	int h[100010];
	rep(i, N)cin >> h[i];

	int dp[100010] = {-1};
	
	dp[0] = 0;
	dp[1] = dp[0] + abs(h[1] - h[0]);
	
	int P1 = 0;
	int P2 = 0;
	for (int i = 2; i < (int)(N); i++) {
		P1 = dp[i-1] + abs(h[i] - h[i-1]);
		P2 = dp[i-2] + abs(h[i] - h[i - 2]);

		if (P1 >= P2)dp[i] = P2;
		else dp[i] = P1;
	}

 cout << dp[N-1] << endl;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ll long long 
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//typedef long long  MOD=1000000009;
ll MOD=998244353;
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll lcm(ll x, ll y) {ll res = (x * y) / __gcd(x, y); return res;}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void iofoj(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

ll par[300000];
ll siz[300000];

ll p(ll a)
{
    if(par[a]==a)return a;
    return par[a]=p(par[a]);
}

void uni(ll a,ll b)
{
    a=p(a);
    b=p(b);
    if(a!=b)
    {
        if(siz[b]>siz[a])
        swap(a,b);
        par[b]=a;
        siz[a]+=siz[b];
    }
}

void solution()
{
    ll k,i,j,h,m,w,n;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        siz[i]=1;
        par[i]=i;
    }
    ll ans=0;
    while(m--)
    {
        cin>>i>>j;
        uni(i,j);
    }
    for(i=1;i<=n;i++)
    ans=max(ans,siz[i]);
    cout<<ans;
}

int main(){
    fio
    //iofoj();
    // ll t;
    // cin>>t;
    // while(t--)
    solution();
    return 0; 
}





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

const int INF = 1e9;

int N;
vector<int> R, C;
vector<vector<int> > dp;

int dfs(int l, int r) {
  if ( r == l ) return 0;
  if ( dp[l][r] ) return dp[l][r];

  int ret = INF;
  for ( int i = l; i < r; i++ ) {
    ret = min(ret, dfs(l, i)+dfs(i+1, r)+R[l]*C[i]*C[r]);
  }
  
  return dp[l][r] = ret;
}

int main() {  
  cin >> N;

  R = vector<int>(N);
  C = vector<int>(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> R[i] >> C[i];
  }

  dp = vector<vector<int> >(N, vector<int>(N, 0));

  cout << dfs(0, N-1) << endl;
  
  return 0;
}



Measured memory_bytes: 3164
s = input()
q = int(input())

for qi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])
    
    if command[0] == 'print':
        print(s[a:b + 1])
        
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b +1][::-1] + s[b + 1:]
        
    else:
        p = command[3]
        s = s[:a] + p + s[b+1:]

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

int main(){
    long long S;
    cin >> S;
    long long X1, Y1, X2, Y2;
    X1 = Y2 = sqrt(S + 0.5);
    if (X1 * Y2 < S) ++X1;
    if (X1 * Y2 < S) ++Y2;
    Y1 = X1 * Y2 - S; X2 = 1;
    cout << "0 0 " << X1 << ' ' << Y1 << ' ' << X2 << ' ' << Y2 << endl;
    return 0;
}

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

int main(){
	char str[21];
	char temp[21];
	int i = 0;

	memset(str, 0, sizeof(str));
	memset(temp, 0, sizeof(temp));

	while(cin >> str){
		int n = strlen(str);
		for(; n!=0; ){
			temp[i++] = str[--n];
		}
		cout << temp << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
int main(){
    int a,i,b,ans=0,sum=0;
    cin>>a;
    for(i=1;i<=a;i++){
        b=i;
        sum=0;
        while(b){
            sum++;
            b/=10;
        }
        if(sum%2) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(i, a, b) for (int i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char a;
    cin >> a;
    cout << char(a+1);
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        cc: String
    }

    let mut c = cc.chars().collect::<Vec<char>>();
    let mut ans = 0;
    let mut lcursor = 0;
    let mut rcursor = n-1;
    while rcursor > lcursor {
        if c[rcursor] == 'R' {
            for i in lcursor..rcursor {
                if c[i] == 'W' {
                    c.swap_remove(i);
                    ans += 1;
                    break;
                }
                lcursor+=1;
            }
        } else {
            c.pop();
        }
        rcursor-=1;
    }
    println!("{}", ans)
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int digit(int n){
    int cnt=0;
    while (n>0){n/=10; ++cnt;}
    return cnt;
}

int M(int n){
    while(n>9) n/=10;
    return n;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a=digit(N),b=M(N),c=(N-b*pow(10,a-1)-N%10)/10+1;
    if (N<10){
        cout << N << endl;
        return 0;
    }
    ll sum=0;
    rep(i,a-1) sum+=pow(10,i);
    ll ans=0;
    rep2(i,1,N+1){
        if (i%10==0) continue;
        ll cnt=0;
        if (M(i)==i%10) cnt+=sum+1;
        else cnt+=sum;
        if (b<=i%10) cnt-=pow(10,a-2);
        if (b==i%10){
            if (M(i)<=N%10) cnt+=c;
            else cnt+=c-1;
        }
        ans+=cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N,M;
    cin >> N >> M;
    long long* H = new long long[N];
    bool* Ti = new bool[N];
    for (long long i=0; i<N; ++i){
        Ti[i] =true;
        cin >> H[i];
    }
    long long a,b;
    for(long long i=0; i < M; ++i){
        cin >> a >> b;
        if(H[a-1] >= H[b-1]){
            Ti[b-1] = false;
        }
        if(H[a-1] <= H[b-1]){
            Ti[a-1] = false;
        }
    }
    long long ans=0;
    for (long long i=0; i<N; ++i){
        if(Ti[i])++ans;
    }
    cout << ans <<endl;
    delete Ti;
    delete H;
}

Measured memory_bytes: 3988
#include <iostream>
#include <list>
using namespace std;
class NewList: private list<int>
{
public:
	NewList(): list<int>()
	{
		iter = end();
	}

	void insert(int x)
	{
		iter = list<int>::insert(iter, x);
	}

	void move(int d)
	{
		if (d > 0)
		{
			for (int i=0; i<d; ++i)
			{
				++iter;
			}
		}
		else if (d < 0)
		{
			for (int i=0; i<-d; ++i)
			{
				--iter;
			}
		}
	}

	void erase()
	{
		iter = list<int>::erase(iter);
	}

	void Display()
	{
		for (iterator iter=begin(); iter!=end(); ++iter)
		{
			cout << *iter <<endl;
		}
	}

private:
	iterator iter;
};

int main()
{
	NewList a;
	int n;
	cin >> n;
	for (int i=0; i<n; ++i)
	{
		int c;
		cin >> c;
		if (c == 0)
		{
			int x;
			cin >> x;
			a.insert(x);
		}
		else if (c == 1)
		{
			int d;
			cin >> d;
			a.move(d);
		}
		else
		{
			a.erase();
		}
	}
	a.Display();
	return 0;
}



Measured memory_bytes: 18544
#include <iostream>

using namespace std;

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

	long long min = 10e9;
	long long max = 1;
	for (int i = 0; i < n; i++) {
		long long ai;
		cin >> ai;

		if (ai < min) min = ai;
		if (ai > max) max = ai;
	}
	
	cout << max - min << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int K;
int a[505][505],N;
void Solve() {
	read(K);
	if(K == 1) {
		puts("1");puts("1");return;
	}
	for(int i = 2 ; i <= 500 ; i += 2) {
		if(2 * i >= K) {N = i;break;}
	}
	for(int i = 0 ; i < N ; ++i) {
		for(int j = 0 ; j < N ; ++j) {
			if(i & 1) a[i][j] = ((i + j) % N) + N;
			else a[i][j] = (i + j) % N;
		}
	}
	int p = N - 1;
	while(K < 2 * N) {
		for(int i = 0 ; i < N ; ++i) {
			for(int j = 0 ; j < N ; ++j) {
				if(a[i][j] == p + N) a[i][j] = p;
			}
		}
		--p;
		++K;
	}
	out(N);enter;
	for(int i = 0 ; i < N ; ++i) {
		for(int j = 0 ; j < N ; ++j) {
			out(a[i][j] + 1);space;
		}
		enter;
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 2176
x = input()
y = 'abcdefghijklmnopqrstuvwxyz'
from collections import deque
li = deque([])
for i in range(len(y)):
    li.append(y[i:i+1])
b = True
while(b):
    p = li.pop()
    if p == x:
        print(q)
        b = False
    q = p

Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < 5; i++) {
			list.add(sc.nextInt());
		}
		
        int k = sc.nextInt();
        
        boolean check = false;
                
        for(int i = 0; i < 5; i++) {
        	for(int j = 0; j < 5; j++) {
        		if(Math.abs(list.get(i) - list.get(j)) <= k) {
        			check = true;
        		} else {
        			check = false;
        			break;
        		}
        	}
        }
        
        if(check) {
        	System.out.print("Yay!");
        } else {
        	System.out.print(":(");        	
        }
	}	
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    li a, b;
    cin >> a >> b;
    // force a>=b
    if (a < b)swap(a, b);

    cout << (a - b > 1 ? "Alice" : "Brown") << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
c=a-b
h_list=[int(input()) for i in range(n)]
l=0
r=(max(h_list)+b-1)//b
while r-l>1:
    m=(l+r)//2
    count=0
    for i in h_list:
        if i<=b*m:
            pass
        else:
            count+=((i-b*m)+c-1)//c
    if count<=m:
        r=m
    else:
        l=m
print(r)









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

int n;
int S[100000];

int BinSearch( int key );

int main()
{

	int q, C = 0;
	int *T;

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

	scanf( "%d", &q );
	T = new int[q];
	for( int i = 0; i < q; i++ ) scanf( "%d", &T[i] );

	for( int i = 0; i < q; i++ ) C += BinSearch( T[i] );
	
	printf( "%d\n", C );

	delete[] T;

	return 0;

}

int BinSearch( int key )
{

	int left = 0, mid, right = n - 1;

	while( left <= right ) {

		mid = ( left + right ) / 2;

		if( S[mid] == key ) return 1;

		if( S[mid] < key )		left  = mid + 1;
		else if( S[mid] > key ) right = mid - 1;

	}

	return 0;

}

Measured memory_bytes: 1576
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b;
	cin >> a >> b;
	int len = max(a, b);
	string x = to_string(min(a, b));
	string ans;
	for (int i = 0; i < len; ++i) {
		ans += x;
	}
	cout << ans << endl;
	return 0;
}


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

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define REP(i,a,b) for(int i = a ; i <= b ; ++i) 
# define Rep(i,a,b) for(int i = a ; i < b ; ++i) 
# define Rrep(i,a,b) for(int i = b ; i >= a ; --i) 
# define FOR(i,b) for(int i = 0 ; i <= b ; ++i)
# define For(i,b) for(int i = 0 ; i < b ; ++i)
# define Rfor(i,b) for(int i = b ; i >= 0 ; --i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

void pe(int a) { cout << a << "\n" ; }
void pe(ll a) {	cout << a << "\n" ; }
void pe(string a) {	cout << a << "\n" ; }
void ps(int a) { cout << a << ' ' ; }
void ps(string a) {	cout << a << " " ; }
void ps(ll a) {	cout << a << " " ; }
template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll nCr(ll n,ll r){
	ll res=1;
	if(r>n) return 0;
	if(r>n-r) r=n-r;
	for(ll i=0;i<r;i++) {
		res*=(n-i);
		res/=(i+1);
	}
	return res;
}

const ll inf = 1e18 ; 
const int MxN = 300005; 
const ll mod = 1e9+7 ; 

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 
	ll n ; 
	cin >> n ; 
	Rep(i,1,3501) {
		Rep(j,1,3501) {
			ll apu = (i*j*n) ; 
			ll rv = (4*i*j - n*(i+j)) ; 
			if(rv <= 0 ) 
				continue ; 
			if(apu % rv == 0 ) {
				ps(i) ; 
				ps(j) ; 
				//ps(apu) ; 
				//ps(rv) ; 
				ll ans = apu / rv ;
				ps(ans) ;  
				return 0 ;
			}

		}
	}
   
	return 0 ; 	
}




Measured memory_bytes: 3612
#include<stdio.h>

int main(){
	int n,i;
	scanf("%d",&n);
	int num[n];
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	for(i=0;i<n;i++){
		if(num[i]%2==0){
			if(num[i]%3==0||num[i]%5==0){
				if(i==n-1)printf("APPROVED");
			}
			else {
				printf("DENIED");
				return 0;
			} 
		}
		else if(i==n-1)printf("APPROVED");
	}
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N], v[N];
typedef pair<int, int> pa;
vector<int> dead[N];

int main() {
    int n, m;
    cin >> n >> m;
    multiset<int> st;
    m++;
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        if(m - a[i] <= 0) continue;
        dead[m - a[i]].push_back(b[i]);
    }
    ll ans = 0;
    for(int i = m; i >= 1; i--) {
        for(int x : dead[i]) {
            st.insert(x);
        }
        if(!st.empty()) {
            auto it = prev(st.end());
            ans += *it;
            st.erase(it);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;

vstr islands(10);
vvll seen(10, vll(10, -1));
vll dx{0, 1, 0, -1};
vll dy{1, 0, -1, 0};

int main()
{
    ll n,k,res;
    cin>>n>>k;
    res = 0;
    for(ll b=k+1;b<=n;b++){
        res+=(n/b)*(b-k);
        for(ll i=1;i<=n%b;i++){
            if(k<=i)res++;
        }
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
X,N=map(int, input().split())
if N==0:
    print(X)
    sys.exit()

P=list(map(int, input().split()))

P.sort()

tmp1 = 0
tmp2 = 0

for i in range(X,102):
    if P.count(i)==0:
        tmp1 = i
        break

j = X
while j >= 0:
    if P.count(j)==0:
        tmp2 = j
        break    
    j -= 1

tmp3 = abs(X - tmp1)
tmp4 = abs(X - tmp2)

if tmp3 >= tmp4:
    print(tmp2)
else:
    print(tmp1)
        

Measured memory_bytes: 72760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  cin >> n;
  int a[n];
  cin >> a[0];
  int hcf = a[0];
  for(int i = 1 ; i < n ; i++){
    	cin >> a[i];
    	hcf = __gcd(hcf , a[i]);
  }
  cout << hcf << endl;
}

Measured memory_bytes: 640
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
    int n;
    cin >> n;
    cout << ((n + 999) / 1000 * 1000 - n);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6 + 5, inf = 1e9;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
queue <int> Q;
int n, s, t, cnt, tot = 1, p[N], q[N], tag[N], cur[N], dep[N], head[N], to[N], val[N], nxt[N];
void add(int x, int y, int c1, int c2) {
	to[++ tot] = y; val[tot] = c1; nxt[tot] = head[x]; head[x] = tot;
	to[++ tot] = x; val[tot] = c2; nxt[tot] = head[y]; head[y] = tot;
}
int bfs() {
	for(int i = s; i <= t; ++ i) cur[i] = head[i];
	for(int i = s; i <= t; ++ i) dep[i] = 0;
	dep[s] = 1; queue <int> q; q.push(s);
	while(! q.empty()) {
		int x = q.front(); q.pop();
		for(int i = head[x]; i; i = nxt[i]) {
			if(val[i] && dep[to[i]] == 0) {
				dep[to[i]] = dep[x] + 1;
				q.push(to[i]);
			}
		}
	}
	return dep[t] > 0;
}
int dfs(int x, int flow) {
	if(x == t) return flow;
	int up = 0;
	for(int &i = cur[x]; i; i = nxt[i]) {
		if(val[i] && dep[to[i]] == dep[x] + 1) {
			int tmp = dfs(to[i], Min(flow, val[i]));
			if(tmp == 0) dep[to[i]] = 0;
			val[i] -= tmp; val[i ^ 1] += tmp;
			flow -= tmp; up += tmp;
			if(flow == 0) return up;
		}
	}
	return up;
}
int Dinic() {
	int res = 0, flow;
	while(bfs()) while(flow = dfs(s, 2e9)) res += flow;
	return res;
}
int main() {
	n = read(); cnt = 2 * n;
	for(int i = 1; i <= n; ++ i) p[i] = read() + 1, tag[i] = 0;
	for(int i = 1; i <= n; ++ i) {
		if(tag[i]) continue;
		int q = i; cnt ++;
		do {
			tag[q] = 1; q = p[q];
			add(cnt, q, inf, inf);
		} while(q != i);
	}
	for(int i = 1; i <= n; ++ i) q[i] = read() + 1, tag[i] = 0;
	for(int i = 1; i <= n; ++ i) {
		if(tag[i]) continue;
		int p = i; cnt ++;
		do {
			tag[p] = 1; p = q[p];
			add(cnt, p + n, inf, inf);
		} while(p != i);
	}
	s = 0; t = cnt + 1;
	for(int i = 1; i <= n; ++ i) {
		if(p[i] == i && q[i] == i) add(s, i, 1, 0), add(i, t, 1, 0);
		if(p[i] == i && q[i] != i) add(s, i + n, 1, 0);
		if(p[i] != i && q[i] == i) add(i, t, 1, 0);
		if(p[i] != i && q[i] != i && p[i] == q[i]) add(i, i + n, 1, 1);
		if(p[i] != i && q[i] != i && p[i] != q[i]) add(i, i + n, 1, 0);
	}
	printf("%d\n", n - Dinic());
	return 0;
}


Measured memory_bytes: 39680