akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

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

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define ll long long

ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    ll K, ans = 0;
    cin >> K;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string N;cin>>N;
    if(N[0]==N[1] && N[1]==N[2]){
        cout<<"Yes"<<endl;
    }else if(N[2]==N[3] && N[1]==N[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3604
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
puts A.inject(0){|res,x| res.gcd(x)}

Measured memory_bytes: 9484
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
    
    string s, r;
    cin >> s >> r;
    
    s += s;
    if(s.find(r) != string::npos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    
}



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




int main(){

    int a,b,c;
    int max, min;

    max = 1;
    min = 100;
    
    scanf("%d%d%d",&a,&b,&c);
    
    
    
    if (max < a) {
        max = a;
    }
    
    if(max < b) {
        max = b;
    }

    if(max < c) {
        max = c;
    }
    
    if (min > a) {
        min = a;
    }
    
    if(min > b) {
        min = b;
    }
    
    if(min > c) {
        min = c;
    }

    
    printf("%d\n",max-min);
    
    
    
    return 0;
    
}


Measured memory_bytes: 128
#include <stdio.h>

/* out function */
void trace(int A[], int N){
    int i;
    for( i = 0; i < N; i++ ){
        if( i > 0) printf(" "); // single space to separate elments
        printf("%d", A[i]);
    }
    printf("\n");
}

/* insert sort (zero origin) */
void insertSort(int A[], int N){
    int j, i, v;
    for( i = 1; i < N; i++ ){
        v = A[i];
        j = i -1;
        while( j >= 0 && A[j] > v ){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }
}

/* main function */
int main(){
    int N, i, j;
    int A[100];

    scanf("%d", &N);
    for( i = 0; i < N; i++) scanf("%d", &A[i]);

    trace(A, N);
    insertSort(A, N);

    return 0;    
}


Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
#define st(p) ll p=0
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define pr2(m,n) cout<<m<<" "<<n<<endl
#define wh(t) ll t; cin>>t; while(t--)
#define arr(a,n) ll a[n]; fr(i,n) cin>>a[i]
#define fr(i,a) for(ll i=0LL;i<a;i++)
#define fab(i,a,b) for(ll i=a;i<=b;i++)
#define fba(i,a,b) for(ll i=b;i>=a;i--)
#define rf(i,a) for(ll i=a;i>=0LL;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 10000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define v1 vector<ll>v 
#define v2 vector<int>v
#define vp1 vector<pair<ll,ll>> vp
#define vp2 vector<pair<int,int>>vp
#define pb push_back
#define fs first
#define sd second

int main() 
{
    sup;
    in(n); in(w);
    ll v[n],wt[n],k[n+1][w+1];
    fr(i,n)
        cin>>wt[i]>>v[i];
    fr(i,n+1)
    {
        fr(j,w+1)
        {
            if(i==0 || j==0)
            k[i][j]=0;
            else if(wt[i-1]<=j)
            k[i][j]=max(v[i-1]+k[i-1][j-wt[i-1]],k[i-1][j]);
            else
            k[i][j]=k[i-1][j];
            
        }
    }
    pr(k[n][w]);
    return 0;
}



Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <functional>

int main(){
  int N;
  double v[52] = {};
  std::cin >> N;
  for(int i = 0; i < N; i++){
    std::cin >> v[i];
  }
  
  std::sort(v, v + N, std::less<double>());
  double result = (v[0] + v[1]) / 2.0;
  for(int i = 2; i < N; i++){
    result = (result + v[i]) / 2.0;
  }
  std::cout << result << std::endl;
  
  return 0;
}

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

typedef pair<int, int> pii;
const int N = 310, INF = 0x3f3f3f3f;
int n, m, q, arr[N], L, ans[N][N];
bool vis[N];
pii dp[N];
vector<pii> g[N];
int main()
{
	scanf("%d%d%d", &n, &m, &L);
	for (int i = 0; i < m; i++)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if (c <= L)
		{
			g[a].push_back(pii(b, c));
			g[b].push_back(pii(a, c));
		}
	}
	for (int s = 1; s <= n; s++)
	{
		static queue<int> q;
		while (!q.empty())
			q.pop();
		for (int i = 1; i <= n; i++)
			dp[i] = pii(INF, 0), vis[i] = 0;
		dp[s] = pii(0, L);
		q.push(s);
		vis[s] = true;
		while (!q.empty())
		{
			int u = q.front();
			q.pop();
			vis[u] = false;
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i].first, w = g[u][i].second;
				int tmp = dp[u].first + (w > dp[u].second), tmp2 = (w > dp[u].second ? L - w : dp[u].second - w);
				if (dp[v].first > tmp || (dp[v].first == tmp && dp[v].second < tmp2))
				{
					dp[v] = pii(tmp, tmp2);
					if (!vis[v])
						q.push(v), vis[v] = true;;
				}
			}
		}
		for (int i = 1; i <= n; i++)
			ans[s][i] = (dp[i].first == INF ? -1 : dp[i].first);
	}
	scanf("%d", &q);
	while (q--)
	{
		int s, t;
		scanf("%d%d", &s, &t);
		printf("%d\n", ans[s][t]);
	}
	return 0;
}

