akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> T MV(T v) { return v; }
template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

int main() {
	IN(string, s);
	s = "0" + s;
	int n = SI(s);
	int INF = 1e8;
	auto dp = MV(INF, n + 1, 2);
	dp[0][0] = 0;
	inc(i, n) {
		int x = s[i] - '0';
		setmin(dp[i + 1][0], dp[i][0] + x);
		setmin(dp[i + 1][1], dp[i][0] + x + 1);
		setmin(dp[i + 1][0], dp[i][1] + 10 - x);
		setmin(dp[i + 1][1], dp[i][1] +  9 - x);
	}
	OUT(dp.BA[0]);
}


Measured memory_bytes: 55856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
//const ll INF = 1LL<<60;
const int INF = 1e9;
const ll MOD = 1e9+7;

//see:http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/26/dijkstra-copy.html

#define MAX_V 10000

struct edge {
    int to;
    int cost;
};


int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    V = (int)pow(2,n);
    int E;cin>>E;
    for (int i=0; i<E; ++i) {
        int  a,b;cin>>a>>b;
        int k = 0;
        for(int i=0; i<b; i++){
            ll c; cin>>c; c--;
            k = k|(1<<c);
        }
        for(int i=0; i<V; i++){
            if((i|k)!=i){
                edge e = {(i|k),a};
                G[i].push_back(e);
            }
        }
    }
    dijkstra(0);
    if(d[V-1]==INF)cout<<-1;
    else cout<<d[V-1];


    return 0;
}

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

using namespace std;

int n;
long long sum;

int main(void)
{
	scanf("%d", &n);
	
	for(int i = 1 ; i <= n ; i++)
	{
		if(i % 3 == 0 || i % 5 == 0)
			continue;
		
		sum += i;
	}
	
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int H,W;
	int c[20][20]={};
	int A[210][210]={};

	cin >> H >> W;
	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cin >> c[i][j];


	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin >> A[i][j];

	for(int k=0;k<10;k++)
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);

	int ans=0;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			if(A[i][j]!=-1)
				ans+=c[A[i][j]][1];

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


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#define N 10000
int cnt=0;
void isPrime(int *, int);
int main(){
    int array[N];
    int i;
    int n;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&array[i]);
    }
    isPrime(array, n);
    printf("%d\n",cnt);
    return 0;
}

void isPrime(int *array, int n){
    int i,j;
    int flag=0;
    for(j=0; j<n; j++){
        if(array[j]==2){
            cnt++;
            continue;
        }
        if(array[j] < 2 || array[j] % 2 == 0){
            continue;
        }
        i=3;
        while(i <= sqrt(array[j]) ){
            if(array[j] % i == 0){
                flag=1;
                break;
            }
            i=i+2;
        }
        if(flag==0){
            cnt++;
        }
        flag=0;
    }
}


Measured memory_bytes: 2052
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long ans = x / 11 * 2;
		if (x % 11 > 6) {
		    ans += 2;
		} else if (x % 11 > 0) {
		    ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, h, w;
  scanf("%lld%lld%lld", &h, &w, &k);
  ll dp[h + 1][w + 2], cnt[20];
  cnt[0] = 1, cnt[1] = 1, cnt[2] = 1;
  for(i = 3; i < 20; ++i) cnt[i] = cnt[i - 1] + cnt[i - 2];
  for(i = 0; i < w + 2; ++i) dp[0][i] = (i == 1 ? 1 : 0);
  for(i = 0; i <= h; ++i) dp[i][0] = dp[i][w + 1] = 0;
  for(i = 1; i <= h; ++i) {
    for(j = 1; j <= w; ++j) {
      dp[i][j] = dp[i - 1][j - 1] * (cnt[j - 1] * cnt[w - j + 1]);
      dp[i][j] += dp[i - 1][j + 1] * (cnt[j] * cnt[w - j]);
      dp[i][j] += dp[i - 1][j] * (cnt[j] * cnt[w - j + 1]);
      dp[i][j] %= mod;
    }
  }
  printf("%lld", dp[h][k]);
  return 0;
}


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

ll N,M;

