akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cstring>

const int N = 100;

int n, m, par[N * N], sz[N * N], cnt[26], need[5];

int find(int u)
{
    if (par[u] != u) {
        par[u] = find(par[u]);
    }
    return par[u];
}

void merge(int a, int b)
{
    a = find(a);
    b = find(b);
    if (a != b) {
        sz[a] += sz[b];
        par[b] = a;
    }
}

int get_id(int a, int b)
{
    return a * m + b;
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("C.in", "r", stdin);
#endif
    while (scanf("%d%d", &n, &m) == 2) {
        for (int i = 0; i < n * m; ++ i) {
            par[i] = i, sz[i] = 1;
        }
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < m; ++ j) {
                merge(get_id(i, j), get_id(i, m - 1 - j));
                merge(get_id(i, j), get_id(n - 1 - i, j));
            }
        }
        memset(need, 0, sizeof(need));
        for (int i = 0; i < n * m; ++ i) {
            if (par[i] == i) {
                need[sz[i]] ++;
            }
        }
        memset(cnt, 0, sizeof(cnt));
        for (int i = 0; i < n; ++ i) {
            static char buf[N + 1];
            scanf("%s", buf);
            for (int j = 0; j < m; ++ j) {
                cnt[buf[j] - 'a'] ++;
            }
        }
        bool ok = true;
        for (int s = 4; s >= 1 && ok; -- s) {
            int left = need[s];
            for (int i = 0; i < 26; ++ i) {
                while (left && cnt[i] >= s) {
                    left --;
                    cnt[i] -= s;
                }
            }
            ok &= left == 0;
        }
        puts(ok ? "Yes" : "No");
    }
}



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