Measured memory_bytes: 2048
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize
    };
    let num = (1..std::usize::MAX).find(|i| i * i > n).unwrap() - 1;
    println!("{}", num * num);
}


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

int main() {
	long a,b,i,j;
	cin >> a >> b;
	
	vector<vector<int>> x(100,vector<int>(100));
	for(i=0; i<50; i++){
		for(j=0; j<100; j++){
			x[i][j]=0;
		}
	}
	for(i=50; i<100; i++){
		for(j=0; j<100; j++){
			x[i][j]=1;
		}
	}
	
	a--; b--;
	for(i=1; i<50; i+=2){
		for(j=1; j<100; j+=2){
			if(a>0){
				a--; x[i][j]=1;
			}
		}
	}
	for(i=51; i<100; i+=2){
		for(j=1; j<100; j+=2){
			if(b>0){
				b--; x[i][j]=0;
			}
		}
	}
	cout << 100 << ' ' << 100 << endl;
	for(i=0; i<100; i++){
		for(j=0; j<100; j++){
			if(x[i][j]==0){
				cout << '#';
			}else{
				cout << '.';
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

ll f(ll n) {return n * (n+1) / 2;}

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll r = n / i;
    ans += f(r) * i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3592
import itertools
import math


def distance():
    N = int(input())
    x_y = [tuple(map(int, input().split())) for _ in range(N)]
    combis = list(itertools.permutations(x_y, N))

    def euclid(p1, p2):
        return math.sqrt((pow((p1[0] - p2[0]), 2) + pow((p1[1] - p2[1]), 2)))
    result = 0
    for combi in combis:
        for i in range(len(combi)-1):
            result += euclid(combi[i], combi[i+1])
    print(float(result / len(combis)))


if __name__ == "__main__":
    distance()


Measured memory_bytes: 7972
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    double p[3][2];
    for(int i=0; i<3; i++)
      for(int j=0; j<2; j++)
	cin >>p[i][j];
    for(int i=1; i<3; i++)
      for(int j=0; j<2; j++)
	p[i][j]-=p[0][j];
    double m[2][2],det,im[2][2],x[2],s[2];
    for(int i=0; i<2; i++)
      for(int j=0; j<2; j++)
	m[i][j] = 2*p[i+1][j];
    for(int  i=0; i<2; i++)
      x[i] = p[i+1][0]*p[i+1][0]+p[i+1][1]*p[i+1][1];
    det = m[0][0]*m[1][1]-m[0][1]*m[1][0];
    im[0][0] = m[1][1]/det;
    im[0][1] = -m[0][1]/det;
    im[1][0] = -m[1][0]/det;
    im[1][1] = m[0][0]/det;
    for(int i=0; i<2; i++)
      s[i] = im[i][0]*x[0]+im[i][1]*x[1];
    printf("%.3lf %.3lf %.3lf\n",s[0]+p[0][0],s[1]+p[0][1],sqrt(s[0]*s[0]+s[1]*s[1]));
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c;cin>>a>>b>>c;
  int ans=3;
  if(a==b)ans--;
  if(a==c)ans--;
  if(b==c)ans--;
  if(ans==0)ans=1;
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

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

#define endl "\n"
#define mt make_tuple
#define mp make_pair

template <typename T1, typename T2>
bool umax(T1 &a, const T2&b) { return a < b ? a = b, 1 : 0;}
template <typename T1, typename T2> 
bool umin(T1 &a, const T2 &b) {return a > b ? a = b, 1 : 0;}
template <typename T>
T sqr(T a) {return a * a;}

mt19937 rng(20010709);
const int mod = 1000000007;
const int INF = 1000000001;

int n, dp[100005][3], cost[3];

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

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> cost[0] >> cost[1] >> cost[2];

        for (int cur = 0; cur < 3; cur++) {
            for (int pr = 0; pr < 3; pr++) {
                if (cur != pr)
                    umax(dp[i][cur], dp[i - 1][pr] + cost[cur]);
            }
        }
    }

    cout << *max_element(dp[n], dp[n] + 3) << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll N;
    cin >> N;
    ll A;
    vl B(N, 0);
    map<ll, ll> map;
    for(ll i=2; i<=N; i++){
        cin >> A;
        B.at(A-1) += 1;
    }

    for(int i=0; i<N; i++){
        cout << B.at(i) << endl;
    }
    
}

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

int main(){
    int a;
    
    int b;
    
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" <<endl;
    }
    if(a > b){
        cout << "a > b" <<endl;
    }
    if(a == b){
        cout << "a == b" <<endl;
    }
return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    int syoki = 0;
    rep(i, N-1){
        if(s[i] == s[i+1]) syoki++;
    }
    int ans = min(syoki+2*K, N-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

int main(){
    int N;
    scanf("%d",&N);
    
    float sum = 0;
    for(int i=0;i<N;i++){
        float x;
        scanf("%f",&x);
        sum += 1/x;
    }
    printf("%f",1/sum);
}

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a,b;
	cin >> a >> b;
	if(a < b){
		if(a == 1)P("Alice");
		else P("Bob");
	}else if(a > b){
		if(b == 1)P("Bob");
		else P("Alice");
	}else{
		P("Draw");
	}
}

int main() {
    solve();
    return 0;
}


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

vector<vector<int>> edge;

vector<int> ts;

void dfs(int par, int now) {
    ts.push_back(now);
    for (int nxt : edge[now]) {
        if (nxt != par) dfs(now, nxt);
    }
    return;
}

int main() {
    int N;
    cin >> N;
    edge.resize(N+1);
    
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(0, 1);
    
    if (N%2 == 1) {
        cout << "First\n";
        return 0;
    }
    
    vector<int> match(N+1, 0);
    for (int i = N-1; i >= 0; i--) {
        int a = 0, b = 0;
        for (int child : edge[ts[i]]) {
            if (match[child] == 1) a++;
            if (match[child] == 2) b++;
        }
        if (b == 0) {
            match[ts[i]] = 2;
        }else if (b == 1) {
            match[ts[i]] = 1;
        }else {
            cout << "First\n";
            return 0;
        }
    }
    cout << "Second\n";
    return 0;
}

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

const long long mod=998244353;
long long n, ans, dp[200003], farthest[200003], tree[1000000];
pair<long long, long long>robot[200003];


bool cmp(pair<long long, long long>a, pair<long long, long long>b){
	if (a.first<b.first) return true;
	if (a.first>b.first) return false;
	return a.second<b.second;
}

void build(long long l, long long r, long long v){
	if (l==r) tree[v]=farthest[l];
	else{
		long long mid=(l+r)/2;
		build(l,mid,v*2);
		build(mid+1,r,v*2+1);
		tree[v]=max(tree[v*2],tree[v*2+1]);
	}
}

long long query(long long l, long long r, long long lb, long long rb, long long v){
	if (r<lb || l>rb) return -1e9;
	if (l>=lb && r<=rb) return tree[v];
	long long mid=(l+r)/2;
	return max(query(l,mid,lb,rb,v*2),query(mid+1,r,lb,rb,v*2+1));
}

void update(long long l, long long r, long long v, long long target){
	if (l==r) tree[v]=farthest[l];
	else{
		long long mid=(l+r)/2;
		if (target<=mid) update(l,mid,v*2,target);
		else update(mid+1,r,v*2+1,target);
		tree[v]=max(tree[v*2],tree[v*2+1]);
	} 
}

void init(){
	for (int i=0;i<n;i++) farthest[i]=i;
	build(0,n-1,1);
}

int main(){
	cin >> n;
	init();
	for (int i=0;i<n;i++) cin >> robot[i].first >> robot[i].second;
	sort(robot,robot+n,cmp);
//	for (int i=0;i<n;i++) cout << "sorted--> " << robot[i].first << " " << robot[i].second << "\n";
	for (int i=n-1;i>=0;i--){
		long long l=i, r=n-1, tmp, far=robot[i].first+robot[i].second;
		while (l<=r){
			long long mid=(l+r)/2;
			if (robot[mid].first<far){
				tmp=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		farthest[i]=query(0,n-1,i,tmp,1);
		update(0,n-1,1,i);
	}
//	for (int i=0;i<n;i++) cout << farthest[i] << "\n";
	memset(dp,0,sizeof dp);
	dp[0]=1;
	for (int i=0;i<n;i++){
		dp[i+1]+=dp[i]; // kalau i remain
		dp[i+1]%=mod;
		dp[farthest[i]+1]+=dp[i]; // kalau i tidak remain
		dp[farthest[i]+1]%=mod;
	}
	cout << dp[n] << "\n"; 
}

Measured memory_bytes: 12288
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

struct edge {
	int to;
	int id;
};
 
vector<vector<edge>> tree;
int u, v;
vector<int> distT;
vector<int> distA;

void dfsT(int x, int p = -1, int d = 0){
  rep(i, sz(tree.at(x))) {
    distT.at(x) = d;
    if (tree.at(x).at(i).to == p) {
			continue;
    }
    dfsT(tree.at(x).at(i).to, x, d+1);
  }
}

void dfsA(int x, int p = -1, int d = 0){
  rep(i, sz(tree.at(x))) {
    distA.at(x) = d;
    if (tree.at(x).at(i).to == p) {
			continue;
    }
    dfsA(tree.at(x).at(i).to, x, d+1);
  }
}
  
int main(){
  int N;
  cin >> N;
  tree.resize(N);
  distT.resize(N);
  distA.resize(N);
  cin >> u >> v;
  u--;
  v--;
  vector<int> a(N - 1);
  vector<int> b(N - 1);
  rep(i, N - 1) {
		cin >> a.at(i) >> b.at(i);
		a.at(i)--;
		b.at(i)--;
		tree.at(a.at(i)).push_back({ b.at(i), i });
		tree.at(b.at(i)).push_back({ a.at(i), i });
  }
  dfsT(u);
  dfsA(v);
  int mx = 0;
  rep(i, N){
    if(distT.at(i) < distA.at(i)){
      chmax(mx, distA.at(i));
    }
  }
  cout << mx - 1 << endl;
}

Measured memory_bytes: 17024
# coding: utf-8
s = list(input())
yymm = False
mmyy = False
# MM

if int("".join(s[0:2])) in range(1,13):
    mmyy = True
if int("".join(s[2:4])) in range(1,13):
    yymm = True

#print(int("".join(s[0:2])), int("".join(s[2:4])))
#print(mmyy,yymm)
if yymm:
    if mmyy:
       print("AMBIGUOUS") 
    else:
        print("YYMM")
elif mmyy:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
//AtCoder ABC106 B - 105
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
//約数を列挙 O(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
    ll N; cin>>N;
    ll ans=0;
    for(ll i=1;i<=N;++i){
        if (i%2==1){
            auto tmp = divisor(i);
            if(tmp.size()==8) ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

vector<int> adj[MAXN+5], children[MAXN+5];
bool visited[MAXN+5];
int grundy[MAXN+5];

vector<int> dfs()
{
    ms(visited,false);
    stack<int> s;
    visited[0] = true;
    s.push(0);
    vector<int> node_order;

    while (!s.empty()) {
        int top = s.top(); s.pop();
        node_order.pb(top);
        iter(adj[top]) {
            if (!visited[*it]) {
                visited[*it] = true;
                children[top].pb(*it);
                s.push(*it);
            }
        }
    }
    return node_order;
}

int32_t main()
{
    #ifdef DEBUG
    freopen("D.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n;
    read(n);
    for0(i,n-1) {
        int u,v;
        read(u); read(v);
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    vector<int> node_order = dfs();
    printv(node_order);

    ms(grundy,0);
    for (int i=sz(node_order)-1; i>=0; i--) {
        int nd = node_order[i];
        iter(children[nd]) {
            grundy[nd] ^= 1+grundy[*it];
        }
    }
    printa(grundy,n)

    if (grundy[0] == 0)
        cout<<"Bob"<<endl;
    else
        cout<<"Alice"<<endl;
    return 0;
}


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

int main(){
	// sengen
	int a[4];
	char s[4];
	// nyuryoku
	cin >> s;
	for(int i=0;i<4;i++){
		a[i] = s[i] - '0';
	}
	// keisan
	int sum = 0;
	char op[3];
	for(int i=0;i<8;i++){
		sum = a[0];
		for(int j=0;j<3;j++){
			if(i & (1 << j)){
				op[j] = '+';
				sum += a[j+1];
			}else{
				op[j] = '-';
				sum -= a[j+1];
			}
		}
		if(sum == 7){
			break;
		}
	}
	cout << a[0];
	for(int i=0;i<3;i++){
		cout << op[i] << a[i+1];
	}
	cout << '=' << '7';
}

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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main(){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int res = 0;
  if(a%10) chmax(res, 10-a%10);
  if(b%10) chmax(res, 10-b%10);
  if(c%10) chmax(res, 10-c%10);
  if(d%10) chmax(res, 10-d%10);
  if(e%10) chmax(res, 10-e%10);
  cout << ((a+9)/10+(b+9)/10+(c+9)/10+(d+9)/10+(e+9)/10)*10-res << endl;
  return 0;
}

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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int left_cost = 0;
    vector<int> a(m);
    for(int i = 0; i < m; i++){
        cin >> a[i];
        if(a[i] < x){left_cost++;}
    }

    cout << min(left_cost,m-left_cost) << endl;


    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

template <typename T>
class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ

        // 重み付きUnionFindでのみ利用
        vector<T> diffWeight; // 親ノードとの値の差
    public:
        UnionFind(int n);          // n要素で初期化
        int Find(int x);           // 木の根を返す
        void Unite(int x, int y);  // xとyの属する集合を併合
        bool Same(int x, int y);   // xとyが同じ集合に属するか否か

        // 重み付きUnionFindでのみ利用
        void Unite(int x, int y, T w);
        T Weight(int x);      // xの重みを返す
        T Diff(int x, int y); // xとyの差を返す
};

template <typename T>
UnionFind<T>::UnionFind(int n) : parent(n), rank(n), diffWeight(n, 0){
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

template <typename T>
int UnionFind<T>::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        int r = Find(parent[x]);
        diffWeight[x] += diffWeight[parent[x]];
        return parent[x] = r;
    }
}

template <typename T>
void UnionFind<T>::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

template <typename T>
bool UnionFind<T>::Same(int x, int y) { return Find(x) == Find(y); }

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];
    reverse(all(a));
    reverse(all(b));

    UnionFind<int> uf(n+1);
    vector<LL> ans(m);
    ans[m-1] = n * (n-1) / 2;
    map<int, int> mp;
    REP(i, n) mp[i+1] = 1;
    REP(i, m-1){
        if(uf.Same(a[i], b[i])){
            ans[m-i-2] = ans[m-i-1];
        }else{
            int sum = mp[uf.Find(a[i])] + mp[uf.Find(b[i])];
            ans[m-i-2] = ans[m-i-1] - mp[uf.Find(a[i])] * mp[uf.Find(b[i])];
            uf.Unite(a[i], b[i]);
            mp[uf.Find(a[i])] = sum;
        }
    }
    REP(i, m) cout << ans[i] << endl;
}

Measured memory_bytes: 12288
#include<iostream>

using namespace std;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    
    int s=x-a;
    if(s<0)s*=-1;
    int t=x-b;
    if(t<0)t*=-1;
    
    if(s>t)cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*int sv[1000000]={0};
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<=maxx;i++){if(!sv[i]){for(int j=2*i;j<=maxx;j+=i)sv[j]=1;}}}//0 hai to prime
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],mod-2)))%mod; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}*/
using namespace std;
int a[3003+1];
int d[3003][3003];
bool dd[3003][3003];
int n;
int f(int l, int r)
{
	int done = n-r+l-1;
	int ans;
	if(dd[l][r])
		return d[l][r];
	if(l == r)
	{
		if(done % 2)
			ans = -1 * a[l];
		else ans = a[l];
	}
	else
	{
		if(done % 2)
			ans = min(f(l+1 , r) - a[l] , f(l , r-1) - a[r]);
		else ans = max(f(l+1 , r) + a[l] , f(l , r-1) + a[r]);
	}
	d[l][r] = ans;
	dd[l][r] = 1;
	return ans;
}
signed main()
{
	int i, j, k;
	cin >> n;
	for(i=1 ; i<=n ; i++)
		cin >> a[i];
	cout << f(1,n) << "\n";
	return 0;
}


