akhauriyash/Code-Regression huggingface dataset:
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

module Util =
    let strRev s =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

[<EntryPoint>]
let main _ =
    let s = read string
    let len = s.Length
    let mid = len / 2

    let l, r =
        if len % 2 = 0 then s.Substring(0, mid), s.Substring(mid)
        else s.Substring(0, mid), s.Substring(mid + 1)

    let r = Util.strRev r

    Seq.map2 (fun x y ->
        if x <> y then 1
        else 0) l r
    |> Seq.sum
    |> printfn "%d"
    0 // return an integer exit code


Measured memory_bytes: 14300
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0,2,5,5,4,5,6,3,7,6]
wv=[]
for i in a:
  wv.append((b[i],i))
wv.sort()
dp=[-1 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
  for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v)
print(dp[n])

Measured memory_bytes: 14516
import scala.math.{min,max}

object Main {
    def main(args: Array[String]) {
        var input = io.Source.stdin.getLines().mkString("\n");
        var ss = input.split('\n').toList;
        val xs = to_array_int(ss(0));
        val a = xs(0);
        val p = xs(1);
        val res = (3 * a + p) / 2;
        println(res);
    }
    def to_array_int(s: String): Array[Int] = {
        return s.split(' ').map(_.toInt).toArray;
    }
}


