akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N;
    string S;
    cin >> N >> S;
    REP(i, S.length()){
        int j = S[i] - 'A';
        j = (j + N) % 26;
        S[i] = 'A' + j;
    }
    PRINT(S);
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

#define SIZE 2000005
ll inv[SIZE], fac[SIZE];

// O(log n)
ll powMOD(ll a, ll b)
{
    ll x = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            x = (x * a) % MOD;
        }
        a = (a * a) % MOD;
        b >>= 1;
    }
    return x;
}

void make(){
    inv[0] = fac[0] = 1;
    FOR(i,1,SIZE) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = powMOD(fac[i], MOD - 2) % MOD;
    }
}

ll C(ll a, ll b){
    if(a<b) return 0;
    return fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}


int main() {
    cin >> n;
    if(n==2){
        cout << 1 << endl;
        return 0;
    }else if(n==3){
        cout << 4 << endl;
        return 0;
    }else if(n==4){
        cout << 16 << endl;
        return 0;
    }
    make();
    ans = fac[n];
    FOR(i,1,n) {
        m = C(i - 1, n - 1 - i) * fac[i] % MOD * fac[n - 1 - i] % MOD;
        //cout << "k = " << i << "  " << m << endl;
        ans -= m;
        if(ans<0){
            ans += MOD;
        }
    }
    cout << ans%MOD << endl;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define per(i,a,b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;

ll x, y, ans;

int main() {
	cin >> x >> y;
	if (x % y == 0)
		return puts("-1"), 0;
	ans = 1000000000000000000ll / x * x;
	if (ans % y == 0)
		ans -= x;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,jj,n,x;
    unsigned long long j=0;
    scanf("%d %d",&n,&x);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            jj=a[i]+a[i+1]-x;
            a[i+1]-=jj;
            j+=jj;
            if(a[i+1]<0){
                a[i+1]=0;
            }
        }
    }
    printf("%llu\n",j);
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    for i in range(0, N+1):
        if (i % 4 == 0) and ((N - i) % 7 ==0):
            return YES
    return NO


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
vector<int> edge[maxn];
int dep[maxn];
int n, mx, mxpos;

void dfs(int u, int pre) {
    for (auto v :edge[u]) {
        if (v == pre) continue;
        dep[v] = dep[u] + 1;
        if (dep[v] > mx) {
            mx = dep[v];
            mxpos = v;
        }
        dfs(v, u);
    }
}

void dfs2(int u, int pre) {
    for (auto v :edge[u]) {
        if (v == pre) continue;
        dep[v] = dep[u] + 1;
        if (dep[v] > mx) {
            mx = dep[v];
        }
        dfs2(v, u);
    }
}

int main() {
    cin >>n;
    if (n == 1) {
        cout << "First" << endl;
        return 0;
    }
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u>> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1,0);
    dep[mxpos] = 1;
    dfs2(mxpos, 0);
    //sort(dep + 1, dep +1 +n);
    int res = (mx) % 3;
    if (res == 2) cout << "Second" << endl;
    else cout <<"First"<<endl;
    return 0;
}


Measured memory_bytes: 21376
a, b, c, d, e, f = map(int, input().split())

water = set()
suger = set()

for i in range(f+1):
    for j in range(f+1):
        x = 100 * (a * i + b * j)
        if x <= f:
            water.add(x)

for i in range(f+1):
    for j in range(f+1):
        y = c * i + d * j
        if y <= f:
            suger.add(y)


conc = 0
S = 0
W = 0

for s in suger:
    for w in water:
        if s + w > f:
            continue
        if s + w == 0:
            continue
        if  s > (w / 100)*e:
            continue
        temp = 100 * s / (s + w)
        if temp >= conc:
            conc = temp
            W = w
            S = s

print(S + W, S)

Measured memory_bytes: 41948
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long
#define int long long 
#define INF 1e18
#define ar array
#define f first
#define s  second
#define REP(i,n) for (int i=0;i<(n);i++)
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);

  freopen("output1.txt","w",stdout);
#endif
}

int power(int a,int b,int mod){
  a=a%mod;
  if(a==0){
    return 1;
  }
  int res=1;
  while(b){
    if(b&1){
      res=(res*a)%mod;
    }
    b>>=1;
    a=(a*a)%mod;
  }
  return res;
}