Measured memory_bytes: 78464
#include <cstdint>
#include <cstdio>
#include <utility>
#include <vector>

#include <atcoder/modint>
#include <atcoder/lazysegtree>

using mi = atcoder::modint998244353;

std::pair<mi, int> op(std::pair<mi, int> s1, std::pair<mi, int> s2) {
  auto [x1, l1] = s1;
  auto [x2, l2] = s2;
  return {x1+x2, l1+l2};
}
std::pair<mi, int> e() { return {mi(0), 0}; }
std::pair<mi, int> mapping(std::pair<mi, mi> f, std::pair<mi, int> s) {
  auto [x, l] = s;
  auto [b, c] = f;
  return {b*x + c*l, l};
}
std::pair<mi, mi> composition(std::pair<mi, mi> f1, std::pair<mi, mi> f2) {
  auto [b1, c1] = f2;
  auto [b2, c2] = f1;
  return {b1*b2, c1*b2+c2};
}
std::pair<mi, mi> id() {
  return {mi(1), mi(0)};
}

int main() {
  int n, q;
  scanf("%d %d", &n, &q);

  std::vector<std::pair<mi, int>> a(n);
  for (auto& ai: a) {
    int tmp;
    scanf("%d", &tmp);
    ai.first = tmp;
    ai.second = 1;
  }

  atcoder::lazy_segtree<std::pair<mi, int>, op, e,
                        std::pair<mi, mi>, mapping, composition, id> st(a);

  for (int i = 0; i < q; ++i) {
    int t;
    scanf("%d", &t);

    if (t == 0) {
      int l, r, b, c;
      scanf("%d %d %d %d", &l, &r, &b, &c);
      st.apply(l, r, std::make_pair(mi(b), mi(c)));
    } else if (t == 1) {
      int l, r;
      scanf("%d %d", &l, &r);
      printf("%u\n", st.prod(l, r).first.val());
    }
  }
}


