akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE ScopedTypeVariables #-}

import Data.List

main :: IO ()
main = do
    c1 :: [Int] <- map read . words <$> getLine
    c2 :: [Int] <- map read . words <$> getLine
    c3 :: [Int] <- map read . words <$> getLine
    let c :: [[Int]] = [c1, c2, c3]
    let a1 :: Int = 10000
    let [b1, b2, b3] :: [Int] = map (subtract a1) c1
    let a2 :: Int = head c2 - b1
    let a3 :: Int = head c3 - b1
    if c2 !! 1 == a2 + b2 && c2 !! 2 == a2 + b3 && c3 !! 1 == a3 + b2 && c3 !! 2 == a3 + b3
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 508
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut seq = vec![0; n];
    let mut ans = 0;
    for i in 0..n {
        seq[i] = read();
        let mut v = seq[i];
        while v % 2 == 0 {
            v /= 2;
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, t;
  std::cin >> n >> t;
  vvl ab = vv(n+1, 2, 99999999, ll);
  for(int i=0;i<n;i++) std::cin >> ab[i+1][0] >> ab[i+1][1];
  vvl dp = vv(3001, 3001, 0, ll);
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());
  for(int i=1;i<=n;i++){
    for(int j=1;j<=t;j++){
      dp[i][j] = max({dp[i][j], dp[i-1][j], dp[i][j-1]});
      if(j==1) dp[i][1] = max({dp[i][0], dp[i][1], ab[i][1]});
      if(j>=ab[i][0]){
        dp[i][j] = max(dp[i][j], dp[i-1][j-ab[i][0]]+ab[i][1]);
      }
    }
  }
  std::cout << dp[n][t] << '\n';
  return 0;
}


Measured memory_bytes: 70912
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val, class Compare>
struct ConvexHullTrick {
    deque<pair<Val, Val> > lines;
    Compare comp;
    ConvexHullTrick() :comp(Compare()) {
    }
    void addLine(Val slope, Val constant) {
        pair<Val, Val> line(slope, constant);
        int n;
        while ((n = (int)lines.size()) >= 2) {
            Val a1, a2, a3, b1, b2, b3;
            tie(a1, b1) = lines[n - 2];
            tie(a2, b2) = lines[n - 1];
            tie(a3, b3) = line;
            if ((a1 - a2)*(b3 - b1) >(a1 - a3)*(b2 - b1))break;
            else lines.pop_back();
        }
        lines.push_back(line);
    }
    Val query(Val x) {
        while ((int)lines.size() >= 2 && comp(f(x, lines[1]), f(x, lines[0]))) {
            lines.pop_front();
        }
        return f(x, lines[0]);
    }
    Val f(Val x, pair<Val, Val> line) {
        return x * line.first + line.second;
    }
};

void solve() {
    int N;
    ll C;
    cin >> N >> C;
    vll H(N);
    ConvexHullTrick<ll, less<ll>> cht;
    
    rep(i, N) {
        cin >> H[i];
    }

    ll f = 0;
    cht.addLine(-2 * H[0], H[0] * H[0]);

    for (int i = 1; i < N; ++i) {
        f = cht.query(H[i]) + H[i] * H[i] + C;
        cht.addLine(-2 * H[i], f + H[i] * H[i]);
    }
    cout << f << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 4096
import numpy as np
 
H,W = map(int,input().split())
MAP = []
for _ in range(H):
    tmp = tuple(input())
    MAP.append(tmp)
 
MAP = np.array(MAP)
L = []
for i in range(H):
    if all(MAP[i,:] == '.'):
        L.append(i)
 
MAP = np.delete(MAP,L,0)
L = []
for i in range(W):
    if all(MAP[:,i] == '.'):
        L.append(i)
 
MAP = np.delete(MAP,L,1)
for m in MAP:
    print(''.join(m))


Measured memory_bytes: 12504
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  string s;cin>>s;
  int k;cin>>k;
  int n=(int)s.length();
  vector<int> sub(n);
  vector<char> ans(n);
  rep(i,n){
    sub[i]='z'-s[i]+1;
    if(sub[i]<=k&&s[i]!='a'){
      k-=sub[i];
      ans[i]='a';
    }
    else{
      ans[i]=s[i];
    }
  }
  k%=26;
  ans[n-1]+=k;
  rep(i,n){
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import deque

N = int(input())
c = list(input())

red = deque()
white = deque()

for i in range(len(c)):
    if c[i] == 'R':
        red.append(i)
    else:
        white.append(i)

ans = 0

while red and white:
    r = red.pop()
    w = white.popleft()
    if r < w:
        break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 81876
#include <stdio.h>
int main (void)
{
  int n,x,i,min,s;
  min=100000;
  scanf("%d %d",&n,&x);
  int m[n];
  
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&m[i]);
    x=x-m[i];
    if(min>m[i])
      min=m[i];
  }
  
  s=n+x/min;
  printf("%d",s);
}

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 6013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
ld dp[MAXN], tdp[MAXN];
ld ans;