int  MMI(int p){
  return power(p,MOD-2,MOD);

}
const int mxN=5e5;
int n, q, c[mxN], ft[mxN+1], ans[mxN];
vector<ar<int, 2>> v[mxN];
 
void upd(int i, int x) {
  for(++i; i<=n; i+=i&-i)
    ft[i]+=x;
}
 
int qry(int i) {
  int r=0;
  for(; i; i-=i&-i)
    r+=ft[i];
  return r;
}
 

int32_t main()
{
 c_p_c();
 cin>>n>>q;
  for(int i=0;i<n;i++)cin>>c[i];
for(int i=0;i<mxN;i++)v[i].clear();
    
 for(int i=0;i<q;i++){
    int l, r;
   cin>>l>>r;
   l--;r--;
    v[r].push_back({l, i});
  }
  map<int, int> mp;
 for(int i=0;i<n;i++) {
    if(mp.find(c[i])!=mp.end())
      upd(mp[c[i]], -1);
    upd(i, 1);
    for(auto a:v[i])
      ans[a[1]]=qry(n)-qry(a[0]);
    mp[c[i]]=i;
  }
 for(int i=0;i<q;i++)
    cout<<ans[i]<<"\n";
return 0;

}








   



   








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

bool is_prime(int n) {
  // naive program
  int p = 2;
  while(p*p <= n) {
    if(n % p == 0) {
      return false;
    }
    p++;
  }
  return true;
}

int main() {
  int N;
  int cnt = 0;

  cin >> N;
  for(int i=0;i<N;i++) {
    int n;
    cin >> n;
    if(is_prime(n)) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vec A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;
    for(ll i = 1; i <= N - 2; ++i) if((A[i - 1] - A[i]) * (A[i + 1] - A[i]) < 0) ++ans;

    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int INF = 1e18;

struct edge {
	int to, cost;
	edge(int to, int cost) : to(to), cost(cost) {}
};

struct data {
	int cur, time, gas;
	bool operator<(const data& right) const {
		if (time < right.time)
			return true;
		else {
			if (gas < right.gas)
				return true;
			else
				return false;
		}
	}
};

void bfs(int n, int l, vector<vector<edge>>& g, int s,
		 vector<vector<int>>& re) {
	queue<data> q;
	q.emplace(data{s, 0, l});

	vector<data> d(n);
	rep(i, n) d[i] = {-1, INF, -1};
	d[s] = data{s, 0, l};

	while (not q.empty()) {
		auto c = q.front();
		// if(s==0)cout << c.cur << ' ' << c.time << ' ' << c.gas << endl;
		q.pop();

		for (auto e : g[c.cur]) {
			if (e.cost > c.gas) continue;
			// if(s==0)show("OK")
			//	show(e.to)
			//	cout << d[e.to].time << ' ' << c.time << endl;
			if (d[e.to].time > c.time) {
				// show("OK")
				d[e.to].time = c.time;
				d[e.to].gas = c.gas - e.cost;
				q.emplace(data{e.to, c.time, c.gas - e.cost});
				q.emplace(data{e.to, c.time + 1, l});
			} else if (d[e.to].time == c.time and
					   d[e.to].gas < c.gas - e.cost) {
				d[e.to].time = c.time;
				d[e.to].gas = c.gas - e.cost;
				q.emplace(data{e.to, c.time, c.gas - e.cost});
				q.emplace(data{e.to, c.time + 1, l});
			}
		}
	}

	rep(i, n) { re[s][i] = d[i].time; }
}

signed main() {
	int n, m, l;
	cin >> n >> m >> l;

	vector<vector<edge>> g(n);
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}

	vector<vector<int>> re(n, vector<int>(n, -1));
	rep(i, n) bfs(n, l, g, i, re);

	// rep(i, n) {
	//	rep(j, n) {
	//		cout << i << " to " << j << ':' << re[i][j] << endl;
	//	}
	//}

	int q;
	cin >> q;
	while (q--) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;

		cout << (re[s][t] == INF ? -1 : re[s][t]) << endl;
	}
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart;
#define setTime tStart = clock();
#define time0 (double)(clock() - tStart)/CLOCKS_PER_SEC
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
#define NMAX 30
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
set<int>st;
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        st.insert(x);
    }
    cout << st.size();
	return(0);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll H,W,K;