Measured memory_bytes: 19268
import java.util.Scanner;
    public class Main{
        int a,b,sa;
    public void solve(){
        Scanner sc=new Scanner(System.in);
        for(int i=0;i<=6;i++){
            a = sc.nextInt();
            b = sc.nextInt();
            sa=a-b;
            System.out.println(sa);
        }
    }
    public static void main(String[] args){
            Main obj= new Main();
            obj.solve();
    }
    }

Measured memory_bytes: 17240
#include<bits/stdc++.h>
using namespace std;
int a,b;
char s;
int main()
{
	cin>>a>>b;
	for(int i=1;i<=a+b+1;++i)
	{
		cin>>s;
		if(i!=a+1&&s!='0'&&s!='1'&&s!='2'&&s!='3'&&s!='4'&&s!='5'&&s!='6'&&s!='7'&&s!='8'&&s!='9')
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(i==a+1&&s!='-')
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(ll i,ll a[],ll n,vector<ll> &dp)
{
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	ll c=0;
	if(i<n-1)
	{
		c=abs(a[i]-a[i+1])+solve(i+1,a,n,dp);
	}
	if(i<n-2)
	{
		c=min(c,abs(a[i]-a[i+2])+solve(i+2,a,n,dp));
	}
	dp[i]=c;
	return dp[i];
}
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for (ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vector<ll> dp(n,-1);
	dp[n-1]=0;
	dp[n-2]=abs(a[n-1]-a[n-2]);
	cout<<solve(0,a,n,dp);
}

Measured memory_bytes: 9088
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
//#pragma GCC optimize ("trapv")

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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
//#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rep(i, a, b) for(lli i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) lli((x).size())
#define what_is(x) cerr << #x << " is " << x << endl;
#define wis cout<<endl<<"I already speak english, bitch"<<endl<<endl;

typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
typedef long double C;

#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}


int main(){
	fastio;

	string s; cin>>s;
	if(s[2]==s[3] and s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;


	return 0;
}

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

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

    int n;
    long long k;
    cin >> n >> k;

    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }

    vector<int> s;
    // 訪れていないところが -1
    vector<int> loop(n + 1, -1); // ループの部分
    int tail = 0; // ループに入るまでの部分
    int period = 1; // 周期
    {
        int v = 1;
        // 訪れていないなら while 文を回す
        while (loop[v] == -1) {
            loop[v] = s.size();
            s.push_back(v);
            v = a[v - 1];
        }
        period = s.size() - loop[v];
        tail = loop[v];
    }

    if (k < tail) {
        cout << s[k] << '\n';
    } else {
        k -= tail;
        k %= period;
        cout << s[tail + k] << '\n';
    }
    return 0;
}

Measured memory_bytes: 5848
fun main(args: Array<String>){
    var N = readLine()!!.toLong()
    val s = StringBuilder()
    while (N != 0L){
        if(N % 2 != 0L){
            N -= 1
            s.append(1)
        }else{
            s.append(0)
        }
        N /= -2
    }
    println(if(s.isEmpty()) 0 else s.reverse().toString())
}

Measured memory_bytes: 31880
package main

import "fmt"

func main() {
	var n, count int
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}

	flag := true
	for flag {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				flag = false
			}
		}
		if flag {
			count++
		}
	}
	fmt.Println(count)
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int h, w;
  cin >> h >> w;
  bool amari[h][w];
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int res;
      cin >> res;
      amari[y][x] = res % 2;
    }
  }

  // for (int y = 0; y < h; y++) {
  //   for (int x = 0; x < w; x++)
  //     cout << amari[y][x] << " ";
  //   cout << endl;
  // }

  vector<pair<int, int>> v, v2;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w - 1; x++) {
      if (amari[y][x]) {
        amari[y][x] ^= 1;
        amari[y][x + 1] ^= 1;
        v.push_back(make_pair(y, x));
        v2.push_back(make_pair(y, x + 1));
      }
    }
  }

  for (int y = 0; y < h - 1; y++) {
    if (amari[y][w - 1]) {
      amari[y][w - 1] ^= 1;
      amari[y + 1][w - 1] ^= 1;
      v.push_back(make_pair(y, w - 1));
      v2.push_back(make_pair(y + 1, w - 1));
    }
  }

  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first + 1 << " " << v[i].second + 1 << " ";
    cout << v2[i].first + 1 << " " << v2[i].second + 1 << endl;
  }
}