int main() {
	int width, height, x, y, r;

	cin >> width >> height >> x >> y >> r;
	if (x >= r&&x <= width - r&&y >= r&&y <= height - r) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

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

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  ll n;
  cin>> n;
  vector<ll> h(n);
  rep(i,n){
    cin>>h[i];
  }
  ll ans =0;
  rep(i,n){
    while(h[i]!=0){
      for(ll j=i;j<n;j++){
        if(h[j]==0)break;
        h[j] --;
      }
      ans ++;
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

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

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    while (true) {
        int M;
        cin >> M;
        if (M == 0) {
            break;
        }
        vector<pair<int, int>> v;
        FOR(i, 0, M) {
            int a, b;
            cin >> a >> b;
            v.emplace_back(make_pair(a, b));
        }

        vector<vector<LL>> dp(10, vector<LL>(1010, 0));
        dp[0][0] = 1;

        FOR(i, 0, v.size()) {
            int a = v[i].first;
            int b = v[i].second;

            FOR(j, 0, dp[0].size()) {
                if (dp[i][j] == 0) {
                    continue;
                }
                FOR(k, 0, b + 1) {
                    if (j + a * k < dp[0].size()) {
                        dp[i + 1][j + a * k] += dp[i][j];
                    }
                }

            }
        }

        int G;
        cin >> G;
        FOR(i, 0, G) {
            int n;
            cin >> n;
            print(dp[M][n]);
        }
    }

	return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
signed main() {
	string s; cin >> s;
	int k; cin >> k;
	int n = s.size();
	vvel st(n, vel(26,0));
	V<queue<int>> list(26);
	rep(i, n) {
		if (i != 0) { st[i] = st[i - 1]; }
		st[i][s[i] - 'a']++;
		list[s[i] - 'a'].push(i);
	}
	vel now_st(26, 0);
	int i = 0;
	string iroha = "abcdefghijklmnopqrstuvwxyz";
	string ans = "";
	while (i < n) {
		rep(j, 26) {
			if (!list[j].empty()) {
				int tp = list[j].front();
				int dist = 0;
				rep(l, 26) {
					dist += st[tp][l] - min(st[tp][l], now_st[l]);
				}
				dist--;
				if (k >= dist) {
					k -= dist;
					now_st[j]++;
					list[j].pop();
					ans +=iroha[j];
					break;
 				}
			}
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 53740
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
vector<LL> v,sq;
int main() {
	int N;
	cin >> N;
	map<LL, int> A;
	for(int i=0;i<N;i++) {
		int a;
		cin >> a;
		A[a]++;
	}

	for(auto i: A) {
		if(i.second >= 2) {
			v.push_back(i.first);
		}
		if(i.second >=4) {
			sq.push_back(i.first);
		}
	}
	if(v.size() < 2 && sq.size() < 1) {
		printf("0");
	} else {
		LL ans = 0;
		if (v.size() >= 2) ans = max(ans, v[v.size()-1]*v[v.size()-2]);
		if (sq.size() >= 1) ans = max(ans, sq[sq.size()-1]*sq[sq.size()-1]);
		printf("%llu\n", ans);
	}
}

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

struct point
{
    string s;
    long long x,id;
};

bool compare(point a,point b)
{
    if(a.s!=b.s) return a.s<b.s;
    else return a.x>b.x;
}

int main()
{
    long long n;
    cin>>n;
    point a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i].s>>a[i].x;
        a[i].id=i+1;
    }
    sort(a,a+n,compare);
    for(int i=0; i<n; i++)
        cout<<a[i].id<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],b[n];
  REP(i,n){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b+n);
  REP(i,n){
    if(a[i] <= b[n/2-1]) cout << b[n/2] << endl;
    else cout << b[n/2-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //gp_hash_table
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
 
const int H = 10;
const int W = 1000;
int S[H + 1][W + 1];
int h, w, k;
 
int sum(int r1, int c1, int r2, int c2) {
    return S[r2 + 1][c2 + 1] - S[r2 + 1][c1] - S[r1][c2 + 1] + S[r1][c1];
}
 
bool calc(int mask, int lastCut, int currentCut) {
    int lastRow = 0;
    for(int i = 0 ; i < h ; i++) {
        if(mask&(1 << i) || i == h - 1) {
            int cnt = sum(lastRow, lastCut, i, currentCut);
            if(cnt > k) return false;
            lastRow = i + 1;
        }
    }
    return true;
}
 
int go(int lastCut, int mask) {
    if(calc(mask, lastCut, w - 1)) return 0;
    if(!calc(mask, lastCut, lastCut)) return (int) 1e9;
    int nextCut = lastCut;
    for(int bit = (1 << 15) ; bit > 0 ; bit >>= 1) {
        if(nextCut + bit >= w) continue;
        if(!calc(mask, lastCut, nextCut + bit)) continue;
        nextCut += bit;
    }
    return 1 + go(nextCut + 1, mask);
}
 
void create2DSs() {
    for(int i = 0 ; i <= h ; i++)
        for(int j = 1 ; j <= w ; j++)
            S[i][j] += S[i][j - 1];
    for(int j = 0 ; j <= w ; j++)
        for(int i = 1 ; i <= h ; i++)
            S[i][j] += S[i - 1][j];
}
 
void solve() {
    cin >> h >> w >> k;
    string row;
    for(int i = 0 ; i < h ; i++) {
        cin >> row;
        for(int j = 0 ; j < w ; j++)
            S[i + 1][j + 1] = row[j] == '1';
    }
    create2DSs();
    // try all horizontal cuts
    int res = (int) 1e9;
    for(int i = 0 ; i < (1 << (h - 1)) ; i++) {
        int cost = go(0, i) + __builtin_popcount(i);
        res = min(res, cost);
    }
    cout << res << "\n";
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
lmax,rmin=0,n
for i in range(m):
	l,r=map(int,input().split())
	if l>lmax:
		lmax=l
	if r<rmin:
		rmin=r
if rmin-lmax<0:
	print(0)
else:
	print(rmin-lmax+1)

Measured memory_bytes: 3060
import math
n,h=map(int,input().split())
furu=[None]*n
nageru=[None]*n
for i in range(n):
    a,b=map(int,input().split())
    furu[i]=a
    nageru[i]=b
rep=max(furu)
nagekaku=[]
for i in range(n):
    if rep<nageru[i]:
        nagekaku.append(nageru[i])
nage_sum=sum(nagekaku)
if nage_sum>=h:
    nagekaku=sorted(nagekaku,reverse=True)
    ans=0
    for i in range(len(nagekaku)):
        h-=nagekaku[i]
        ans+=1
        if h<=0:
            break
else:
    ans=len(nagekaku)
    h-=nage_sum
    ans+=math.ceil(h/rep)

print(ans)

Measured memory_bytes: 87004
using System;
class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            string[] data = Console.ReadLine().Split(' ');
            if (data[1] == "?")
            {
                break;
            }else if(data[1] == "+"){
                Console.WriteLine(int.Parse(data[0]) + int.Parse(data[2]));
            }
            else if (data[1] == "-")
            {
                Console.WriteLine(int.Parse(data[0]) - int.Parse(data[2]));
            }
            else if (data[1] == "*")
            {
                Console.WriteLine(int.Parse(data[0]) * int.Parse(data[2]));
            }
            else if (data[1] == "/")
            {
                Console.WriteLine(int.Parse(data[0]) / int.Parse(data[2]));
            }            
        }
        
    }
}

Measured memory_bytes: 5608
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[]
for i in range(1,m):
    a.append(x[i]-x[i-1])

a.sort()
a.reverse()

ans=sum(a)-sum(a[0:n-1])
print(ans)


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(){
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  ll ans = 0;
  for (int i = 0; i < n;i++){
    int cnt = 0;
    while (1+cnt*a[i]<=d){
      cnt++;
    }
    //cout << cnt << endl;
    ans += cnt;
  }
  cout << ans + x << endl;

  return 0;
}


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

using namespace std;

vector<ll> lun;

void func(ll n, int d) {
  if(d == 11) return;
  int last = n % 10;
  for(int i = max(0, last - 1); i <= min(9, last + 1); i++) {
    lun.push_back(n * 10 + i);
    func(n * 10 + i, d + 1);
  }
}

int main() {
  for(int i = 1; i < 10; i++) {
    lun.push_back(i);
    func(i, 1);
  }
  sort(lun.begin(), lun.end());
  int k;
  scanf("%d", &k);
  printf("%lld", lun[k - 1]);
}

Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=5005*5005;
ll dp[2][maxn];
int a[4],b[4];
void work(int A[],int B[],ll f[],int n)
{
    ll mx=0;
    for(int i=1;i<maxn;i++)
    {
        f[i]=f[i-1]+1;
        for(int j=0;j<3;j++)
            if(A[j]<=i) f[i]=max(f[i],f[i-A[j]]+B[j]);
        mx=max(mx,f[i]);
    }
}
ll cal(int n)
{
    ll ans=0;
    for(int i=0;i<=n;i++)
    {
        ans=max(ans,dp[1][dp[0][i]+n-i]);
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<3;i++)
        cin>>a[i];
    for(int i=0;i<3;i++)
        cin>>b[i];
    work(a,b,dp[0],n);
    work(b,a,dp[1],n);
    printf("%lld\n",cal(n));
    return 0;
}


Measured memory_bytes: 391680
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;

ll C[51][51];
int N,M,L;
int P[102],T[102],V[102];
double A[102][51];
double B[102][51];

double f(int a,int b) {
    double ret=A[a][b];
    rep(i,N) if(a!=i) {
        double p=0;
        rep(j,M+1) {
            if(B[a][b]<B[i][j]) p+=A[i][j];
        }
        ret*=p;
    }

    return ret;
}
int main() {
    rep(i,51) C[i][0]=1;
    rep(i,51) for(int j=1;j<=i;j++) C[i][j]=C[i-1][j-1]+C[i-1][j];

    cin>>N>>M>>L;
    rep(i,N) cin>>P[i]>>T[i]>>V[i];

    rep(i,N) {
        // j?????????
        rep(j,M+1) {
            double p=C[M][j];
            rep(k,j) p*=P[i]/100.0;
            rep(k,M-j) p*=(100-P[i])/100.0;
            A[i][j]=p;

            double t=0;
            t+=j*T[i];
            t+=1.0*L/V[i];
            B[i][j]=t;
        }
    }

    double ans[102];

    rep(i,N) {
        ans[i]=0;
        rep(j,M+1) {
            ans[i]+=f(i,j);
        }
    }
    rep(i,N) printf("%.20f\n",ans[i]);



    return 0;
}

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

int main() {
int n,m;
string s[1000];
cin>>n;
REP(i,n){
  cin>>s[i];
}
cin>>m;
for (int i = n; i < n+m; i++)
{
  /* code */
  cin>>s[i];
}

int v=0;
int ans=0;
REP(i,n){
  REP(j,n+m){
    if (s[i]==s[j]&&j<n)
  {
    /* code */
    v++;
  }
  else if (s[i]==s[j]&&j>=n)
  {
    /* code */
    v--;
  }
  }
    ans=max(v,ans);
    v=0;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
s = gets.chomp

if s.length > 9
  puts 'NO'
  exit
end

str = 'AKIHABARA'
(0..('1'*4).to_i(2)).each do |i|
  bits = i.to_s(2).rjust(4, '0').chars
  tmp = str.dup

  bits.each.with_index do |bit, j|
    if bit == '1'
      case j
      when 0
        tmp[0] = 'x'
      when 1
        tmp[4] = 'x'
      when 2
        tmp[6] = 'x'
      when 3
        tmp[8] = 'x'
      else
        raise '?'
      end
    end
  end

  tmp.gsub!('x', '')
  if tmp == s
    puts 'YES'
    exit
  end
end

puts 'NO'


Measured memory_bytes: 14264
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N, num = 0;
    cin >> N;
    string S;
    cin >> S;
    Fp(i, 0, N - 2){
        if(S[i] == 'A'){
            if(S[i + 1] == 'B'){
                if(S[i + 2] == 'C') num++;
            }
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long K, X;
  scanln(K, X);
  if (500*K >= X) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}

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


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int n,m;
    cin>>n>>m;
    int a = m/n;
    for (int i = a; i >= 2; i--) {
        if(i*n<=m){
            int t=m-(n*i);
            if(t%i==0||(t>=i&&t%i==0)){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

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

  string X = S;
  reverse( X.begin(), X.end() );
  if ( S!=X ) {
    cout << "No" << endl;
    return 0;
  }

  string Y = "";
  string Z = "";
  int Len = S.size();
  for ( int i=0; i<(Len-1)/2; i++ ) Y += S[i];
  Z = Y;
  reverse( Z.begin(), Z.end() );
  if ( Y!=Z ) {
    cout << "No" << endl;
    return 0;
  }

  Y = "";
  for ( int i=( Len+3 )/2-1; i<Len; i++ ) Y += S[i];
  Z = Y;
  reverse( Z.begin(), Z.end() );
  if ( Y!=Z ) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}


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

int main(){
	int n, k;
  	cin >> n >> k;
  	
  	vector<int> A;
  	
  	for(int i = k;; i *= k){
    	A.push_back(n % i);
      	if(i > n) break;
    }
  	
  	cout << A.size() << endl;
}

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

int main() {
	int n;
	cin >> n;
	int count = 0;
	
	if (n % 10 == 7) count++;
	n /= 10;
	if (n % 10 == 7)count++;
	n /= 10;
	if (n % 10 == 7)count++;
	

	if (count > 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3612
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var r = Enumerable.Range(1, 1009).FirstOrDefault(x => x * 2 / 25 == h[0] && x / 10 == h[1]);
		Console.WriteLine(r > 0 ? r : -1);
	}
}


Measured memory_bytes: 28380
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

int A,B;
char s[12];
int  main() {
    scanf("%d%d", &A, &B);
    scanf("%s", &s);
    for (int i = 0; i < A; i++)
        if (!('0' <= s[i] && s[i] <= '9')) {
            puts("No");
            return 0;
        }
    if (s[A] != '-') {
        puts("No");
        return 0;
    }
    for (int i = A + 1; i <= A + B; i++)
        if (!('0' <= s[i] && s[i] <= '9')) {
            puts("No");
            return 0;
        }
    puts("Yes");
}

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

int main() {
  int N;
  bool minus_flg=false;
  int temp, max_i=-1, min_i=-1, max_val=-1, min_val=1;
  scanf("%d", &N);
  for (int i=0; i<N; i++){
    scanf("%d", &temp);
    if(temp>max_val){
      max_val=temp;
      max_i=i+1;
    }
    if(temp<min_val){
      min_val=temp;
      min_i=i+1;
    }
  }
  if(max_val+min_val<0)minus_flg=true;
  printf("%d\n", 2*N-2);
  if(minus_flg){
    for(int i=1;i<=N;i++){
      if(i==min_i) continue;
      printf("%d %d\n", min_i, i);
    }
    for(int i=N;i>1;i--){
      printf("%d %d\n", i, i-1);
    }
  }else{
    for(int i=1;i<=N;i++){
      if(i==max_i) continue;
      printf("%d %d\n", max_i, i);
    }
    for(int i=1;i<N;i++){
      printf("%d %d\n", i, i+1);
    }
  }
  return 0;
}

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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; ++i) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];

  bool can = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;
  }

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

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  string s;
  int n, k, c;
  cin >> n >> k >> c >> s;

  vector<int> l(k), r(k);
  for (int i = 0, j = 0; i < n && j < k; ++i) {
    if (s[i] == 'x')  continue;
    l[j++] = i;
    i += c;
  }

  for (int i = n-1, j = k-1; i >= 0 && j >= 0; --i) {
    if (s[i] == 'x')  continue;
    r[j--] = i;
    i -= c;
  }

  int ans = 0;
  for (int i = 0; i < k; ++i)
    if (l[i] == r[i]) 
      cout << l[i] + 1 << '\n';
}



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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

void solve() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll d = B - A;
  if (d % 2 == 0) {
    cout << d / 2 << endl;
  } else {
    cout << (B - A + 1) / 2 + min(A - 1, N - B) << endl;
  }
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int num = sc.nextInt();

        int ans = 1;
        int highest = sc.nextInt();
        for(int i = 1; i < num; i++){
            int height = sc.nextInt();
            if(height >= highest){
                ans++;
                highest = height;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
typedef long long ll;
#define MOD 1000000007
int main()
{
    int X, N;
    cin >> X >> N;
    vector<bool> p(101);
    for (int i = 0; i < N; ++i)
    {
        int P;
        cin >> P;
        p[P] = true;
    }
    // 下
    int low_memo = 0;
    int high_memo = 0;
    for (int i = X; i > 0; --i)
    {
        if (!p[i])
        {
            low_memo = i;
            break;
        }
    }

    //　上
    for (int i = X; i <= 101; ++i)
    {
        if (!p[i])
        {
            high_memo = i;
            break;
        }
    }
    if (high_memo - X >= X - low_memo)
    {
        cout << low_memo << endl;
    }
    else
    {
        cout << high_memo << endl;
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 10000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N,H,W;
	cin>>N>>H>>W;
	vector<int>A(N);
	vector<int>B(N);
	int ans=0;
	REP(i,N)cin>>A[i]>>B[i];
	REP(i,N){
		if(A[i]>=H && B[i]>=W)ans++;
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
c = map(int, raw_input().split())
num = [0] * N
Q = input()
for i in range(Q):
    t, x, d = map(int, raw_input().split())
    if t == 1:
        num[x - 1] += d
    else:
        num[x - 1] -= d
    if not 0 <= num[x - 1] <= c[x - 1]:
        print x
        exit()
print 0


Measured memory_bytes: 8168
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power( ll a, ll n, ll m){
  ll ans = 1;
  while(n){
  if(n&1)
  {
  ans *= a;
  ans%=m;
  }
  a*=a;
  n/=2;
  }
  return ans ;
} 


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){



int k ;
cin>>k;

int n ;
cin>>n;

vector <int  > cl( n+1) ;
vector < int > an( n+1);

vector < int > ar(n+1);

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

int ans = INT_MAX;

cl[0] = ar[0]+ (k-ar[n-1]);


for( int i=1 ; i <n;i++){
	cl[i] = ar[i] - ar[i-1];
	
}

an [n-1] = ar[0]+ (k-ar[n-1]);
for( int i=n-2;i>=0;i--)
an[i] = ar[i+1]-ar[i];

int sn =0 ;
for( int i=0 ; i < n;i+=1)
sn+=an[i];

int mn = INT_MAX;

for(int i=0 ; i < n;i++)
mn = min(mn , sn - an[i]);

int mx = INT_MAX ;
int sx =0 ;
for( int i=0 ; i< n ;i++)
sx+= cl[i];

for( int i  =0 ; i < n;i++){
	mx = max(mx, sx - cl[i]);
}

cout<<min(mx, mn)<<endl;


return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


Measured memory_bytes: 5572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        int counter = 0;
        for (int i = 1; i <= n; i++) {
            final int a = scanner.nextInt();
            if (i % 2 == 1 && a % 2 == 1) {
                counter++;
            }
        }
        System.out.println(counter);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<int> diffcnt(n+1);
  int mincnt = 0;
  for(int i=0;i < n;i++){
    if(s.at(i) == '.'){
      diffcnt.at(0)++;
    }
  }
  mincnt = diffcnt.at(0);
  rep(i,n){
    if(s.at(i) == '.'){
      diffcnt.at(i+1) = diffcnt.at(i) - 1;
    }else{
      diffcnt.at(i+1) = diffcnt.at(i) + 1;
    }
    mincnt = min(mincnt,diffcnt.at(i+1));
  }
      
    
  cout << mincnt << endl;
}
    
      
    


Measured memory_bytes: 1412
#include<iostream> 
#include<vector>
#include<map>
using namespace std;

	map<string,int> m;
int main(){
	int n;
	cin >> n;
	vector<string> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
		m[v[i]]++;
	}
	for(int i=0;i<n-1;i++){
		if(v[i][v[i].size()-1] != v[i+1][0]){
			cout << "No" << endl;
			return 0;
		}
		if(m[v[i]] > 1|| m[v[i+1]]>1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

	


Measured memory_bytes: 256
import sys
 
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
 
 
def input():
    return sys.stdin.readline().strip()
 
 
def main():
    N, M = map(int, input().split())
    dp = [0] * (N + 1)
    safe = [True] * (N + 1)
    for _ in range(M):
        a = int(input())
        safe[a] = False
 
    dp[0] = 1
    for i in range(1, N + 1):
        if i == 1 and safe[i]:
            dp[i] = dp[i - 1]
        else:
            if safe[i]:
                dp[i] = dp[i - 1] + dp[i - 2]
                dp[i] %= MOD
 
    print(dp[-1])
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 7668
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=200005;
const LL inf=(LL)1e16;

int n,a[N];
LL s[N][3],dp[N][5];

void work()
{
	for (int i=1;i<=n;i++)
	{
		int x=a[i];
		if (!x) s[i][2]=2,s[i][1]=1,s[i][0]=0;
		else if (x&1) s[i][2]=1,s[i][1]=0,s[i][0]=x;
		else s[i][2]=0,s[i][1]=1,s[i][0]=x;
	}
	for (int i=1;i<=n+1;i++)
	{
		LL mn=dp[i-1][0];
		dp[i][0]=dp[i-1][0]+s[i][0];
		mn=std::min(mn,dp[i-1][1]);
		dp[i][1]=mn+s[i][2];
		mn=std::min(mn,dp[i-1][2]);
		dp[i][2]=mn+s[i][1];
		mn=std::min(mn,dp[i-1][3]);
		dp[i][3]=mn+s[i][2];
		mn=std::min(mn,dp[i-1][4]);
		dp[i][4]=mn+s[i][0];
	}
}

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

Measured memory_bytes: 13568
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Divide the Problems
            int n = int.Parse(Console.ReadLine());

            //点数の低い順にソート
            var d = ReadLine().OrderBy(x => x).ToList();

            int a = d[n / 2 - 1];
            int b = d[n / 2];

            Console.WriteLine(b - a);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 22112
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N, K;
  cin >> N >> K;
  
  long long ans = K * pow(K - 1, N - 1);
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  int n;
  cin >> n;
  ll sum = 0;

  for(int i=1; i<=n; ++i) {
    if(i%3!=0&&i%5!=0) sum += i;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b / a) << endl;
    return 0;
}

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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0) cout << a - b << endl;
  else cout << b - a << endl;
  return 0;
} 

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

using namespace std;
priority_queue<long long> num;
int main()
{
    //freopen("cbarn.out", "w", stdout) ;
    //freopen("cbarn.in", "r", stdin) ;
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    long long a,b,sum=0,n;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>n;
        num.push(n);
    }
    while(b--)
    {
        long long m=num.top();
        m/=2;
        num.pop();
        num.push(m);
    }
    for(int i=0;i<a;i++)
        {
            sum+=num.top();
            num.pop();
        }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1400
import qualified Data.IntSet as S
import Data.List
import Control.Monad
import Data.Maybe
 
main = do
 getLine
 ls <- map read. words <$> getLine
 let als = scanl1 (+) (init ls)
 let als' = scanr1 (+) (tail ls)
 let s1 = S.fromList als
 let s2 = S.fromList als'
 let med = div (sum ls) 2
 print $ pile s1 s2 med
 
pile s1 s2 med = min (abs (hi-lo)) (abs (hi'-lo'))
 where
  lo = maybe 0 id (S.lookupLE med s1)
  hi = maybe (maxBound :: Int) id (S.lookupGE med s2)
  lo' = maybe 0 id (S.lookupGE med s1)
  hi' = maybe (maxBound :: Int) id (S.lookupLE med s2)

Measured memory_bytes: 74108
// CODE by Kazhybay Askar

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

using namespace std;
using namespace __gnu_pbds;

/*
find_by_order(k);
order_of_key(k);
ordered_set(int) s;
*/

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
rng();
shuffle(permutation.begin(), permutation.end(), rng);
*/

/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC    optimize("Ofast")
#pragma GCC    target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define F      first
#define S      second
#define pb     push_back
#define pf     push_front
#define ppb    pop_back
#define ppf    pop_front
#define Speed  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz     size()
#define all(x) x.begin(),x.end()
#define cont   continue
#define r0     return 0
#define nl     '\n'
#define ordered_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef long double   ld;
typedef pair<ll,ll>   pll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;

const int MAXN  = 5e5  + 7;
const int MOD   = 1e9  + 7;
const int INF   = 1e9  + 7;
const ll  MINF  = 1e18 + 7;
const int EPS   = 1e-6;
const int dx[]  = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[]  = {1, -1, 0, 0, -1, 1, -1, 1};
const double pi = acos(-1.0);

ll n,a[MAXN];

void solve(){
    cin>>n;
    ll k;
    cin>>k;
    if(k>n){
        cout<<min(n,k-n);
        return;
    }
    n%=k;
    if(n==0){
        cout<<0;
        return;
    }
    n=k%n;
    cout<<n;
}



int main(){
    Speed;
    ll T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    r0;
}


Measured memory_bytes: 256
[n,m] = [int(i) for i in input().split()]
if n == 1:
    print(m)
else:
    ans = -1
    #a1は高々この値
    a1_max = m // n
    for i in range(a1_max,0,-1):
        if (m - i) % i == 0 and (m - i)//i >= (n-1):
            ans = max(ans,i)
    print(ans)


Measured memory_bytes: 63696
n=int(input())
br=[]
for i in range(n):
  br.append(input())
m=int(input())
re=[]
for i in range(m):
  re.append(input())
point=[]
for i in br:
  bri=br.count(i)
  rei=re.count(i)
  point.append(bri-rei)
point.append(0)
print(max(point))

Measured memory_bytes: 38384
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define repk(a) for(int k=0;k<int(a);k++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)
#define l_b lower_bound
#define u_b upper_bound
#define b_s binary_search

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}


signed main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){
    ll K; cin >> K;
    cout << (K / 2) * (K - K / 2) << endl; 
}

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

int main()
{
  int a,b,bb,c,d = 0;
  
  cin >> a >> b;
  
  if(a < b){
    cout << "a " << "<" << " b" << endl;
  }
  else if(a > b){
    cout << "a " << ">" << " b" << endl;
  }
  else
    cout << "a " << "==" << " b" << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[1000005];
multiset<int>M;
int main(){
	cin >> n;
	repn(i,n) cin >> a[i];
	M.insert(0); M.insert(0); M.insert(0);
	ll ans = 1;
	repn(i,n){
		ll w = 0;
		for(auto A:M) if(A == a[i]) w++;
		ans = ans*w%mod;
		if(w == 0) break;
		for(auto A:M){
			if(A == a[i]){
				M.erase(M.find(A));
				M.insert(A+1);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
#define ll long long
#define pii pair<int,int>
#define eps 1e-9
#define mii map<int,int>
#define vi vector<int>
#define all(n) n.begin(),n.end()
#define inf INF
#define INFLL 9223372036854775807
using namespace std;
int main()
{
    int n,m,cnt=0,i,j,k,tc,t;
    string s,s1,s2;
    cin>>s;
    n=s.length();
    s1.pb('0');
    s2.pb('1');
    for(i=1;i<n;i++)
    {
        s1.pb(s1[i-1]=='0'?'1':'0' );
        s2.pb(s2[i-1]=='0'?'1':'0' );
    }
    int cnt1=0,cnt2=0;
    for(i=0;i<n;i++)
    {
        if(s[i]!=s1[i])cnt1++;
        if(s[i]!=s2[i])cnt2++;
    }
    cout<<min(cnt1,cnt2);

}


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

int main() {
  int num;
  int nowX = 0;
  int nowY = 0;
  int tmp1,tmp2,tmp3,tmptCnt;
  int tCnt,tX,tY;
  bool chk = true;
  
  cin >> num;
  
  for(int i = 0; i < num; i++){
    cin >> tCnt >> tX >> tY;
    tmp1 = abs(nowX - tX);
    tmp2 = abs(nowY - tY);
    tmp3 = tmp1 + tmp2;
    tmptCnt = tCnt - tmptCnt;
    
    if(tmp3 > tmptCnt){
      // timeout
      chk = false;
      break;
    }
    
    if(tmptCnt % 2 == 0){
      if(tmp3 % 2 == 0){
        nowX = tX;
        nowY = tY;
        tmptCnt = tCnt;
      }else{
        chk = false;
        break;
      }
    }else{
      if(tmp3 % 2 == 1){
        nowX = tX;
        nowY = tY;
        tmptCnt = tCnt;
      }else{
        chk = false;
        break;
      }
    }
  }
  if(chk == true) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256