vector<string> S;
vector<vector<ll>> res;

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

  cin>>H>>W>>K;
  S.resize(H);
  res.resize(H);
  rep(i,H){
    cin>>S[i];
    res[i].resize(W,-1);
  }

  ll prei=0;
  ll num=1;
  rep(i,H){
    ll prej=0;
    rep(j,W){
      if(S[i][j]=='#'){
        repl(ni,prei,i+1)repl(nj,prej,j+1){
          res[ni][nj]=num;
        }
        num++;
        prej=j+1;
      }
    }
    if(prej>0){
      repl(ni,prei,i+1)repl(nj,prej,W){
        res[ni][nj]=num-1;
      }
      prei=i+1;
    }
  }
  rep(j,W){
    ll prenum=-1;
    for(ll i=H-1;i>=0;i--){
      if(res[i][j]!=-1){
        prenum=res[i][j];
        break;
      }
    }
    for(ll i=H-1;i>=0;i--){
      if(res[i][j]==-1){
        res[i][j]=prenum;
      }else break;
    }
  }

  rep(i,H){
    rep(j,W)cout<<res[i][j]<<" ";
    cout<<endl;
  }

  return 0;
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1000000007;

int main() {
	int n,k;
	cin >> n >> k;
	int h[n];
	int dp[n];
	for (int i = 0;i < n;i++) {
		cin >> h[i];
		dp[i] = inf;
	}
	dp[0] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 1;j < k+1;j++) {
			if (i+j < n) {dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));}
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF (1<<20)


int main() {
	string s; cin >> s;
	ll K; cin >> K;

	vector<ll> c(s.length());
	for (ll i = 0; i < s.length(); i++) {
		ll d1;
		d1 = 26-abs('a'-s[i]);
		if(s[i]=='a') d1=0;
		//cout << d1 << endl;
		c[i] = d1;
	}

	for (ll i = 0; i < s.length(); i++) {
		if (K >= c[i]) {
			K -= c[i];
			s[i] = 'a';
		}
	}
	//cout << K <<" "<< s << endl;
	ll n = (ll)s.length() - 1LL;
	K %= (ll)26;
	for (int i = 0; i < K; i++) {
		if(s[n]=='z') s[n]='a';
		else s[n]++;
	}

	cout << s << endl;
}



Measured memory_bytes: 1408
<?php

fscanf(STDIN, '%d %d %d', $n, $m, $l);

for ($i = 0; $i < ($n + $m); $i++) {
    if ($i < $n) {
        $A[] = explode(' ', trim(fgets(STDIN)));
    } else {
        $B[] = explode(' ', trim(fgets(STDIN)));
    }
}

for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $l; $j++) {
        $C[$i][$j] = 0;
        for ($k = 0; $k < $m; $k++) {
            $C[$i][$j] += $A[$i][$k] * $B[$k][$j];
        }
    }
    $result[] = implode(' ', $C[$i]);
}

echo implode(PHP_EOL, $result), PHP_EOL;

Measured memory_bytes: 11872
import java.util.Scanner


object Main extends App{
	def gcd(a:Int,b:Int):Int={
	if(b == 0)a
	else{
		if(a<b)gcd(b,a)
		else gcd(b, a % b)
		}
	}
	val sc = new Scanner(System.in)
	val a = sc.nextInt
	val b = sc.nextInt
	val k = sc.nextInt
	
	val d = gcd(a,b)
	val res = (1 to d).filter(d % _ == 0).reverse(k -1)
	println(res)
}

Measured memory_bytes: 55448
#include<bits/stdc++.h>
using namespace std;
int main(){
    // Your code here!
    string wd;
    int num, num2, num3;
    
    cin >> wd >> num;
    
    for(int i=0; i<num; i++){
        string od;
        cin >> od;
        
        if(od=="replace"){
            string wkWd;
            cin >> num2 >> num3 >> wkWd;
            wd.replace(num2, num3 - num2 + 1, wkWd);

        }else if(od=="reverse"){
            cin >> num2 >> num3;
            //tmp = wd.substr(num2, num3 - num2 + 1);
            reverse(wd.begin() + num2, wd.begin() + num3 + 1);
            //wd.replace(num2, num3 - num2 + 1, tmp);

        }else if(od=="print"){
            cin >> num2 >> num3;
            cout << wd.substr(num2, num3 - num2 + 1) << endl;
        }
    }
}