Measured memory_bytes: 4588
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b, c) for(int i=(a); i<=(b); i+=(c))
#define rep(i,a,b) for (int i=(a); i<=(b); ++i)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define debug(x) cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define ms(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const double PI=acos(-1);
const double eps=1e-9;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
int qpow(int a, int b, int mod){int res=1, base=a%mod;while(b){if(b&1)res*=base;base*=base;b>>=1;}return res;}
ll qpow(ll a, ll b, ll mod){ll res=1, base=a%mod;while(b){if(b&1)res*=base;base*=base;b>>=1;}return res;}
void file_put() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}
const int maxn = 105;

int n, m;
int num[maxn];
int main() {
//	file_put();
	int N, k;
	scanf("%d %d", &N, &k);
	rep(i, 1, N) scanf("%d", &num[i]);
	int sum=0;
	rep(i, 1, N){
		sum+=2*min(num[i], k-num[i]);
	}
	cout << sum <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  ll n,r;
  string s;
  cin >> n >> r;
  ll now=1;
  ll ans=0;
  while(n >= now ){
      now*=r;
      ans++;
  }
  cout << ans << endl;
  return 0;
}



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

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            long[] nk = Console.ReadLine().Split(' ').Select(val => long.Parse(val)).ToArray();
            long n = nk[0];
            long k = nk[1];
            n = n % k;
            while(Math.Abs(n - k) <= n)
            {
                n = Math.Abs(n - k);
            }
            Console.WriteLine(n);
        }
    }

    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }

    int c0 = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == "AC")
        {
            c0++;
        }
        else if (s[i] == "WA")
        {
            c1++;
        }
        else if (s[i] == "TLE")
        {
            c2++;
        }
        else if (s[i] == "RE")
        {
            c3++;
        }
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
bitset<4000008> dp;
int main(){
int n;
int i,j;
cin>>n;
int a[n];
int sum=0;
for(i=0;i<n;i++)
   {

    cin>>a[i];
sum=sum+a[i];
   }


dp=1;
for(i=0;i<n;i++)
{
    dp|=(dp<<a[i]);


}

for(i=(sum+1)/2;i<=sum;i++)
{
    if(dp[i]==1)
    {
        cout<<i<<endl;
        break;
    }
}






return 0;}



