akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int usg(int a,int b)
{
	while (max(a,b)%min(a,b)!=0)
	{
		if (a>b) a=a%b;
		else b=b%a;
	}
	return min(a,b);
}
int i,k,j,l,usj,s;
int main ()
{
	cin>>k;
	for (i=1; i<=k; i++)
	
		for (j=1; j<=k; j++)
		
	
			for (l=1; l<=k; l++)
			{
				usj=usg(i,j);
				usj=usg(usj,l);
				s+=usj;
				
			}
		
		cout<<s;
	

}



Measured memory_bytes: 3672
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

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

int main() {
  int vec[14][14];
  rep(i,14){
    rep(j,14) vec[i][j]=0;
  }
  
  int a,b,c;
  char x,y;
  while(cin>>a>>x>>b>>y>>c){
    
    vec[a+2][b+2]++;
    vec[a+1][b+2]++;
    vec[a+3][b+2]++;
    vec[a+2][b+1]++;
    vec[a+2][b+3]++;
    if(c>1){
      vec[a+1][b+1]++;
      vec[a+1][b+3]++;
      vec[a+3][b+1]++;
      vec[a+3][b+3]++;
    }
    if(c>2){
      vec[a][b+2]++;
      vec[a+4][b+2]++;
      vec[a+2][b]++;
      vec[a+2][b+4]++;
    }
  }
    
  int ma=0,cnt=0;
    
  for(int i=2;i<=11;i++){
    for(int j=2;j<=11;j++){
      if(vec[i][j]==0) cnt++;
      chmax(ma,vec[i][j]);
    }
  }
    
  cout<<cnt<<endl;
  cout<<ma<<endl;
      
  return 0;
}


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

typedef long long int64;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SZ(c) ((int)(c).size())

const int MAXV = 1 << 17;

int V;
vector<pii> G[MAXV];
int ans[MAXV];