Measured memory_bytes: 3176
fun main(args: Array<String>) {
    var H = nextLong()
    var A = mutableListOf<Long>()
    var b = 1L
    while (H > 0) {
        A.add(b)
        b = b shl 1
        H /= 2
    }
    println(A.sum())
}
fun next() = readLine()!!
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll stones[200005];

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  string s;
  cin >> s;

  for (ll i = 0; i < N; i++) {
    stones[i] = (s[i] == 'W') ? 0 : 1;
  }

  for (ll i = 1; i < N; i++) {
    ll pc = stones[i - 1];
    ll cc = stones[i];
  }

  ll l = 0;
  ll r = N - 1;

  ll ans = 0;
  for (;;) {
    for (ll i = l; i < N; i++) {
      l = i;
      if (stones[i] == 0) {
        break;
      }
    }
    for (ll i = r; i >= 0; i--) {
      r = i;
      if (stones[i] == 1) {
        break;
      }
    }

    if (l >= r) {
      break;
    }

    stones[l] = 1;
    stones[r] = 0;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
//#define int ll
const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1000000007;
//#define DEBUG//#define lowbit(x) ((x) & -(x))//<<setiosflags(ios::fixed)<<setprecision(9)
void read(){}
template<typename T,typename... T2>inline void read(T &x,T2 &... oth) {
	x=0; int ch=getchar(),f=0;
	while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	if(f)x=-x;
	read(oth...);
}
signed main()
{
	std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	#ifdef DEBUG
		freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	#endif
	ll a,b,c,k,ans=0;
	cin>>a>>b>>c>>k;
	ans+=min(k,a);
	if(k>a)
	{
		k-=a;
		k-=b;
		if(k>0)
		{
			ans-=k;
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3652
#!/usr/bin/env python3

d_init = [0] * 10
while True:
    data = d_init[:]
    n = int(input())
    if n == 0:
        break

    for _ in range(n):
        in_data = int(input())
        data[in_data] += 1

    for d in data:
        if d == 0:
            print("-")
        else:
            print("*" * d)

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

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

  int ans = 0;
  int MAX = 0;

  for (int i = 0; i < N; i++){
    if(S[i] == 'I'){
      ans += 1;
      MAX = max(ans,MAX);
    }else if(S[i] == 'D'){
      ans -= 1;
    }
  }
  cout << MAX << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, H, W;
int ans[100][100];
int a[100005];

int main() {
  scanf("%d %d %d", &H, &W, &N);
  rep(i, 1, N+1) scanf("%d", &a[i]);
  
  int num = 1;
  int c = 1;
  rep(i, 0, H) {
    if (i%2 == 0) {
      rep(j, 0, W) {
        ans[i][j] = num;
        if (++c > a[num]) {
          num++;
          c = 1;
        }
      }
    } else {
      per(j, 0, W) {
        ans[i][j] = num;
        if (++c > a[num]) {
          num++;
          c = 1;
        }
      }
    
    }
  
  }
 
  rep(i, 0, H) {
    rep(j, 0, W) {
    if (j > 0) printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }

}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main
{
    public static void main(String[] arg)
    {
        Scanner sc = new Scanner(System.in);
        for(int i = 1; ;i++)
        {
            int x = sc.nextInt();
            if(x!=0) System.out.println("Case "+i+": "+x);
            else break;
        }
        sc.close();
    }
}


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

int N;
int now=0;
int a;

int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		scanf("%d",&a);
		if(a==now+1) now++;
	}
	printf("%d\n",now==0?-1:N-now);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<complex>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
 
int main(){
	int n, y;
	cin >> n >> y;
	int count = 0;
	rep(i, n + 1) {
        rep(j, n + 1 - i) {
            int z = n - i - j;
            if (10000 * i + 5000 * j + 1000 * z == y) {
                cout << i << " " << j << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
	return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  switch (a) {
    case 1:
      if (b == 2) {
        cout << 3 << endl;
      }
      if (b == 3) {
        cout << 2 << endl;
      }
    break;
    case 2:
      if (b == 3) {
        cout << 1 << endl;
      }
      if (b == 1) {
        cout << 3 << endl;
      }
    break;
    case 3:
      if (b == 1) {
        cout << 2 << endl;
      }
      if (b == 2) {
        cout << 1 << endl;
      }
    break;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int calc(int y, int i){
	if(y % (i+1) == 0){
		return y/(i+1) -1;
	} else {
		return y/(i+1);
	}
}
int main(){
	int n,a,b,c,d;
	int ax,bx,cx,dx,ay,by,cy,dy;
	int mind = 100000;
	cin >> n >> a >> b >> c >> d;
	for(int i = 0; i < n; i++){
		ay = calc(a,i);
		ax = a-(ay*(i+1)) -1; 
		by = calc(b,i);
		bx = b-(by*(i+1)) -1; 
		cy = calc(c,i);
		cx = c-(cy*(i+1)) -1; 
		dy = calc(d,i);
		dx = d-(dy*(i+1)) -1; 
		mind = min(mind, abs(ax-bx) + abs(ay-by) + abs(cx-dx) + abs(cy-dy));
	}
	cout << mind << endl;
}

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

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

    int n;
    cin >> n;
    vector<int> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        B[i] = A[i];
    }

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

    for(int i = 0; i < n; i++){
        int idx = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        if(idx < n / 2) cout << A[n / 2] << endl;
        else cout << A[n / 2 - 1] << endl;
    }

    return 0;
}

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

int n, h[100005], dp[100005];

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for (int i = 3; i <= n; i++) {
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n];
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

using namespace std;

int a[3000];
int f[3000][3000];
long long dp[3000][3000];

long long calc(int l, int r, int p) {
    if (l > r) return 0;
    if (f[l][r] == 1) return dp[l][r];
    
    f[l][r] = 1;
    
    if (p == 0) {
        return dp[l][r] = max(a[l] + calc(l + 1, r, 1), a[r] + calc(l, r - 1, 1));
    } else {
        return dp[l][r] = min(calc(l + 1, r, 0) - a[l], calc(l, r - 1, 0) - a[r]);
    }
}

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    printf("%lld\n", calc(0, n - 1, 0));
    
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}
#define int ll
const int N = 2e5 + 10;
int n, k;
int a[N];

void read() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)  {
		cin >> a[i];
	}
}

bool check(int len) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] <= len) continue;
		ans += (a[i] + len - 1) / len - 1;
	}
	return ans <= k;
}