Measured memory_bytes: 1664
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

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

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a;
	cin >> n;
	cin >> a;
	bool ans = false;
	rep(i, 0, a + 1) {
		int money = n - i;
		if (money % 500 == 0) {
			ans = true;
			break;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
nyukyo=[list(map(int, input().split())) for i in range(n)]
bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for ny in nyukyo:
    bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3]

for i,b in enumerate(bld):
    for f in b:
        print("",*f)
    if i != 3:
        print("####################")

Measured memory_bytes: 7740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            var tmp = ReadAndParseIntArr();
            int a = tmp[0];
            int b = tmp[1];
            string s = Console.ReadLine();

            bool success = true;
            for(int i=0;i<s.Length;++i)
            {
                char c = s[i];
                if( i == a)
                {
                    if(c != '-') { success = false; break; }
                }else
                {
                    if( c == '-') { success = false; break; }
                }
            }
            string ans = success ? "Yes" : "No";
            Console.WriteLine(ans);
        }


        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val (r, s, p) = readLine()!!.split(" ").map { it.toLong() }
    val t = readLine()!!

    val hands = t.map {
        when (it) {
            'r' -> 'p'
            'p' -> 's'
            's' -> 'r'
            else -> 'x'
        }
    }.toMutableList()

    for (i in k until n) {
        if (hands[i] == hands[i-k]) hands[i] = 'x'
    }

    val ans = hands.map {
        when (it) {
            'r' -> r
            'p' -> p
            's' -> s
            else -> 0L
        }
    }.sum()
    println(ans)
}


