akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(std::vector<long long> A){
    sort(A.begin(), A.end());
    cout << abs(A[2] - A[1]) + abs(A[1] - A[0]) << endl;
}

int main(){

    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}



Measured memory_bytes: 256
k, n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
max_d = 0
for i in 0...(n - 1) do
  d = a[i + 1] - a[i]
  max_d = [max_d, d].max
end
max_d = [max_d, k - a[n - 1] + a[0]].max
puts k - max_d


Measured memory_bytes: 19332
count = 0
def mizu(h):
    global count

    if len(h) is 0:
        return

    if len(h) is 1:
        count += h[0]
        return

    m = min(h)
    count += m

    h = [i - m for i in h]

    while 0 in h:
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)

if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    mizu(h)
    print(count)

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    lint h, w, k;
    cin >> h >> w >> k;
    k--;
    lint dp[110][10];
    rep(i, h+1){
        rep(j, w+1){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    rep(y, h){
        rep(x, (1 << (w-1))){
            bool flag = false;
            rep(i, w-2){
                if((x >> i) % 4 == 3){
                    flag = true;
                    break;
                }
            }
            if(flag){
                continue;
            }
            vector<lint> pos(w);
            rep(i, w){
                pos[i] = i;
            }
            rep(i, w-1){
                if((x >> i) & 1){
                    swap(pos[i], pos[i+1]);
                }
            }
            rep(i, w){
                dp[y+1][pos[i]] += dp[y][i];
                dp[y+1][pos[i]] %= MOD;
            }
        }
    }
    cout << dp[h][k] << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ls=list(map(int,input().split()))
kk=0
km=100

for i in range(n):
    if ls[i]%2==1:
        kk+=1
        if ls[i]<km:
            km=ls[i]
if kk%2==0:
    print(sum(ls)//2)
else:
    print((sum(ls)-km)//2)



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

#define ll long long
#define vec vector<ll>
#define rev(a); reverse(a.begin(), a.end());
#define sorta(a); sort(a.begin(), a.end());
#define sortd(a); sort(a.begin(), a.end(), greater<int>());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';
#define pb push_back
#define mp make_pair

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/


bool same(int i, char c) {
	return ((i==0 && c=='R') || (i==1 && c=='G') || (i==2 && c=='B'));
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	int cum[n][3];
	FOR(i,0,n) FOR(j,0,3) cum[i][j]=0;
	vector<set<int>> ind (3);
	FOR(i,0,n) {
		if (s[i]=='R') {
			cum[i][0]++;
			ind[0].insert(i);
		}
		if (s[i]=='G') {
			cum[i][1]++;
			ind[1].insert(i);
		}
		if (s[i]=='B') {
			cum[i][2]++;
			ind[2].insert(i);
		}
		if (i==0) continue;
		FOR(j,0,3) {
			cum[i][j]+=cum[i-1][j];
		}
	}

	FOR(j,0,3) {
		FOR(i,0,n) {
			cum[i][j] = cum[n-1][j] - cum[i][j];
			if (same(j, s[i])) cum[i][j]++;
		}
	}

	// FOR(i,0,n) cout<<cum[i][0]<<" ";cout<<endl;
	// for(int i : ind[0]) cout<<i<<" ";
	
	ll out=0;
	FOR(i,0,3) {
		FOR(j,0,3) {
			if (i==j) continue;
			int k=-1;
			FOR(l,0,3) {
				if (l!=i&&l!=j) {
					k=l;
					break;
				}
			}

			FOR(a,0,n-2) {
				if (!same(i,s[a])) continue;
				FOR(b,a+1,n-1) {
					if (!same(j,s[b])) continue;
					out += cum[b+1][k];
					int s = b-a;
					s = b+s;
					if (ind[k].count(s)) {
						out--;
					}
				}
			}
		}
	}

	cout<<out;
}

Measured memory_bytes: 3860
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>E[101010];
int ok[101010], ans;

void dfs(int now, int p) {
	int ccnt = 0;
	fore(x, E[now]) {
		if (x != p) {
			dfs(x, now);
			ccnt++;
		}
	}
	int ngcnt = 0;
	int okcnt = 0;
	int other = 0;
	fore(x, E[now]) {
		if (x != p) {
			if (ok[x] == 0)ngcnt++;
			else if (ok[x] == 1)okcnt++;
			else if(ok[x] == 2)other++;
		}
	}
	if (ccnt >= 2) {
		if (ngcnt == 0)ok[now] = 1;
		else { ok[now] = 2; ans += ngcnt - 1; }
		if (now == 0 && other == 1 && ngcnt == 1 && okcnt == 0)ans++;
	}
	else if(ccnt == 1){
		if (ngcnt)ok[now] = 0;
		else if (other)ok[now] = 2;
		else ok[now] = 1;
		if (now == 0 && (other || ngcnt))ans++;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		E[a].pb(b);
		E[b].pb(a);
	}
	dfs(0, -1);
	puts(ans);
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
int a[maxn],b[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	rep(i,0,n) cin>>a[i]>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	if(n%2!=0)
	{
		cout<<b[n/2]-a[n/2]+1<<"\n";
	}
	else
	{
		ll val1=(ll)b[n/2]+b[n/2-1],val2=a[n/2]+a[n/2-1];
		cout<<val1-val2+1<<"\n";
	}
	return 0;
}

Measured memory_bytes: 5220
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


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

  if(n==0){
    cout<<0<<endl;
  }else{
    string s;
    while(n!=1){
      if(n>0){
        if(n%2==0){
          s.push_back('0');
          n/=-2;
        }else{
          s.push_back('1');
          n=(n-1)/-2;
        }
      }else{
        if(-n%2==0){
          s.push_back('0');
          n/=-2;
        }else{
          s.push_back('1');
          n=(n-1)/-2;
        }
      }
      // cout<<n<<endl;
    }
    s.push_back('1');
    // cout<<s<<endl;
    reverse(s.begin(),s.end());
    cout<<s<<endl;

  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll l,r,ans=INT_MAX;
    cin>>l>>r;
    if((l-1)/2019!=r/2019)//finds if there is any number in between l and r that is div by 2019 (L-1) hbo
        cout<<0;
    else
    {
        for(ll i=l;i<r;i++)
            for(ll j=l+1;j<=r;j++)
                ans=min(ans,(i%2019*j%2019)%2019);
        cout<<ans;
    }
}

Measured memory_bytes: 256
L,d,M[51],m[];main(l){while(~scanf("%d",&d))if(m[l++]=d,getchar()==10){for(d=l>L?-1:1,L=l;--l;)m[l]+=M[l]>M[l+d]?M[l]:M[l+d];L-d-++l||printf("%d\n",m[1]);memcpy(M,m,204);}}

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

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String base = br.readLine();
            String pairBase = "T";

            switch (base) {
                case "T":
                    pairBase = "A";
                    break;
                case "C":
                    pairBase = "G";
                    break;
                case "G":
                    pairBase = "C";
                    break;
            }

            System.out.println(pairBase);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23124
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(N);
	READV(K);
	cout<<min(N%K,K-(N%K))<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,m,c = readInts()
b = readInts()
a = []
for i in range(n):
	a.append(readInts())
ans = 0

for i in range(n):
	tmp = c
	for j in range(m):
		tmp+=a[i][j]*b[j]
	if tmp>0:
		ans+=1

print(ans)

Measured memory_bytes: 3444
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

for i in range(len(data)):
    data[i] = [j.replace('\n', '') for j in data[i]]

dx = [-1,-1,-1,0,1,1,1,0]
dy = [1,0,-1,-1,-1,0,1,1]

if S == 1 and H == 1:
    if data[0][0] == ".":
        data[0][0] = str(0)

for i in range(S):
    for j in range(H):
        if data[i][j] == '#':
            continue
        else:
            count = 0
            for k in range(8):
                x = j + dx[k]
                y = i + dy[k]
                if x < 0 or x >=H or y < 0 or y >= S:
                    continue
                elif data[y][x] == "#":
                    count = count+1
                data[i][j] = str(count)

for i in range(len(data)):
    print(str(data[i]).replace('[', '').replace(']', '').replace(',', '').replace("'", '').replace(' ', ''))


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m;
LL   d[1000][1000];
bool r[1000][1000];

int main() {
	cin >> n >> m;
	
	inc(i, n) {
	inc(j, n) {
		d[i][j] = -1000000000000001;
		r[i][j] = false;
	}
	}
	inc(i, n) {
		d[i][i] = 0;
		r[i][i] = true;
	}
	
	inc(i, m) {
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		r[a][b] = true;
	}
	
	inc(k, n) {
	inc(i, n) {
	inc(j, n) {
		setmax(d[i][j], d[i][k] + d[k][j]);
		r[i][j] |= (r[i][k] & r[k][j]);
	}
	}
	}
	
	bool flag = false;
	inc(i, n) {
		if(r[0][i] && r[i][n - 1] && d[i][i] > 0) { flag = true; }
	}
	
	if(flag) { cout << "inf" << endl; }
	else { cout << d[0][n - 1] << endl; }
	
	return 0;
}


Measured memory_bytes: 9088
s = gets.chomp.split("")
s.push("#")
id = 0
while s[id] != "#"
  if s[id] == "B" && s[id+1] == "C"
    s[id] = "D"
    s[id+1] = "."
  end
  id += 1
end
id = 0
cnt = as = 0
while s[id] != "#"
  if s[id] == "A"
    as += 1
  elsif s[id] == "D"
    cnt += as
  elsif s[id] == "B" || s[id] == "C"
    as = 0
  end
  id += 1
end
s.delete_at(-1)
puts cnt

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

using namespace std;

int main () {


	long long x, k, d;
	cin >> x >> k >> d;

	x = abs(x);

	if (x / d >= k) cout << x - d * k << "\n";
	else {
	
		k -= x / d;

		x = x % d;

		if (k % 2 == 0) cout << x << "\n";
		else cout << abs(x - d) << "\n";
	}

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

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

    vector<int> ans(10010,0);

    rep1(x,100)rep1(y,100)rep1(z,100){
        if(x*x + y*y + z*z + x*y + y*z + z*x > 10000) continue;

        ans[x*x + y*y + z*z + x*y + y*z + z*x -1]++;
    }

    rep(i,N) cout << ans[i] << endl;
}  

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

int main(){
	int x;
	cin >> x;
	
	int amari = x%100;
	if(amari==0){
		cout << 1 << endl;
		return 0;
	}
	
	int kosuu = x/100;
	if(amari <= kosuu*5){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a > 0) {
        cout << (b - a) * e << '\n';
    } else {
        int ans = b * e;
        ans += d;
        ans += abs(a) * c;
        cout << ans << '\n';
    }
}


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

int main() {
	
	int N;
	cin >> N;
	int color = 3;
	for(int i=0;i<N;++i) {
		char S;
		cin >> S;
		if(S == 'Y') color = 4;
	}
	
	if(color == 4) cout << "Four" << endl;
	else cout << "Three" << endl;
	
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<int, int> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	int a, b;
	cin >> a >> b;

	int time = a + b;

	if (time < 24) {
		cout << time << endl;
	}
	else {
		cout << time - 24 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	vector<int> d(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		d[i] = a[i + 1] - a[i];
	}
	if (n % 2 == 0) {
		long long ans = 0;
		for (int i = 0; i < n - 1; ++i) {
			ans += 2LL * d[i] * min(i + 1, n - i - 1);
		}
		cout << ans - d[n / 2 - 1] << endl;
	}
	else {
		long long ans = 0;
		for (int i = 0; i < n - 1; ++i) {
			ans += 2LL * d[i] * min(i + 1, n - i - 1);
		}
		cout << ans - min(d[n / 2 - 1], d[n / 2]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<set>
using namespace std;
int main(){
	set<int>a;
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		a.insert(x);
	}
	int m;
	cin>>m;
	while(m--){
		int x;
		cin>>x;
		if(a.find(x)!=a.end())
			cout<<x<<endl;
	}
	return 0;
}


Measured memory_bytes: 12468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
int main(){
  int N;
  cin>>N;
  int a;
  set<int> A;
  rep(i,N){
    cin>>a;
    if(A.find(a)==A.end()) A.insert(a);
    else A.erase(a);
  }
  cout<<A.size()<<endl;
}

Measured memory_bytes: 4864
#include <iostream>
#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

int main()
{
    int N, M;
    int A, B;
    int ans = 0;

    cin >> N;
    cin >> M;

    dsu d(N);

    for (int i = 0; i < M; i++) {
        cin >> A;
        cin >> B;
        d.merge(A-1, B-1);
    }

    for (int i = 0; i < N-1; i++) {
        if (d.leader(i) != d.leader(i + 1)) {
            ans++;
            d.merge(i, i+1);
        }
    }
    cout << ans;

}


Measured memory_bytes: 3760
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n, f, m = 0, l = 1;
	cin >> n >> f;
	for (int i = 1; i < n; i++) {
		int p; cin >> p;
		if (p == f)l++;
		else {
			m += (l - l % 2) / 2;
			l = 1;
			f = p;
		}
	}m += (l - l % 2) / 2;
	cout << m << endl;
}

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

int N;
long long a,b;

int main(){
	cin >> N;
	long long sum = 0,mi = 1e18;
	bool judge = false;
	for(int i=0;i<N;i++){
		cin >> a >> b;
		if(a!=b) judge = true;
		sum += a;
		if(a>b) mi = min(mi,b);
	}
	if(!judge) cout << 0 << endl; 
	else cout << sum-mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
 
using namespace std;
int n, m;
int ans = -1;
 
int main()
{
    scanf("%d%d",&n,&m);

    for (int i = 1; i * i <= m; ++i)
    {
        if (m % i == 0) 
        {
            int i1 = i;
            int i2 = m / i;
            if (i1 <= m / n) ans = max(ans, i1); 
            if (i2 <= m / n) ans = max(ans, i2);
        }
    }
    cout << ans;
}


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

int main(){
    int n[6];
    for(int i = 1 ; i <=5 ; i++){
        cin >> n[i];
    }
    for (int i = 1 ; i <= 5; i++){
        if(n[i]==0){
            cout << i;
        } 
    }
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
N=int(input())
s= [0 for i in range(10002)]
for x in range(1,100):
    for y in range(1,100):
        if x*x + y*y>10000:break
        for z in range(1,100):
            a = x*x + y*y + z*z +x*y + y*z + z*x
            if a >10000:break
            s[a] +=1

for i in range(N):
    print(s[i+1]) 

Measured memory_bytes: 69480
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  string s[h][w];
  int now = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[now] == 0) now++;
      s[i][j] = to_string(now + 1);
      a[now]--;
    }
    i++;
    if (i >= h) break;
    for (int j = w - 1; j >= 0; j--) {
      if (a[now] == 0) now++;
      s[i][j] = to_string(now + 1);
      a[now]--;
    }
  }
  rep(i, h) {
    rep(j, w) { cout << s[i][j] << " "; }
    cout << endl;
  }
}

Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>
int main()
{

    int n, i, j;
    char s[101],t[101];

    scanf("%d %s %s", &n, &s, &t);

    for(i=0; i<n; i++)
        printf("%c%c",s[i], t[i]);
}


Measured memory_bytes: 128
#include<stdio.h>

int main()
{	int j,k;
	int N;
	int i=0;
	long v;

	scanf("%d",&N);
	long A[N];
	for (i = 0; i < N; ++i)
	{
		scanf("%ld",&A[i]);
	}
		for(i=0;i<N-1;i++){
		printf("%ld",A[i]);
		printf(" ");
		}
		printf("%ld\n",A[i]);	

	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j >= 0 && A[j]>v){
			A[j+1]=A[j];
			j--;}
			A[j+1]=v;
		for(k=0;k<N-1;k++){
		printf("%ld",A[k]);
		printf(" ");
		}
	printf("%ld\n",A[k]);
	}

	return 0;
}

Measured memory_bytes: 1808
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W, K = [int(x) for x in input().split()]
    X1, Y1, X2, Y2 = [int(x) for x in input().split()]
    C = [input().strip() for _ in range(H)]

    q = collections.deque()
    q.append((X1 - 1, Y1 - 1, 0))

    V = [[float("inf")] * W for j in range(H)]
    V[X1 - 1][Y1 - 1] = 0


    while q:
        c = q.popleft()
        x = c[0]
        y = c[1]
        d = c[2]

        if y == Y2 - 1 and x == X2 - 1:
            print(c[2])
            return

        e, w, n, s = True, True, True, True
        for k in range(1, K + 1):
            if not e and not w and not n and not s:
                break
            if e:
                if y + k >= W or C[x][y + k] == "@":
                    e = False
                else:
                    if V[x][y + k] == float("inf"):
                        V[x][y + k] = d + 1
                        q.append((x, y + k, d + 1))

                    if V[x][y + k] < d + 1:
                        e = False
            if w:
                if y - k < 0 or C[x][y - k] == "@":
                    w = False
                else:
                    if V[x][y - k] == float("inf"):
                        V[x][y - k] = d + 1
                        q.append((x, y - k, d + 1))
                    if V[x][y - k] < d + 1:
                        w = False

            if n:
                if x - k < 0 or C[x - k][y] == "@":
                    n = False
                else:
                    if V[x - k][y] == float("inf"):
                        V[x - k][y] = d + 1
                        q.append((x - k, y, d + 1))
                    if V[x - k][y] < d + 1:
                        n = False

            if s:
                if x + k >= H or C[x + k][y] == "@":
                    s = False
                else:
                    if V[x + k][y] == float("inf"):
                        V[x + k][y] = d + 1
                        q.append((x + k, y, d + 1))
                    if V[x + k][y] < d + 1:
                        s = False

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 130708
#include<stdio.h>
int main(void)
{
	int n,sum,box,a;
	scanf("%d",&n);
	box=n;
	sum=0;
	while(box>0){
		a=box%10;
		sum=sum+a;
		box=box/10;
	}
	if(n%sum==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
ll c[10][10];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string a = to_string(i);
        c[a[0] - '0'][a.back() - '0']++;
    }
    ll res = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            res += c[i][j] * c[j][i];
        }
    }
    cout << res << endl;
}


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

using namespace std;
using ll = long long;
using p = pair<int, int>;
#define rep(i,n)  for(int i = 0; i < n ; i++)

int main()
{
	string S;
	cin >> S;
	string keyword = "hi";
	
    if(S.size() == 1)
    {
      cout << "No" << endl;
           return 0;
    }
	for (int i = 0; i < S.size(); i++)
	{
		if (i % 2 == 0 && S[i] == 'h' && i < S.size()-1)
		{
		
		}
		else if(i % 2 == 1 &&S[i] == 'i')
		{

		}
		else
		{
			cout << "No" << endl;
           return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rmin 1e-9
using namespace std;

int main(){
  double t,n,m,v[100],r[100],e=-1,s,rr,rs;
  double E;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n>>m;
    s=0;
    rs=0;
    for(int j=0;j<m;j++) cin>>v[j]>>r[j],rs+=r[j];
    for(int j=0;j<m;j++){
      rr=0;
      while(r[j]>rmin) rr+=r[j],r[j]*=(1-rs);
      s+=rr*v[j];
    }
    e=max(e,s);
  }
  cin>>n>>m;
  s=0;
  rs=0;
  for(int i=0;i<m;i++) cin>>v[i]>>r[i],rs+=r[i];
  for(int i=0;i<m;i++){
    rr=0;
    while(r[i]>rmin) rr+=r[i],r[i]*=(1-rs);
    s+=v[i]*rr;
  }
  E=s;
  if(e>E) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>

int main() {
	int num;
	int ans;
	char s[2];
	//def
	scanf("%d", &ans);
	while (1) {
		scanf("%s", s);
		if (s[0] == '=')break;
		else scanf("%d", &num);
		if (s[0] == '+')ans += num;
		else if (s[0] == '-')ans -= num;
		else if (s[0] == '*')ans *= num;
		else if (s[0] == '/')ans /= num;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
using namespace std;
int main() {
  char B;
  cin >> B;
  
  switch(B){
    case 'A':
      cout << 'T'; return 0;
    case 'C':
      cout << 'G'; return 0;
    case 'G':
      cout << 'C'; return 0;
    case 'T':
      cout << 'A'; return 0;
  }
  return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))
tmin = 10000000
for i in range(N):
  if tmin > abs(A - (T - H[i] * 0.006)):
    ans = i+1
    tmin = abs(A - (T - H[i] * 0.006))
print(ans)



Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int main() {
	int N, X;
	cin >> N >> X;
	vector<int> L(N);
	for (int i = 0; i < N; i++)
		cin >> L[i];

	vector<int> D(N + 1);
	D[0] = 0;
	for (int i = 1; i <= N; i++)
		D[i] = D[i - 1] + L[i - 1];

	int ans = 0;
	for (int i = 0; i < N+1; i++)
		if (D[i] <= X)
			ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import itertools

N, K = map(int, input().split())
S = list(input())

# 2 * k + 1
# 累積和
# W 白(0)から
if S[0] == '0':
    W = [0, 0, 1]
else:
    W = [0, 1]
    
for i in range(1,N):
    if S[i-1] == S[i]:
        W[-1] += 1
    else:
        W.append(1)
if S[-1] == '0':
    W.append(0)

W_ac = list(itertools.accumulate(W))
W_un = list(set(S))
if len(W_ac) <= 2 * K + 1 or len(W_un) == 1:
    ans = N
    print(ans)
else:
    ans = []
    for i in range(2*K+1, len(W_ac)):
        if i % 2 == 1:
            ans.append(W_ac[i] - W_ac[i-(2*K+1)])
    print(max(ans))
    


Measured memory_bytes: 10196
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main() {
	int n;
	ull a[200001];
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin>>a[i];
	}

	ull ans = 0;
	ull x=0,y=0;
	for (int i = 0,j=0;j < n;) {
		while(((x+a[i])==(y^a[i]))&&(i<n)){
			x += a[i];
			y ^= a[i];
			i++;
		}
		ans += (i - j);
		x -= a[j];
		y ^= a[j];
		j++;
	
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
   int t,n;
   for(int i = 0; i < 4; i++){
       cin >> t >> n;
       if(t == 1)cout << n*6000 << endl;
       if(t == 2)cout << n*4000 << endl;
       if(t == 3)cout << n*3000 << endl;
       if(t == 4)cout << n*2000 << endl;
   }
}


Measured memory_bytes: 3100
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;


public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		if (h > w) {
			System.out.println((n + h - 1) / h);
		} else {
			System.out.println((n + w - 1) / w);
		}
	}
}



class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21076
# -*- coding: utf-8 -*-

def main():
     n, x, y = map(int, input().split())
     ans = [0 for i in range(n)]

     for i in range(1, n+1):
          for j in range(i+1, n+1):
               route_a = j - i
               route_b = abs(x-i) + abs(j-y) + 1
               dis = min(route_a, route_b)
               # print('i:{}, j:{}, dis:{}, r_a:{}, r_b:{}'.format(i, j, dis, route_a, route_b))
               ans[dis] += 1
     
     print('\n'.join(map(str, ans[1:])))

if __name__ == "__main__":
    main()


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const ll MOD = 1e9 + 7;
const int MX = 1e5 + 5;

string s;

ll mpow(ll a, ll b) {
	a %= MOD;
	b %= (MOD - 1);
	ll res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> s;
	ll l = sz(s) - 1;
	ll ans = mpow(3, l);
		
	// Len, (0 -> same, 1 -> below L)
	ll dp[MX][2];
	
	dp[0][0] = 2; dp[0][1] = 0;
	for (int i = 1; i <= l; ++i) {
		if (s[i] == '1') {
			if (dp[i - 1][1]) {
				dp[i][1] = dp[i - 1][1] * 3 % MOD;
				dp[i][1] = (dp[i][1] + dp[i - 1][0]) % MOD;
			} else dp[i][1] = dp[i - 1][0];
			
			dp[i][0] = dp[i - 1][0] * 2 % MOD;
		} else {
			dp[i][0] = dp[i - 1][0];
			dp[i][1] = dp[i - 1][1] * 3 % MOD;
		}
	}
	
	cout << ((ans + dp[l][0]) % MOD + dp[l][1]) % MOD;
}	


Measured memory_bytes: 5280
def triangle(n):
    return (n*(n+1))//2

#firsttriangles = []
#for i in range(1,1000):
#    firsttriangles.append(triangle(i))

ins = input().split(' ')
a = int(ins[0])
b = int(ins[1])

#for i in range(0,999):
#    if firsttriangles[i] > a:
#        print(abs(a-firsttriangles[i]))
#        break

print((triangle(b-a))-b)

Measured memory_bytes: 2940
# b
s = input()
if len(s) % 2 ==0:
    s_m = s[:int(len(s) / 2)]
    s_u = s[int(len(s) / 2):][::-1]
else:
    s_m = s[:int(len(s) / 2)]
    s_u = s[int(len(s) / 2) + 1:][::-1]
    
count = 0
for i in range(len(s_m)):
    if s_m[i] != s_u[i]:
        count += 1
print(count)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define MAX 100001
#define MOD 1000000007
using namespace std;

ld probability(int n,ld p[] )
{
    int max_tail = n/2 ;

    ld dp[max_tail+1];

    memset(dp , (ld)0 , sizeof(dp));

    dp[0] = (ld)1;// only 1 head ,tail 0

    for(int i=0;i<n;++i)
    {
        
        for(int j=max_tail ;j > 0; --j)
        {
            dp[j] *= p[i];
            dp[j] += dp[j-1]*(1-p[i]);
        }
        dp[0] = dp[0]*p[i];
    }

    ld sum = 0;

    for(int j=0;j<=max_tail;++j)
    {
        sum += dp[j];
    }

    return sum;
}

 
int32_t main()
{
    int n;
    cin>>n;
    ld p[n];
    for(int i=0;i<n;++i)
        cin>>p[i];

    cout << fixed << setprecision(10) << probability(n,p) <<endl;

    return 0;
}

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

const int N = 5005;
const int mod = 1e9 + 7;

void add(int& x,int y) {
	x += y; if (x >= mod) x -= mod;
}

void sub(int& x,int y) {
	x -= y; if (x < 0) x += mod;
}

int mul(int x,int y) {
	return (long long) x * y % mod;
}

int n;
vector<int> g[N];
int h[N];
vector<int> f[N];
int child[N];

void dfs(int u,int p) {
	child[u] = 1;
	f[u] = vector<int>(2, 0);
	f[u][1] = 1;
	for (int v : g[u]) if (v ^ p) {
		dfs(v, u);
		vector<int> nf(child[u] + child[v] + 1, 0);
		for (int i = 0; i <= child[u]; ++i) {
			for (int j = 0; j <= child[v]; ++j) {
				add(nf[i + j], mul(f[u][i], f[v][j]));
			}
		}
		f[u].swap(nf);
		child[u] += child[v];
	}
	for (int i = 2; i <= child[u]; ++i) {
		sub(f[u][0], mul(f[u][i], h[i]));
	}
}

int main() {
	scanf("%d", &n);
	h[0] = 1;
	for (int i = 2; i <= n; i += 2) h[i] = mul(h[i - 2], i - 1);
	for (int i = 2; i <= n; ++i) {
		int u, v; scanf("%d %d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	dfs(1, -1);
	int ans = 0; sub(ans, f[1][0]);
	printf("%d\n", ans);
}

Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;


int main() {
    ll n,k;
    cin>>n>>k;
    ll ans=n%k;
    cout<<min(ans,abs(ans-k))<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    vector<int> P(N);
    int ans = 0;

    for(int i = 0;i<N;i++){
        cin >> V[i];
    }
    for(int i = 0;i<N;i++){
        cin >> C[i];
        if(V[i] - C[i] > 0){
            ans = ans + V[i] - C[i];
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInt()
    val A = readLongList().sortedDescending()

    if (n == 2) {
        println(A[0])
        return
    }
    var count = A[0]

    var plsnt = 0
    var idx = 1
    for (i in 2 until n ) {
        if (plsnt  == 2) {
            idx++
            plsnt = 0
        }
        count += A[idx]
        plsnt++
    }

    println(count)

}


private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readStringList() = read().split(" ")

private fun readIntList() = readStringList().map { it.toInt() }

private fun readLongList() = readStringList().map { it.toLong() }

private fun readDoubleList() = readStringList().map { it.toDouble() }

private fun readStringMatrix(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readStringList()
        matrix.add(list)
    }
    return matrix
}

private fun readIntMatrix(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readIntList()
        matrix.add(list)
    }
    return matrix
}

private fun readDoubleMatrix(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readDoubleList()
        matrix.add(list)
    }
    return matrix
}

private fun readLongMatrix(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readLongList()
        matrix.add(list)
    }
    return matrix
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    string S;
    cin >> S;
    if(S == "ABC") _PR("ARC");
    else _PR("ABC");


    return 0;
}

/*



*/

Measured memory_bytes: 3624
import time
from random import randrange
start = time.time()

D=int(input())
c=list(map(int,input().split()))
def compare(d,q):
  score=maxscore
  changebefore=currentans[d]-1
  changeafter=q-1
  r=contests[changebefore]
  score-=s[d][changebefore]
  score+=s[d][changeafter]
  for j in range(len(r)-1):
    if r[j]==d:
      score-=c[changebefore]*((r[j+1]-r[j-1]-1)*(r[j+1]-r[j-1]))//2
      score+=c[changebefore]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score+=c[changebefore]*((d-r[j-1]-1)*(d-r[j-1]))//2
      break
  r=contests[changeafter]
  for j in range(len(r)-1):
    if r[j+1]>d:
      score+=c[changeafter]*((r[j+1]-r[j]-1)*(r[j+1]-r[j]))//2
      score-=c[changeafter]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score-=c[changeafter]*((d-r[j]-1)*(d-r[j]))//2
      break
  if score>maxscore:
    return score
  else:
    return maxscore

s=[0]
last=[0]*26
currentans=[0]*(D+1)
for i in range(D):
  s.append(list(map(int,input().split())))
contests=[]
for i in range(26):
  contests.append([])
  contests[-1].append(0)
  contests[-1].append(D+1)
#Donyoku
for i in range(1,D+1):
  score=0
  t=0
  score+=s[i][t]
  lasttemp=last[t]
  last[t]=i
  for j in range(26):
    score-=c[j]*(i-last[j])
  maxscore=score
  bestans=1
  last[t]=lasttemp
  for t in range(1,26):
    score=0
    score+=s[i][t]
    lasttemp=last[t]
    last[t]=i
    for j in range(26):
      score-=c[j]*(i-last[j])
    if maxscore<score:
      bestans=t+1
      maxscore=score
    last[t]=lasttemp
  last[bestans-1]=i
  currentans[i]=bestans
for i in range(1,D+1):
  contests[currentans[i]-1].append(i)
counter=0
breakflag=0
while True:
  if counter%100==0:
    now=time.time()
    if now-start>1.5:
      breakflag=1
  if breakflag==1:
    break
  q=randrange(26)+1
  d=randrange(D)+1
  if currentans[d]==q:
    continue
  score2=compare(d,q)
  if score2>maxscore:
    changebefore=currentans[d]-1
    changeafter=q-1
    contests[changebefore].remove(d)
    contests[changeafter].append(d)
    contests[changeafter].sort()
    currentans[d]=q
    maxscore=score2
  counter+=1
for i in range(1,D+1):
  print(currentans[i])

Measured memory_bytes: 82448
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;

int main() {
  string s;
  cin >> s;
  int cnt_a, cnt_b;
  cnt_a = cnt_b = 0;
  for (int i = 0; i < (int) s.size(); ++i) {
    if (s[i] == '0') cnt_a++;
    else cnt_b++;
  }
  cout << 2 * min(cnt_a, cnt_b) << '\n';
}


Measured memory_bytes: 512
<?php

$stdins = [];
while($line=fgets(STDIN)){
    $stdins[] = trim($line);
}

foreach($stdins as $stdin){
    $S = $stdin;

    $vs = explode(" ", $S);
    $count = 0;
    while(true){
        if($vs[0] == $vs[1] && $vs[1] == $vs[2]) break;

        sort($vs);
        $diff = max(max($vs[0], $vs[1]), $vs[2]) - min(min($vs[0], $vs[1]), $vs[2]);
        if($diff >= 2){
            $vs[0] += 2;
        }else{
            $vs[0] += 1;
            $vs[1] += 1;
        }
        $count++;
    }
    print($count);

    print("\n");
}


Measured memory_bytes: 3956
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}

int main(void){
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    int a[n],b[m],amax=x,bmin=y;
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
        if (amax<a[i]){
            amax=a[i];
        }
    }
    for (int i=0; i<m; i++){
        scanf("%d",&b[i]);
        if (bmin>b[i]){
            bmin=b[i];
        }
    }
    if (amax<bmin){
        printf("No War\n");
    } else {
        printf("War\n");
    }
    return 0;
}

Measured memory_bytes: 128
from collections import deque
S = input()
d = deque()
d2 = deque()
r = []
r_l = 0
buf = 0
for i, s in enumerate(S):
    i += 1
    if s == '\\':
        d.append(i)
    elif s == '/' and len(d) > 0:
        k = d.pop()
        r_l += i - k
        buf = i - k
        while(len(d2) > 0 and d2[-1][0] > k):
            _d = d2.pop()
            buf += _d[1]
        l = [k, buf]
        d2.append(l)

r = []
for i in d2:
    r.append(i[1])
print(r_l)
print(len(r), *r)



Measured memory_bytes: 6828
<?php
$r=explode(" ",trim(fgets(STDIN)));
$ans=0;
$i=0;
while($i<2){
  switch($r[$i]){
    case 1:
      $ans+=300000;
      break;
    case 2:
      $ans+=200000;
      break;
    case 3:
      $ans+=100000;
      break;
  }
  ++$i;
}
echo ($ans==600000)?1000000:$ans;

Measured memory_bytes: 4604
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, M, K, i, j;
	scanf("%d%d%d", &N, &M, &K);
	for(i = 0; i <= N; i++){
		for(j = 0; j <= M; j++){
			if(N * j + M * i - 2 * i * j == K){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128