void dfs(int u, bool color, int parent = -1) {
  ans[u] = color;
  for (auto& e : G[u]) {
    int v = e.first;
    int w = e.second;
    if (v == parent) continue ;
    dfs(v, color ^ (w % 2 == 1), u);
  }
}

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

  cin >> V;
  for (int i = 0; i < V - 1; ++i) {
    int u, v, w; cin >> u >> v >> w;
    --u;
    --v;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }

  dfs(0, 0);
  for (int i = 0; i < V; ++i) {
    cout << ans[i] << "\n";
  }


  return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<bool>> fie(H,vector<bool>(W,false));

  int black = 0;

  for(int i = 0;i < H;i++){
    string s;
    cin >> s;
    for(int j = 0;j < W;j++){
      fie[i][j] = s[j] == '.';
      if(fie[i][j]){
        black++;
      }
      else{
      }
    }
  }

  struct state{
    int x;
    int y;
  };

  vector<vector<int>> dist(H,vector<int>(W,1e9));
  dist[0][0] = 1;
  queue<state> que;
  int dx[] = {1,-1,0,0};
  int dy[] = {0,0,1,-1};
  que.push({0,0});
  while(!que.empty()){
    auto s = que.front();
    que.pop();
    for(int i = 0;i < 4;i++){
      int x = s.x + dx[i];
      int y = s.y + dy[i];
      if(0 <= x && x < H && 0 <= y && y < W && fie[x][y] && dist[x][y] > dist[s.x][s.y] + 1){
        dist[x][y] = dist[s.x][s.y] + 1;
        que.push({x,y});
      }
    }
  }

  if(1e9 == dist[H - 1][W - 1]){
    cout << -1 << endl;
    return 0;
  }

  cout << black - dist[H - 1][W - 1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int c1, c5,c10, c50, c100, c500;
	cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
	int sum = c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
	if (sum >= 1000)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll INF = 1e18;

int main() {
  //
  ll h, w, n;
  cin >> h >> w >> n;
  map<pll, ll> mp;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    rep(i, 3) {
      rep(j, 3) {
        int ni = a - i;
        int nj = b - j;
        if (0 <= ni && ni <= h - 3 && 0 <= nj && nj <= w - 3) {
          if (mp.find({ni, nj}) == mp.end()) {
            mp[{ni, nj}] = 1;
          } else {
            mp[{ni, nj}]++;
          }
        }
      }
    }
  }
  vl cnt(10, 0);
  ll total = 0;
  for(auto& m: mp) {
    ll c = m.second;
    cnt[c]++;
  }
  REP(i, 1, 10) total += cnt[i];
  cnt[0] = (h - 2) * (w - 2) - total;
  REP(i, 0, 10) {
    cout << cnt[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 56448
#include<stdio.h>
int main(void){
    int h=0,m=0,s=0,S,i;
    
    scanf("%d %d %d",&S);
    for(i=S;i>=3600;i-=3600){
        S-=3600;
        h+=1;
    }
    for(i=S;i>=60;i-=60){
        S-=60;
        m+=1;
    }
    s=S;
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}


Measured memory_bytes: 2760
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

void solve() {

    double ans = 0.0;
    vector<pair<double, double>> v;
    int n;
    SI(n);
    REP(i, n) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        v.push_back(make_pair(x, y));
    }
    int tmp = 0;
    for(int i = 0 ; i < n ; i++) {
        for(int j = i+1 ; j < n ; j++) {
            ans += sqrt((v[i].first - v[j].first) * (v[i].first - v[j].first) +
            (v[i].second - v[j].second) * (v[i].second - v[j].second));
            tmp++;
        }
    }

    printf("%.9f\n", ans * (n-1) / tmp);
}

void init() {
    


}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <math.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

//最大公約数
ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

//最小公倍数
ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main(){
    int x,y;
    cin >> x >> y;

    cout << x+y/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {    
	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; i++) {
      arr[i] = sc.nextInt();
    }
    Arrays.sort(arr);
    int Alice = 0;
    int Bob = 0;
    boolean order = true;
    for(int i = n - 1; i >= 0; i--) {
      if(order) {
        Alice += arr[i];
        order = false;
      } else {
        Bob += arr[i];
        order = true;
      }
    }
    System.out.println(Alice - Bob);
  }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define ll long long
const ll MOD=1e9+7;
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    string ans="",s;
    vector<int> alp(26,100);
    rep(i,0,n){
        cin>>s;
        vector<int> buf(26,0);
        rep(j,0,(int)s.length()){
            buf[s[j]-'a']++;
        }
        rep(j,0,26)alp[j]=min(alp[j],buf[j]);
    }
    rep(i,0,26){
        for(int j=alp[i];j>0;j--)ans+='a'+i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200010
using namespace std;
int a[N];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i); 
	}
	for(int i=k;i<n;i++)
	{
		if(a[i]>a[i-k])
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 4540
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        S: i64,
    }
    let div = 10i64.pow(9u32);
    match S / div {
        y if y == div => println!("{} {} {} {} {} {}", 0, 0, div, 0, 0, div),
        y if 0 <= y && y < div => {
            let x = S % div;
            println!("{} {} {} {} {} {}", 0, 1, div, 0, x, y + 1);
        }
        _ => unreachable!()
    }
}

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