int main(){
  cin >> N >> M;
  ll ans=0;
  if(N*2 <= M) ans += N + (M-(2*N))/4;
  else ans += M/2;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

// const int N = ;
long long n, nr, ans;
string s;
int main() {
	ios_base::sync_with_stdio(false);

 cin >> s;
 for(auto i : s) {
 	if(i == 'B') nr++;
 	else ans += nr;
 }
 cout << ans << '\n';
}	

	

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
// const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

ll a[100010];


int main () {

    int n;cin>>n;
    ll x;cin>>x;

    rep(i,n) cin>>a[i];

    ll ans =0;
    rep(i,n-1) {
        ll dif = a[i]+a[i+1]-x;
        if (dif>0) {
            ans+=dif;
            a[i+1]=max((ll)0,a[i+1]-dif);
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int A,B,i,mins,maxs,ming,maxg,num;
  scanf("%d %d",&A,&B);
  
  if (A%2==0){
    mins=A*12.5;
    maxs=(A+1)*12.5;
  }
  else{
    mins=A*12.5+1;
    maxs=(A+1)*12.5-1;
  }
  ming=B*10;
  maxg=(B+1)*10-1;
  if(mins<=maxg && ming<=mins) num=mins;
  else if(ming<=maxs && mins<=ming) num=ming;
  else num=-1;
  printf("%d",num);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
int MAX_digit = 50;
long long dp[100][2];
int main() {
    long long N, K; cin >> N >> K;
    long long A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int d = 0; d < MAX_digit; d++)
    {
        long long mask = 1LL << (MAX_digit - d - 1);
        long long num = 0;
        for(int i = 0; i < N; i++) {
            if(A[i] & mask) num++;
        }
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);
        if(dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
        }
        if(dp[d][0] != -1) {
            if(K & mask) {
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }
        if(dp[d][0] != -1) {
            if(K & mask) {
                chmax(dp[d+1][0], dp[d][0] + cost1);
            }
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[MAX_digit][0], dp[MAX_digit][1]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, q, a, b, p, x;
int num[200010];
vector<int> vec[200010];
bool used[200010];
signed main() {
	cin >> n >> q;
	rep(i, n - 1) {
		cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	rep(i, q) {
		cin >> p >> x;
		num[p] += x;
	}
	queue<int> que;
	que.push(1);
	used[1] = true;
	while (!que.empty()) {
		int node = que.front();
		que.pop();
		for (int i : vec[node]) {
			if (used[i])continue;
			que.push(i);
			num[i] += num[node];
			used[i] = true;
		}
	}
	REP(i, n - 1)cout << num[i] << " ";
	cout << num[n] << endl;
}

Measured memory_bytes: 18032
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define deb(x) cout << #x << "=" << x << endl

int main() {
	// your code goes here
	ll t;
	t=1;
	while(t--)
	{
	    string a,b;
	    cin>>a;
	    cin>>b;
	    ll n=a.length();
	    ll m=b.length();
	    ll t[n+1][m+1];
	    for(ll i=0;i<n+1;i++)
	    {
	        t[i][0]=0;
	    }
	    for(ll j=0;j<m+1;j++)
	    {
	        t[0][j]=0;
	    }
	    for(ll i=1;i<n+1;i++)
	    {
	        for(ll j=1;j<m+1;j++)
	        {
	            if(a[i-1]==b[j-1])
	            t[i][j]=1+t[i-1][j-1];
	            else
	            t[i][j]=max(t[i-1][j],t[i][j-1]);
	        }
	    }
	   /*for(ll i=0;i<n+1;i++)
	   {
	       for(ll j=0;j<m+1;j++)
	       {
	           cout<<t[i][j]<<" ";
	       }
	       cout<<"\n";
	   }*/
	   string ans="";
	   ll i=n;
	   ll j=m;
	   if(t[n][m]==0)
	   ans.pb(' ');
	   while(i>0 && j>0)
	   {
	       if(a[i-1]==b[j-1])
	       {
	           ans.pb(a[i-1]);
	           i--;
	           j--;
	       }
	       else
	       {
	           if(t[i][j-1]>=t[i][j])
	           j--;
	           else
	           i--;
	       }
	   }
	   reverse(ans.begin(),ans.end());
	   cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 73884
#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 1000003

int dic[Lim];

int toint(string s) {
    int ret = 0;
    for (int i = 0; i < s.size(); ++i) {
        ret *= 5;
        switch (s[i]) {
            case 'A':
                ret += 1;
                break;
            case 'T':
                ret += 2;
                break;
            case 'G':
                ret += 3;
                break;
            case 'C':
                ret += 4;
                break;
        }
    }
    return ret;
}

void push(string s) {
    int a = toint(s);
    int i = a % Lim;
    while (true) {
        if (!dic[i]) {
            dic[i] = a;
            return;
        }
        i = (i + Jmp) % Lim;
    }
}

int find(string s) {
    int a = toint(s);
    int i = a % Lim;
    while (true) {
        if (!dic[i]) {
            return 0;
        }
        if (dic[i] == a) {
            return 1;
        }
        i = (i + Jmp) % Lim;
    }
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s, t;
        cin >> s >> t;
        if (s == "insert") {
            push(t);
        }
        else {
            if (find(t)) {
                printf("yes\n");
            }
            else {
                printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 31044
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}

vector<string> v(200);
int bfs(int s, int n)
{
   queue<int> q;
   vector<int> used(n, 0);
   q.push(s);
   q.push(0);
   q.push(-1);
 
   while (!q.empty())
   {
      int now = q.front();
      q.pop();
      int way = q.front();
      q.pop();
      int mae=q.front();
      q.pop();
      way++;
 
      if (used[now])
      {
         if ((max(used[now],way)-min(used[now],way))%2 != 0)
         {
            return -1;
         }
         else
         {
            continue;
         }
      }
 
      used[now] = way;
 
      rep(i, 0, n)
      {
         if (v[now][i] == '1' && i!=mae)
         {
            q.push(i);
            q.push(way);
            q.push(now);
         }
      }
   }
 
   int res = 0;
   rep(i, 0, n) res = max(res, used[i]);
   return res;
}
int main(){
    int n, ans = -1;
      cin >> n;
    
      rep(i, 0, n)
      {
         cin >> v[i];
      }
    rep(i, 0, n)
    {
       ans = max(ans, bfs(i, n));
    }
    cout << ans << endl;
    return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    llint A, B, C, K;

    cin >> A >> B >> C >> K;

    if(K <= A){
        cout << K << endl;
    }else if(K <= A + B){
        cout << A << endl;
    }else{
        cout << A - (K - A - B) << endl;
    }
}

Measured memory_bytes: 3624
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

template<typename T> T gcd(T x, T y) {
  while (y > 0){
    T tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

template<typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0) return 0;
  else return x * y / gcd(x, y);
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int64 a, b, c, d; cin >> a >> b >> c >> d;
  cout << b - b / c - b / d + b / lcm(c, d) - (a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm(c, d)) << '\n';

  return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
n, m = max(n, m), min(n, m)
if n == 1 and m == 1:
    print(1)
else:
    a = min(2, n)
    b = max(0, n-2)
    c = min(2, m)
    d = max(0, m-2)
    if m == 1:
        print(b)
    else:
        print(b*d)

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

using i64 = long long;

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

const int MOD = 1000000007;

i64 pow64(i64 a, i64 b) {
    a %= MOD;
    i64 result = 1;
    while(b) {
        if(b & 1) result = result * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return result;
}

const int MAXN = 101000;

int n;
int arr[MAXN];

int main() {
    std::scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        std::scanf("%d", &arr[i]);
    bool ok = true;
    for(int i = 0; i < n; ++i)
        if((arr[i] & 1) == (n & 1)) { ok = false; break; }
    if(!ok) std::puts("0");
    else {
        std::map<int, int> mp;
        for(int i = 0; i < n; ++i)
            ++mp[arr[i]];
        for(auto&& p : mp) {
            if(p.first == 0) {
                if(p.second > 1) { ok = false; break; }
            } else {
                if(p.second > 2) { ok = false; break; }
            }
        }
        if(!ok) std::puts("0");
        else std::printf("%lld\n", pow64(2, n / 2));
    }
}

Measured memory_bytes: 2944
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i;
ll a[nmax],l[nmax],r[nmax];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i];
    n++;
    for(i=1;i<=n;i++)l[i]=l[i-1]+abs(a[i]-a[i-1]);
    for(i=n;i>=1;i--)r[i]=l[n]-l[i-1];
    for(i=1;i<n;i++)
	{
		cout<<l[i-1]+r[i+2]+abs(a[i-1]-a[i+1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        if (n % 2 != 0) {
            System.out.println("No");
            return;
        }

        char[] chars = s.toCharArray();
        int half = s.length() / 2;
        for (int i = 0; i < half; i++) {
            if (chars[i] != chars[i + half]) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main () {
 int n,d;
 cin >>n>>d;
 int ans =0;
 int sq =0;
 
 vector<vector<int>> x(n,vector<int>(d));

  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  for (int i=0;i<n;i++){
    for(int j=0;j<i;j++){  
      for(int k=0;k<d;k++){
        int set= x[i][k]-x[j][k];
        sq += set*set;//2乗の計算
      } 
       int s =sqrt(sq)+0.5;//int 切り捨て後四捨五入
      if(s*s == sq)ans++;
      sq =0;
    }   
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Search(A []int, s int) int {
  N := len(A)
  if s <= A[0] { return 0 }
  if A[N - 1] < s { return N }
  lts, ges := 0, N - 1
  for 1 < ges - lts {
    med := (ges + lts) / 2
    if A[med] < s {
      lts = med
    } else {
      ges = med
    }
  }
  return ges
}

func Solve() {
  var N int
  NextInt(&N)
  var A, B []int
  NextIntVec(&A)
  NextIntVec(&B)
  ans := 0
  MA := make([]int, N)
  MB := make([]int, N)
  for i := 0; i < 30; i++ {
    M := 1 << uint(i + 1)
    for i := range MA {
      MA[i] = A[i] % M
      MB[i] = B[i] % M
    }
    sort.Ints(MA)
    sort.Ints(MB)
    cnt := 0
    m := 1 << uint(i)
    for _, a := range MA {
      k1 := Search(MB, m - a)
      k2 := Search(MB, 2 * m - a)
      k3 := Search(MB, 3 * m - a)
      k4 := Search(MB, 4 * m - a)
      cnt += k4 - k3 + k2 - k1
    }
    ans += (cnt % 2) * m
  }
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}

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

long long int turno;
const long long int MAX=3003;
long long int dp[MAX][MAX];
long long int arr[MAX];

long long int solve(long long int left, long long int right, long long int turno){
    if(dp[left][right]!=-1) return dp[left][right];
    if(left>right) return 0;
    if(turno==1){
        return dp[left][right]=max(arr[left]+solve(left+1, right, 0), arr[right]+solve(left, right-1, 0));
    }
    else return dp[left][right]=min(solve(left+1, right, 1)-arr[left], solve(left, right-1, 1)-arr[right]);
}

int main(void){
    long long int n;
    cin>>n;
    for(long long int i=0;i<n;i++) cin>>arr[i];
    memset(dp, -1, sizeof dp);
    cout<<solve(0, n-1, 1)<<endl;

    return 0;
}


Measured memory_bytes: 70912
#include<iostream>
using namespace std;
int main()
{
    int n;float m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int sum=0;
  for(int i=0;i<n;i++)
  {
    sum+=a[i];
  }
  float z;
  z=1/(4*m);
  float k;
  k=sum*z;
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]>=k)
    {
      count++;
    }
  }
  if(count>=m)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    map<ll,ll>m;
    while(k--)
    {
        ll d;
        cin>>d;
        ll a[d];
        f(i,d)
            cin>>a[i];
        f(i,d)
        {
            m[a[i]]++;
        }
    }
    ll c=0;
    for(ll i=1;i<=n;i++)
        if(m[i]==0)
            c++;
    cout<<c;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int s[n];
    long long count = 0;
    int z = 101;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        count += s[i];
        if (s[i] % 10 != 0)
        {
            z = min(z, s[i]);
        }
    }
    if (z == 101)
    {
        cout << 0 << endl;
    }
    else
    {
        if (count % 10 == 0)
        {
            cout << count - z << endl;
        }
        else
        {
            cout << count << endl;
        }
    }
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

struct union_find {
	vector<int> uf;

	union_find(int n):uf(n, -1) {}

	int find(int x) {
		return uf[x] < 0 ? x : uf[x] = find(uf[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if(x == y) return;

		if(uf[x] > uf[y]) swap(x, y);
		else if(uf[x] == uf[y]) --uf[x];

		uf[y] = x;
	}

	int number_of_sets() const {
		return count_if(begin(uf), end(uf), [](int x) { return x < 0; });
	}
};

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

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

	bool edge = false;
	vector<vector<int>> hor(h + 1), ver(w + 1);

	for(int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;

		hor[y].emplace_back(i);
		ver[x].emplace_back(i);
		if(x == 1 || y == 1 || x == w || y == h) edge = true;
	}

	union_find uf(n);
	for(const auto &vec : hor) {
		REP(i, 1, vec.size()) {
			uf.unite(vec[i], vec[i - 1]);
		}
	}

	for(const auto &vec : ver) {
		REP(i, 1, vec.size()) {
			uf.unite(vec[i], vec[i - 1]);
		}
	}

	const int S = uf.number_of_sets();
	const int ans = (S == 1 ? n - 1 : n + S - 1 - edge);
	cout << ans << endl;

	return EXIT_SUCCESS;
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 10;
int n, m, ans, k[MAXN + 5], p[MAXN + 5], a[MAXN + 5], s[MAXN + 5][MAXN + 5];

inline bool judge() {
	for (int cnt, i = 1; i <= m; ++i) {
		cnt = 0;
		for (int j = 1; j <= k[i]; ++j)
			if (a[s[i][j]]) ++cnt;
		if ((cnt & 1) != p[i]) return 0;
	}
	return 1;
}

void dfs(int x) {
	if (x == n) {
		if (judge()) ++ans;
		return;
	}
	a[x + 1] = 0;
	dfs(x + 1);
	a[x + 1] = 1;
	dfs(x + 1);
}

int main() {
	read(n), read(m);
	for (int i = 1; i <= m; ++i) {
		read(k[i]);
		for (int j = 1; j <= k[i]; ++j)
			read(s[i][j]);
	}
	for (int i = 1; i <= m; ++i) read(p[i]);
	dfs(0);
	write(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
S = input()
print(S + 's' if S[-1] != 's' else S + 'es')


Measured memory_bytes: 10196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
    int n;
    cin >> n;
    VI a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    int r = 0;
    int now = 0;
    rep(l, n) {
        while(r < n && (now & a[r]) == 0) {
            now ^= a[r];
            r++;
        }
        ans += r - l;
        now ^= a[l];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4056
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (long int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long int N;
    cin>>N;
    vector<vector<long int> > A(3,vector<long int>(N));
    rep(i,3){
        rep (j,N) cin>>A[i][j];
    }
    rep(i,3) sort(A[i].begin(),A[i].end());
    long int n=0;
    long long ans=0;
    rep (i,N){
        while (n<N && A[1][n]<A[2][i]){
            auto it=lower_bound(A[0].begin(),A[0].end(),A[1][n]);
            n++;
            long int nn=it-A[0].begin();
            ans+=nn*(N-i);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3328
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = (int("".join(x))
               for x in product("753", repeat=i + 1)
               if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3824
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + A - 1) / A
	}

	sort.Sort(byX(XH))
	result := 0
	damage := 0
	q := make([]t, 0)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		for len(q) != 0 {
			if x <= q[0].X {
				break
			}
			damage -= q[0].H
			q = q[1:]
		}
		h -= damage
		if h <= 0 {
			continue
		}
		result += h
		damage += h
		q = append(q, t{x + 2*D, h})
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 12928
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
#include <atcoder/dsu>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int n, q; std::cin >> n >> q;
    atcoder::dsu uf(n);
    while(q--){
        char c; int u, v; std::cin >> c >> u >> v;
        if(c == '0') uf.merge(u, v);
        else{
            if(uf.same(u, v)) std::cout << '1' << '\n';
            else std::cout << '0' << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3832
a = int(input())
b = 2#int(input())
x = list(map(int, input().split()))
dp = [0]+[10**10]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
    if i<a-b:
        for di in range(1,b+1):
            dp[i+di] = min(dp[i+di],dp[i]+abs(h-x[i+di]))
    elif i <=a-b:
        dp[i+1] =min(dp[i+1],dp[i]+abs(h-x[i+1]))
#print(dp)
print(dp[a-1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main()
{
    ll h, w;
    cin >> h >> w;
    ll sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--;
    sx--;
    gy--;
    gx--;
    vector<vector<char>> s(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> s[i][j];

    deque<P> que;
    que.push_front({sy, sx});
    vector<vector<ll>> dist(h, vector<ll>(w, INF));
    dist[sy][sx] = 0;

    while(que.size()){
        P now = que.front();
        que.pop_front();

        //隣接マスへの移動
        for(ll dy=-1;dy<=1;dy++){
            for(ll dx=-1;dx<=1;dx++){
                if (dy == 0 && dx == 0)
                    continue;
                if(dy * dx != 0)
                    continue;

                ll ny = now.fi + dy, nx = now.se + dx;
                if (!(0 <= ny && ny < h && 0 <= nx && nx < w))
                    continue;
                if (s[ny][nx] == '#')
                    continue;

                if (dist[ny][nx] > dist[now.fi][now.se]){
                    dist[ny][nx] = dist[now.fi][now.se];
                    que.push_front({ny, nx});
                }
            }
        }

        //魔法での移動
        for(ll dy=-2;dy<=2;dy++){
            for(ll dx=-2;dx<=2;dx++){
                if (dy == 0 && dx == 0) continue;

                ll ny = now.fi + dy, nx = now.se + dx;
                if (!(0 <= ny && ny < h && 0 <= nx && nx < w))
                    continue;
                if (s[ny][nx] == '#')
                    continue;

                if(dist[ny][nx] > dist[now.fi][now.se] + 1){
                    que.push_back({ny, nx});
                    dist[ny][nx] = dist[now.fi][now.se] + 1;
                }
                
            }
        }
    }

    /*rep(i,h){
        rep(j,w){
            if(dist[i][j]!=INF) cout<<dist[i][j]<<" ";
            else cout<<-1<<" ";
        }
        cout<<endl;
    }*/

    if (dist[gy][gx] != INF)
        cout << dist[gy][gx] << endl;
    else
        cout << -1 << endl;

    return 0;
}

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

using namespace std;

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

    vector<int> h(n), dp(n, 2e9);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

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

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int LLI;

int main()
{
	int n;
	cin >> n;
	
	LLI ans[n], sum = 0;
	for(int i = 0; i < n; i++)
		cin >> ans[i];
	sort(ans,ans+n);
	
	
	for(int i = 0; i < n-2; i++)
		for(int j = i+1; j < n-1; j++)
			for(int k = j+1; k < n; k++)
				if( ans[i] + ans[j] > ans[k] and ans[i] != ans[j] and ans[j] != ans[k] )
					sum++;
	cout << sum;
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int gcd(int,int);

int main(){
	int k;
	cin>>k;
	int sum=0;
	for(int l=1;l<=k;l++)
	{
		for(int m=1;m<=k;m++)
		{
			for(int n=1;n<=k;n++)
			{
				int gcd1 = gcd(l,m);
				int gcd2 = gcd(gcd1,n);
				sum+=gcd2;
			}
		}
	}
	cout<<sum;
	return 0;
}
int gcd(int x,int y)
{
	if(y <= 0)return x;
	else return gcd(y,x%y); 
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  map<char, ll> m;
  for (ll i = 0; i < n; ++i) {
    string s;
    cin >> s;
    m[s[0]]++;
  }

  string s = "MARCH";
  ll ans = 0;
  for (ll i = 0; i < s.size(); ++i) {
    for (ll j = i+1; j < s.size(); ++j) {
      for (ll k = j+1; k < s.size(); ++k) {
        ans += m[s[i]] * m[s[j]] * m[s[k]];
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

void setIO(string name)
{
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //setIO("");
    ll n, k;
    cin >> n >> k;
    if(n>=k)
    {
        cout << min(k-n%k, n%k);
    }
    else
    {
        cout << min(n, k-n);
    }


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int cnt;
    char s[200010];
    char t[200010];
    fgets(s, sizeof(s), stdin);
    fgets(t,sizeof(t),stdin);
    int len = strlen(s);
    cnt=0;
    for(int i = 0; i < len; i++){
        if(s[i]!=t[i]){
            s[i]=t[i];
            cnt++;
            }
    }
    printf("%d\n",cnt);
    return 0;
}

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

int main(){
  int N, M, C;
  int i, j;
  
  cin >> N >> M >> C;
  
  signed int A[N][M];
  int B[M];

  
  for(i=0; i < M; ++i){
    cin >> B[i];
  }
  
  for (i=0;i<N; ++i){
	for (j=0;j<M; ++j){
      cin >> A[i][j];
    }
   }  
  
  signed int lin_sum = 0;
  int solve_num = 0;
  
  
  for (i=0; i < N; ++i){
  	for (j=0; j < M; ++j){
  	  lin_sum += A[i][j] * B[j];
    }
      lin_sum += C;
  
    if (lin_sum > 0){
  	  solve_num += 1;
  	}
      lin_sum = 0;
  }
  
  cout << solve_num << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    vector<int> v;
    for (int i = 0; i < 5; i++) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    for (int i = 0; i < 5; i++) {
        if (v[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

bool es, ee, en, ew;

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

	string yes = "Yes";
	string no = "No";

	rep(i, S.size()) {
		if (S[i] == 'S') es = true;
		if (S[i] == 'E') ee = true;
		if (S[i] == 'N') en = true;
		if (S[i] == 'W') ew = true;
	}

	if (en && !es) {
		cout << no << endl;
	} else if (es && !en) {
		cout << no << endl;
	} else if (ew && !ee) {
		cout << no << endl;
	} else if (ee && !ew) {
		cout << no << endl;
	} else {
		cout << yes << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
inline void read(int &x){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	x=s*w;
	return ;
}
inline int gcd(int a,int b){
	if(!b||!a) return max(a,b);
	if(a%b==0) return b;
	return gcd(b,a%b);
}
int n,k,a[100100];
/*
如果a1~an=k或者将|ai-aj|加进去数列中,在过程中持续做上述相减操作,能得到k输出possible否则impossible 
对于两个数x,y将他们不断相减,取绝对值,再让这个绝对值也与他们相减,类似于辗转相减法,一定能得到gcd(x,y),并且gcd(x,y)~max(x,y)中gcd(x,y)的所有倍数都能得到
也就是说设gcd(a1,a2,...,an)=p,ai=si*p,那么无论这些数怎么减显然减出来得数的绝对值一定是p的倍数,那么如果k>=p&&k<=max(a1,a2,...,an)且k%p==0那么cout<<impossible 
*/
int main(){
	read(n),read(k);
	int maxx=0,x=0;
	for(int i=1;i<=n;i++){
		read(a[i]);
		x=gcd(x,a[i]);
		maxx=max(maxx,a[i]);
	}
	if(k>=x&&k<=maxx&&k%x==0) cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        Arrays.sort(a);
        int i = 0;
        long ans = 0;
        while (i < n) {
            long x = a[i];
            int j = 0;
            while (i + j < n && a[i + j] == x) {
                j++;
            }
            if (j > x) {
                ans += j - x;
            } else if (j < x) {
                ans += j;
            }
            i += j;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 58692
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double

#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}

typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const ll mod =1e9+7;
const ll maxn=1e5+10;

int main()
{ 

   IOS
  
  ll n;
  cin>>n;
  vector<pair<double,pair<double,double>> >a(n);
  double temp=0;
  double f[10];
  f[0]=1.0;
  for(ll i=1;i<=n;i++)
    f[i]=f[i-1]*i;
  for(ll i=0;i<n;i++)
  {
    a[i].ff=i;
    cin>>a[i].ss.ff>>a[i].ss.ss;
  }
  do{
    for(ll i=1;i<a.size();i++)
    {
      temp+=sqrt((a[i].ss.ff-a[i-1].ss.ff)*(a[i].ss.ff-a[i-1].ss.ff)+(a[i].ss.ss-a[i-1].ss.ss)*(a[i].ss.ss-a[i-1].ss.ss));
    }

  }while(next_permutation(a.begin(),a.end()));
  temp/=f[n];
  cout<<setprecision(15)<<fixed<<temp<<endl;
  

}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

enum Tenki
{
    Sunny,
    Cloudy,
    Rainy
};

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

    cout << (N * 800) - (N / 15) * 200 << endl;
}

Measured memory_bytes: 256