int32_t main()
{
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(10);
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	dp[N] = 1.0;
	FOR(i, 0, N)
	{
		ld p; cin >> p;
		FOR(j, 0, 2 * N + 1)
		{
			tdp[j - 1] += dp[j] * (1.0 - p);
			tdp[j + 1] += dp[j] * (p);
		}
		FOR(j, 0, 2 * N + 1)
		{
			dp[j] = tdp[j];
			tdp[j] = 0;
		}
	}
	FOR(i, N, 2 * N + 1) ans += dp[i];
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;

signed main()
{
    cin >> n;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    int ans = 0;
    int temp = 0;

    rep1(i, n)
    {
        if (h[i - 1] >= h[i])
        {
            temp++;
            //cout << temp << "  ";
        }
        else
        {
            ans = max(ans, temp);
            temp = 0;
        }
    }

    ans = max(ans, temp);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	int a, b;
	cin >> a >> b;

	if (a - b >= 0) {
		cout << a - b << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

    vector <int> V(3);
    cin >> V[0] >> V[1] >> V[2];
    sort(V.begin(), V.end());

    int ans = 0;

    int d = (V[2] - V[0]) / 2;
    ans += d;
    V[0] += 2 * d;
    int e = (V[2] - V[1]) / 2;
    ans += e;
    V[1] += 2 * e;

    if (V[0] == V[2] && V[1] == V[2]){
    }else if(V[0] != V[2] && V[1] != V[2]){
        ans += 1;
    }else{
        ans += 2;
    }
    
    cout << ans << endl;

    return 0;
}

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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S[2];
vec v;

string ans;

void solve(){
  // main algorithm
  if(S[0].size() <= S[1].size()) {
    for (int i = 0; i < S[0].size(); ++i)
    {
      ans += S[0][i];
      ans += S[1][i];
    }
    if (S[0].size() != S[1].size())
    {
      ans += S[1].back();
    }
  }
  else {
    for (int i = 0; i < S[1].size(); ++i)
    {
      ans += S[0][i];
      ans += S[1][i];
    }
    ans += S[0].back();
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> S[0] >> S[1];
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

	vector<long long> v;
	queue<long long> q;
	for (int x = 1; x <= 9; ++x) {
		q.push(x);
	}
	while ((int)v.size() < K) {
		auto x = q.front();
		q.pop();
		v.push_back(x);
		auto y = x % 10;
		if (0 < y) {
			q.push(10 * x + y - 1);
		}
		q.push(10 * x + y);
		if (y < 9) {
			q.push(10 * x + y + 1);
		}
	}
	cout << v[K - 1] << endl;
}


Measured memory_bytes: 2548
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e10
#define EPS 1e-10
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main(){
  int n;
  while(cin>>n,n){
    bool gem[21][21] = {false};
    rep(i,n){
      int x, y;
      cin >> x >> y;
      gem[x][y] = true;
    }
    int m, cnt = 0;
    int rx = 10, ry = 10;
    cin >> m;
    rep(i,m){
      char d;
      int l;
      cin >> d >> l;
      if(d=='N'){
	while(l--){
	  ry++;
	  if(gem[rx][ry]){
	    cnt++;
	    gem[rx][ry] = false;
	  }
	}
      }else if(d=='E'){
	while(l--){
	  rx++;
	  if(gem[rx][ry]){
	    cnt++;
	    gem[rx][ry] = false;
	  }
	}
      }else if(d=='S'){
	while(l--){
	  ry--;
	  if(gem[rx][ry]){
	    cnt++;
	    gem[rx][ry] = false;
	  }
	}
      }else if(d=='W'){
	while(l--){
	  rx--;
	  if(gem[rx][ry]){
	    cnt++;
	    gem[rx][ry] = false;
	  }
	}
      }
    }
    if(cnt==n) cout << "Yes\n";
    else cout << "No\n";
  }
}

Measured memory_bytes: 1124
def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt

def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt

n = int(input())
S = list(map(int, input().split()))
cnt = merge_sort(S, 0, n)
print(*S)
print(cnt)


Measured memory_bytes: 61656
#include<iostream>

int main ()
{
    int n;
    int five_count = 0;
    int seven_count = 0;
    for (int i = 0; i < 3; ++i) {
        std::cin >> n;
        switch (n){
            case 5:
            five_count++;
            break;
            case 7:
            seven_count++;
            break;
        }
    }
    if (five_count == 2 && seven_count == 1) {
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

unsigned long func(unsigned long h, unsigned long l){
    unsigned long a = h%l;
    while(a != 0){
        h = l;
        l = a;
        a = h%l;
    }
    return l;
}

unsigned long sub_func(unsigned long x){
    unsigned long c = 0;
    for(unsigned long i=2; i*i<=x; i++){
        if(x%i == 0){
            c++;
            while(x%i == 0){
                x = x/i;
            }
        }
    }
    if(x>1){
        c++;
    }

    return c;
}

int main(){
    unsigned long a, b;
    scanf("%lu%lu", &a, &b);
    unsigned long h, l, g;
    if(a>b){
        h = a;
        l = b;
    }else{
        h = b;
        l = a;
    }
    g = func(h, l);
    printf("%lu", sub_func(g) + 1);

    return 0;
}

Measured memory_bytes: 128
n = gets.strip.to_i - 1
bars = gets.strip.split(' ').map(&:to_i)
max_count = 0
count = 0
n.times do |i|
  if bars[i] >= bars[i + 1]
    count += 1
    max_count = count if count > max_count
  else
    count = 0
  end
end

puts max_count

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;
typedef long long ll;


/* constant */
const ll inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}




signed main(){

    int a, b;
    cin  >> a >> b;
    cout << a - 1 + (a <= b) << endl;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5100+10;
const ll inf = 1e9+7;
int n,m,q;
int a[maxn],b[maxn],c[maxn],d[maxn];
int ans[maxn],sum=0;
void dfs(int x,int xia) {
    if(x==n+1) {
        int p = 0;
        for(int i=1; i<=q; i++) {
            if(ans[b[i]]-ans[a[i]]==c[i])
                p+=d[i];
        }
        sum=max(p,sum);
        return ;
    }
    for(int i=xia;i<=m;i++){
        ans[x]=i;
        dfs(x+1,i);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin>>n>>m>>q;
    for(int i=1; i<=q; i++)
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(1,1);
    cout<<sum<<endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;



void solve() {
  ll n; cin >> n;
  ll cnt[n + 5];
  ms(cnt, 0);
  f1r(i, 1, 105) f1r(j, 1, 105) f1r(k, 1, 105) {
    ll v = i * i + j * j + k * k + i * k + i * j + j * k;
    if (v <= n) ++cnt[v];
  }
  f1r(i, 1, n + 1) cout << cnt[i] << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3692
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = S()

if N == "ABC":
    print("ARC")
else:
    print("ABC")

Measured memory_bytes: 27092
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;



int main(){
    int H,W;
    cin >> H >> W;
    char A[1000][1000];
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }
    
    queue< pair<int,int> > q;
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j]=='#'){
                q.push(make_pair(i,j));
            }
        }
    }

    int num[1000][1000];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j]=='#'){
                num[i][j]=0;
            }else{
                num[i][j]=-1;
            }
        }
    }
    
    while(!q.empty()){
        int tempi=q.front().first;
        int tempj=q.front().second;
        if(tempi-1>=0){
            if(num[tempi-1][tempj]==-1){
                num[tempi-1][tempj]=num[tempi][tempj]+1;
                q.push(make_pair(tempi-1,tempj));
            }
        }
        if(tempj-1>=0){
            if(num[tempi][tempj-1]==-1){
                num[tempi][tempj-1]=num[tempi][tempj]+1;
                q.push(make_pair(tempi,tempj-1));
            }
        }
        if(tempi+1<H){
            if(num[tempi+1][tempj]==-1){
                num[tempi+1][tempj]=num[tempi][tempj]+1;
                q.push(make_pair(tempi+1,tempj));
            }
        }
        if(tempj+1<W){
            if(num[tempi][tempj+1]==-1){
                num[tempi][tempj+1]=num[tempi][tempj]+1;
                q.push(make_pair(tempi,tempj+1));
            }
        }
        
        q.pop();
    }
    
    int ans=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            ans=max(ans,num[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 13328
// D - Triangles
// 累積和による方法
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define rp(i,s,e) for(ll i=(s);i<(e);++i)

ll solve(int N, vl &L){
	vl csum(2000+10); //[length]<count>: 累積和: cumulative sum
	rp(i, 0, N) csum[L[i]]++;
	rp(i, 1, csum.size()) csum[i] += csum[i-1]; // その長さまでの棒の個数

	ll ans = 0;
	rp(ia, 0, N-1){
		rp(ib, ia+1, N){
			ll a = L[ia], b = L[ib];
			ll minL = abs(a - b), maxL = a + b;
			// |a-b| < c < a+b : cの範囲
			ans += csum[maxL-1] - csum[minL];
			if(minL<a && a<maxL) ans--; // cの範囲にaがあれば一本不要
			if(minL<b && b<maxL) ans--; // cの範囲にbがあれば一本不要
		}
	}
	return ans/3; //3本で△1つ
}

int main(){
	ll N; cin>>N;
	vl L(N); rp(i, 0, N) cin>>L[i];
	cout<< solve(N, L) <<endl;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base);

        base=(base*base);
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    string ans="";

    while(n>0)
    {
        li rem=n%26;

        if(rem==0)
        {
            ans+='z';
            n=n/26-1;
        }
        else
        {
            ans+=('a'+rem-1);
            n/=26;
        }
    }

    reverse(ans.B,ans.E);

    cout<<ans;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main () {
    array<int, 12> a{1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    cin >> x >> y;
    a[x - 1] == a[y - 1] ? cout << "Yes" : cout << "No";

}


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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();

        if (b % a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 22224
/*
/ ATcoder /
ID : lalit kumar
TASK : A
LANG : c++14
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

 string s;
 cin>>s;
 int n = (int)s.size();
 int a[26]={0};
 for(int i =0;i<n;i++)
 {
     a[s[i]-'a']++;
 }
if(a[0] && a[1] && a[2]) cout<<"Yes\n";
else cout<<"No\n";
 return 0;
}

Measured memory_bytes: 3584
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-03-01 21:01:06
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    vector<int> evec(3);
    vector<vector<int>> a(3, evec);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++)
        cin >> b[i];

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (b[k] == a[i][j]) {
                    a[i][j] = 0;
                }
            }
        }
    }

    // for (int i = 0; i < 3; i++) {
    //     for (int j = 0; j < 3; j++) {
    //         cout << a[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    int det = 0;
    for (int i = 0; i < 3; i++) {
        det = det + a[0][i] * ( a[1][(i+1)%3] * a[2][(i+2)%3] - a[1][(i+2)%3] * a[2][(i+1)%3]);
    }

    if (det == 0) {
        cout << "Yes" << endl;
    } else {
        if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] == 0) {
            cout << "Yes" << endl;
        } else if (a[2][0] == a[1][1] && a[2][0] == a[0][2] && a[2][0] == 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long 
#define F first
#define final 100000000
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
 
int main()
{
  string s,t;
  cin >> s >> t;ll count=0;
  for(ll i=0;i<s.length();i++)
  {
      if(s[i]!=t[i])
      {
          count++;
      }
  }
  cout << count << endl;
}

Measured memory_bytes: 3856
#include<stdio.h>

int main( )
{
    int n , num[500] , temp , a[500];
    int i , j , k ;
    scanf("%d" , &n);
    
    for( int i = 1 ; i <= n ; i++)
    {
         scanf("%d" , &num[i] );
         a[i] = num[i] ;
    }
   

    for(  i = 1 ; i <= n ; i++)
    {
        for(  j = 1 ; j < n ; j++)
        {
            if( a[j] > a[j+1] )
            {
                temp = a[j] ;
                a[j] = a[j+1] ;
                a[j+1] = temp ;
            }
        }
    }
    
    int count = 0 ;
    for( i = 1 ; i <= n ; i++)
    {
        if( a[i] == num[i] )
            continue ;
        else
            count++ ;
    }
    
    if( count==0 || count== 2)
        printf("YES\n");
    else 
        printf("NO\n");

   
    return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll mx=INT_MAX;
ll mn=INT_MIN;

int main()
{
    ll n;
    cin>>n;
    ll i,j;
    ll a[n][3];
    for(i=0;i<n;i++)
        for(j=0;j<3;j++)
            cin>>a[i][j];
    ll dp[n][3]={0};
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            if(j==0)
                dp[i][j]=max(dp[i-1][j+1]+a[i][j],dp[i-1][j+2]+a[i][j]);
            else if(j==1)
                dp[i][j]=max(dp[i-1][j+1]+a[i][j],dp[i-1][j-1]+a[i][j]);
            else
                dp[i][j]=max(dp[i-1][j-1]+a[i][j],dp[i-1][j-2]+a[i][j]);
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}

Measured memory_bytes: 4992
class BIT
	def initialize n
		@a = [0]*n
	end

	def [] i
		i += 1
		s = 0
		while 0 < i
			s += @a[i-1]
			i -= i&-i
		end
		return s
	end

	def []= i,n
		d = n-self[i]
		return unless 0 < d # allow increasing update only
		i += 1
		until @a.size < i
			@a[i-1] += d
			i += i&-i
		end
	end
end

N,Q = gets.split.map(&:to_i)
bk = (N-2)**2
bb = BIT.new(N-1),BIT.new(N-1)
Q.times{
	b,x = gets.split.map(&:to_i).then{|b,x| [b-1,N-x] }
	y = bb[1-b][x]
	bk -= N-2-y
	bb[b][y] = x
}
p bk


Measured memory_bytes: 17472
using System;

class Program
{
    static void Main(string[] args)
    {
        int[, ,] array = new int[4, 3, 10];
        int n, b, f, r, v;

        //配列初期化
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    array[i, j, k] = 0;
                }
            }
        }

        //入居件数受け取り
        string str1 = Console.ReadLine();
        n = int.Parse(str1);

        //入居詳細受け取り、入居人数を配列に追加
        for (int h = 0; h < n; h++)
        {
            string[] str2 = Console.ReadLine().Split(' ');
            b = int.Parse(str2[0]);
            f = int.Parse(str2[1]);
            r = int.Parse(str2[2]);
            v = int.Parse(str2[3]);

            switch (b)
            {
                case 1:
                    array[b - 1, f - 1, r - 1] += v;
                    break;
                case 2:
                    array[b - 1, f - 1, r - 1] += v;
                    break;
                case 3:
                    array[b - 1, f - 1, r - 1] += v;
                    break;
                case 4:
                    array[b - 1, f - 1, r - 1] += v;
                    break;
            }
        }
            
        //入居人数出力
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    if (array[i, j, k] == 0)
                    {
                        Console.Write(" 0");
                    }else if(array[i, j, k] != 0)
                        Console.Write(" " + array[i, j, k]);
                }
                Console.WriteLine("");
            }
            if(i < 3)
            {
                Console.WriteLine("####################");
            }
            else
            {
                break;
            }
        }
    }
}


Measured memory_bytes: 9196
s = input()
se = s.replace('x','')
if se != se[::-1]:
    print(-1)
else:
    xc = []
    now = 0
    for i in s:
        if i == 'x':
            now += 1
        else:
            xc.append(now)
            now = 0
    xc.append(now)
    ans = 0
    for i in range(len(xc)//2):
        ans += abs(xc[i]-xc[-i-1])
    print(ans)


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long
#define xll __int128
#define fo(i,n) for(int i=0;i<n;i++)
#define rfo(i,n) for(int i=n-1;i>=0;i--)
#define Fo(i,q,n) for(int i=q;i<n;i++)
#define rFo(i,q,n) for(int i=n-1;i>=q;i--)
#define fO(i,n,k) for(int i=0;i<n;i+=k)
#define FO(i,q,n,k) for(int i=q;i<n;i+=k)
#define zero(a,n) memset(a,0,sizeof(a[0])*n)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
using namespace std;
const int MOD=1000000007;
void print(){cout <<endl;}
template <typename T, typename... Types> 
void print(T var1, Types... var2){cout << var1 << " " ;print(var2...) ;}
//ceil of a/b
template <typename T>
T fceil(T a,T b){return (T)(a+b-1)/b;}
template <typename T>
void printvec(vector<T> v){ for(int i=0;i<(int)v.size();i++){ cout<<v[i]<<" ";} cout<<endl;}
template <typename T>
void printarr(T a[],int n){ for(int i=0;i<n;i++){ cout<<a[i]<<" ";} cout<<endl;}
//const int N=2e5;
//int arr[N+1];

 
int main(){
	int n;
	cin>>n;
	int x,y;
	vector<int> val1,val2;
	fo(i,n){
		cin>>x>>y;
		val1.pb(x+y);
		val2.pb(x-y);
	}
	sort(val1.begin(),val1.end());
	sort(val2.begin(),val2.end());
	cout<< max(val1[n-1]-val1[0],val2[n-1]-val2[0])<<endl;
	return 0;
}






/*NOTE: Take MOD after sorting and not before sorting!*/


Measured memory_bytes: 4964
n, m = map(int, input().split())
h = list(map(int, input().split()))

edge = [[] for _ in range(n)]

## 接している各頂点をまとめる
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

cnt = 0

for node in range(n):
    good = True 
    for neighbor in edge[node]:
        if h[node] <= h[neighbor]:
            good = False
            
    if good:
        cnt += 1

print(cnt)

Measured memory_bytes: 29516
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  double R; cin >> R;
  printf("%.10lf\n", 2 * R * PI);
  return 0;
}


Measured memory_bytes: 3780
N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
  a[i] = int(input())
 
c = 0
x = 1
while(x != 2):
  nex = a[x-1]
  if not nex:
    c = -1
    break
  else:
    c += 1
    a[x-1] = 0
  x = nex
 
print(c)

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N,M;
    cin >> N >> M;
    vector<string> a(N),b(M);
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }

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

    bool ans = false;
    for (int i = 0; i < N; i++){
        for (int k = 0; k < N; k++){
            if (i + M <= N && k + M <= N){
                bool match = true;
                for (int p = 0; p < M; p++){
                    for (int r = 0; r < M; r++){
                        if (a[i+p][k+r] != b[p][r]){
                                match = false;
                        }
                    }
                }
                if (match){
                    ans = true;
                }
            }
        }
    }
    if (ans){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if (S.at(0) == S.at(1)&&S.at(2)==S.at(3)&&S.at(0)!=S.at(2)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int a, b;
    cin >> a >> b;

    cout << ceil((double)(b - 1) / (double)(a - 1));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;

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

signed main() {
    ll n,k;
    cin>>n>>k;
    vector<pl> r(n);
    rep(i,n)cin>>r[i].first>>r[i].second;
    sort(r.begin(),r.end());
    rep(i,n){
        k-=r[i].second;
        if(k<=0){
            cout<<r[i].first<<endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
S=input()
odd=set(S[0::2])
even=set(S[1::2])
odd_=['R','U','D']
even_=['L','U','D']
flag=0
for i in odd:
    if i not in odd_:
        flag=1
for i in even:
    if i not in even_:
        flag=1
print('Yes' if flag==0 else 'No')

Measured memory_bytes: 3064
N = int(input())
word1 = list(input())
word2 = list(input())
word3 = list(input())
count = 0

for i in range(N):
    if word1[i] == word2[i]:
        if word1[i] == word3[i]:
            count += 0
        elif word1[i] != word3[i]:
            count += 1
    elif word1[i] != word2[i]:
        if word1[i] == word3[i]:
            count += 1
        elif word1[i] != word3:
            if word2[i] == word3[i]:
                count += 1
            elif word2[i] != word3[i]:
                count += 2


print(count)


Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())

c = 0

m500 = min(X//500, A) #500円玉の最大個数
for i in range(m500+1):
  Y = X - i * 500
  m100 = min(Y//100, B) #100円玉の最大個数
  for j in range(m100+1):
    Z = Y - j * 100
    if Z <= C*50:
      c += 1

print(c)

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

class Program
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var B = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        int ans = 0;

        for(int i = 0; i < N ; i++)
        {
            if(i == 0)
            {
                ans = ans + B[0];
            }
            else if(i == N-1)
            {
                ans = ans + B[N-2];
            }
            else
            {
                ans = ans + Math.Min(B[i-1],B[i]);
            }
        }
        Console.WriteLine(ans);
    }
}


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

void nextYear(int idx, int x_i,int r, int D) {
    int x_i_1 = r * x_i - D;
    cout << x_i_1 << endl;

    if (idx + 1 == 2010) {
        return;
    }

    nextYear(idx +1, x_i_1, r, D);
}

int main() {
    int r, d, x_2000; cin >> r >> d >> x_2000;
    nextYear(2000, x_2000, r, d);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
  public static void main(String agrs[])
  {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    double a = in.nextDouble();
    double b = in.nextDouble();
    out.println((long)(a * b));
    out.close();
  }
}

Measured memory_bytes: 37344
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        long n = sc.nextLong();
        long k = sc.nextLong();
        n = n % k;
        if (n == 0) {
            System.out.println(0);
            return;
        }
        long next = Math.abs(n - k);
        long min = n;
        while (n != next) {
            n = Math.abs(n - k);
            next = Math.abs(Math.abs(next - k) - k);
            min = Math.min(min, n);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using ll = long long;

using namespace std;

const int inf = 1e6 + 7;

int main(){	
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	
	vector<ll> b(n);
	for(int i = 0; i < n; i++){
		b[i] = (a[i] - (i + 1));
	}
	
	sort(b.begin() , b.end());
	
	ll c;
	if(n % 2 == 1){
		c = b[n / 2];
	}else{
		c = b[n / 2] + b[n / 2 - 1];
		c /= 2;
	}
	
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += abs(b[i] - c);
	}
	cout << ans << endl;
	return 0;
}
 

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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

vector<int> getNext(vector<int> v)
{
    int keta = v.size();
    if(keta==1)
    {
        if(v[0]<9)
        {
            v[0]++;
            return v;
        }
        else
        {
            v[0]=1;
            v.push_back(0);
            return v;
        }
    }
    
    for (int nowKeta = keta - 2; nowKeta >= 0; nowKeta--)
    {
        if(v[nowKeta]>=v[nowKeta+1] && v[nowKeta+1]<9) //xx32, xx33 mitaina
        {
            v[nowKeta+1]++;
            for (int sitanoKeta = nowKeta+2; sitanoKeta < keta; sitanoKeta++)
            {
                v[sitanoKeta]=max(0,v[sitanoKeta-1]-1);
            }
            return v;
        }
    }
    
    if(v[0]<9)
    {
        v[0]++;
        for (int i = 1; i < keta; i++)
        {
            v[i]=max(0,v[i-1]-1);
        }
        
        return v;
    }
    else
    {
        v[0]=1;
        for (int i = 1; i < keta; i++)
        {
            v[i]=0;
        }
        v.push_back(0);
        return v;
    }


}

void printV(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout<<v[i];
    }
    cout<<endl;
}

int main()
{
    ll k;
    cin>>k;
    vector<int> v;
    v.push_back(0);
    for (int i = 0; i < k; i++)
    {
        v=getNext(v);
//        cout<<i+1<<"\t";
//        printV(v);
    }
    printV(v);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

class BIT {
public:
  int n;
  VI dat;
  BIT(int n_) {
    n = n_;
    dat = VI(n+1, 0);
  }
  void add(int i, int x) {
    while (i <= n) {
      dat[i] += x;
      i += i & -i;
    }
  }
  int sum(int i) {
    int acc = 0;
    while (i > 0) {
      acc += dat[i];
      i -= i & -i;
    }
    return acc;
  }
};

string S;
deque<int> dq[26];

void solve() {
  BIT bit(S.size());
  REP (i, S.size()) {
    dq[S[i]-'a'].push_back(i+1);
    bit.add(i+1, 1);
  }
  int odd = 0;
  REP (i, 26) {
    if (dq[i].size() % 2) {
      odd += 1;
    }
  }
  if (odd >= 2) {
    cout << -1 << endl; return;
  }
  int n = S.size();
  int ans = 0;
  while (n >= 2) {
    int min_move = 1e7;
    int alph = -1;
    REP (i, 26) {
      if (dq[i].size() == 0) { continue; }
      int l = bit.sum(dq[i].front());
      int r = bit.sum(dq[i].back());
      int move = l + (n - 1 - r);
      if (move < min_move) {
        min_move = move;
        alph = i;
      }
    }
    ans += min_move;
    bit.add(dq[alph].front(), -1);
    bit.add(dq[alph].back(), -1);
    dq[alph].pop_front();
    dq[alph].pop_back();
    n -= 2;
  }
  cout << ans << endl;
}

signed main() {
  cin >> S;
  solve();
}


Measured memory_bytes: 3716
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0}; //次に行くところ
int dx[] = {0,1}; //上に同じ

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

  string s;
  char c;
  ll ans = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++){
    c = s[i];
    ans += c -'0';
    if (ans % 9 == 0){
      ans = 0;
    }
  }
  
  if (ans % 9 == 0){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3760