Measured memory_bytes: 27452
s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(da,dp,G):
    for i in range(len(da)):
        tmp=set()
        for j in dp:
            tmp.add(j-da[i])
            tmp.add(j+da[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False
    """amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][G]>=1:
            return True
    return False"""
    """#print(a)
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    #print(dp)
    if G in dp:
        return True
    return False"""

d=[len(x) for x in s.split("T")]

dx=d[2::2]
dy=d[1::2]

if solve(dx,{d[0]},X) and solve(dy,{0},Y):
    print("Yes")
else:
    print("No")


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

// flag ?????¨????????????????????????
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for ( int i = 0; flag; i++ ) {
    flag = 0;
    for ( int j = N - 1; j >= i + 1; j-- ) {
      if ( A[j] < A[j - 1] ) {
        // ??£??\????´????????????????
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for ( int i = 0; i < N; i++ ) cin >> A[i];
  
  sw = bubbleSort(A, N);
  
  for ( int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    int n, k;
    while (cin >> n >> k) {
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        int s = 0;
        int m = 0;
        for (int i = 0; i < n; ++i) {
            s += a[i];
            if (i - k >= 0) {
                s -= a[i - k];
            }
            m = max(m, s);
        }
        cout.precision(10);
        cout << fixed << (m + k) / 2. << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder=new StringBuilder();
        while(true){
            String data[]=reader.readLine().split(" ");
            int x=Integer.parseInt(data[0]);
            int y=Integer.parseInt(data[1]);
            if(x==0 && y==0) break;
            builder.append(Integer.toString(x<y?x:y)).append(" ").append(Integer.toString(x<y?y:x)).append("\n");
        }
        System.out.print(builder);
    }
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
pair <int, int> p[200100];
int nreach[200100], dp[200100];
int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) cin >> p[i].first >> p[i].second;
    sort (p, p + N);
    dp[N] = 1;
    for (int i = N - 1; i >= 0; i--) {
        int xend = p[i].first + p[i].second, cloc = i + 1;
        while (cloc < N && p[cloc].first < xend) cloc = nreach[cloc];
        dp[i] = (dp[i+1] + dp[nreach[i] = cloc]) % 998244353;
    }
    cout << dp[0] << "\n";
}

Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        int flag=1;
        a=0,b=0;
        queue<int>que;
        while(que.size())que.pop();
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                flag=0;
                break;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        if(flag)cout<<"YES\n";
    }

    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  string s;
  cin >> n >> s;
  vl r(n + 1, 0), g(n + 1, 0), b(n + 1, 0);
  rep(i, n) {
    r[i + 1] = r[i];
    g[i + 1] = g[i];
    b[i + 1] = b[i];
    if(s[i] == 'R')
      r[i + 1]++;
    else if(s[i] == 'G')
      g[i + 1]++;
    else
      b[i + 1]++;
  }
  ll ans = 0;
  rep(i, n - 2) rep2(j, i, n - 1) {
    if(s[i] == s[j]) continue;
    char x = s[i];
    char y = s[j];
    if(x < y) swap(x, y);
    ll now;
    int k = 2 * j - i;
    if(x == 'R' && y == 'G') {
      now = b[n] - b[j];
      if(k < n && s[k] == 'B') now--;
    } else if(x == 'G' && y == 'B') {
      now = r[n] - r[j];
      if(k < n && s[k] == 'R') now--;
    } else {
      now = g[n] - g[j];
      if(k < n && s[k] == 'G') now--;
    }
    ans += now;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3712
N, M = map(int, input().split())
height = list(map(int, input().split()))
l = [1] * N
for i in range(M):
    A, B = map(int, input().split())
    if height[A - 1] > height[B - 1]:
        l[B - 1] = 0
    else:
        if height[B - 1] > height[A - 1]:
            l[A - 1] = 0
        else:
            l[B - 1] = 0
            l[A - 1] = 0
print(l.count(1))

Measured memory_bytes: 20116
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include<map>
#include <sstream>
#include <deque>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define ll long long int
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;

//insta  -------  __ansh7
//MSDIAN




int main()
{
    fastio

    ll n;
    cin>>n;

    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }

    ll count=0;

    ll i=0;

    while(i<n)
    {
        if(a[i]%2!=0)
        {
            count++;
        }
        i=i+2;
    }

 

        cout<<count<<"\n";




  

  
    
 



    




    return 0;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())

ans = 0
# mod k == 0の数
m0 = n // k
ans += m0**3
# mod k == 0の数

if k % 2 == 0:
    k2 = k // 2
    mk2 = 0
    for i in range(1, n+1):
        if i % k == k2:
            mk2 += 1
    ans += mk2 ** 3

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define TRUE 1
#define FALSE 0

void print_array(int *A, int N) {
	for (int i = 0; i < N - 1; i++) {
		printf("%d ", A[i]);
	}
	printf("%d\n", A[N-1]);
}

void insertion_sort(int *A, int N) {
	int v, j;
	for (int i = 1; i < N; i++) {
		print_array(A, N);
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
	print_array(A, N);
}

int main(void) {
	int N;
	int *array;
	scanf("%d", &N);
	array = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		scanf("%d", array + i);
	}
	insertion_sort(array, N);
	return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    for (int i = 0; i < N - 1; i++) {
        if (A[i] < 0) {
            A[i] *= -1;
            A[i + 1] *= -1;
        }
    }

    ll sum = 0;
    int m = 1e9 + 10;
    for (int i = 0; i < N; i++) {
        sum += A[i];
        m = min(m, abs(A[i]));
    }

    if (A[N - 1] >= 0) {
        cout << sum << endl;
    } else {
        cout << sum - 2 * A[N - 1] - 2 * m << endl;
    }
}


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


int main() {

    int x, y;
    cin >> x >> y;
    int mn = 10000;
    for (int i = 0; i <= x; ++i) {
        int ans = 1;
        int a = i;
        int b = x - i;
        for (int j = 0; j < a; ++j) {
            ans *= 2;
        }
        for (int k = 0; k < b; ++k) {
            ans += y;
        }
        mn = min(mn, ans);
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	string sthat[27][27],sthis[27][27];
	for(int a=0;a<27;a++){
		for(int b=0;b<27;b++){
			sthat[a][b]=(char)((a*('t'-'a')+b)%26+'a');
			sthat[a][b]+=(char)((a*('h'-'a')+b)%26+'a');
			sthat[a][b]+=(char)((a*('a'-'a')+b)%26+'a');
			sthat[a][b]+=(char)((a*('t'-'a')+b)%26+'a');
			sthis[a][b]=(char)((a*('t'-'a')+b)%26+'a');
			sthis[a][b]+=(char)((a*('h'-'a')+b)%26+'a');
			sthis[a][b]+=(char)((a*('i'-'a')+b)%26+'a');
			sthis[a][b]+=(char)((a*('s'-'a')+b)%26+'a');
		}
	}

	int n;
	string in,inp;
	int mm;
	bool f;

	cin>>n;
	getchar();
	for(int i=0;i<n;i++){
		inp=("");
		while(1){
			in=getchar();
			if(in=="\n") break;
			else inp+=in;
		}
		f=true;
		for(int a=0;f&&a<27;a++){
			for(int b=0;f&&b<27;b++){
				if(inp.find(sthat[a][b])!=-1||inp.find(sthis[a][b])!=-1){
					for(int j=0;j<inp.length();j++){
						if(inp[j]!=' '){
							for(int k=26;;k+=26){
								if(((inp[j]-'a')+k-b)%a==0){
									mm=((inp[j]-'a')+k-b)/a;
									while(mm>=26) mm-=26;
									inp[j]=(char)(mm+'a');
									f=false;
									break;
								}
							}

						}
					}
				}
			}
		}
		cout<<inp<<endl;
	}

	return 0;
}

Measured memory_bytes: 1288
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  while b != 0:
    a, b = b, a%b
  return a

for i in range(n-1):
  a[i+1] = gcd(a[i], a[i+1])
  
print(a[-1])

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int A, B;
	cin >>A >>B;
	int C=10001;
	Rep0(i, C) {
		int D=i*8/100;
		int E=i/10;
		if ((D==A)&&(E==B)) {
			cout <<i <<endl;
			return 0;
		}
	}
	cout <<-1 <<endl;
	return 0;
}



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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
    int N, ans = 0, count = 0;
    IN(N);
    FOR(i, 1, N + 1) {
        ans = log10(i);
        if(ans % 2 == 0) count++;
    }
    OUT(count);
}

Measured memory_bytes: 512
#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 998244353

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N;
ll D[100010],cnt[100010];

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

  cin>>N;
  rep(i,N){
    cin>>D[i];
    cnt[D[i]]++;
  }
  {
    bool ok=true;
    if(D[0]!=0){
      ok=false;
    }
    repl(i,1,N){
      if(D[i]==0)ok=false;
    }
    if(!ok){
      cout<<0<<endl;
      return 0;
    }
  }

  ll res=1;
  rep(i,N-1){
    if(cnt[i]==0&&cnt[i+1]>0){
      res=0;
    }else if(cnt[i]>0&&cnt[i+1]>0){
      res*=mod_pow(cnt[i],cnt[i+1]);
      res%=mod;
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

const int MAX_ROW = 70;
const int MAX_COL = 100005;
struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

void GaussJordan(BitMatrix& A, bool is_extended = false) {
	vector<bool> used(A.H, 0);
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = 0; row < A.H; ++row) {
			if (used[row]) continue;
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		for (int row = 0; row < A.H; ++row) {
			if (row != pivot && A[row][col]) A[row] ^= A[pivot];
		}
		used[pivot] = true;
	}
}
const int MD = 60;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	ll ans = 0;

	BitMatrix BM(MD+1, N+1);//65個の方程式，各方程式に対してN個の変数(0か1)
	vector<bool> cannot(MD+1, 0);

	for (ll mask = MD; mask >= 0; mask--)
	{
		int num = 0;
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				num++;
			}
		}

		if (num == 0) {
			//全て0
			cannot[mask] = 1;
			continue;
		}
		else if (num & 1) {
			//1が奇数個(この桁は値は一定)
			cannot[mask] = 1;
			ans += (1LL << mask);
			continue;
		}

		//ここは1が偶数個存在する場合
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				BM[MD - mask][i] = 1;
			}

		}
		BM[MD - mask][N] = 1;
	}

	GaussJordan(BM, true);

	for (int mask = MD; mask >= 0; mask--)
	{
		if (cannot[mask]) {
			continue;
		}

		bool ok = false;

		for (int i = 0; i < N; i++)
		{
			if (BM[MD - mask][i]) {
				ok = true;
			}
		}
		if (!BM[MD - mask][N]) {
			ok = true;
		}

		if (ok) {
			ans += (1LL << (mask + 1));
		}
	}

	cout << ans << endl;
	

}



