akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
int main(){
    ll A,B;read(A);read(B);
    if(A == B){
        puts("1");
        return 0;
    }
    ll r,k;
    for(r = 60;(A & (1LL << r)) == (B & ( 1LL << r));-- r);
    A &= (1LL << (r+1)) - 1;B &= (1LL << (r+1)) - 1;
    ll ans = (1LL << r+1) - A;
    for(k = r-1;k >= 0 && (B & (1LL << k)) == 0;-- k);
    if(A > (1LL << k+1)) ans -= A - (1LL << k+1);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int  a,b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;
  return 0;
} 

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main(){
  int N,i;
  cin >> N;
  long long a[N];
  for(i=0;i<N;i++){
    cin >> a[i];
  }
  for(i=N-1;i>-1;i-=2){
    cout << a[i] << " ";
  }
  if(i==-2)i=1;
  else i=0;
  for(;i<N;i+=2){
    cout << a[i];
    if(i==N-2 || i== N-1)break;
    cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3712
import java.util.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
    	Scanner s=new Scanner(System.in);
    	int n;
    	n=s.nextInt();
    	for(int i=0;i<n;i++){
    		BigInteger a=s.nextBigInteger().add(s.nextBigInteger());
    		if(a.toString().length()>80) System.out.println("overflow");
    		else System.out.println(a.toString());
    	}
    }
}
//by Tuvshee 12.05.2012
//National budget

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

bool binary_search( int* a, int n , int v )
{
    int left = 0, right = n; 
    bool judge = false;

    while( left < right )
    {
        int mid = ( left + right ) / 2;
        if( a[mid] > v )
            right = mid;
        else if( a[mid] < v )
            left = mid + 1;                     // midではなくて、mid+1
        else
        {
            judge = true;
            break;
        }
    }
    return judge;
}

