akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<limits>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(3);
  for(int& ai: a) cin >> ai;
  vector<int> l(N);
  for(int& li: l) cin >> li;
  int mm = numeric_limits<int>::max();
  for(int pp=0; pp<(1<<(N*2)); pp++){
    int c[4]{};
    int s[4]{};
    for(int i=0; i<N; i++){
      int pi = (pp>>(i*2))&0x3;
      c[pi]++;
      s[pi] += l[i];
    }
    if(min({c[0], c[1], c[2]})==0) continue;
    int m=0;
    for(int j=0; j<3; j++){
      m += (c[j]-1)*10;
      m += abs(a[j]-s[j]);
    }
    mm = min(mm, m);
  }
  cout << mm << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque


def main():
    n = int(input())
    base = 26
    orig = ord('a')
    ans = deque()
    for exp in range(1, 12):
        if (tmp := pow(base, exp)) >= n:
            n -= 1  # zero_indexed for ASCII mod
            for digit in range(exp):
                ans.appendleft(chr(orig + n % base))
                n //= base
            break
        else:
            n -= tmp
    print(''.join(ans))


if __name__ == '__main__':
    main()


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

int main(){
  int n,m;
  cin >> n >> m;
  
  bool out = false;
  if(n%2 == 0){
    for(int i=0; i < (n/2)+1; i++){
      if(out) cout << ' ';
      cout << 0;
      out = true;
    }
    for(int i=0; i < (n/2)-1; i++){
      if(out) cout << ' ';
      cout << m;
      out = true;
    }
    cout << endl;
    return 0;
  }
  else
  {
    for(int i=0; i < (n+1)/2; i++){
      if(out) cout << ' ';
      cout << 0;
      out = true;
    }
    for(int i=0; i < (n-1)/2; i++){
      if(out) cout << ' ';
      cout << m;
      out = true;
    }
    cout << endl;
    return 0;
  }
  return 0;
}


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