int ans;

void run() {
	int l = 0, r = 1e9 + 228;
	while (l < r - 1) {
		int mid = (l + r) / 2;
		if (check(mid)) {
			r = mid;
		} else {
			l = mid;
		}
	}
	ans = r;
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
	read();
	run();
	write();
	return 0;
}

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

N = int(input())
_N = N

size = len(str(N))

f = 0
while(size > 0):
    if(size > 1):
        f += int(N/(10**(size-1)))
        N %= 10**(size-1)
    else:
        f += N
    size -= 1

if(_N%f == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
s = gets.chomp.split("").map(&:to_s)
out = false
count = 0

s.each do |st|
    if st == "A" then
        count += 1
    elsif (st == "C") && (count.to_i > 0) then
        out = true
    else
        count = 0
    end
end

puts out == true ? "Yes" : "No"

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int N, M;

int main(){
  scanf("%d%d",&N,&M);
  vi a(N*2);
  rep (i, N*2) {
    scanf("%d",&a[i]);
  }
  sort(a.begin(), a.end());
  int l = 0;
  int r = N*2-1;
  while (l<r) {
    if (a[l]+a[r]<M) {
      ++l;
    } else {
      ++l;
      --r;
    }
  }
  int L = N*2-1-r;
  int ans = 0;
  int LL = N-L;
  rep (i, LL) {
    ans = max(ans, a[i]+a[LL*2-1-i]);
  }
  rep (i, L) {
    ans = max(ans, a[LL*2+i]+a[N*2-1-i]-M);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<vector<int> > edge(N);
    int a, b;
    for(int i=0;i<N-1;++i){
        cin>>a>>b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> c(N);
    for(int i=0;i<N;++i){
        cin>>c[i];
    }
    sort(c.begin(), c.end(), greater<int>());

    int par[N];
    par[0] = 0;
    for(int i=1;i<N;++i){
        par[i] = -1;
    }
    queue<int> que;
    que.push(0);
    int state;
    while(!que.empty()){
        state = que.front();que.pop();
        for(int i=0;i<edge[state].size();++i){
            if(par[edge[state][i]]!=-1)continue;
            par[edge[state][i]] = state;
            que.push(edge[state][i]);
        }
    }
    int anstree[N];
    int ans = 0;
    for(int i=1;i<N;++i){
        ans += c[i];
    }
    vector<vector<int> > children(N);
    for(int i=1;i<N;++i){
        children[par[i]].push_back(i);
    }
    que.push(0);
    int num = 0;
    while(!que.empty()){
        state = que.front();que.pop();
        anstree[state] = c[num];
        num++;
        for(int i=0;i<children[state].size();++i){
            que.push(children[state][i]);
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<N;++i){
        cout<<anstree[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define REPI(i,a,b) for (ll i=(a);i<(b);i++)
#define REP(i,n) REPI(i,0,n)

typedef long long int ll;

int SURP = 1000000007;

int main(){
	ll A,B,C;

	cin >> A >> B >> C;

	ll out = 0;

	out += min(A+B+1,C);
	out += B;

	cout << out << endl;

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;


int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  rep(i, m){
    int k;
    cin >> k;
    rep(j, k){
      int x;
      cin >> x;
      s[i].push_back(x);
    }
  }
  vector<int> p(m);
  rep(i, m){
    cin >> p[i];
  }

  int ans = 0;
  for (int bit = 0; bit < (1<<n); bit++){
    vector<bool> sui(n, false);
    for (int i = 0; i < n; i++){
      if (bit & (1<<i)){
        sui[i] = true;
      }
    }
    int d = 0;
    for (int i = 0; i < m; i++){
      int c = 0;
      for (int j = 0; j < s[i].size(); j++){
        int x = s[i][j] - 1;
        if (sui[x]) c++; 
      }
      if (c % 2 == p[i]) d++;
    }
    if (d == m) ans++;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long 
#define repi(a,b) for(int i =a;i<=b;++i)
#define repj(c,d) for(int j =c;j<=d;++j)
using namespace std;
const int N = 10000;
int a[N] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    int k ;
    cin>>k;
    cout<<a[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
m=min(A);M=max(A)
print(M-m)

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;
typedef pair<int, int>P;

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


const int MAX = 500010;
const int MOD = 1000000007;
const ll INF = 10e17;
const double pi = acos(-1);
double EPS = 1e-10;




int cum[200010];
int N, X;
int x[200010];
signed main() {
	cum[0] = 0;
	cin >> N >> X;
	REP(i, N) {
		cin >> x[i];
		cum[i + 1] = cum[i] + x[i];
	}
	ll ans = INF;
	for (int k = 1;; k++) {
		int res = N * X;
		if (2 * k >= N) {
			res += (cum[N] - cum[0]) * 5 + k * X;
			ans = min(ans, res);
			break;
		}

		res += k * X;
		res += (cum[N] - cum[N - 2 * k]) * 5;
		int pos = N - 2 * k, cnt = 1;
		while (pos > 0) {
			if (pos < k) {
				res += (cum[pos])*(5 + 2 * cnt);
				ans = min(ans, res);
				break;
			}
			res += (cum[pos] - cum[pos - k])*(5 + 2 * cnt);
			if (res >= 10e15) {
				goto END;
			}
			cnt++; pos -= k;
		}
		ans = min(ans, res);
	END:
		;
	}
	print(ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X)< 0 ? -(X): (X))
#define LCM(X, Y)  ( ( (X) / (GCD( (X)  , (Y) ))) * (Y) )
#define MEM( A,  B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL ) fill( V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A,I) cout<<"at pos "<< I <<"  value is: "<< A[I]
#define TURBO ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0)
const double EPS =1e-9 ;
const double PI = 3.1415926535897932384626433832795 ;
using namespace std ;
inline ll GCD(ll A, ll B){
      if ( B == 0 ) return A;
      return GCD( (B) ,  (A % B) );
}
inline ll POW(ll BASE, ll EXP) {
   ll RES = 1;
   for(ll I= 0; I < EXP; I++) RES *= BASE ;
   return RES;
}

inline ll BIGMOD  ( ll a, ll p, ll m ) {
   ll res = 1 % m;
   ll x = a % m;
   while ( p > 0 ) {
       if ( (p & 1) > 0 ) res = ( res * x ) % m;
       x = ( x * x ) % m; p >>= 1;
   }
   return res;
}
inline void FILE_HANDLE( ){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

int main()
{

            TURBO;
            //FILE_HANDLE() ;
            string s1, s2;
            cin >> s1 ;
            cin >> s2 ;
            if(s1.size() == s2.size())
            {
                  if(s1 == s2)
                  {
                        cout << "EQUAL" << endl ;
                  }
                  else if(s1 > s2)
                  {
                        cout <<"GREATER" << endl ;
                  }
                  else cout <<"LESS" << endl ;
            }
            else if(s1.size() > s2.size()) cout <<"GREATER" << endl ;
            else cout << "LESS" << endl ;
}



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

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 3000;
const int MaxM = 3000;
const int M = 1000000007;

int n, m;
char s[MaxN + 3];

int sum[MaxN + 1];

int pos[MaxN + 1];

int f[MaxN + 2][MaxN + 1];

inline void add(int i, int j, int d)
{
	f[i][j] = (f[i][j] + d) % M;
}

int main()
{
	cin >> n >> m;
	cin >> s + 1;

	for (int i = 1; i <= n; ++i)
		sum[i] = s[i] - '0';
	for (int i = 2; i <= n + 1; ++i)
		sum[i] += sum[i - 1];

	for (int i = 1; i <= n + 1; ++i)
		pos[i] = i;
	for (int i = 1; i <= m; ++i)
	{
		int l = getint();
		pos[l] = max(pos[l], getint());
	}

	for (int i = 1; i <= n; ++i)
		pos[i] = max(pos[i], pos[i - 1]);

	f[1][sum[pos[1]]] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
		{
			int cur = f[i][j];
			if (cur == 0)
				continue;

			int l = sum[pos[i + 1]] - sum[pos[i]];
			int k = pos[i] - i + 1 - j;
			if (k > 0)
				add(i + 1, j + l - 0, cur);
			if (j > 0)
				add(i + 1, j + l - 1, cur);
		}

	cout << f[n + 1][0] << endl;

	return 0;
}

Measured memory_bytes: 33920
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    s <- getLine
    if solve n s then putStrLn "Yes" else putStrLn "No"

solve n s = take n' s == drop n' s
    where n' = n `div` 2

Measured memory_bytes: 508
#include <stdio.h>
int c[1201];

int main(void) {
    char ch;
    while( scanf( "%c", &ch ) != EOF ) {
        if( 'a' <= ch && ch <= 'z' ){
            c[ ch - 'a' ]++;
        } else if( 'A' <= ch && ch <= 'Z' ) {
            c[ ch - 'A' ]++;
        }
    }
    for( int i = 0; i < 26; i++ ){
        printf( "%c : %d\n", 'a' + i, c[i] );
    }
    return 0;
}


Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1e9+7;
const ll N=1e6+6;
const ll inf=1e18+1e17;
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
void solve(){
	ll n,k;
	cin>>n>>k;
	n=n%k;
	cout<<min(n,k-n);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	// cin>>t;
 	while ( t--)
 		solve();
}

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

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

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

  string ans = t + s;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007

int n, W;
vector<int> val, wt;
// map<pair<int, int>, int> m;
int memo[105][100005];

int dp(int idx, int w)
{
    // if(m.find({idx, w})!=m.end())
    //     return m[{idx, w}];
    if(memo[idx][w]!=-1)
        return memo[idx][w];
    // cout<<idx<<" "<<w<<endl;
    if(idx==n)
        return 0;
    int ans=dp(idx+1, w);
    if(w>=wt[idx])
        ans=max(ans, val[idx]+dp(idx+1, w-wt[idx]));
    return memo[idx][w]=ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int i=0; i<105; i++)
        for(int j=0; j<100005; j++)
            memo[i][j]=-1;
    cin>>n>>W;
    for(int i=0; i<n; i++)
    {
        int x, y;
        cin>>x>>y;
        wt.pb(x);
        val.pb(y);
    }
    cout<<dp(0, W);
    return 0;
}

Measured memory_bytes: 82432
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int a[] = {2, 1, 0}, b[3][3] = {{0, 0, 0}, {0, 1, 1}, {0, 1, 2}}, c[3][3] = {{0, 1, 2}, {1, 1, 2}, {2, 2, 2}};
signed main(void)
{
	while(true) {
		string s;
		cin >> s;
		if(s == ".") break;
		int ans = 0;
		REP(p, 3) REP(q, 3) REP(r, 3) {
			//cout << p << " " << q << " " << r << endl;
			//???????????°??????????????????
			string t = s;
			REP(i, t.size()) {
				if(t[i] == 'P') t[i] = p + '0';
				if(t[i] == 'Q') t[i] = q + '0';
				if(t[i] == 'R') t[i] = r + '0';
			}
			//cout << t << endl;
			while(true) {
				//???????????????
				int cnt = 0;
				REP(i, t.size()) {
					if(t[i] == '-') cnt++;
					else {
						if(cnt > 0) {
							if('0'<=t[i]&&t[i]<'3') {
								int tmp = t[i] - '0';
								//cout << "cnt:" << cnt << endl << tmp << " ";
								REP(j, cnt) {
									tmp = a[tmp];
									//if(p == 0 && q == 0 && r == 0) cout << tmp << " ";
								}
								//if(p == 0 && q == 0 && r == 0) cout << endl;
							t = t.substr(0, i-cnt) + (char)(tmp+'0') + t.substr(i+1);
							i -= cnt;
							}
						}
						cnt = 0;
					}
					//cout << "i:" << i << " cnt:" << cnt << endl;
				}
				//cout << "a:" << t << endl;
				//?????£?????????+??¨*?????????
				REP(i, t.size()) {
					if(t[i] == '+') {
						if(IN('0', '3', t[i-1]) && IN('0', '3', t[i+1]) && t[i-2] == '(' && t[i+2] == ')') {
							int tmp = c[t[i-1]-'0'][t[i+1]-'0'];
							t = t.substr(0, i-2) + (char)(tmp + '0') + t.substr(i+3);
							i -= 3;
							//cout << "c:" << t << endl;
						}
					} else if(t[i] == '*') {
						if(IN('0', '3', t[i-1]) && IN('0', '3', t[i+1]) && t[i-2] == '(' && t[i+2] == ')') {
							int tmp = b[t[i-1]-'0'][t[i+1]-'0'];
							t = t.substr(0, i-2) + (char)(tmp + '0') + t.substr(i+3);
							i -= 3;
							//cout << "d:" << t << endl;
						}
					}
				}
				//cout << "b:" << t << endl;
				if(t.size() == 1) break;
			}
			if(t == "2") ans++;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}

///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;



int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes"<<'\n';return 0;
            }
        }
    }
    cout<<"No"<<'\n';
    return 0;
}


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

const int MAX_V = 1000;

int match[MAX_V];
bool used[MAX_V];
vector<int> G[MAX_V];

void add_edge(int u, int v)
{
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v)
{
  used[v] = true;
  for (int i = 0; i < G[v].size(); ++i) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(int V)
{
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; ++v) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v))
	++res;
    }
  }
  return res;
}

int main()
{
  int m, n;
  while (~scanf("%d %d", &m, &n)) {
    if ((m|n) == 0)
      break;

    for (int i = 0; i < MAX_V; ++i)
      G[i].clear();

    vector<int> b(m), r(n);
    for (int i = 0; i < m; ++i)
      scanf("%d", &b[i]);
    for (int i = 0; i < n; ++i)
      scanf("%d", &r[i]);

    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
	if (__gcd(b[i], r[j]) != 1)
	  add_edge(i, m+j);
      }
    }

    printf("%d\n", bipartite_matching(n+m));
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

ll n;
ll a[200111];
vector <ll> ansv;
ll ans = 0;


bool cmp(ll a, ll b){
    return a > b;
}

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

    cin >> n;

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

    sort(a, a+ n, cmp);

    ansv.push_back(a[0]);
    for (int i = 1; i < n - 1; i++){
        for (int j = 0; j < 2; j++){
            ansv.push_back(a[i]);
        }
    }

    for (int i = 0; i < n - 1; i++){
        ans+=ansv[i];
    }
    cout << ans << endl;

    return 0;
}

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

void dfs(int i, vector<vector<pair<int, int>>> &way, vector<int> &color, int col) {
  color.at(i) = col;
  for(int j = 0; j < way.at(i).size(); j++) {
    if(color.at(way.at(i).at(j).first) != -1) {
      continue;
    }
    if(way.at(i).at(j).second == 0) {
      dfs(way.at(i).at(j).first, way, color, col);
    }
    else {
      dfs(way.at(i).at(j).first, way, color, 1 - col);
    }
  }
}
   
int main() {
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> way(N);
  for(int i = 0; i < N; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    way.at(a - 1).push_back(make_pair(b - 1, w % 2));
    way.at(b - 1).push_back(make_pair(a - 1, w % 2));
  }
  vector<int> color(N, -1);
  dfs(0, way, color, 0);
  for(int i = 0; i < N; i++) {
    cout << color.at(i) << endl;
  }
}

Measured memory_bytes: 9728