int main()
{
    int n, q, v;

    cin >> n;

    int a[n];

    for( int i = 0; i < n; i++ )
        cin >> a[i];
    
    cin >> q;

    for( int i = 0; i < q; i++ )
    {
        cin >> v;
        if( binary_search( a, n, v ) == true )
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 3492
#include <stdio.h>
#include <string.h>
int main(void){
    int N,R;
    scanf("%d %d",&N,&R);
    if(N>=10){
        printf("%d\n",R);
    }
    else{
        printf("%d\n",R+(100*(10-N)));
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{

 public static void main(String[] args)
 {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        if(a>=3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }
        
    }

}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;++i){
    cin>>p[i];
  }
  int ans=0;
  for(int i=1;i<n-1;++i){
    if((p[i-1] < p[i]) && (p[i] < p[i+1])){
      ++ans;
    }else if((p[i-1] > p[i]) && (p[i] > p[i+1])){
      ++ans;
    }
  }
  cout<<ans<<endl;
}

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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

template<typename T>
void chmin(T a, T b){if(a>b)a=b;}

template<typename T>
void chmax(T a, T b){if(b>a)a=b;}


int main(){
    int n=read();
    while(n){
        if(n%10==7){
            puts("Yes");
            return 0;
        }
        n/=10;
    }
    puts("No");

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>

using lint = long long int;
using Graph = std::vector<std::vector<lint>>;

template<class T>
struct edge
{
	T dist;
	lint to;
	edge(){}
	edge(const T &a_dist,const lint &a_to) : dist(a_dist), to(a_to) {}
	~edge(){}
};

int main(int argc,char *argv[])
{
	int a,b,x;
	std::cin >> a >> b >> x;
	
	double v0 = a*a*b;

	constexpr double pi = std::acos(-1);
	
	double s = static_cast<double>(x)/a;

	if(s >= a*b/2.0) std::cout << std::setprecision(10) << std::atan((2*(v0-x))/(a*a*a))*180/pi << std::endl;
	else std::cout << std::setprecision(10) << atan2(b,2*s/b)*180/pi  << std::endl;

	return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i=0 ; i<N ; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());
  
  int answer = 0;
  for (int i=0 ; i<K ; i++)
    answer += p.at(i);
  cout << answer << endl;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		String W = sc.nextLine();
		W = W.toLowerCase();
		
		List<String> T = new ArrayList<String>();

		String line = sc.next();
		while (!"END_OF_TEXT".equals(line)) {
			T.add(line.toLowerCase());
			line = sc.next();
		}
		int cnt = 0;
		for (int i = 0; i < T.size(); i++) {
			if (T.get(i).equals(W)) cnt++;
		}
		System.out.println(cnt);
	}
}



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

using namespace std;

const int  MAXN=3;

int n,h[MAXN],f[MAXN]= {0},cnt=1;

int main() {
	scanf("%d%d%d",&n,&h[0],&h[1]);
	f[1]=abs(h[0]-h[1]);
	for(int i=3; i<=n; ++i) {
		scanf("%d",&h[2]);
		f[2]=min(abs(h[2]-h[0])+f[0],abs(h[2]-h[1])+f[1]);
		f[0]=f[1],f[1]=f[2];
		h[0]=h[1],h[1]=h[2];
	}
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define INF 1e9
#define MOD 1e9 + 7
int main() {
    int N;
    cin >> N;
    int ans = N;
    rep(i, 2) ans *= N;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,ans = 1e6,mn = 1e6;string l , r;
  cin>>n;
  for(int i = 1 ; i <= n / 2 + 1 ;i ++)
  {
    stringstream ss;
    ss << i;
    string str = ss.str();
    l = str;
    stringstream ss1;
    ss1 <<n - i;
    str = ss1.str();
    r = str;int a= 0,b = 0;
    for(int j = 0 ; j < l.size() ;j ++)
    {
      a+=l[j] - 48;
    }
    for(int j = 0 ;j < r.size(); j ++)
    {
      b+=r[j] - 48;
    }
     ans = min(ans,a + b);
  }cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
int n, q, a, b, v[200005];
long long c[200005];

void dfs(int p, int v) {
  ::v[p] = 1;
  c[p] += v;
  for(int i: g[p])
    if(!::v[i])
      dfs(i, c[p]);
}

int main() {
  cin >> n >> q;
  for(int i = 0; i < n - 1; ++i)
    cin >> a >> b, g[a].push_back(b), g[b].push_back(a);
  for(int i = 0; i < q; ++i)
    cin >> a >> b, c[a] += b;
  dfs(1, 0);
  for(int i = 1; i <= n; ++i)
    cout << c[i] << " ";
  cout << endl;
}

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

long long min(long long a,long long b){
  if(a < b){
    return a;
  }
  return b;
}

int compare_int(const void *a,const void *b){
  if(*(long*)b-*(long*)a > 0) return 1;
  return -1;
}

int main(void){
  int X,Y,Z,K;
  scanf("%d%d%d%d",&X,&Y,&Z,&K);

  long long A[X],B[Y],C[Z];
  for(int i = 0;i < X;i++) scanf("%lld",&A[i]);
  for(int i = 0;i < Y;i++) scanf("%lld",&B[i]);
  for(int i = 0;i < Z;i++) scanf("%lld",&C[i]);

  qsort(A,X,sizeof(long),compare_int);
  qsort(B,Y,sizeof(long),compare_int);
  qsort(C,Z,sizeof(long),compare_int);

  int cnt = 0;
  long long D[110000];
  for(int i = 0;i < 110000;i++) D[i] = 0;
  for(int i = 0;i < X;i++){
    for(int j = 0;j < Y;j++){
      for(int k = 0;k < Z;k++){
        if((i+1)*(j+1)*(k+1) <= K) D[cnt++] = A[i]+B[j]+C[k];
        else break;
      }
    }
  }

  qsort(D,110000,sizeof(long long),compare_int);

  for(int i = 0;i < K;i++){
    printf("%lld\n",D[i]);
  }

  return 0;
}

Measured memory_bytes: 1916
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [-1 * i for i in a]
heapq.heapify(a)
cnt = 0
while cnt < m:
    x = heapq.heappop(a) * -1
    x = x // 2
    cnt += 1
    heapq.heappush(a, x * -1)
print(sum(a) * -1)

Measured memory_bytes: 14180
import java.util.*;

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

        if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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

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

  vector<int> v;
  v.push_back(1);
  for (int i = 2; i*i <= X; i++) {
    int b = i, p = 2;
    do {
      v.push_back(pow(b, p));
      p++;
    } while (pow(b, p) <= X);
  }

  sort(v.begin(),v.end());
  cout << v.back() << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int h[n];
    int a[n];
    scanf("%d %d", &h[0], &h[1]);
    a[0] = 0; a[1] = abs(h[1]-h[0]);
    for(int i = 2 ; i < n; i++){
        scanf("%d", &h[i]);
        a[i] = min((a[i-2] + abs(h[i] - h[i-2])), (a[i-1] + abs(h[i] - h[i-1])));
    }
    printf("%d", a[n-1]);
    return 0;
}


Measured memory_bytes: 896
from collections import Counter
N, M = map(int, input().split())

class UnionFind:
    def __init__(self, N):
        self.root = list(range(N + 1))
        self.size = [1] * (N + 1)

    def __getitem__(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def merge(self, x, y):
        x = self[x]
        y = self[y]
        if x == y:
            return
        sx, sy = self.size[x], self.size[y]
        if sx < sy:
            x, y = y, x
            sx, sy = sy, sx
        self.root[y] = x
        self.size[x] += sy


A, B = [], []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

count = 0
for i in range(M):
    uni = UnionFind(N)
    for j in range(M):
        if j == i:
            continue
        uni.merge(A[j], B[j])
    # UnionFindの連結成分の個数を数える
    roots = [uni[x] for x in uni.root[1:]]
    counter = Counter(roots)
    if len(counter) > 1:
        count += 1

print(count)

Measured memory_bytes: 9376
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  string Sunny = "Sunny";
  string Cloudy = "Cloudy";
  string Rainy = "Rainy";
  if (S == Sunny) cout << Cloudy << endl;
  if (S == Cloudy) cout << Rainy << endl;
  if (S == Rainy) cout << Sunny << endl;
  return;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int mod = (int)1e9 + 7;

int pow_mod(int x, int n, int m) {
  int res = 1;
  for (; n != 0; n >>= 1) {
    if ((n & 1) == 1) {
      res = ((long long)res * x) % m;
    }
    x = ((long long)x * x) % m;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int p10 = pow_mod(10, n, mod);
  int p9 = pow_mod(9, n, mod);
  int p8 = pow_mod(8, n, mod);
  int ans = (p10 + p8) % mod;
  ans = (ans - 2 * p9) % mod;
  if (ans < 0) {
    ans += mod;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
unittest
{
	assert( [ "2 4" ].parse.expand.solve == 5 );
	assert( [ "123 456" ].parse.expand.solve == 435 );
	assert( [ "123456789012 123456789012" ].parse.expand.solve == 123456789012 );
	
	assert( [ "0 1000000000000" ].parse.expand.solve == 1000000000000 );		// 追加ケース
	assert( [ "2 1000000000000" ].parse.expand.solve == 1000000000001 );		// 追加ケース
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	auto ans = a;
	
	for( auto i = a + 1; i <= b; i++ )
	{
		ans ^= i;
		
		// ansとaが同じ値の場合、4つ進んでもansはaのままになるので、その間の計算は省略できる
		// ansが0の場合も同上
		if( ans == a || ans == 0 ) i += ( b - i ) - ( b - i ) % 4;
	}
	
	return ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using static System.Console;

class Program
{
    static void Main()
    {
        var input = ReadLine().Split(' ');
        var X = int.Parse(input[0]);
        var Y = int.Parse(input[1]);
        if (X % Y != 0) WriteLine(X);
        else WriteLine(-1);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  string s;
  cin >> s;

  rep(i,2) s.pop_back();

  while(1){
    int size = s.size();
    if(size == 0){
      break;
    }
    if(size%2 == 0){
      if(s.substr(0,size/2) == s.substr(size/2, size/2)){
        cout << size << endl;
        return 0;
      }else{
        rep(i,2) s.pop_back();
      }
    }
  }
}

Measured memory_bytes: 256
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

import itertools

A = [i+1 for i in range(N)]
all_permutation_list = list(itertools.permutations(A))
a = all_permutation_list.index(P)
b = all_permutation_list.index(Q)
print(abs(a - b))

Measured memory_bytes: 8052
#include <cstdio>
#include <iostream>
#include <cstdio>

using std::cin;
using std::cout;
using std::endl;

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

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

	return 0;
}

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

const int maxn=1e9+10;

int main()
{
	double a,b;
	cin>>a>>b;
		if (a>=13)
		cout<<b<<endl;
	else if (a>=6)
		cout<<b/2<<endl;
	else
		cout<<0<<endl;


	return 0;
}


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

int main()
{
	int n;
	cin>>n;
	int ans=0;
	vector<int> arr(n+1);
	for(int i=1;i<=n;i++) cin>>arr[i];
	vector<int> dp(n+1,0);
	dp[2]=abs(arr[2]-arr[1]);
	for(int i=3;i<=n;i++)
	{
		dp[i]=min( dp[i-1]+abs(arr[i]-arr[i-1]) , dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n];
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int p1 = m / 2, p2 = m / 2;
    if (m % 2 == 1) p1++;

    for (int i = 1; i <= p1; i++) {
        cout << i << " " << 2 * p1 + 1 - i << endl;
    }
    int base = p1 * 2;
    for (int i = 1; i <= p2; i++) {
        cout << i + base << " " << base + 2 * p2 + 2 - i << endl;
    }
}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	int t, x, y;
	int pt = 0;
	int xy = 0;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		int tmpt = t-pt;
		int tmpxy = x + y;
		if (tmpxy-xy > tmpt) {
			cout << "No" << "\n";
			return 0;
		}
		if (abs((tmpxy-xy)) % 2 == 0 && tmpt%2 != 0) {
			cout << "No" << "\n";
			return 0;
		}
		if (abs((tmpxy-xy)) % 2 != 0 && tmpt%2 == 0) {
			cout << "No" << "\n";
			return 0;
		}
		xy = tmpxy;
		pt = t;
	}
	cout << "Yes" << endl;

}


Measured memory_bytes: 256
//I am so vegetable
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define _for(i,a,b) for(ll i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
//#define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 2e3;
const int MOD = 998244353;
const double exps = 1e-6;
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
int main() {
#ifdef _LOCAL_
	ifstream cin("E:\\acm dream\\in.txt");
	ofstream cout("E:\\acm dream\\out.txt");
#endif
	//srand((unsigned)time(nullptr));
	FIO;
	int a, b; cin >> a >> b;
	int i;
	bool flag = false;
	for(i = max(a,b);i<=2e3;++i) {
		int x = i * 0.08, y = i * 0.1;
		if (x == a && y == b) {
			flag = true;
			break;
		}
	}
	if (flag)cout << i;
	else cout << -1;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
char t;
int n,m,flag=1,k,p;
vector<char> v1,v2;
int main(){
	cin>>s>>n;
	while(n--){
		cin>>k;
		if(k==1)
			flag=3-flag;
		else{
			cin>>p>>t;
			if((p+flag)%2){
				v2.push_back(t);
			}else{
				v1.push_back(t);
			}
		}
	}
	if(flag==2){
		for(int i=v2.size()-1;i>=0;i--)
			cout<<v2[i];
		for(int i=s.size()-1;i>=0;i--)
			cout<<s[i];
		for(int i=0;i<v1.size();i++)
			cout<<v1[i];
	}else{
		for(int i=v1.size()-1;i>=0;i--)
			cout<<v1[i];
		cout<<s;
		for(int i=0;i<v2.size();i++)
			cout<<v2[i];
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

double dp[301][301][301];
int n;

double fun(int one, int two, int three){
    if(one+two+three==0)    return 0;
    if(dp[one][two][three]!=0) return dp[one][two][three];
    dp[one][two][three]=n*1.0/(one+two+three);
    if(one>0){
        dp[one][two][three]+=(one*fun(one-1,two,three))/(one+two+three);
    }
    if(two>0){
        dp[one][two][three]+=(two*fun(one+1,two-1,three))/(one+two+three);
    }
    if(three>0){
        dp[one][two][three]+=(three*fun(one,two+1,three-1))/(one+two+three);
    }
    return dp[one][two][three];
}

int main(){
	ios::sync_with_stdio(false);
	int i;  cin>>n;
	int one=0,two=0,three=0;
	for(i=1;i<=n;i++){
	    int num;    cin>>num;
	    if(num==1)  one++;
	    if(num==2)  two++;
	    if(num==3)  three++;
	}
	printf("%.12lf",fun(one,two,three));
	return 0;
}

Measured memory_bytes: 213248
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var ans = cin.ReadIntArray(N).Min(x => {
                var c = 0;
                while(x % 2==0 && x!= 0){x >>= 1; ++c;}
                return c;
            });
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}

Measured memory_bytes: 13396
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Zahyou = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		list.add(Zahyou);
		Collections.sort(list);


		int kyori = 1000000001;
		int num = 0;
		for(int i = 0; i < N; i++) {
			num = Math.abs(list.get(i+1)-list.get(i));

			if(num == 0) {
				continue;
			}
			if(kyori == 1000000001) {
				kyori = num;
				continue;
			}
			kyori = gcd(kyori,num);

		}

		if(kyori == 1000000001) {
			kyori = 0;
		}
		System.out.println(kyori);
		sc.close();
	}


	//最大公約数gcd
	static int gcd (int a, int b) {
		if(b == 0) {
			return a;
		}
		if(b % a == 0) {
			return a;
		}
		if(a % b == 0) {
			return b;
		}

		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}

}

Measured memory_bytes: 59848
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 55;
const LL MOD = 1000000007;

LL calc(int N, int K) {
	int p[MAXN];
	LL ans = 0;
	for (int i = 1; i <= N; i++) p[i] = i;
	do {
		LL odd = 0;
		for (int i = 1; i <= N; i++) {
			odd += abs(p[i] - i);
		}
		if (odd == K) ans++;
	} while (next_permutation(p + 1, p + N + 1));
	return ans;
}

int N, K, C;
LL dp[2][MAXN][MAXN * MAXN * 2];

bool valid(int oddness, int i) {
	int bound = i * (i + 1);
	return -bound <= oddness && oddness <= bound;
}

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

	cin >> N >> K;
	int shift = N * (N + 1);
	dp[1][0][shift] = dp[1][1][-2 + shift] = 1;
	for (int i = 2; i <= N; i++) {
		auto pre = dp[(i - 1) % 2], cur = dp[i % 2];
		for (int j = 0; j <= i; j++) {
			for (int k = -i * (i + 1); k <= i * (i + 1); k++) {
				cur[j][k + shift] = pre[j][k + shift];
				if (j >= 1) cur[j][k + shift] += 2 * j * pre[j][k + shift];
				if (valid(k - 2 * i, i - 1)) cur[j][k + shift] += (j + 1) * (j + 1) * pre[j + 1][k - 2 * i + shift];
				if (j >= 1 && valid(k + 2 * i, i - 1)) cur[j][k + shift] += pre[j - 1][k + 2 * i + shift];
				cur[j][k + shift] %= MOD;
//				cout << "At " << i << " " << j << " " << k << " " << cur[j][k + shift] << '\n';
			}
		}
	}
	
//	for (int i = 1; i <= N * (N + 1); i++) {
//		int real = calc(N, i);
//		if (dp[N % 2][0][i + shift] != real) {
//			cout << "Nope " << i << " " << real << " " << dp[N % 2][0][i + shift] << '\n';
//		}
//	}
//	cout << "Real " << calc(N, K) << '\n';
	cout << dp[N % 2][0][K + shift] << '\n';

	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
#define ll long long
ll a[500];
int main()
{
	ll sum=1e18;
	int n;
	cin>>n;
	ll c=0;
	for(int i=0;i<n;++i){
        cin>>a[i];
        c+=a[i];
	}
	ll k=c/n;
	ll tp=0;
	for(int i=0;i<n;++i)tp+=(a[i]-k)*(a[i]-k);
	sum=min(sum,tp);
	++k;
	tp=0;
	for(int i=0;i<n;++i)tp+=(a[i]-k)*(a[i]-k);
	sum=min(sum,tp);
	cout<<sum<<endl;
	return 0;
}


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

int main(void)
{
	char password[21];
	int num, lower, upper;
	int i;
	
	scanf("%s", password);
	
	num = lower = upper = 0;
	
	i = 0;
	while (password[i] != '\0'){
		if ('A' <= password[i] && password[i] <= 'Z'){
			upper = 1;
		}
		if ('a' <= password[i] && password[i] <= 'z'){
			lower = 1;
		}
		if ('0' <= password[i] && password[i] <= '9'){
			num = 1;
		}
		i++;
	}
	
	if (strlen(password) >= 6 && num == 1 && lower == 1 && upper == 1){
		printf("VALID\n");
	}
	else {
		printf("INVALID\n");
	}
	
	return (0);
}

Measured memory_bytes: 524
/****************************
<ABC164_D>
****************************/
#include<bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<(n);i++)
#define ll long long
using namespace std;
int main(){
    const int MAX = 200000; 
    string s; cin >> s;
    int n = s.length();
    reverse(s.begin(),s.end()); 
    int a[MAX+1],b[MAX+1];
    rep(i,n) a[i] = s[i] - '0';
    int num = 1;
    b[n-1] = 0;
    rep(i,n){
        b[i+1] = (num*a[i] + b[i]) % 2019;
        num = (10 * num) % 2019;    //10^iになるのか？
    }
    ll cnt[2019] = {};
    rep(i,n+1) cnt[b[i]] ++;
    ll ans = 0;
    rep(i,2019){
        if(cnt[i] > 1) ans += (cnt[i]*(cnt[i] - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5296
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i].append((1, (i + 1) % k))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0] + 1
print(ans)


Measured memory_bytes: 42328
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    int count = 0;
    rep(i, 1, N + 1){
        int a;
        cin >> a;
        if((i % 2 == 1) && (a % 2 == 1)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N, r;
  cin >> N;
  cin >> r;
  bool flag = false;
  int a;
  while(true){ 
  	N -= 500;
    if(N < 500){
      a = N;
      flag = true;
    }
    if(flag)break;
  }
  
  if(r >= a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
S = gets.chomp
if S != S.reverse
  puts "No"
  exit
end

length = S.length
s2 = S[0...(length/2)]
if s2 != s2.reverse
  puts "No"
  exit
end

s3 = S[length...-1]
if s3 != s3.reverse
  puts "No"
  exit
end

puts "Yes"

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	static int intN =0;
	static int sosuCnt =0;

	public static void main(String[] args) {
		//test
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String result = "";
		if (Integer.parseInt(s) < 1200) {
			result = "ABC";
		} else if (Integer.parseInt(s) < 2800) {
			result = "ARC";
		} else {
			result = "AGC";
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 21844
N = int(input())

import sys
input = sys.stdin.readline

testimony = {}

for n in range(1, N+1):
    A = int(input())
    testimony[n] = {}
    for _ in range(A):
        x, y = map(int, input().split())
        testimony[n][x] = y
#print(testimony)        

def dfs(idx, ans):
    #print(idx, ans)
    if not idx in testimony:
        ret = 0
        #print(ans)
        for a in ans:
            if a != 0:
                ret += 1
        return ret
    
    ans_true = ans[:]
    flag_true = True
    ans_false = ans[:]
    flag_false = True
    
    if ans[idx] == 0:
        flag_true = False
    else:
        ans_true[idx] = 1
        for k, v in testimony[idx].items():
            if ans_true[k] == 2 or ans_true[k] == v:
                ans_true[k] = v
            else:
                flag_true = False
                break
    if ans[idx] == 1:
        flag_false = False
    else:
        ans_false[idx] = 0
        #for k, v in testimony[idx].items():
        #    v = (v+1)%2
        #    if ans_false[k] == 2 or ans_false[k] == v:
        #        ans_false[k] = v
        #    else:
        #        flag_false = False
        #        break
            
    if flag_false and flag_true:
        a = dfs(idx+1, ans_true)
        b = dfs(idx+1, ans_false)
        return max(a, b)
    elif flag_false:
        return dfs(idx+1, ans_false)
    elif flag_true:
        return dfs(idx+1, ans_true)
    else:
        return 0
        
    
ans = dfs(1, [0]+[2]*N)
print(ans)

Measured memory_bytes: 41064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9023372036854775807ll;
long long n,m,w[105],v[105],dp[105][N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];
	memset(dp,63,sizeof(dp));
	dp[1][0]=0,dp[1][v[1]]=w[1];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=100000;j++)
			dp[i][j]=dp[i-1][j];
		for(int j=v[i];j<=100000;j++)
			dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
	}
	for(int i=100000;i>=0;i--)
		if(dp[n][i]<=m)
		{
			cout<<i;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 82432
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N,P,ans=1;
    cin>>N>>P;
    map<ll,ll> m;
    for(ll i=2;i*i<=P;i++){
        if(P<=1) break;
        while(P%i==0){
            m[i]++;
            P/=i;
        }
    }
    m[P]++;
    for(auto a:m){
        ans*=pow(a.first,a.second/N);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main
import "fmt"

func main(){
    var a,b int
    fmt.Scan(&a,&b)
    if a>b {
        fmt.Print("a > b\n")
    }else if a<b{
        fmt.Print("a < b\n")
    }else{
        fmt.Print("a == b\n")
    }
}



Measured memory_bytes: 1128
#include <cstdio>

int main(void){
	int c[3][3]={0};
	int i, j;
	int sum_a[3] = {0};
	int sum_b[3] = {0};
	int diff_a[2] = {0}; //a1 a2 a3 の差
	int diff_b[2] = {0}; //b1 b2 b3 の差

	scanf("%d%d%d%d%d%d%d%d%d", &c[0][0], &c[0][1], &c[0][2], &c[1][0], &c[1][1], &c[1][2], &c[2][0], &c[2][1], &c[2][2]);

	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			sum_a[i] += c[i][j] ;
		}
	}

	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			sum_b[i] += c[j][i] ;
		}
	}

	for(i=0;i<2;i++)
	{
		diff_a[i] = (sum_a[i+1] - sum_a[0])/3;
		diff_b[i] = (sum_b[i+1] - sum_b[0])/3;
	}
	
	for(i=1;i<3;i++)
	{
		for(j=1;j<3;j++)
		{
			if(c[i][j]!=(c[0][0] + diff_a[i-1] + diff_b[j-1]))
			{
				printf("No\n");
				return 0;
			}
		}
	}


	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
string s, t;
int main() {
	cin >> s >> t;
	bool pos = false;
	for (int i = 0; i < s.length(); i++) {
		for (int j = i; j < i + t.length(); j++) {
			if (s[(j - i)] != t[j % s.length()])
				break;
			if (j == i + t.length() - 1) {
				pos = true;
			}
		}
	}
	if (pos)
		cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
	int A, B,X;
	cin >> A >> B;

	if (A > B) cout << A + (A - 1) << endl;
	else if (A < B) cout << B + (B - 1) << endl;
	else cout << A + B << endl;

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,p;
map<ll,ll> cnt;

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

  cin>>n>>p;
  for(ll i=2;i*i<=p;i++){
    while(p%i==0){
      cnt[i]++;
      p/=i;
    }
  }
  if(p!=1)cnt[p]=1;

  ll res=1;
  for(P ps : cnt){
    res*=pow(ps.fi,ps.se/n);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,m,i,n,x,y,z;
	x=0;
	y=0;
	z=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		if(a>=n){
			x=0;
		}
		if(a<n){
			x=n-a;
		}
		if(y<x){
			y=x;
		}
		z=z+x;
	}
	z=z-y;
	cout<<z<<endl;
	
	return 0;
}



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

using namespace std;

int main() {
int o0=0,o1=0,e0=0,e1=0;
string s="x";
string s1;
cin>>s1;
s=s+s1;
for(int i=1;i<s.length();i++)
{
    if(s[i]=='0'&&i%2!=0)
    {
        o0++;
    }
    else if(s[i]=='0'&&i%2==0)
    {
        e0++;
    }
    if(s[i]=='1'&&i%2!=0)
    {
        o1++;
    }
    if(s[i]=='1'&&i%2==0)
    {
        e1++;
    }
}
cout<<min(e0,o0)+min(e1,o1);
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

int64_t x;

int main(int argc, char **argv) {
    std::cin >> x;

    int64_t ret = 0;

    ret = (x / 11) * 2;
    x %= 11;

    if (1 <= x && x <= 6) {
        ret += 1;
    } else if (6 < x) {
        ret += 2;
    }

    std::cout << ret << std::endl;
    
    return 0;
}

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





int32_t main()
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0 ; i<n ; i++)
    {
        cin>>v[i];

    }
    vector<int>dp(n+1,0);
    dp[0]=0;
    dp[1] = 0;
    dp[2] = dp[1]+abs(v[1]-v[0]);
    for(int i=3 ; i<=n ; i++)
    {
        dp[i] = min(dp[i-1]+abs(v[i-1]-v[i-2]) , dp[i-2]+abs(v[i-1]-v[i-3]));

    }
    cout<<dp[n]<<endl;

}


Measured memory_bytes: 4784
import qualified Data.ByteString.Char8 as B

main = B.getLine >>= print . check . B.tail . B.reverse
    where
        check xs
            | odd len = solve (B.tail xs) (len - 1)
            | otherwise = solve xs len
            where
                len = B.length xs


solve :: B.ByteString -> Int -> Int
solve xs len
    | ys == zs = len
    | otherwise = solve (B.drop 2 xs) (len - 2)
    where
        (ys, zs) = B.splitAt (len `div` 2) xs


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int N;
  int K;
  int i=0;
  int sum=0;
  cin>>N>>K;
  while(i<N){
    int a;
    cin>>a;
    if(a>=K-a){
      sum=sum+2*K-2*a;
    }else{
      sum+=2*a;
    }
    i++;
  }
    cout<<sum<<endl;

}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=1e5+5;
ll i,j;

/*


*/
ll dp[N];
void solve(){
	in2(n,W);
	for(ll item=0;item<n;item++){
		in2(w,v);
		for(i=W-w;i>=0;i--){
			dp[i+w]=max(dp[i]+v,dp[i+w]);
		}
	}    
	ll best=0;
	for(i=0;i<=W;i++){
		best=max(best,dp[i]);
	}
	ce(best);
}

int32_t main(){
    // jaldi
    ll t; 
    // cin>>t;
    t=1;     
    while(t--){
        solve();
    }
}

/*


*/

  

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

int N, M;

struct Node {
    int p = -1;
    veci connects;
};

int main(void) {
    cin >> N >> M;
    
    vector<Node> dg(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        dg[a].connects.push_back(b);
        dg[b].connects.push_back(a);
    }

    queue<int> Q;
    veci searched(N, 0);

    Q.push(0);
    searched[0] = 1;
    while(!Q.empty()) {
        int idx = Q.front();

        for (int i = 0; i < dg[idx].connects.size(); ++i) {
            int k = dg[idx].connects[i];
            if (searched[k] == 0)
            {
                searched[k] = 1;
                Q.push(k);
                dg[k].p = idx;
            }
        }

        Q.pop();
    }

    cout << "Yes" << endl;
    REP(i, 1, N) {
        cout << dg[i].p + 1 << endl;
    }

    return 0;
}

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

struct DisjointSet
{
  vector<int> par;
  DisjointSet(int n) : par(n, -1) {}
  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x)
  {
    if (par[x] < 0)
      return x;
    int r = find(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
};

int n, q, x, y;
string s;
long long a[6060];

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<pair<int, int>> edge;
  for (size_t i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge.emplace_back(a, b);
  }

  int ans = 0;
  for (size_t i = 0; i < m; i++)
  {
    DisjointSet ds(n);
    for (size_t j = 0; j < m; j++)
    {
      if (i == j)
        continue;
      ds.unite(edge[j].first, edge[j].second);
    }
    if (ds.sizeOf(0) != n)
      ++ans;
  }

  cout << ans;

  return 0;
}


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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int m = max(a, max(b, c));
    for(int i = 0;i < k;i++){
        m *= 2;
    }
    if(max({a, b, c}) == c)cout << a + b + m << endl;
    else if(max({a, b, c}) == b)cout << a + c + m << endl;
    else if(max({a, b, c}) == a)cout << b + c + m << endl;


}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt;
struct sell{
	int l,r;
}a[300005];
struct Query{
	int l,r,d;
}b[2000005];
int f[100005],g[100005],ans[100005];

int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}

void print(int x){
	if(x>=10) print(x/10);
	putchar(x%10+'0');
}

int cmp(Query u,Query v){
	return u.l>v.l;
}

int cmp1(sell u,sell v){
	return u.l>v.l;
}

void updata(int x){
	for(int i=x;i<=m;i+=i&-i) f[i]++;
}

void updata1(int x){
	for(int i=x;i<=m;i+=i&-i) g[i]++;	
}

int query(int x){
	int res=0;
	for(int i=x;i;i-=i&-i) res+=f[i];
	return res;
}

int query1(int x){
	int res=0;
	for(int i=x;i;i-=i&-i) res+=g[i];
	return res;	
}

int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=(sell){read(),read()};
	for(int i=1;i<=m;i++){
		for(int j=i;j<=m;j+=i) b[++cnt]=(Query){j-i,j,i};
	}
	sort(b+1,b+cnt+1,cmp);
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++) updata(a[i].l);
	int L=0;
	for(int i=1;i<=cnt;i++){
		while(L<n&&a[L+1].l>b[i].l) L++,updata1(a[L].r);
		ans[b[i].d]+=L-query1(b[i].r-1)-(n-query(b[i].r));
	}
	for(int i=1;i<=m;i++) print(ans[i]),puts("");
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
string s, t;
/******* define variable end *******/
int solve() {
	cin >> s >> t;
	t.erase(t.size()-1, 1);
	if(s == t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3644
N=int(input())
q=list(map(int,input().split()))

ans=[]
while q:
    n=len(q)
    for i in range(0,n):
        if q[n-i-1]==n-i:
            ans.append(n-i)
            if i==0:
                q=q[:n-1]
                break
            else:
                q=q[:n-i-1]+q[n-i:]
                break
    else:
        print(-1)
        break
else:
    for i in range(0,N):
        print(ans[-i-1])

Measured memory_bytes: 38512