int main() {
  int d,n;
  cin >> d >> n;
  if(d == 0){
    if(n == 100){
      cout << 101 << endl;
    }
    else{
      cout << n << endl;
    }
  }
  else if(d == 1){
    if(n == 100){
      cout << 10100 << endl;
    }
    else{
      cout << n*100 << endl;
    }
  }
  else{
    if(n == 100){
      cout << 1010000 << endl;
    }
    else{
      cout << n*10000 << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

ll f(vector<ll>a, ll m){
    ll res = 0;
    rep(i,a.size())res+=abs(a[i]-m);
    return res;
}


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int cons = 1;
    rep(i,n)a[i]-=(cons++);
    sort(a.begin(),a.end());
    ll m = a[n/2];
    ll ans = f(a,m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		int[][] table = new int[1000][1000];
		for (int i=0; i<1000; i++) {
			Arrays.fill(table[i], -1);
		}

		table[500][500] = 0;

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

		for (int k=1; k<n; k++) {
			int p = in.nextInt();
			int d = in.nextInt();

			for (int i=0; i<1000; i++) {
				for (int j=0; j<1000; j++) {
					if (table[i][j] == p) {
						table[i+dy[d]][j+dx[d]] = k;
					}
				}
			}
		}

		int yd = -1, yt = -1;
		int xd = -1, xt = -1;

		for (int i=0; i<1000; i++) {
			for (int j=0; j<1000; j++) {
				if (yt == -1 && table[i][j] != -1) {
					yt = i;
				}
				if (table[i][j] != -1) {
					yd = i;
				}
			}
		}

		for (int j=0; j<1000; j++) {
			for (int i=0; i<1000; i++) {
				if (xt == -1 && table[i][j] != -1) {
					xt = j;
				}
				if (table[i][j] != -1) {
					xd = j;
				}
			}
		}

		out.println((xd - xt + 1) + " " + (yd - yt + 1));

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 72716
#include <bits/stdc++.h>
using namespace std;
#define FS ios_base::sync_with_stdio(0);
#define FOR(i,s,e) for(int i=s; i<e; ++i)
#define FFOR(i,s,e) for(int i=s; i<=e; ++i)
#define mem(o,s) memset(s,o,sizeof(s));
typedef long long ll;
#define MOD 1000000007
#define pi pair<int,int>
#define fi first
#define se second
#define pb push_back

int main(){
  FS
  ll N;
  cin>>N;
  ll C[10][10]; mem(0,C);
  FFOR(i,1,N){
    if(i%10==0) continue;
    ll x = i;
    while(x>9){
      x/=10;
    }
    C[x][i%10]++;
  }
  ll ans = 0;
  FFOR(i,1,9){
    FFOR(j,1,9){
      ans+= C[i][j]*C[j][i];
    }
  }
  cout<<ans<<'\n';
  
}
    


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
long long int dp[500005] = {0};
long long int tree[2000005] = {0};
void build(long long int node, long long int start, long long int endi)
{
    if(start == endi)
    {
        // Leaf node will have a single element
        tree[node] = dp[start];
    }
    else
    {
        int mid = (start + endi) / 2;
        // Recurse on the left child
        build(2*node, start, mid);
        // Recurse on the right child
        build(2*node+1, mid+1, endi);
        // Internal node will have the sum of both of its children
        tree[node] = max(tree[2*node] , tree[2*node+1]);
    }
}
void update(long long int node, long long int start, long long int endi, long long int idx, long long int val)
{
    if(start == endi)
    {
        /// Leaf node
        dp[idx] = val;
        tree[node] = val;
    }
    else
    {
        int mid = (start + endi) / 2;
        if(start <= idx and idx <= mid)
        {
            /// If idx is in the left child, recurse on the left child
            update(2*node, start, mid, idx, val);
        }
        else
        {
            /// if idx is in the right child, recurse on the right child
            update(2*node+1, mid+1, endi, idx, val);
        }
        /// Internal node will have the sum of both of its children
        tree[node] = max(tree[2*node], tree[2*node+1]);
    }
}
long long int query(long long int node, long long int start, long long int endi, long long int l, long long int r)
{
    if(r < start or endi < l)
    {
        /// range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and endi <= r)
    {
        /// range represented by a node is completely inside the given range
        return tree[node];
    }
    /// range represented by a node is partially inside and partially outside the given range
    long long int mid = (start + endi) / 2;
    long long int p1 = query(2*node, start, mid, l, r);
    long long int p2 = query(2*node+1, mid+1, endi, l, r);
    return max(p1 , p2) ;
}
int main(){
    long long int n;
    cin>>n;
    vector <long long int> h;
    vector <long long int> b;
    for(int i = 0;i<n;i++){
        long long int z;
        cin>>z;
        h.push_back(z);
    }
    for(int i = 0;i<n;i++){
        long long int z;
        cin>>z;
        b.push_back(z);
    }
    dp[h[0] ] = b[0];
    build(1 , 0 ,n  );
    for(int i = 1;i< n;i++){
        long long int x = query(1 , 0,n,0,h[i]-1  );
        update(1 ,0 ,n ,h[i] ,x+ b[i]  );
    }
    long long int answer = 0;
    for(int i = 1;i<=n;i++){
        answer = max(answer , dp[i] );
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 13680
#include <iostream>
using namespace std;
typedef long long ll;

const ll INF = 1e18;

int main(){
  int n, k; cin >> n >> k; ll h[n+2]; h[n]=0;
  for(int i=1; i<=n; i++) cin >> h[i]; h[0]=0;
  
  ll dp[k+1][n+2][n+2], mn=INF; fill(dp[0][0], dp[k+1][0], INF);
  dp[0][0][1] = 0;
  for(int i=0; i<=k; i++) {
    for(int j=0; j<=n+1; j++) {
      for(int m=0; m<=n+1; m++) {
        if (i!=0 && m!=0 && dp[i-1][j][m-1]!=INF) {
          //dp[i+1][j][m+1] = min(dp[i+1][j][m+1], dp[i][j][m]);
          ll df_new = max(0LL, h[j] - h[m]);
          ll df_old = max(0LL, h[j] - h[m-1]);
          dp[i][j][m] = min(dp[i][j][m], dp[i-1][j][m-1]-df_old+df_new);
        }
        //dp[i][m][m+1] = min(dp[i][m][m+1], dp[i][j][m] + df);
        if (j!=0 && m!=0) {
          ll df = max(0LL, h[m-1] - h[m]);
          dp[i][m-1][m] = min(dp[i][m-1][m], dp[i][j-1][m-1]+df);
        }
        //if (m==n+1) mn = min(dp[i][j][m], mn);
        //if (dp[i][j][m] != INF)
          //cout << i << " " << j << " " << m << " " << dp[i][j][m] << endl;
      }
    }
  }
  for(int i=0; i<=k; i++) {
    for(int j=0; j<=n+1; j++) {
      for(int m=0; m<=n+1; m++) {
        //cout << dp[i][j][m] << " ";
      } //cout << endl;
    } //cout << endl;
  }
  
  for(int i=0; i<=k; i++) {
    for(int j=0; j<=n+1; j++) {
      mn = min(mn, dp[i][j][n+1]);
      //cout << dp[i][j][n+1] << " ";
    }//cout << endl;
  }
  
  cout << mn << endl;
}


Measured memory_bytes: 214656
#include <iostream>
using namespace std;
int main(void) {
	long long N, T, t1, t2, sum = 0;
	cin >> N >> T >> t2;
	for (int i = 0; i < N; ++i) {
		t1 = t2;
		cin >> t2;
		if (t2 - t1 >= T) sum += T;
		else sum += t2 - t1;
	}
	sum += T;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a > b) {
        printf("a > b\n");
    }
    else if(a < b) {
        printf("a < b\n");
    }
    else {
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2036
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        List<Restaurant> list = new ArrayList<>();

        for(int i=1; i<=n; i++){
            String city = sc.next();
            int score = sc.nextInt();
            list.add(new Restaurant(city, score, i));
        }
        Collections.sort(list);
        for(Restaurant res: list){
        	System.out.println(res.i);
        }
    }
}

class Restaurant implements Comparable<Restaurant>{
	String city;
    int score;
    int i;
    public Restaurant(String city, int score, int i){
    	this.city = city;
        this.score = score;
        this.i = i;
    }
    public int compareTo(Restaurant other){
    	int ans = city.compareTo(other.city);
        if(ans != 0){
        	return ans;
        }
        return Integer.compare(other.score, score);
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

inline int convert(int h,int m,int s){
	int from=h%5*12,to=(h%5+1)*12;
	if(m<from||to<=m) return -1;
	return 3600*(h/5)+60*m+s;
}

int main(void){
	int n;
	while(cin >> n,n){
		int check[43200][10];
		int s[11],t[11],u[11];
		rep(i,n) cin >> s[i] >> t[i] >> u[i];

		clr(check,0);
		rep(i,n){
			rep(offset,60){
				int perm[3]={(s[i]+offset)%60,(t[i]+offset)%60,(u[i]+offset)%60};
				sort(perm,perm+3);
				do{
					int res=convert(perm[0],perm[1],perm[2]);
					if(res!=-1) check[res][i]++;
				}while(next_permutation(perm,perm+3));
			}
		}

		const int all=43200;
		int si=0,ti=0,sum[10];
		clr(sum,0);

		int from=0,to=all;
		while(ti<all){

			while(ti<all){
				rep(i,n) sum[i]+=check[ti][i];
				ti++;
				bool ok=true;
				rep(i,n) if(sum[i]==0) ok=false;
				if(ok) break;
			}


			while(si<ti){
				rep(i,n) sum[i]-=check[si][i];
				bool ok=false;
				rep(i,n) if(sum[i]==0) ok=true;
				if(ok) break;
				si++;
			}

			if(to-from>ti-si) to=ti,from=si;
			if(to-from==ti-si&& from > si) to=ti,from=si;

			si++;
		}
		
		to--;
		printf("%02d:%02d:%02d %02d:%02d:%02d\n",from/3600,from/60%60,from%60,to/3600,to/60%60,to%60);
	}	
	return 0;
}

Measured memory_bytes: 4872
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long gcd = gcd(a, b);
            int ans = 1;
            for (long v = 2; v * v <= gcd; v++) {
                if (gcd % v == 0) {
                    gcd /= v;
                    ans++;
                    while (gcd > 1) {
                        if (gcd % v == 0)
                            gcd /= v;
                        else
                            break;
                    }
                }
            }
            if (gcd > 1)
                ans++;
            out.println(ans);
        }

        private long gcd(long a, long b) {
            if (b == 0)
                return a;
            else
                return gcd(b, a % b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	ll N,L;
	cin >> N >> L;
	vector<ll> A(N),ans;
	rep(i,N)cin >> A[i];
	int start = -1;
	rep(i,N-1){
		if(A[i]+A[i+1] >=L){
			start = i;
			break;
		}
	}
	ans.push_back(start);
	for(int i=start+1;i<N-1;i++)ans.push_back(i);
	for(int i=start-1;i>=0;i--)ans.push_back(i);
	reverse(ALL(ans));
	if(start !=-1){
		cout << "Possible" << endl;
		for(auto x:ans)cout << x+1 << endl;
	}else cout <<"Impossible" << endl;
}

Measured memory_bytes: 2548
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
template<class T>
using V = vector<T>;
template<class T>
using VV = vector<vector<T>>;
typedef unsigned long long ULL;

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int W, H,K;
	cin >> H >> W >> K;
	VVLL item(H+1, VLL(W+1, -1));   //[y][x]、-1は非存在
	for (int k = 0; k < K; k++) {
		int r, c, v;
		cin >> r >> c >> v;
		item[r][c] = v;
	}
	VVLL DP[4];
	VVLL DPall[4];
	VVLL DPy[4];
	DP[0].resize(H + 1, VLL(W + 1, 0));
	DPall[0].resize(H + 1, VLL(W + 1, 0));
	DPy[0].resize(H + 1, VLL(W + 1, 0));
	for (int b = 1; b < 4; b++) {
		DP[b].resize(H + 1, VLL(W + 1, -1));
		DPall[b].resize(H + 1, VLL(W + 1, -1));
		DPy[b].resize(H + 1, VLL(W + 1, -1));
	}
	for (int y = 1; y <= H; y++) {
		for (int x = 1; x <= W; x++) {
			for (int b = 0; b <= 3; b++) {
				DP[0][y][x] = max(DP[0][y][x], DP[b][y - 1][x]);
			}
			for (int n = 1; n <= 3; n++) {
				DP[n][y][x] = DP[n][y][x - 1];
				if (item[y][x] != -1) {
					if (DP[n - 1][y][x - 1] != -1) {
						DP[n][y][x] = max(DP[n][y][x], DP[n - 1][y][x - 1] + item[y][x]);
					}
					for(int b = 0;b <= 3;b++){
						if (DP[b][y - 1][x] != -1) {
							DP[n][y][x] = max(DP[n][y][x], DP[b][y - 1][x] + item[y][x]);
						}
					}
				}
			}
			for (int n = 0; n <= 3; n++) {
				DPall[n][y][x] = DP[n][y][x];
				DPall[n][y][x] = max(DPall[n][y][x], DPall[n][y - 1][x]);
				DPall[n][y][x] = max(DPall[n][y][x], DPall[n][y][x - 1]);
				DPy[n][y][x] = max(DP[n][y][x], DPy[n][y][x - 1]);
			}
		}
	}
	LL ans = 0;
	for (int n = 0; n <= 3; n++) {
		ans = max(ans, DPall[n][H][W]);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 918720
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= print . solve

solve :: Int -> Int
solve = (3 *) . (^ 2)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;++i) {
    cin>>A[i];
  }
  for(int i=1;i<N;++i) A[i] += A[i-1];
  int index1, index2;
  ll P, Q, R, S;
  int index11, index22;
  ll maxnum, minnum;
  ll ans = big;
  for(int i=0;i<N;++i) { // [0, i], (i, N]
    index1 = upper_bound(A.begin(), A.begin()+i, A[i]/2) - A.begin();
    index2 = upper_bound(A.begin()+i+1, A.end(), (A[N-1]-A[i])/2+A[i]) - A.begin();
    for(int j=-10;j<=10;++j) {
      for(int k=-10;k<=10;++k) {
        index11 = index1 + j;
        index22 = index2 + k;
        if(0<=index11 && index11<i && i<index22 && index22<N) {
          P = A[index11];
          Q = A[i]-A[index11];
          R = A[index22]-A[i];
          S = A[N-1]-A[index22];
          maxnum = max(P, max(Q, max(R, S)));
          minnum = min(P, min(Q, min(R, S)));
          ans = min(ans, maxnum-minnum);
        }
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4820
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int group[100000];
vector<int> member[100000];

int main(){
  int N, M;
  
  cin >> N >> M;
  REP(i, N) {
    group[i] = i;
    vector<int> tv;
    tv.push_back(i);
    member[i] = tv;
  }
  REP(i, M) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--; Y--;
    if(group[X] != group[Y]) {
      int gS = member[group[X]].size() < member[group[Y]].size() ? group[X] : group[Y];
      int gL = group[X] + group[Y] - gS;
      for(auto itr=member[gS].begin(), end=member[gS].end(); itr!=end; ++itr) {
        group[*itr] = gL;
        member[gL].push_back(*itr);
      }
      member[gS] = vector<int>();
    }
  }
  int ret = 0;
  REP(i, N) {
    if(member[i].size() > 0) {
      ++ret;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 6784
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);
        String s = sc.next();
        String t = sc.next();
        StringBuilder sb;
        List<String> list = new ArrayList<>();
        boolean matched = true;
        for (int i = s.length() - t.length(); i >= 0; i--) {
            matched = true;
            for (int j = 0; j < t.length(); j++) {
                if(s.charAt(i + j) != '?'
                        && s.charAt(i + j) != t.charAt(j)){
                    matched = false;
                    break;
                }
            }
            if(matched){
                sb = new StringBuilder();
                if(i != 0) sb.append(s.substring(0, i));
                sb.append(t);
                if(i != s.length() - t.length()) sb.append(s.substring(i + t.length()));
                list.add(sb.toString().replace('?', 'a'));
            }
        }

        if(list.size() > 0){
            Collections.sort(list);
            System.out.println(list.get(0));
        }
        else System.out.println("UNRESTORABLE");
        sc.close();
    }

}


Measured memory_bytes: 22736
#include<iostream>
#include<vector>
#include<cmath>

int main(void){
    long long n;
    std::cin >> n;
    int rn = std::sqrt(n);
    std::vector<int> a, b;

    for(int i = 2; i <= rn; i++){
	int cnt = 0;
	bool flag = 0;
	while(true){
	    if(n % i != 0){
		break;
	    }else{
		n /= i;
		cnt++;
		flag = 1;
	    }
	}
	if(flag){
	    a.push_back(i);
	    b.push_back(cnt);
	}
    }
    if(n != 1){
	a.push_back(n);
	b.push_back(1);
    }

    // for(int i = 0; i < a.size(); i++){
    //     if( i != 0 ) std::cout << " * ";
    //     std::cout << a[i] << "^" << b[i];
    // }
    // std::cout << std::endl;
    //
    long long ans = 0;
    for(int i = 0; i < a.size(); i++){
	int j = 1;
	while(true){
	    if(b[i] >= j){
		b[i] -= j;
		j++;
		ans++;
	    }else{
		break;
	    }

	}
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3668
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

int a, b;

int main(){
    scanf("%d%d", &a, &b);
    if(b == (b/a) * a){
        printf("%d", a + b);
    }
    else{
        printf("%d", b - a);
    }
    return 0;
}


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

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

int n, m, a;

int main()
{
	while (cin >> n >> m >> a, n|m|a) {
		vector<pair<int, pair<int, int> > > lines;

		rep(i, m) {
			int h, p, q;
			cin >> h >> p >> q;
			lines.push_back(make_pair(h, make_pair(p, q)));
		}
		sort(lines.begin(), lines.end());
		reverse(lines.begin(), lines.end());
		int h = lines[0].first;

		rep(i, lines.size()) {
			int t = lines[i].first;
			if (t <= h) {
				int l1, l2;
				l1 = lines[i].second.first;
				l2 = lines[i].second.second;

				if (l1 == a) {
					//printf("%d -> %d\n", l1, l2);
					a = l2;
					t = h;
				} else if (l2 == a) {
					//printf("%d -> %d\n", l2, l1);
					a = l1;
					t = h;
				}
			}
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a + b + c - max({a, b, c}) << endl;
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto kx = readln.split.to!(int[]);
    auto K = kx[0];
    auto X = kx[1];
    writeln(500*K >= X ? "Yes" : "No");
}

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

namespace AtCoder_Beginner_Contest_129
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static void Main(string[] args)
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var am = new int[N];
            for (var i = 0; i < M; ++i)
            {
                am[Sarray()[0] - 1] = 1;
            }
            var num = new long[N];
            if (N == 1)//1の場合
            {
                WriteLine(1);
                return;
            }
            if (0 == am[0]) num[0] = 1;
            if (0 == am[1]) num[1] = 1 + num[0];
            if (num[0] == 0 & num[1] == 0)
            {
                WriteLine(0);
                return;
            }
            for (var i = 2; i < N; ++i)
            {
                if (0 != am[i])
                {
                    if (0 != am[i - 1])
                    {
                        WriteLine(0);
                        return;
                    }
                    continue;
                }
                num[i] = (num[i - 1] + num[i - 2])%1000000007;
            }
            WriteLine(num[N - 1]);
        }
    }
}


Measured memory_bytes: 17448
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

int main(){
  int N, M;
  vi k(12), p(12);
  vector<vi> s(12, vi(12));

  cin >> N >> M;
  for(int i=0; i<M; i++){
    cin >> k[i];
    for(int j=0; j<k[i]; j++) cin >> s[i][j];
  }
  for(int i=0; i<M; i++) cin >> p[i];

  int ans = 0;
  for(int bit=0; bit < (1<<N); bit++){
    bool flag = true;
    for(int i=0; i<M; i++){
      int cnt = 0;
      for(int j=0; j<k[i]; j++){
        if((bit >> (s[i][j]-1)) & 1 == 1) cnt++;
      }
      if(cnt % 2 != p[i]) flag = false;
    }

    if(flag) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
for i in range(len(s)):
    mojime = i + 1
    if mojime % 2 == 1:
        if s[i] == "L":
            print("No")
            exit()
    if mojime % 2 == 0:
        if s[i] == "R":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin >> n>> k;
  vl h(n);
  rep(i,n){
    cin>>h[i];
  }
  sort(rng(h));
  ll ans = 1LL<<60;
  rep(i,n){
    if((i+k-1)>=n)continue;
    mins(ans,h[i+k-1]-h[i]);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;
}
 
const int MOD = 998244353, MAXN = 2e5 + 10, INF = 1e18 + 10, BASE = 37; 

void solve() {
	int n, k;
	cin >> n >> k;
	vec<int> a(n);
	cin >> a;

	for (int i = 0; i < min(100ll, k); ++i) {
	    vec<int> ps(n + 1);
	    for (int i = 0; i < n; ++i) {
	     	int l = max(0ll, i - a[i]), r = min(n - 1, i + a[i]);
	     	ps[l]++, ps[r + 1]--;
	    }
	    for (int i = 1; i < n; ++i) ps[i] = ps[i - 1] + ps[i];
	    for (int i = 0; i < n; ++i) a[i] = ps[i];
	}	

	cout << a << endl;
}	

Measured memory_bytes: 6364
#include<stdio.h>

char S[200010];

int main(){
	scanf("%s",S);
	int b=0;
	int l=strlen(S);
	long long ans=0;
	for(int i=l-1;i>=0;i--){
		if(S[i]=='B'){
			b++;
			ans+=l-i-b;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
#define MAXXXX 500000
void calc(lli n){
    char str[MAXXXX];
    lli i = 0;
    while (n>0)
    {
        lli rem = n%26;
        if (rem==0){
            str[i++] = 'z';
            n = (n/26)-1;
		}
        else{
            str[i++] = (rem-1) + 'a';
            n = n/26;
        }
    }
    str[i] = '\0';
    reverse(str, str + strlen(str));
    cout << str << endl;
}
int main(){
	lli n;
	cin>>n;
	calc(n);
}

Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
int main() {
	cin >> Q;
	while (Q--) {
		ll A, B;
		cin >> A >> B;
		if (A > B)
			swap(A, B);
		if (A == B || A + 1 == B) {
			cout << 2 * A - 2 << endl;
			continue;
		}
		ll C = (ll)sqrt(A * B);
		if (C * C == A * B)
			C--;
		if (C * (C + 1) >= A * B) {
			cout << 2 * C - 2 << endl;
		} else
			cout << 2 * C - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
A=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
a=list(A)
b=list(B)
c=list(C)
s=0

for i in range(n):
    if i==n-1:
        s=s+b[i]
    elif a[i]+1==a[i+1]:
        s=s+b[i]+c[a[i]-1]
    else:
        s=s+b[i]

print(s)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl
using lint=long long;
int MOD=1000000007;

signed main(){
    int a,b;cin>>a>>b;
    int n=b-a;
    cout<<n*(n+1)/2-b<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> T(N), A(N);
	for(int i =0; i < N; i++) cin >> T[i];
	for(int i =0; i < N; i++) cin >> A[i];

	vector<int> known(N,-1), mx(N);
	int last =-1, g =-1;
	for(int i =0; i < N; i++) {
		mx[i] =min(T[i],A[i]);
		g =max(g,mx[i]);
		if(g < T[i]) {
			cout << "0\n";
			return 0;
		}
		if(T[i] > last) known[i] =T[i];
		last =T[i];
	}
	last =g =-1;
	for(int i =N-1; i >= 0; i--) {
		if(A[i] > last) {
			if(known[i] != -1 && known[i] != A[i]) {
				cout << "0\n";
				return 0;
			}
			known[i] =A[i];
		}
		g =max(g,mx[i]);
		if(g < A[i]) {
			cout << "0\n";
			return 0;
		}
		last =A[i];
	}

	cat ans =1, mod =1000000007;
	for(int i =0; i < N; i++) if(known[i] == -1) ans =(ans*mx[i])%mod;
	if(ans < 0) ans +=mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if(n % 2 != 0) {
        cout << "No" << endl;
    } else {
        bool ok = true;
        for(int i = 0; i < n; i += 2) {
            string t = s.substr(i, 2);
            if(t != "hi") {
                ok = false;
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
using Int = __int128;
int dp[2222][2222];
bool used[2222][2222];
bool used2[2222][2222];
Int dp2[2222][2222];
struct st{
  int l,r,c;
  st(){}
  st(int l,int r,int c):l(l),r(r),c(c){}
  bool operator<(const st &a)const{
    return c>a.c;
  }
};
string s;
int k,n;
Int K;
Int dfs(int l,int r){
  if(used2[l][r]) return dp2[l][r];
  used2[l][r]=1;
  //cout<<l<<" "<<r<<endl;
  if(r-l<2){
    return dp2[l][r]=1;
  }
  map<char,Int> m;
  if(used[l+1][r-1]&&s[l]==s[r-1]&&dp[l][r]==dp[l+1][r-1]+2){
    if(m.count(s[l])) assert(m[s[l]]==dfs(l+1,r-1));
    m[s[l]]=dfs(l+1,r-1);
  }else{
    if(used[l+1][r]&&dp[l][r]==dp[l+1][r]+2){
      //cout<<l<<" "<<r<<":"<<(int)m[s[l]]<<" "<<(int)dfs(l+1,r)<<endl;
      if(m.count(s[l])) assert(m[s[l]]==dfs(l+1,r));
      m[s[l]]=dfs(l+1,r);
    }
    if(used[l][r-1]&&dp[l][r]==dp[l][r-1]+2){
      if(m.count(s[r-1])) assert(m[s[r-1]]==dfs(l,r-1));
      m[s[r-1]]=dfs(l,r-1);
    }
  }
  Int res=0;
  for(auto p:m){
    res+=p.second;
    if(res>LLONG_MAX) res=LLONG_MAX;
  }
  //cout<<l<<" "<<r<<":"<<(int)res<<endl;
  return dp2[l][r]=res;
}
string ans;
void dfs2(int l,int r,Int x){
  //cout<<l<<" "<<r<<":"<<(int)x<<endl;
  if(r-l<2){
    cout<<ans;
    if(l<r) cout<<s[l];
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return;
  }
  map<char,Int> m;
  typedef pair<int,int> P;
  map<char,P> mp;
  if(s[l]==s[r-1]&&dp[l][r]==dp[l+1][r-1]+2){
    //if(m.count(s[l])) assert(m[s[l]]==dfs(l+1,r-1));
    m[s[l]]=dfs(l+1,r-1);
    mp[s[l]]=P(+1,-1);
  }else{
    if(dp[l][r]==dp[l+1][r]+2){
      //if(m.count(s[l])) assert(m[s[l]]==dfs(l+1,r));
      m[s[l]]=dfs(l+1,r);
      mp[s[l]]=P(+1,0);
    }
    if(dp[l][r]==dp[l][r-1]+2){
      //if(m.count(s[r-1])) assert(m[s[r-1]]==dfs(l,r-1));
      m[s[r-1]]=dfs(l,r-1);
      mp[s[r-1]]=P(0,-1);
    }
  }
  for(auto p:m){
    if(p.second<x){
      x-=p.second;
      continue;
    }
    ans+=p.first;
    dfs2(l+mp[p.first].first,r+mp[p.first].second,x);
    break;
  }
}
signed main(){
  cin>>s>>k;
  K=k;
  n=s.size();
  memset(used,0,sizeof(used));
  priority_queue<st> q;
  for(int i=0;i<n;i++){
    q.push(st(i,i,0));
    q.push(st(i,i+1,1));
  }
  while(!q.empty()){
    st p=q.top();q.pop();
    int l=p.l,r=p.r,c=p.c;
    if(used[l][r]) continue;
    used[l][r]=1;
    dp[l][r]=c;
    if(l>0&&r<n) if(s[l-1]==s[r]) q.push(st(l-1,r+1,c+2));
    if(l>0) q.push(st(l-1,r,c+2));
    if(r<n) q.push(st(l,r+1,c+2));
  }
  //cout<<dp[0][n]<<endl;
  memset(used2,0,sizeof(used2));
  dfs(0,n);
  //cout<<(int)dp2[0][n]<<endl;
  if(dp2[0][n]<K){
    cout<<"NONE"<<endl;
    return 0;
  }
  dfs2(0,n,K);
  return 0;
}

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

#define int long long

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

	int k, a, b;
	cin >> k >> a >> b;

	if (a / k == b / k && a % k != 0 && b % k != 0) {
		cout << "NG";
	} else {
		cout << "OK";
	}
}


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

namespace Number
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string i = Console.ReadLine();
                if(i == "0 0") break;
                List<int> a = i.Split(' ')
                               .Select(e => int.Parse(e))
                               .ToList();
                a.Sort();
                Console.WriteLine("{0} {1}", a[0], a[1]);
            }
        }
    }
}

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

string s;
ll cnt[26];

void solve()
{
	const int n = s.length();
	ll ans = 1LL*n*(n-1)/2;
	for(int i=0;i<n;++i){
		ans -= cnt[s[i]-'a'];
		cnt[s[i]-'a']++;
	}
	cout << ans+1 << '\n';
}

int main()
{
	cin >> s;
	solve();
	return 0;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int maxKin = a;
  if (b > maxKin) maxKin = b;
  if (c > maxKin) maxKin = c;

  cout << a + b + c - maxKin << endl;
}

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

using namespace std;
using ll = long long int;

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

    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll r=0, g=0, b=0;
    for(auto &c: s) {
        switch(c) {
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }
    ll res = r*g*b;
    for(ll i=1; i<n; i++) {
        for(ll j=0; j<n; j++) {
            if(j+2*i >= n) break;
            ll a = j, b = j+i, c = j+2*i;
            res -= s[a] != s[b] && s[b] != s[c] && s[c] != s[a];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3656
from collections import Counter

n = int(input())
a_input = list(map(int,input().split()))

a_c = sorted(Counter(a_input).items(),key=lambda x:x[0],reverse=True)

max_len=0
next_len=0
ans=0
for a in a_c:
    if a[1]<2:
        continue
    max_len = max(max_len,a[0])
    if a[1]>=4:
        ans = max(ans,a[0]**2)
    if max_len>a[0]:
        next_len = max(next_len,a[0])
print(max(ans,max_len*next_len))

Measured memory_bytes: 22436
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//WA

int main(void){
	ll N,L;
	string s[110];
	scanf("%lld%lld",&N,&L);
	rep(i,N)cin>>s[i];
	sort(s,s+N);
	rep(i,N)cout<<s[i];
	cout<<endl;
	return 0;
}

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



int main(void){
    int n,m;
    cin >> n >>m;
    vector<int> p(m);
    
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int x;
            cin >> x;
            p[x-1] += 1;
        }
    }
    int ans = 0;
    rep(i,m){
        if(p[i] == n){
            ans++;
        }
    }
    cout << ans <<endl;
    
    return 0;
}






































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

string str;
int n, k, c;
int main()
{
	usecppio
	cin >> n >> k ;
	cin >> str;
	int res = n-1;
	int len = str.length();
	for(int i = 1; i<len; i++)
		if(str[i] == str[i-1])
			c++;
	res = min(res, c+2*k);
	cout << min(n-1, res) << '\n';
}

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

using namespace std;

int main() {
  double A, B, H, M;
  double result, angle_c, ans;
  cin >> A >> B >> H >> M;
  angle_c = cos(2.0*M_PI*(H/12.0 + M/720.0) - 2.0*M_PI*(M/60.0));
  result = (A*A) + (B*B) - (2.0*A*B*angle_c);
  ans = sqrt(result);
  printf("%.20f", ans);

  return 0;
}

Measured memory_bytes: 4228