Measured memory_bytes: 41588
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e15;
using namespace std;

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

    vector<ll>t(5);

    ll Min = INF;

    for(int i=0; i<5; i++){
        cin>>t[i];
        Min = min(Min,t[i]);  
    }

    cout<<(ll )ceil((long double)n/Min) + 4 <<endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string expr;
int n,sweet[10],s,ans;
int eval(int b,int e){
	if(b+1==e)return sweet[expr[b]-'1'];
	int l,o,r,d;
	for(o=b,d=0;o<e;o++){
		char c=expr[o];
		if(c=='(')d++;
		if(c==')')d--;
		if(d==0&&(c=='&'||c=='|'||c=='^'))break;
	}
	if(o==e&&expr[b]=='(')return eval(b+1,e-1);
	l=eval(b,o),r=eval(o+1,e);char c=expr[o];
	return c!='&'?c=='^'?l^r:l|r:l&r;
}
void op(int c){
	for(;c<s;c++)if(expr[c]==' ')break;
	if(c<s)rep(i,3){
		expr[c]="&|^"[i];op(c+1);expr[c]=' ';
	}else if(eval(0,s)==15)ans++;
}
int main(){
	while(getline(cin,expr),expr!="END"){
		s=expr.size(),ans=0;cin>>n;
		rep(i,n){
			int t;sweet[i]=0;
			rep(j,4)cin>>t,sweet[i]<<=1,sweet[i]+=t;
		}
		op(0);
		cout<<ans<<endl;
		cin.ignore();
	}
	return 0;
}

Measured memory_bytes: 936
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
	string str;
	cin >> str;

	int res;

	for(auto ch : str)
	{
		res ^= ch;
	}

	if(res == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256