Measured memory_bytes: 1920
n = gets.to_i
a = gets.split.map(&:to_i).sort

ans = 10 ** 9
(a.min..a.max).each do |y|
  sum = 0
  a.each do |x|
    sum += (x - y) ** 2 
  end
  ans = sum if sum < ans
end
puts ans


Measured memory_bytes: 1788
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

o = lc()
e = lc()

ans = []

if len(o)-len(e) == 0:
    for i in range(len(o)):
        ans.append(o[i])
        ans.append(e[i])
        
else:
    for i in range(len(e)):
        ans.append(o[i])
        ans.append(e[i])
        
    ans.append(o[i+1])


print("".join(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1
 
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;
int main(){
	int A,B;
	cin>>A>>B;
	REP(i,(A-1)*2+1){
	    cout<<B-A+1+i;
	    if(i!=(A-1)*2)cout<<" ";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int si=s.size();
  string cp;
  int min=INF;
  rep(i,si){
    char key=s[i];
    bool fg;
    int count=0;
    cp=s;
    while(true){
      fg=true;
      int si2=cp.size();
      string cp2;
      string cp3;
      rep(i,si2){
        if(cp[i]!=key){
          fg=false;
          break;
        }
      }
      if(fg){
        break;
      }
      cp2=cp;
      cp="";
      rep(j,si2-1){
        if(cp2[j]==key){
          cp+=cp2[j];
        }
        else if(cp2[j+1]==key){
          cp+=cp2[j+1];
        }
        else{
          cp+=cp2[j];
        }
      }
      cp+=cp2[si2-1];
      cp2="";
      bool fg2=true;
      int tmp=0;
      /* for(int j=si2-1;j>=0;j--){
        if(fg2 && cp[j]!=key){
          fg2=false;
          fg=false;
          tmp=j;
        }
        }*/
      rep(j,si2-1){
        cp2+=cp[j];
      }
      
      cp=cp2;
      count++;
    }
    chmin(min,count);
  }
  cout<<min<<'\n';
  return(0);
}


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

using ll = long long;

const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;

int n, k;
ll ans;
ll f[N], inv[N];

ll fpow(ll a, ll b) {
    if (b == 0) return 1;
    if (b == 1) return a % MOD;
    ll ret = fpow(a, b / 2);
    ret = (ret * ret) % MOD;
    if (b & 1) ret = (ret * a) % MOD;
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;    

    f[0] = 1;
    inv[0] = 1;

    for (int i = 1; i <= n; i++) {
        f[i] = (i * f[i - 1]) % MOD;
        inv[i] = fpow(f[i], MOD - 2);
    }

    vector<ll> ar(n + 1), br(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> ar[i];
        br[i] = ar[i];
    }

    ar[n] = -1e18;
    br[n] = 1e18;
    sort(begin(ar), end(ar));
    sort(br.rbegin(), br.rend());

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (n - i < k - 1) continue;
        ll mul = (f[n - i] * inv[k - 1]) % MOD;
        // cout << i << " " << n - i << " " << k - 1 << '\n';
        mul = (mul * inv[n - i - k + 1]) % MOD;
        // cout << i << " " << mul << '\n';
        ll a = (br[i] - ar[i]) % MOD;
        while (a < 0) a += MOD;
        a = (a * mul) % MOD;
        ans = (ans + a) % MOD;
    }
    cout << ans << '\n';
    return 0;
}

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

#define ll long long

int main() {
	int n;
	scanf ("%d", &n);
	int arr[n], sorted[n];
	for (int i = 0; i < n; i++) {
		scanf ("%d", arr + i);
		sorted[i] = arr[i];
	}
	sort (sorted, sorted + n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (sorted[i] != arr[i])
			cnt++;
	}
	if (cnt > 2)
		puts("NO");
	else puts("YES");
	return 0;
}

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

using namespace std;

vector<vector<int> > x, y;
vector<int> A;
set<int> s;
vector<int> h;
int n;

//i番目
int dfs(int i) {
    if (i == n) {
        bool check = true;
        for (int j = 0; j < h.size(); j++) {
            //k番目の人が正直者である。
            int k = h[j];

            for (int l = 0; l < A[k]; l++) {
                if (y[k][l] == 1 && s.find(x[k][l]) == s.end())
                    check = false;
                if (y[k][l] == 0 && s.find(x[k][l]) != s.end())
                    check = false;
            }
        }

        if (check) {
            return h.size();
        }
        else 
            return 0;
    }

    int ans = 0;
    
    h.push_back(i);
    s.insert(i);
    ans = max(ans, dfs(i+1));
    h.pop_back();
    s.erase(i);

    ans = max(ans, dfs(i+1));

    return ans;
}

int main() {
    cin >> n;
    x.resize(n);    y.resize(n);
    A.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> A[i];
        x[i].resize(A[i]);  y[i].resize(A[i]);
        for (int j = 0; j < A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    
    cout << dfs(0) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*
import kotlin.math.*

fun main() {
    val (n, w) = readIntList()
    val items = List(n) { readIntList() }

    val dp = List(n + 1) { MutableList(w + 1) { 0L } }

    for (i in 0 until n) {
        for (j in 0..w) {
            dp[i + 1][j] = if (j >= items[i][0]) {
                max(dp[i][j - items[i][0]] + items[i][1], dp[i][j])
            } else {
                dp[i][j]
            }
        }
    }
    println(dp[n][w])
}


fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 352480
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  while (B <= A && K) {
    K--;
    B *= 2;
  }
  while (C <= B && K) {
    K--;
    C *= 2;
  }
  bool isok = A < B && B < C;
  cout << (isok ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;
    VL a(n);
    REP(i,n){
        cin>>a[i];
    }
    //a.PB(-1);
    LL now=0;
    LL count=0;
    LL result=0;
    REP(i,n){
        if((now+a[i])==(now^a[i])){
            count++;
            now+=a[i];
        }
        else{
            //cerr<<i<<" "<<count<<endl;
            REP(j,count){
                result+=j+1;
            }
            while(count>0){
                now-=a[i-count];
                count--;
                if((now+a[i])==(now^a[i])){
                    count++;
                    now+=a[i];
                    REP(j,count){
                        result-=j;
                    }
                    break;
                }
            }

            if(count==0){
                count=1;
                now=a[i];
            }


        }
    }
    REP(j,count){
        result+=j+1;
    }
    cout<<result<<endl;
	return;
}

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

Measured memory_bytes: 1792
#include <stdio.h>
long long min(long long n,long long m){
    if(n<m) return n;
    else return m;
}
int main(void){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    printf("%lld",min(n%k,k-n%k));
    return 0;
}

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

using i64 = int64_t;

std::vector<i64> divisor(i64 n) {
    std::vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> v;
    i64 sum = 0;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
        sum += a;
    }
    auto div = divisor(sum);
    sort(div.rbegin(), div.rend());
    i64 ans = 0;
    for(auto d: div){
        vector<i64> m;
        for(auto e: v){
            m.push_back(e%d);
        }
        sort(m.begin(), m.end());
        vector<i64> cumsum_left(n+1), cumsum_right(n+1);
        for(int i=1;i<=n;++i)cumsum_left[i] = cumsum_left[i-1] + m[i-1];
        for(int i=n-1;i>=0;--i)cumsum_right[i] = cumsum_right[i+1] + (d-m[i]);
        for(int i=0;i<=n;++i){
            i64 diff = abs(cumsum_right[i] - cumsum_left[i]);
            if(diff % d != 0)continue;
            if(max(cumsum_left[i], cumsum_right[i]) > k)continue;
            ans = d;
            break;
        }
        if(ans > 0)break;
    }

    assert(ans > 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
lp=[[] for i in range(n)]
ln={}
for i in range(m):
  p,y=map(int,input().split())
  lp[p-1].append(y)
  ln[i]=str(p)+','+str(y)

lcode={}
for i in range(n):
  p = i+1
  lp[i]=sorted(lp[i])
  for j in range(len(lp[i])):
    lcode[str(p)+','+str(lp[i][j])]=format(p,'06d')+format(j+1,'06d')

for i in range(m):
  print(lcode[ln[i]])


Measured memory_bytes: 58264
($N,$M,$Q)=glob<>;
%A;
for my$m(1..$M){
    ($l,$r)=glob<>;
    $A{$l}->{$r}++;
}

for my$i(1..$N){
    for my$j($i..$N){
        $A{$i}->{$j}+=$A{$i}->{$j-1};
    }
}

for my$i(1..$N){
    for my$j(1..$N){
        $A{$i}->{$j}+=$A{$i-1}->{$j};
    }
}

for my$qq(1..$Q){
    ($p,$q)=glob<>;
    print$A{$q}->{$q}
        +$A{$p-1}->{$p-1}
        -$A{$p-1}->{$q}
        -$A{$q}->{$p-1}
     ,"\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  int ans = 2000000000;
  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, h.at(K + i - 1) - h.at(i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

ll solver(int N, vector<ll> &A){

    ll sum = 0, dif = 0;
    for(int i=0; i != N-1; ++i){
        if(A.at(i) > A.at(i+1)){
            dif = A.at(i) - A.at(i+1);
            sum += dif;
            A.at(i+1) += dif;
        }
        dif = 0;
    }

    return sum;
}

int main(){

    int N;
    cin >> N;
    vector<ll> A(N);
    for(auto iter = A.begin(); iter != A.end(); ++iter) cin >> *iter;

    cout << solver(N, A) << endl;

    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const int mod = (int)1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin >> n;
	vector<lli> dp(n+1);
	if(n<3) {
		cout << 0;
		return 0;
	}
	dp[0] = 1LL;
	for(int i=0; i<n; i++){
		for(int j=3; j<=n; j++){
			if(i+j<=n) dp[i+j] = (dp[i+j]+dp[i])%mod;
		}
	}
	cout << dp[n] ;
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, k; cin >> n >> k;
  ll ans = 1;
  for(int i = 1; i < n; i++){
    ans *= k-1;
  }
  cout << k*ans << endl;
  system("pause");
}

Measured memory_bytes: 504
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final String n;		// 1≦N<10000
		final int k;	// 1≦K<10
		final int[] d;	// 0≦D1<D2<…<DK≦9  {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
		try(Scanner scan = new Scanner(System.in)) {
			n = "0" + scan.next();				// 繰り上がり用に先頭に0を挿入。
			k = scan.nextInt();
			d = new int[k];
			for (int i = 0; i < k; i++) {
				d[i] = scan.nextInt();
			}
		}
		
		// 嫌いでない数字の配列  maxはlike[10 - k -1] minはlike[0]
		final int[] like = IntStream.range(0, 10).filter(i -> Arrays.stream(d).noneMatch(dd -> dd == i)).toArray();
		
		// 各位の数字の取得		上記よりvalue[0] = 0が挿入されている。
		final int[] original = n.chars().map(i -> i - (int) '0').toArray();
		int[] result = Arrays.copyOf(original, original.length);
		
		// 末尾の桁から処理する。最上位の桁は別処理。
		for (int j = result.length - 1; j > 0; j--) {
			final int i = j;
			
			OptionalInt tempInt = Arrays.stream(like).filter(likevalue -> likevalue >= result[i]).min();
			if (tempInt.isPresent()) {
				result[i] = tempInt.getAsInt();
			} else {
				result[i - 1]++;	// 繰り上がり処理
				result[i] = like[0];
			}		
		}
		
		// 一番上の桁はlikeに0がなくても0でもよい。
		if (result[0] == 0) {
			result[0] = 0;
		} else {		// result[0] ==1で {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}により値があることが保証されている。
			result[0] = Arrays.stream(like).filter(likevalue -> likevalue >= result[0]).min().getAsInt();
		}
		
		// 上の方で値が増えれていれば、そこから先は関係ない。
		for (int i = 0; i < result.length - 1; i++) {
			if (result[i] > original[i]) {
				Arrays.fill(result, i + 1, result.length, like[0]);
				break;
			}
		}
		//上の桁から処理するよりも処理量が多くなってしまった。
		//まだ間違いがあるらしい。

		//数値に戻して出力
		out.println(Arrays.stream(result).reduce((start, element) -> start * 10 + element).getAsInt());
		out.flush();
	}
}


Measured memory_bytes: 15948
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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



int main(){
    llong A,B,C;
    cin  >> A >> B >> C;
    llong ans = min(B/A,C);
    cout << ans << endl;


    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    vec ans(26,INF), temp(26,0);
    rep(i,N){
        cin>>S;
        rep(j,S.size()) ++temp[S[j] - 'a'];
        rep(j,26) {
            ans[j] = min(ans[j], temp[j]);
            temp[j] = 0;
        }
    }
    rep(i,26){
        rep(j, ans[i]) cout<<char(i + 97);
    }
    cout<<endl;
}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(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; }




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}



int main() {
  string s,t;

  cin >> s >> t;

  int len = s.size(),ans = len;
  rep(i, 0, len){
    if(s[i] == t[i]){
      ans--;
    }
  }

  cout << ans << endl;
  // cout << setprecision(8) << ans << endl;  // For double
}



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

using namespace std;

int n, a[101];

int main() {
    scanf("%d", &n);
    for ( int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    vector < int > ans;
    for (int i = 0; i < n; i++) {
        int f = -1;
        for (int j = n-i-1; j >= 0; j--)
            if (a[j] == j+1) {
                f = j;
                ans.push_back(a[j]);
                break;
            }

        if (f == -1) {
            printf("-1\n");
            return 0;
        }
        for (int j = f+1; j <= n-i-1; j++)
            a[j-1] = a[j];
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++)
        printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int INF = 1 << 30;

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

	cout << 48 - N << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        String s=sc.nextString();
        if(s.equals("AAA") || s.equals("BBB"))ret("No");

        out.println("Yes");
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int p,h,f; long m;
    P(int p,int h, int f, long m) {
    	this.p=p;
    	this.h=h;
    	this.f=f;
    	this.m=m;
    }

    public int compareTo(P p){
    	if(this.p==p.p) {
    		if(this.f==-1) return 1;
    		return -1;
    	}
        return this.p-p.p;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 24020
package main

import "fmt"

func judgeStatusSummary(s []string) map[string]int {
	c := map[string]int{
		"AC": 0,
		"WA": 0,
		"TLE": 0,
		"RE": 0,
	}

	for _, v := range s {
		c[v]++
	}

	return c
}

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]string, n)
	for i := range s {
		fmt.Scan(&s[i])
	}

	ans := judgeStatusSummary(s)
	fmt.Println(fmt.Sprintf("AC x %v", ans["AC"]))
	fmt.Println(fmt.Sprintf("WA x %v", ans["WA"]))
	fmt.Println(fmt.Sprintf("TLE x %v", ans["TLE"]))
	fmt.Println(fmt.Sprintf("RE x %v", ans["RE"]))
}

Measured memory_bytes: 6860
import Control.Monad (replicateM,unless)
import Data.List (lookup)
import Data.Maybe (fromJust)
import System.IO (isEOF)

type Surface = [String]
type Coord = (Int, Int)

figures :: [([Coord], Char)]
figures = [
    ([(0,0),(1,0),(0,1),(1,1)], 'A'),
    ([(0,0),(0,1),(0,2),(0,3)], 'B'),
    ([(0,0),(1,0),(2,0),(3,0)], 'C'),
    ([(1,0),(0,1),(1,1),(0,2)], 'D'),
    ([(0,0),(1,0),(1,1),(2,1)], 'E'),
    ([(0,0),(0,1),(1,1),(1,2)], 'F'),
    ([(1,0),(2,0),(0,1),(1,1)], 'G')
    ]

main = do
    quit <- isEOF
    if quit then return () else do
        input >>= return . solve >>= output
        main

input :: IO Surface
input = do
    lines <- replicateM 8 getLine

    -- consume empty line unless EOF
    eof <- isEOF
    unless eof (getLine >> return ())

    return lines

output :: Char -> IO ()
output c = putStrLn [c]

solve :: Surface -> Char
solve s = fromJust $ lookup (adjust $ coords s) figures

coords :: Surface -> [Coord]
coords ls = concat $ zipWith lineCoords [0..] ls
    where
    lineCoords y l = lineCoords' y 0 l
    lineCoords' y x "" = []
    lineCoords' y x ('1':cs) = (x,y):lineCoords' y (x+1) cs
    lineCoords' y x (_:cs) = lineCoords' y (x+1) cs

adjust :: [Coord] -> [Coord]
adjust cs = minX `seq` minY `seq` map (`sub` (minX,minY)) cs
    where
    minX = minimum $ map fst cs
    minY = minimum $ map snd cs
    (ax,ay) `sub` (bx,by) = (ax-bx,ay-by)

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


ll N, K;
vll A(N);
vll Bit(50, 0); //Bit[i]はAのうちi番目のビットが立っているものの個数
ll dp[50][2];

ll rec(int k, int f = 0 ) { //fは構成した数がKより真に小さいか管理するフラグ
    if (k == -1) return 0;
    if (dp[k][f] != -1) return dp[k][f];

    ll res = 0;

    if (f) {
        res = max(Bit[k], N - Bit[k]) * (1LL << k) + rec(k - 1, 1);
    }
    else if (K & (1LL << k)) {
        ll tmp1 = Bit[k] * (1LL << k) + rec(k - 1, 1); //構成する数のibitに0を選ぶ場合
        ll tmp2 = (N - Bit[k]) * (1LL << k) + rec(k - 1, 0);
        res = max(tmp1, tmp2);
    }
    else {
        res = Bit[k] * (1LL << k) + rec(k - 1, 0);
    }


    dp[k][f] = res;
    return res;

}



int main() {
    cin >> N >> K;
    A.assign(N, 0);
    rep(i, N) {
        cin >> A[i];
    }

    int k = 0;
    for (int i = 40; i >= 0; i--) {
        if (K & (1LL << i)) {
            k = i;
            break;
        }
    }
    for (int i = 40; i >= 0 ; i--) {
        rep(j, N) {
            if (A[j] & (1LL << i)) Bit[i]++;
        }
    }
    memset(dp, -1, sizeof(dp));

    ll ans = rec(k);
    for (int i = 40; i > k; i--) {
        ans += Bit[i] * (1LL << i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024