int main(){
  string s,t;
  cin>>s>>t;
  vector<char> a(s.size()),b(t.size());
  for(int i=0;i<s.size();i++){
    a[i] = s.at(i);
  }
  for(int i=0;i<t.size();i++){
    b[i] = t.at(i);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  int count=0;
  for(int i=0;i<s.size();i++){
    if(a[i]>b[i]){
      cout<<"No"<<endl;
      return 0;
    }else if(a[i]==b[i]) count++;
    else break;
    if(i==t.size()-1 && i<s.size()-1){
      if(count==i+1){
		cout<<"No"<<endl;
        return 0;
      }else break;
    }else if(s.size()==t.size() && s.size()-1==i && a[i]>=b[i]){
       cout<<"No"<<endl;
       return 0;
    }
  }
  cout<<"Yes"<<endl;
}

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

long M;

int trade(long *a,long *b){
        long tmp=*a;
        *a=*b;
        *b=tmp;
}

int sort(long l[],int N){
        int i=1,j,k;
        while(N>i)i*=2;

        long h[i];

        for(i=0;i<N;i++){
                h[i]=l[i];
                for(j=i;j>0;j=(j-1)/2){
                        if(h[j]>h[(j-1)/2])
                                trade(&h[j],&h[(j-1)/2]);
                        else
                                break;
                }
        }


        for(i=0,k=N-1;i<N;i++){
                l[i]=h[0];
                h[0]=h[k--];
                for(j=0;j*2+1<=k;){
                        if(j*2+2>k || h[j*2+1]>h[j*2+2]){
                                if(h[j]<h[j*2+1]){
                                        trade(&h[j],&h[j*2+1]);
                                        j=j*2+1;
                                }else{
                                        break;
                                }
                        }
                        else if(h[j]<h[j*2+2]){
                                trade(&h[j],&h[j*2+2]);
                                j=j*2+2;
                        }else{
                                break;
                        }
                }
        }

        return 0;

}

long search(long l[],int head,int tail,long ft){
        if(tail-head<0){
                while(l[tail]+ft>M)tail++;
                return l[tail]+ft;
        }

        int i=(tail+head)/2;


        if(l[i]+ft>M)
                return search(l,i+1,tail,ft);
        else
                return search(l,head,i-1,ft);
}


main(){
        int i,j,k;

        long N,N2;

        long l[1000+500500+1];
        long maxpt;

        while(1){
                scanf("%ld %ld",&N,&M);
                if(N==0)break;
                for(i=0;i<N;i++)
                        scanf("%ld",&l[i]);

                for(i=0,k=N;i<N;i++)
                        for(j=i;j<N;j++)
                                if(l[i]+l[j]<M)
                                        l[k++]=l[i]+l[j];
                l[k++]=0;
                N=k;

                sort(l,N);

                maxpt=0;
                for(i=0;i<N;i++){
                        j=search(l,i,N-1,l[i]);
                        if(maxpt<j)
                                maxpt=j;
                }

                printf("%ld\n",maxpt);

        }
        return 0;
}

Measured memory_bytes: 8608
import java.util.*;

public class Main {
    public static void main (String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = 0;
        for (int i = a; i <= b; i++) {
            String tmp = String.valueOf(i);
            char[] tmp_char = tmp.toCharArray();

            if (tmp_char[0] == tmp_char[4] && tmp_char[1] == tmp_char[3]) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

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

int gcd(int a,int b) {
  if (a>b) {
    swap(a,b);
  }
  if (b%a == 0) {
    return a;
  }
  return gcd(b%a,a);
}

int main() {
  int R,D,x;
  cin >> R >> D >> x;
  for (int i=0; i<10; i++) {
    x = x*R - D;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# segment tree
class SegmentTree:
    def _max(self,a,b):
        if a < b:
            return b
        else:
            return a

    def __init__(self,n):
        self.N = 1
        while(self.N < n):
            self.N *= 2
        self.seg = [0] * (self.N * 2 -1)

    def max_update(self,k,a):
        k += self.N - 1
        self.seg[k] = a

        while(0 < k):
            k = (k-1)//2;
            self.seg[k] = self._max(self.seg[2*k +1], self.seg[2*k + 2])

    def _max_query(self,a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self._max_query(a, b, k * 2 + 1, l, (l + r)//2)
            vr = self._max_query(a, b, k * 2 + 2, (l + r)//2, r)
            return self._max(vl,vr)

    def max_query(self,a, b):
        return self._max_query(a, b, 0, 0, self.N)

n = int(input())
X = list(map(int,input().split()))
st = SegmentTree(n+1)

for x in X:
    st.max_update(x, st.max_query(0,x) + x)
print((n * (n + 1))//2 - st.max_query(0,n+1))

Measured memory_bytes: 21528
A, B, C, X = [int(input()) for _ in range(4)]
m = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (500 * a) + (100 * b) + (50 * c) == X:
                m += 1
print(m)


Measured memory_bytes: 2940
s = input()

flg = True
if s[0] != 'A':
    flg = False
elif 'C' not in s[2:-1]:
    flg = False
elif s[2:-1].count('C') > 1:
    flg = False
elif not  s[1:].replace('C','').islower():
    flg = False
else:
    pass

print('AC' if flg else 'WA')

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		for (int i=0; i<N; i++) {
			x[i] = sc.nextInt();
		}
		int res = 0;
		for (int i=0; i<N; i++) {
			res += Math.min(Math.abs(0-x[i]), Math.abs(K-x[i]));
		}		
		System.out.println(res*2);
	}
}


Measured memory_bytes: 21844
N,A,B=map(int,input().split())
S=input()
S=list(S)
count=0
world=1
for i in S:
    if i=="a":
        if count<A+B:
            print("Yes")
            count+=1
        else:
            print("No")
    elif i=="b":
        if (count<A+B) & (world<=B):
            print("Yes")
            count+=1
            world+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4712
#include <iostream>
#include <stdio.h>
using namespace std;

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

    int A[n][m];
    for(int y = 0; y < n; y++){
        for(int x = 0; x < m; x++){
            scanf("%d", &A[y][x]);
        }
    }

    int b[m];
    for(int x = 0; x < m; x++){
        scanf("%d", &b[x]);
    }

    int sum;
    for(int y = 0; y < n; y++){
        sum = 0;
        for(int x = 0; x < m; x++){
            sum = sum + A[y][x] * b[x];
        }
        printf("%d\n", sum);
    }
    return 0;
    }


Measured memory_bytes: 3212
#include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin >> n, !cin.eof())
	{
		double hg, wg;
		char c;
		cin >> c;
		cin >> wg;
		cin >> c;
		cin >> hg;
		
		if( wg / (hg*hg) >= 25.0 )
			cout << n << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
#define MOD 1000000007
using namespace std;
INT n, a[110], b[110];
stack<INT> ans, s;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 1 ; i <= n ; i++ ) cin>>a[i];
    while( n )
    {
        bool t = false;
        for(int i = n, j = n ; i > 0 ; i-- )
        {
            if( !t and i == a[i] )
            {
                ans.push(a[i]);
                t = true;
            }
            else s.push(a[i]);
        }
        if( !t ) return cout<<-1<<endl, 0;
        for(int i = 1 ; !s.empty() ; i++ ) a[i] = s.top(), s.pop();
        n--;
    }
    while( !ans.empty() ) cout<<ans.top()<<endl, ans.pop();
    return 0;
}


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

int main(){
	int N,i,n;

	cin>>N;

	for(i=1;i<10;i++){
		for(n=1;n<10;n++){
			if(i*n == N){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}

	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
a_N = list(map(int, input().split(' ')))
break_count = 0
remain_count = 1
for a_n in a_N:
    if a_n == remain_count:
        remain_count += 1
    else:
        break_count += 1
if break_count == N:
    print(-1)
else:
    print(break_count)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    vector<ll> a(n),b(n);
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    rep(i,n){
        cin>>b[i];
        mp[b[i]]++;
    }
    
    for(auto& p:mp){
        if(p.second>n){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    ll buf=-1,j=0;
    rep(i,n){
        if(buf!=a[i])j=0;
        if(a[i]==b[i]){
            for(;j<n;j++){
                if(b[i]!=a[j]&&b[j]!=a[i]){
                    swap(b[i],b[j]);
                    break;
                }
            }
        }
        buf=a[i];
    }
    rep(i,n)cout<<b[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 18688
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    int n,m,f=0,sum=0;
    cin>>n>>m;
    vector<int>a(1000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(),a.end(),greater<>());
    for(int i=0;i<m;i++){
        if(4*a[i]*m<sum){
            f=1;
            break;
        }
    }
    if(f==1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 7224
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, C = na()
ans = [0] * ((10 ** 5) * 2 + 10)
for i in range(N):
    s, t, c = na()
    ans[s] += 1
    ans[t+1] -= 1

for i in range(len(ans)-1):
    ans[i+1] += ans[i]
print(min(max(ans), C))

 






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

using namespace std ;

const int MAX = 1e6 + 10 ;

int arr[MAX] , Plus[MAX] , Minus[MAX] ;
int n ;

bool cmp(int &i , int &j)
{
	if(Minus[i] == 0 && Minus[j] == 0)
		return Plus[i] > Plus[j] ;
	else if(Minus[i] == 0 || Minus[j] == 0)
		return Minus[i] < Minus[j] ;
	else
	{
		if(Plus[i] - Minus[i] > 0 && Plus[j] - Minus[j] > 0)
			return Minus[i] < Minus[j] ;
		else if(Plus[i] - Minus[i] > 0 || Plus[j] - Minus[j] > 0)
			return Plus[i] - Minus[i] > Plus[j] - Minus[j] ;
		else
		{
			if(Plus[i] > 0 && Plus[j] > 0)
				return Plus[i] - Minus[i] > Plus[j] - Minus[j] ;
			else if(Plus[i] > 0 || Plus[j] > 0)
				return Plus[i] > Plus[j] ;
			else
				return Minus[i] < Minus[j] ;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	string s ;
	vector<int>perm ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>s ;
		int cnt = 0 ;
		for(auto &c : s)
		{
			if(c == '(')
				cnt++ ;
			else
			{
				if(cnt == 0)
					Minus[i]++ ;
				cnt-- ;
				cnt = max(cnt , 0) ;
			}
		}
		Plus[i] = cnt ;
		perm.push_back(i) ;
	}
	sort(perm.begin() , perm.end() , cmp) ;
	int cnt = 0 ;
	for(auto &i : perm)
	{
		cnt -= Minus[i] ;
		if(cnt < 0)
			return cout<<"No\n" , 0 ;
		cnt += Plus[i] ;
	}
	if(cnt == 0)
		cout<<"Yes\n" ;
	else
		cout<<"No\n" ;
	return 0 ;
}		

Measured memory_bytes: 15144
#include <cstdio>
#include <cstring>
int g[101][101], d[101], f[101], vis[101];
int time = 0, n;

void dfs(int u)
{
  if (vis[u] != 0) return;
  vis[u] = 1;
  d[u] = ++time;
  for (int i = 0; i < n; i++)
  {
    if (g[u][i] == 1)
    {
      dfs(i);
    }
  }
  vis[u] = 2;
  f[u] = ++time;
}

int main()
{
  memset(g, 0, sizeof(g));
  memset(vis, 0, sizeof(vis));
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    int u, adj_num;
    scanf("%d%d", &u, &adj_num);
    while (adj_num--)
    {
      int v;
      scanf("%d", &v);
      g[u - 1][v - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (!vis[i]) dfs(i);
  }
  for (int i = 0; i < n; i++)
  {
    printf("%d %d %d\n", i + 1, d[i], f[i]);
  }
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll a,b;
ll ans = 1;

ll gcd(ll a,ll b){
  while(a != 0){
    b = b%a;
    swap(a,b);
  }
  return b;
}

int main(){
  cin >> a >> b;
  ll g = gcd(a,b);
  ll g_ = g;
  for(ll i = 2;i*i <= g_;i++){
    if(g%i == 0){
      ans++;
      while(g%i == 0) g /= i;
    }
  }
  if(g != 1) ans++;
  cout << ans << endl;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    
    int a, b, c;
    cin >> a >> b >> c;
    int x;
    cin >> x;
    int ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(x == 500*i + 100*j + 50*k) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B; std::cin >> A >> B;
  if (A > B) std::cout << 2*A-1 << std::endl;
  else if (A < B) std::cout << 2*B-1 << std::endl;
  else std::cout << A + B << std::endl;
}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N /1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;
  
  if ((a == b && b == c) || (b == c && c == d))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = sorted(map(int, input().split()))
mi = A[0]
ma = A[-1]
Ans = []
for i, a in enumerate(A[1:-1], 1):
    if a < 0:
        Ans.append([ma, a])
        ma -= a
    else:
        Ans.append([mi, a])
        mi -= a

print(ma - mi)
for x, y in Ans:
    print(x, y)
print(ma, mi)


Measured memory_bytes: 23108
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string s,t;
    cin>>s>>t;
    int cnt=0;
    rep(i,0,s.size()){
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}




Measured memory_bytes: 3824
import sys
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
ct = Counter(a).most_common()
num = len(ct)

if num == 1:
	print('Yes' if ct[0][0] == 0 else 'No')
elif num == 2:
	if N % 3 == 0:
		if ct[0][0] != 0 and ct[0][1] == 2*N//3:
			if ct[1][0] == 0 and ct[1][1] == N//3:
				print('Yes')
				sys.exit()
	print('No')
elif num == 3:
	if N % 3 == 0:
		if ct[0][1] == ct[1][1] == ct[2][1]:
			if ct[0][0]^ct[1][0]^ct[2][0] == 0:
				print('Yes')
				sys.exit()
		
	print('No')
else:
	print('No')
	

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

typedef long long ll;
const int N = 2e3 + 10;
int n, arr[N];
ll ans;
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	sort(arr, arr + n);
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			ans += max(0, (int)(upper_bound(arr, arr + n, arr[i] + arr[j] - 1) - 1 - arr - j));
	printf("%lld", ans);	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int getBitN(int n, int k) {
	int c = 0;
	if (n == 0) {
		return 1;
	}
	while (n) {
		c += 1;
		n = n / k;
	}
	return c;
}
int main() {
	int n, k;
	cin >> n >> k;
	cout << getBitN(n, k) << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    N = int(input())
    h_lst = [int(x) for x in stdin.readline().split()]
    lst = []
    count = 0
    for i in range(N):
        lst.append(h_lst[i])
        if h_lst[i] >= max(lst):
            count += 1
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5;
int n,tot,head[N],nxt[N<<1],adj[N<<1],deg[N],del[N],v[N],q[N],now,dis;
char col[N];
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y; 
}
inline void solve(){
	ri l,r,i,x,y;
	l=1;r=0;
	for(i=1;i<=n;++i)
		if(deg[i]<=1&&col[i]=='B')
			del[i]=1,
			q[++r]=i;
	while(l<=r){
		x=q[l++];
		for(i=head[x];i;i=nxt[i])
			if(!del[y=adj[i]]&&--deg[y]<=1&&col[y]=='B')
				del[y]=1,
				q[++r]=y;
	}
}
inline void dfs(ri x,ri fa,ri res){
	res+=v[x];
	if(res>dis) dis=res,now=x;
	for(ri y,i=head[x];i;i=nxt[i])
		if((y=adj[i])!=fa&&!del[y])
			dfs(y,x,res);
}
int main(){
	ri i,x,y,rt,ans;
	gi(n);
	for(i=1;i^n;++i) gi(x),gi(y),addedge(x,y),addedge(y,x),++deg[x],++deg[y];
	read(col);
	solve();
	rt=0;
	for(i=1;i<=n;++i)
		if(!del[i]){
			rt=i;
			break;
		}
	if(!rt) return puts("0"),0;
	if(deg[rt]==0) return puts("1"),0;
	ans=0;
	for(i=1;i<=n;++i)
		if(!del[i]){
			ans+=deg[i];
			if(col[i]=='W'){
				if(deg[i]&1)
					v[i]=1+(-1);
				else
					++ans,
					v[i]=2;
			}
			else{
				if(~deg[i]&1)
					v[i]=1+(-1);
				else
					++ans,
					v[i]=2;
			}
		}
	now=0;dis=-1;
	dfs(rt,0,0);
	dis=-1;
	dfs(now,0,0);
	ans-=dis;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8448
s = input()
q = int(input())

r_addition = ""
l_addition = ""
is_rev = False

for i in range(q):
    qs = input().split()

    if len(qs) == 1:
        is_rev = not is_rev
        # print(is_rev)
    else:
        if int(qs[1]) == 1:
            if is_rev:
                r_addition += qs[2]
            else:
                l_addition += qs[2]
        else:
            if is_rev:
                l_addition += qs[2]
            else:
                r_addition += qs[2]

# print(l_addition)
# print(r_addition)
#
# print(l_addition[::-1])
# print(r_addition[::-1])

if is_rev:
    print(r_addition[::-1]+s[::-1]+l_addition)
else:
    print(l_addition[::-1]+s+r_addition)

Measured memory_bytes: 4468
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NM = input.shift().split(' ').map(v => Number(v))
  input = input.map(v => Number(v)).sort((a, b) => a - b)

  let distance = []
  for (let i = 0; i <= NM[0] - NM[1]; i++) {
    distance.push(input[i+NM[1]-1] - input[i])
  }
  console.log(Math.min(...distance))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 30260
import numpy as np

n = int(input())
A = list(map(int, input().split()))
As = sorted(A)
m = As[-1]
s = np.searchsorted(As,m/2)
d1 = abs(m/2-As[s])
d2 = abs(m/2-As[s-1])
if d1 >= d2:
    r = As[s-1]
else:
    r = As[s]
print(m,r)

Measured memory_bytes: 23092
#include <iostream>
#include <string>
#include <math.h>
#include <list>
using namespace std;

int main(){
    long N;
    long sum = 0;
    cin >> N;

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

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int> pre, in, post;
int pos;
int n, k;

void reconstruction(int left, int right) {
	// ????????°??¶??????
	if (left >= right)
		return;

	// ??????????????????
	int root = pre[pos++];
	// ???????????????????????¨????????°???????????????
	int m = distance(in.begin(), find(in.begin(), in.end(), root));

	reconstruction(left, m);
	reconstruction(m + 1, right);

	//?????\??°????????°???
	post.push_back(root);

}
void solve() {
	pos = 0;
	reconstruction(0, pre.size());
	for (int i = 0; i < n; i++) {
		printf("%d%c", post[i], i == n-1?'\n':' ');
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &k);
		pre.push_back(k);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &k);
		in.push_back(k);
	}
	solve();
	return 0;
}

Measured memory_bytes: 3288
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(d,n):
    if  n != 100 :
        return (100**d)*n
    elif n == 100:
         return (100**d)*101 
    else:
        return n

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  pp=1e9+7; 
double pi=3.141592653589793238;
const long long MAX_SIZE = 10000001; 
  vector<long long >isprime(MAX_SIZE , true); 
vector<long long >prime; 
vector<long long >SPF(MAX_SIZE); 

// function generate all prime number less then N in O(n) 
void manipulated_seive(int N) 
{ 
    // 0 and 1 are not prime 
    isprime[0] = isprime[1] = false ; 
  
    // Fill rest of the entries 
    for (long long int i=2; i<N ; i++) 
    { 
        // If isPrime[i] == True then i is 
        // prime number 
        if (isprime[i]) 
        { 
            // put i into prime[] vector 
            prime.push_back(i); 
  
            // A prime number is its own smallest 
            // prime factor 
            SPF[i] = i; 
        } 
  
        // Remove all multiples of  i*prime[j] which are 
        // not prime by making isPrime[i*prime[j]] = false 
        // and put smallest prime factor of i*Prime[j] as prime[j] 
        // [ for exp :let  i = 5 , j = 0 , prime[j] = 2 [ i*prime[j] = 10 ] 
        // so smallest prime factor of '10' is '2' that is prime[j] ] 
        // this loop run only one time for number which are not prime 
        for (long long int j=0; 
             j < (int)prime.size() && 
             i*prime[j] < N && prime[j] <= SPF[i]; 
             j++) 
        { 
            isprime[i*prime[j]]=false; 
  
            // put smallest prime factor of i*prime[j] 
            SPF[i*prime[j]] = prime[j] ; 
        } 
    } 
} 
 int main() {
        ff;
        ll n;
        cin>>n;
        manipulated_seive(n+1);
        ll ans=0;
        ll a[n+1];
        a[1]=1;
        a[2]=2;
        ll p[n+1]={0};
        for(ll i=2;i<=n;i++){
            for(ll j=1;i*j<=n;j++){
                p[i*j]++;
            }
        }
        for(ll i=3;i<=n;i++){
            if(isprime[i]==1){
                a[i]=2;
            }else if(i%2==0){
                a[i]=a[i/2]+1;
            }else {
                a[i]=a[(i/2)-1]+1;
            }
        }
        
        for(ll i=1;i<=n;i++){
      
            ans+=i*(p[i]+1);
        }
        cout<<ans<<endl;
		
    return 0;
}

            
		
        
           
  

Measured memory_bytes: 321144
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, K; cin >> n >> K;
    int res = 0;
    rep(i, n){
        int x; cin >> x;
        res += min(2 * x, 2 * (K - x));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

template<class T>
vector<pair<T,int>> runlength(vector<T> arr) {
	int i = 0;
	int n = arr.size();
	vector<pair<T, int>> run;
	while (i < arr.size()) {
		T t = arr[i];
		int k = 0;
		while (i + k < n && arr[i + k] == t) k++;
		run.push_back(pair<T, int>(t, k));
		i += k;
	}
	return run;
}

int main(void){
   int n;cin >> n;
   string s;
   cin >> s;
   vector<char> t(n);
   rep(i,n)t[i] = (char)s[i];
   cout << runlength(t).size() << endl;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n-1; i++)
		cin >> a[i];
	
	int ans = a[0];
	
	for(int i = 1; i < n-1; i++){
		if(a[i] <= a[i-1]){
			ans += a[i];
		}
		else{
			ans += a[i-1];
		}
	}
	ans += a[n-2];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
program main
    implicit none
    integer:: fep(0:9,0:9), n,i, top, bottom, count, j

    fep(:,:) = 0

    read*, n

    do i = 1, n
        top = i
        do while (top >= 10)
            top = top / 10
        end do
        bottom = mod(i, 10)
        fep(top,bottom) = fep(top,bottom) + 1
    end do
    
    count = 0
    do i = 1, 9
        count = count + fep(i,i)*fep(i,i)
        do j = i+1,9
             count = count + fep(i,j)*fep(j,i)*2
        end do
    end do
    print*, count
end program main

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b)
    tree[b-1].append(a)
# px = [ list(map(int,input().split())) for _ in range(q) ]
c = [0]*n
# for i in range(len(px)):
for _ in range(q):
    p,x = map(int,input().split())
    c[p-1] += x  
visited = [0]*n
cnd = [1]   # current_node
while len(cnd)>0:
    nnd = []
    for j in cnd:
        visited[j-1]=1
        ko = tree[j-1]
        for k in ko:
            if visited[k-1]==0:
                c[k-1] += c[j-1]
                nnd.append(k)
    cnd = nnd
print(" ".join(map(str,c)))

Measured memory_bytes: 120268
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	fmt.Fprintln(wr, (n+1)/2)
}


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

int main() {
ll a,b,n;
cin >> a >> b >> n;
ll x = n;
if (n >= b-1) x = b-1;
ll ans = a*(x%b)/b;
 cout << ans << endl;
return 0;

}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

bool is_vowel(char ch) {
    return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

int N;
string S[50];

string T[50];

int solve() {
    for (int i = 0; i < N; ++i) T[i] = "";

    int lim = 0;
    for (int i = 0; i < N; ++i) {
        T[i] += S[i][0];

        for (int j = 1; j < S[i].size(); ++j) {
            if (is_vowel(S[i][j-1]))
                T[i] += S[i][j];
        }
        lim = max(lim, (int)T[i].size());
    }

    for (int k = 1; k <= lim; ++k) {
        bool ok = true;
        for (int i = 0; i < N; ++i) {
            for (int j = i+1; j < N; ++j) {
                string ti = T[i].substr(0, min(k, (int)T[i].size()));
                string tj = T[j].substr(0, min(k, (int)T[j].size()));

                if (ti == tj)
                    ok = false;
            }
        }

        if (ok) return k;
    }

    return -1;
}

int main(){while(1){
    cin >> N;
    if (N == 0) break;
    for (int i = 0; i < N; ++i)
        cin >> S[i];
    cout << solve() << endl;
}
return 0;
}



Measured memory_bytes: 3176
import java.io.*;
import java.util.*;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (1e4);
	static List<Integer>[] edges;
    static long[][] dp;
    static int[] a;
    static long[] pre;
    
	
	public static void main(String[] args) throws IOException {
		
	//Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	a = new int[n+1];
	pre = new long[n+1];
	for(int i=1;i<=n;++i) {
		a[i] = sc.nextInt();
		pre[i] = pre[i-1] + a[i];
	}
	
    dp = new long[n+1][n+1];
    for(int i=0;i<=n;++i) Arrays.fill(dp[i], -1);
    out.println(f(1,n));    

out.close();
}
private static long f(int i, int j) {
	if(i >= j) return 0;
	
	if(dp[i][j] != -1) return dp[i][j];
    dp[i][j] = Long.MAX_VALUE;
    
	for(int k=i;k<=j;++k) { // choose a pivot
	long o1 = f(i,k);
	long o2 = f(k+1,j);
    dp[i][j]=Math.min(dp[i][j],o1+o2+pre[j]-pre[i-1]);
	}
	return dp[i][j];
}
	
	}




Measured memory_bytes: 24612
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = n; i < 1000; i++){
        if(i/100 == (i%100)/10 && i/100 == i%10){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256