akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N,K;
  cin>>N>>K;
  vector<ll> A(N);
  for(int i(0);i<N;i++){
    cin>>A[i];
  }
  if(K==0){
    ll ans(0);
    for(int i(0);i<N;i++){
      ans = max(ans,A[i]);
    }
    cout << ans << endl;
    return 0;
  }
  ll l = 0,r = 1e9+1;
  while(r-l>1){
    ll x = (l+r)/2;
    //ccout << x << endl;
    //cout << l << " " << r << endl;
    bool ok = [&]{
      // ll nedan = A*x + B*int(to_string(x).size());
      // if (nedan <= X) return true;
      // else return false;
      ll cnt(0);
      for(int i(0);i<N;i++){
        if(A[i]%x == 0) cnt += A[i]/x-1;
        else cnt += A[i]/x;
      }
      if(cnt > K) return true;
      else return false;
    }();
    if (ok) l = x;
    else r = x;
  }
  int cnt(0);
  if(l == 0){
    cout << 1 << endl;
    return 0;
  }
  for(int i(0);i<N;i++){
    if(A[i]%l==0) cnt+=A[i]/l-1;
    else cnt+=A[i]/l;
  }
  if(cnt <= K) cout << l << endl;
  else cout << r << endl;
  return 0;
}



Measured memory_bytes: 4796
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
typedef long long LL;
int main() {
	std::string a,b;
	std::cin >> a >> b;
	if (b > a) { std::cout << '<' << std::endl; }else 
		if (a > b) { std::cout << '>' << std::endl; }
		else {
			std::cout << "=" << std::endl;
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  string S;
  cin>>S;
  int ans=100;
  rep(i,26){
    char A=i+'a';
    int X=-1,M=0;
    rep(j,S.size()+1){
      if(S[j]==A||j==S.size()){
        M=max(M,j-X-1);
        X=j;
      }
    }
    ans=min(ans,M);
  }
  cout<<ans<<endl;
}

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

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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            out.println((Math.abs(a - x) < Math.abs(b - x)) ? "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 int nextInt() {
            return Integer.parseInt(next());
        }

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

        public double nextFloat() {
            return Double.parseDouble(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


Measured memory_bytes: 21076
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;


ll sum[200001];
ll dp[2001][2001];
int notes[2001];
ll beauty[100001];

int main(){
  int num_of_notes;
  int num_of_beauty;
  ll force_of_repulsion;
  while(~scanf("%d %d %lld",
               &num_of_notes,
               &num_of_beauty,
               &force_of_repulsion)){

    for(int note_idx = 0; note_idx < num_of_notes; note_idx++){
      scanf("%d",notes + note_idx);
      notes[note_idx]--;
    }

    memset(sum,0,sizeof(sum));

    for(int beauty_idx = 0; beauty_idx < num_of_beauty; beauty_idx++){
      scanf("%d",beauty + beauty_idx);
      sum[beauty_idx] = (beauty_idx - 1 >= 0 ? sum[beauty_idx - 1] : 0) + beauty[beauty_idx];
    }

    sort(notes,notes + num_of_notes);
    reverse(notes,notes + num_of_notes);

    memset(dp,0x3f,sizeof(dp));

    dp[0][0] = 0;
    for(int i=0;i<num_of_notes;i++){
      for(int j=0;j<=i;j++){
        int larger_idx = max(i,j) + 1;
        dp[larger_idx][j]
          = min(dp[larger_idx][j],
                dp[i][j] + (sum[notes[i]] - sum[notes[larger_idx] - 1]) / force_of_repulsion);

        dp[larger_idx][i]
          = min(dp[larger_idx][i],
                dp[i][j] + (sum[notes[j]] - sum[notes[larger_idx] - 1]) / force_of_repulsion);
      }
    }

    ll res = LINF;
    for(int i=0;i<num_of_notes;i++){
      res = min(dp[num_of_notes - 1][i]
                + (sum[notes[i]] - sum[notes[num_of_notes - 1] - 1]) / force_of_repulsion,
                res);
    }

    printf("%lld\n",res);
  }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;
    int k;
    cin >> k;

    int n = s.size();

    for(int i = 0; i < n; i++){
        if('z'-s[i] < k && s[i] != 'a'){
            k -= 'z'-s[i]+1;
            s[i] = 'a';
        }
        if(k > 0 && i == n-1){
            s[i] += k%26;
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3748
#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 ll;
typedef pair<int, int> P;
const int INF = 1000000007;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


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

    map<int, int> M;
    bool z = true;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(a!=0) z = false;
        M[a]++;
    }
    
    if(z){
        cout << "Yes" << endl;
        return 0;
    }
    
    if(N%3!=0){
        cout << "No" << endl;
        return 0;
    }
    
    
    if(M.size()==2){
        vector<PII> V;
        for(auto m:M){
            V.push_back({m.fs, m.sc});
        }
        
        bool z = false;
        int zidx = 0;
        for(int i=0; i<2; i++){
            if(V[i].fs==0){
                z = true;
                zidx = i;
            }
        }
        if(!z){
            cout << "No" << endl;
            return 0;
        }
        
        if(V[zidx].sc*2==V[zidx^1].sc){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
        return 0;
    }
    
    
    
    
    if(M.size()!=3){
        cout << "No" << endl;
        return 0;
    }
    
    vector<int> V;
    for(auto m:M){
        V.push_back(m.fs);
        if(m.sc*3 != N){
            cout << "No" << endl;
            return 0;
        }
    }
    
    if((V[0]^V[1])==V[2]){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    
    

    
    
    
    
    return 0;
}



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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

int n, k;
char s[N];
vector<int> seq;
LL sum[N];

int main()
{
	scanf("%d%d%s", &n, &k, s);
	
	seq.push_back(0);
	for (int i = 0; i < n; i ++ )
	{
		int j = i, cnt = 0;
		while (j < n && s[i] == s[j]) j ++ , cnt ++ ;
		seq.push_back(cnt);
		i = j - 1;
	}
	
	n = seq.size() - 1;
	
	for (int i = 1; i <= n; i ++ ) sum[i] = sum[i - 1] + seq[i];
	LL tot = sum[n];
	int res = 0, len = 2 * k + 1;
	for (int i = 1; i <= n; i ++ )
	{
		// cout << i + len - 1 << ' ' << i - 1 << endl;
		int j = min(i + len - 1, n);
		int part = sum[j] - sum[i - 1];
		// cout << part << endl;
		int cnt = part - 1;
		// cout << tot << ' ' << part << ' ' << n - len << endl;
		cnt += tot - part - (n - (j - i + 1));
		// cout << cnt << endl;
		res = max(res, cnt);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAXN = 200000;

vector<int> g[MAXN];

int idx, d;

bool visited[MAXN];

void dfs(int v, int dd) {
	if (dd > d) {
		idx = v;
		d = dd;
	}
	visited[v] = true;
	FOR (i, g[v].sz) {
		int w = g[v][i];
		if (visited[w])
			continue;
		dfs(w, dd + 1);
	}
}

int p[MAXN];

pair<int, int> dfsIdx(int v) {
	visited[v] = true;
	pair<int, int> ret = make_pair(v, 1);
	FOR (i, g[v].sz) {
		int w = g[v][i];
		if (visited[w])
			continue;
		p[w] = v;
		pair<int, int> pp = dfsIdx(w);
		if (pp.second + 1 > ret.second) {
			ret = pp;
			ret.second++;
		}
	}
	return ret;
}

int N;
bool onPath[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	FOR (i, MAXN)
		g[i].clear();

	cin >> N;
	int a, b;
	FOR (i, N - 1) {
		cin >> a >> b;
		a--;
		b--;
		g[a].pb(b);
		g[b].pb(a);
	}

	d = idx = -1;
	SET(visited, 0);
	dfs(0, 0);


	SET(p, 255);
	SET(visited, 0);
	pair<int, int> start = dfsIdx(idx);

	SET(onPath, 0);
	int v = start.first;
	while (v != -1) {
		onPath[v] = true;
		v = p[v];
	}
	
	vector<int> P;
	P.clear();
	v = start.first;
	int cnt = 1, w;
	//cout << start.first << " " << start.second << endl;
	while (v != -1) {
		int tmp = cnt;
		FOR (i, g[v].sz) {
			w = g[v][i];
			if (!onPath[w]) {
				cnt++;
				P.pb(cnt);
			}
		}
		P.pb(tmp);
		cnt++;
		v = p[v];
	}
	
	v = start.first;
	int pp = -1;
	while (v != -1) {
		int w = p[v];
		p[v] = pp;
		pp = v;
		v = w;
	}
	

	vector<int> P1;
	P1.clear();
	v = idx;
	cnt = 1;
	//cout << start.first << " " << start.second << endl;
	while (v != -1) {
		int tmp = cnt;
		FOR (i, g[v].sz) {
			w = g[v][i];
			if (!onPath[w]) {
				cnt++;
				P1.pb(cnt);
			}
		}
		P1.pb(tmp);
		cnt++;
		v = p[v];
	}

	if (P.sz != N) {
		cout << "-1" << endl;
	}
	else {
		bool first = true;
		FOR (i, N) {
			if (P[i] < P1[i])
				break;
			if (P[i] > P1[i]) {
				first = false;
				break;
			}
		}
		if (first) {
			FOR (i, P.sz)
				cout << P[i] << " ";
		}
		else {
			FOR (i, P1.sz)
				cout << P1[i] << " ";

		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 17016
#include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
     
    //D日目時点のスコアを計算
    int score(int D, int c[], int s[][26], int t[]){
        int pen_day[26]={1};
        for(int i=0; i<26; i++){
            pen_day[i]=1;
        }
        int score=0;
        
        for(int i=0; i<D; i++){
            int type=t[i]-1;
            pen_day[type]=0;
            //満足度増加
            score+=s[i][type];
            //満足度低下
            for(int j=0; j<26; j++){
                int dec=c[j]*pen_day[j];
                score-=dec;
            }
            //日数追加
            for(int j=0; j<26; j++){
                pen_day[j]++;
            }        
        }
        return score;
    }
     
    void Greedy(int D, int c[], int s[][26]){
        int t[D], max_type=0, max_score=0;
     
        for(int i=0; i<D; i++){
            max_score=0;
            for(int j=0; j<26; j++){
                t[i]=j+1;
                int S=score(i+1, c, s, t);
                if(max_score < S){
                    max_score = S;
                    max_type=j+1;
                }
            }
            t[i]=max_type;
        }
     
        //局所探索
        int new=0;
        int roop_num=0;
        int MAX=max_score;
        while(1){
            int a=rand()%D;
            int b=rand()%D;
     
            //a,bを入れ替え
            int tmp;
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;
     
            //scoreを計算
            int now_score=score(D, c, s, t);
            if(MAX<now_score) MAX=now_score;
            else{
                tmp=t[a];
                t[a]=t[b];
                t[b]=tmp;  
            }
            new++;
            roop_num++;
            if(roop_num==D*500) break;
        }
     
        for(int i=0; i<D; i++){
            printf("%d\n", t[i]);
        }
    }
     
    int main(void){
        int D, c[26], s[365][26], t[365];
     
        //入力
        scanf("%d", &D);
        for(int i=0; i<26; i++){
            scanf("%d", &c[i]);
        }
        for(int i=0; i<D; i++){
            for(int j=0; j<26; j++){
                scanf("%d", &s[i][j]);
            }
        }
        /*
        for(int i=0; i<D; i++){
            scanf("%d", &t[i]);
        }
        */
     
       /*ここから処理*/
       /*
        int num=1;
        for(int i=0; i<D; i++){
            printf("%d\n", num);
            num++;
            if(num>26) num=1;
        }
        */
     
       Greedy(D, c, s);
     
     
        return 0;
    }

Measured memory_bytes: 1768
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define pb(z) push_back(z)
#define ff first
#define ss second
#define pi(a,b) make_pair(a,b)
#define pii pair<ll,ll>
#define T int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define input(v,n) vector<int>v;for(int i=0;i<n;i++){int x;cin>>x;v.push_back(x);}
#define debugg(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


const int inf    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 2e5+5;
//vector<int>v;
//for(int i=0; i<n; i++)
//{
//    int x;
//    cin>>x;
//    v.push_back(x);
//}


int main()
{
    IOS
    vector<ll>a,b,c;
    map<int,int>mp;
    int n,k;
    cin>>n;
    int cnt1=0,cnt2=0;
    rep(i,0,n+1)
    {
        ll t,x,y;
        cin>>t;
        a.pb(t);
    }
    rep(i,0,n)
    {
        ll t,x,y;
        cin>>t;
        b.pb(t);
    }
    ll tmp=-2,sum=0;
    rep(i,0,n)
    {
        //um+=min(b[i],a[i]+a[i+1]);
        if(b[i]<a[i]+a[i+1])
        {
            sum+=b[i];
           // a[i]=max(0LL,a[i]-b[i]);
            a[i+1]-=max(b[i]-a[i],0LL);
        }
        else
        {
            sum+=a[i]+a[i+1];
            a[i+1]=0;
        }
//        if(a[i]>=b[i] && a[i] && b[i])
//        {
//            sum+=b[i];
//            b[i]=0;
//            a[i]-=b[i];
//
//        }
//        else if(a[i]<b[i] && a[i] && b[i])
//        {
//            sum+=a[i];
//            b[i]-=a[i];
//            a[i]=0;
//        }
//        if(a[i+1]>=b[i] && a[i+1] && b[i])
//        {
//            sum+=b[i];
//            b[i]=0;
//            a[i+1]-=b[i];
//        }
//        else if(a[i+1]<b[i] && a[i+1] && b[i])
//        {
//            sum+=a[i+1];
//            b[i]-=a[i+1];
//            a[i+1]=0;
//        }
    }
    cout<<sum<<endl;

}



Measured memory_bytes: 5592
N = int(input())
S = input()

flg_l = False
cnt_r = 0
cnt_l = 0

for i in range(N):
    if(S[i] == "("):
        cnt_r += 1
        flg_l = True            
    else:
        if(flg_l):
            if(cnt_r > 0):
                cnt_r -= 1
            else:
                cnt_l += 1
                flg_l = False
        else:
            cnt_l += 1
    
ans = ""

ans += ("("*cnt_l)+S+(")"*cnt_r)
print(ans)

Measured memory_bytes: 9204
#include <stdio.h>
#include <math.h>
int main(void){
	char op;
	int a,b;
	int x;
	while(1){
		scanf("%d %c %d", &a,&op,&b);
		if(op=='+'){
			x=a+b;
		}else if(op=='-'){
			x=a-b;
		}else if(op=='/'){
			x=a/b;
		}else if(op=='*'){
			x=a*b;
		}else{
			break;
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 600
N,K = map(int,input().split())

H = []
for i in range(N):
    h = int(input())
    H.append(h)

H = sorted(H)

tmp = 0
ans = H[-1]
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
#    print(H[i:i+K])

    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 8280
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	string s;
	cin>>s;
	array<int,2019> cnt{};
	cnt[0]=1;
	ll res=0;
	int cur=0;
	for (char c:s) {
		array<int,2019> next{};
		rep(i,0,2019) next[i*10%2019]+=cnt[i];
		cur=(cur*10+c-'0')%2019;
		res+=next[cur];
		next[cur]++;
		cnt=next;
	}
	cout<<res<<'\n';

}


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

using namespace std;

const int maxn=1e5+10;

int n,t;
int e[maxn],o[maxn],ro[maxn],re[maxn];

bool cmp1(int a,int b)
{
	return o[a]>o[b];
}

bool cmp2(int a,int b)
{
	return e[a]>e[b];
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(i&1)o[t]++;
		else e[t]++;
	}
	
	for(int i=1;i<=100000;i++)
		ro[i]=re[i]=i;
	
	sort(ro+1,ro+100001,cmp1);
	sort(re+1,re+100001,cmp2);
	
	if(re[1]==ro[1])printf("%d",min(n-e[re[1]]-o[ro[2]],n-e[re[2]]-o[ro[1]]));
	else printf("%d",n-e[re[1]]-o[ro[1]]);
	
	return 0;
}

Measured memory_bytes: 1792
M=10**9+7
x,y=map(int,input().split())
d,m=divmod(x+y,3)
if m or y>2*x or x>2*y: print(0); exit()
x-=d
y-=d
s=t=1
for i in range(min(x,y)):
  s=s*(x+y-i)%M
  t=t*(i+1)%M
print(s*pow(t,M-2,M)%M)

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i=0; i<N; i++) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    ll ans = 0;
    for (ll i=0; i<N/2; i++) {
        ans += 2*A[i];
    }
    ans -= A[0];

    if (N%2!=0) {
        ans += A[(N+1)/2-1];
    }

    cout << ans << endl;
}

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

#define maxn 16
#define maxs (1<<maxn)

typedef long long ll;
const ll mod = 1000000007;

ll dp[maxs];
int g[maxn];
int n, m;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x] |= 1 << y;
    }
    dp[0] = 1;
    for (int s = 0; s < (1 << n); s++)
    {
        if (!dp[s])
        {
            continue;
        }
        int ns = ((1 << n) - 1)^s;
        for (int s1 = ns; s1; s1 = (s1 - 1)&ns)
        {
            if (s1 % 4 == 3)
            {
                continue;
            }
            ll x = dp[s];
            for (int k = 0; k < n; k++)
            {
                if (s & (1 << k))
                {
                    continue;
                }
                if (s1 & (1 << k))
                {
                    x = (x << __builtin_popcount(g[k] & (~(s | s1))));
                }
                else
                {
                    x = x * ((1 << __builtin_popcount(g[k] & s1)) - 1);
                }
                x %= mod;
            }
            dp[s | s1] += x;
            dp[s | s1] %= mod;
        }
    }
    printf("%lld\n", dp[(1 << n) - 1]);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 233;
int f[maxn];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=200;i++)
	for(int j=1;j<=200;j++)
	for(int k=1;k<=200;k++){
		f[i*i+j*j+k*k+i*j+i*k+j*k]++;
	}
	for(int i=1;i<=n;i++)printf("%d\n",f[i]);
}


Measured memory_bytes: 4584
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

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 << 100 * n << endl;
	}
	else {
		if (n == 100) cout << 1010000 << endl;
		else cout << 10000 * n << endl;
	}
}


Measured memory_bytes: 384
using System;

namespace KthTerm
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = "1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51";
            String[] splitted = S.Split(' ');
            int K = int.Parse(Console.ReadLine());
            Console.WriteLine(splitted[K - 1]);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
long long mod = 1000000007;
int n;
string s1;
string s2;
long long memo[4][4][53];
long long go(int now, int a, int b){
    if(now==n){
        return 1LL;
    }
    if(memo[a][b][now]!=-1LL){
        return memo[a][b][now];
    }
    int f = 3;
    int s = 3;
    if(a!=3 && s1[now]==s1[now-1]){
        f = a;
    }
    if(b!=3 && s2[now]==s2[now-1]){
        s = b;
    }
    long long ret = 0LL;
    for(int c1 = 0; c1<3; c1++){
        if(f!=3 && c1!=f){
            continue;
        }
        if(now>0 && s1[now]!=s1[now-1] && c1==a){
            continue;
        }
        for(int c2 = 0; c2<3; c2++){
            if(s!=3 && c2!=s){
                continue;
            }
            if(s1[now]==s2[now]){
                if(c1!=c2){
                    continue;
                }
            }
            else{
                if(c1==c2){
                    continue;
                }
            }
            if(now>0 && s2[now]!=s2[now-1] && c2==b){
                continue;
            }
            ret += go(now+1,c1,c2);
            ret %= mod;
        }
    }
    memo[a][b][now] = ret;
    return ret;
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    for(int a = 0; a<4; a++){
        for(int b = 0; b<4; b++){
            for(int c = 0; c<53; c++){
                memo[a][b][c] = -1LL;
            }
        }
    }
    cin >> n >> s1 >> s2;;
    long long ans = go(0,3,3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int g[101][101];
int a[10001],h,w,n;
bool vis[101][101];

void dfs(int i,int j,int in,int cur,int r){
    if (i<1 or i>h or j<1 or j>w or vis[i][j]) return ; 
    vis[i][j]=true;
    if (cur==r) in++,r=a[in],cur=0;
    g[i][j]=in;
    dfs(i-1,j,in,cur+1,a[in]);
    dfs(i+1,j,in,cur+1,a[in]);
    dfs(i,j-1,in,cur+1,a[in]);
    dfs(i,j+1,in,cur+1,a[in]);
}

inline void solve(){
    cin>>h>>w>>n; 
    for (int i=1;i<=n;i++)  cin >> a[i] ; 
    dfs(1,1,1,0,a[1]);
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            cout << g[i][j] << " ";
        } cout << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main (){
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    
    int ans = 1;
    int now = p[0];
    rep2(i,1,n){
        if(p[i] < now){
            ans++;
            now = p[i];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n; 
	long long a=0, l0=2, l1=1, s; 
	cin >> n;
	if(n == 0){
		cout << '2'<< endl; 
		return 0;
	}else if(n == 1){
		cout << '1'<<endl; 
		return 0;
	}
	for(int i=0; i<n-1; i++){
		s = l0 + l1; 
		a = s; 
		l0 = l1;
		l1 = s;
	}
	cout << a << '\n'; 
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int64 n, m;
	while(cin >> n >> m && n+m){
		priority_queue<PLL> pq;
		int64 res = 0;
		REP(i, n){
			int64 a, b;
			cin >> a >> b;
			res += a*b;
			pq.push(PLL(b, a));
		}
		while(m && pq.size()){
			int64 cnt = min(pq.top().sc, m);
			m -= cnt;
			res -= pq.top().fs*cnt;
			pq.pop();
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 3368
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int x=0;
        int n[]=new int[3];
        for(int i=0; i<3; i++){
            n[i]=sc.nextInt();
        }
        for(int i=1; i>=0; i--){
            if(n[i]<n[i+1]){
                x=n[i+1];
                n[i+1]=n[i];
                n[i]=x;
            }
        }
        System.out.println(n[0]*10+n[1]+n[2]);
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll r1,r2,c1,c2;
ll n;
ll fac[2000005],inv[2000005];
//ll ans;
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline ll mx(ll _x,ll _y)
{
	return _x>_y?_x:_y;
}
inline ll qpow(ll a,ll b)
{
	ll rest=1;
	while(b)
	{
		if(b&1) rest=(rest*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return rest;
}
//inline ll C(ll n,ll m) 
//{
//    if(n<m) return 0;
//    if(m>n-m) m=n-m;
//    ll s1=1,s2=1;
//    for(ll i=0;i<m;++i) 
//	{
//        s1=(s1*(n-i))%mod;
//       s2=(s2*(i+1))%mod;
//    }
//    return s1*qpow(s2,mod-2)%mod;
//}
//inline ll lucas(ll n,ll m)
//{
//	if(m==0) return 1;
//	else return (C(n%mod,m%mod)*lucas(n/mod,m/mod))%mod;
//}
inline ll C(ll n,ll m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline ll xigema(ll n,ll m){
	ll rest=0;
	for(ll i=1;i<=m;i++) rest=(rest+C(n+i+1,i+1))%mod;
	return ((rest-m)%mod+mod)%mod;
}
int main()
{
	read(r1);read(c1);read(r2);read(c2);
//	for(ll i=r1;i<=r2;i++)
//		for(ll j=c1;j<=c2;j++)
//			printf("%lld\n",lucas(i+j,i)); 
//	for(ll i=r1;i<=r2;i++)
//	{
//		ans=(ans+(lucas(i+c2+1,i+1)-lucas(i+c1,i+1))%mod)%mod;
//	}//TLE lucas R.I.P
	n=mx(r2,c2)*2+1;
	fac[0]=1;
	for(ll i=1;i<=n;i++) 
		fac[i]=fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(ll i=n-1;i>=0;i--) 
		inv[i]=inv[i+1]*(i+1)%mod;
	printf("%lld\n",((xigema(r2,c2)-xigema(r1-1,c2)-xigema(r2,c1-1)+xigema(r1-1,c1-1))%mod+mod)%mod);
	return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>

using namespace std;

size_t selection_sort(vector<int> &nums) {
  size_t swapNum = 0;

  for (size_t i = 0; i < nums.size(); i++) {
    size_t mini = i;
    for (size_t j = i; j < nums.size(); j++) {
      if (nums[j] < nums[mini]) {
        mini = j;
      }
    }

    if (i != mini) {
      swap(nums[i], nums[mini]);
      swapNum++;
    }
  }

  return swapNum;
}

void print(const vector<int> &nums) {
  for (auto itr = nums.begin(); itr != nums.end(); itr++) {
    if (itr != nums.begin()) {
      cout << " ";
    }
    cout << *itr;
  }

  cout << endl;
}

int main(int argc, char *argv[]) {
  // read input
  int n;

  cin >> n;

  vector<int> nums;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    nums.push_back(a);
  }

  size_t swapNum = selection_sort(nums);

  print(nums);
  cout << swapNum << endl;

  return 0;
}

Measured memory_bytes: 3160
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        Set<Integer>[] switches = new Set[N];
        for(int i = 0; i < N; i++){
            switches[i] = new HashSet<>();
        }
        
        for(int i = 0; i < M; i++){
            int k = sc.nextInt();
            
            for(int j = 0; j < k; j++){
                int s = sc.nextInt() - 1;
                switches[s].add(i);
            }
        }
        
        int[] P = new int[M];
        for(int i = 0; i < M; i++){
            P[i] = sc.nextInt();
        }
        
        
        int sum = 0;
        for(int i = 0; i < 1 << N; i++){
            
            int x = i;
            int X = i;
            int[] check = new int[M];
            
            for(int j = 0; j < N; j++){
                
                if( (x & 1) == 1 ){
                    for( int mame : switches[j] ){
                        check[mame]++;
                    }
                }
                
                x >>= 1;
            }
            
            boolean isOK = true;
            for(int j = 0; j < M; j++){
                if( check[j] % 2 != P[j] ){
                    isOK = false;
                    break;
                }
            }
            
            if(isOK){
                sum++;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 23764
#include<cstdio>
int main(){
      int a,b,c,x,y;
      scanf("%d %d %d",&a,&b,&c);
       x=c%b;
       for(int i=1;i<=100000;i++){
             y=(a*i)%b;
             if(y==x){
                 printf("YES");
                 break;
}
}
        if(y!=x)
           printf("NO");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 1e5 + 10;
int a[110], dp[mxn][2];
bool sol[mxn][2];
int n, K;

int f(int m, int c)
{
	if(sol[m][c])
		return dp[m][c];
	if(m < a[1])
		dp[m][c] = 1 ^ c;
	else
	{
		dp[m][c] = 1 ^ c;
		for(int i = 1; i <=n  && m >= a[i]; i++)
		{
			if(f(m - a[i], 1 ^ c) == c)
			{
				dp[m][c] = c;
				break;
			}
		}
	}
	sol[m][c] = 1;
	return dp[m][c];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> K;
	FOR(i,1,n)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	memset(sol,0,sizeof(sol));

	bool check =  f(K, 0);
	if(check)
		cout << "Second";
	else
		cout << "First"; 

	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

ll n,ans=0;
void nya(ll x,ll a,ll b,ll c){
  if(x>n)return;
  if(a&&b&&c)ans++;
  nya(x*10+3,1,b,c);
  nya(x*10+5,a,1,c);
  nya(x*10+7,a,b,1);
}
int main(){
  cin >> n;
  nya(0,0,0,0);
  cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import *
n, m, q = map(int, input().split())

a, b, c, d = [], [], [], []

for i in range(q):
    a_temp, b_temp, c_temp, d_temp = map(int, input().split())
    a.append(a_temp)
    b.append(b_temp)
    c.append(c_temp)
    d.append(d_temp)

A = list(combinations_with_replacement(range(1,m + 1),n))

ans = 0
ans_i = 0

for A_i in A:
    for i in range(q):
        if A_i[b[i] - 1] - A_i[a[i] - 1] == c[i]:
            ans_i += d[i]

    ans = max(ans, ans_i)
    ans_i = 0

print(ans)

Measured memory_bytes: 21432
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    while (true) {
        int n = readint;
        if (n == 0) break;

        auto ss = readints;
        double avg = 1.0 * ss.sum / n;
        auto a2 = ss.map!(e => (e - avg) ^^ 2).sum / n;
        writefln("%.6f", sqrt(a2));
    }
}



Measured memory_bytes: 2592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007
double tick() { static clock_t oldt; clock_t newt = clock(); double diff = 1.0*(newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff; }
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}


int main()
{
	LL n, k;
	cin >> n >> k;
	vector<LL> v(n);
	rep(i, n)cin >> v[i];
	k = min(n, k);
	sort(rall(v));
	LL ans = 0;
	int count = 0;
	rep(i, n)
	{
		
		count++;
		if (count > k)break;
		ans += v[i];
	}
	cout << accumulate(all(v),0LL)-ans << endl;



	

}



Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
int main() {
    int n, m, l;
    cin >> n >> m >> l;
    int A[n][m];
    int B[m][l];
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            cin >> A[i][j];
        }
    }
    for (int j=0;j<m;j++) {
        for (int k=0;k<l;k++) {
            cin >> B[j][k];
        }
    }

    long long int C[n][l];
    for (int i=0;i<n;i++) {
        for (int k=0;k<l;k++) {
            C[i][k] = 0;
        }
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            for (int k=0;k<l;k++) {
                C[i][k] += A[i][j] * B[j][k];
            }
        }
    }
    for (int i=0;i<n;i++) {
        for (int k=0;k<l;k++) {
            if (k>0) {
                cout << " ";
            }
            cout << C[i][k];
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3176
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

int N, M, L;

struct Edge {
	int to, dist, enemy;
	Edge(int _t, int _d, int _e) : to(_t), dist(_d), enemy(_e) {}
};
bool operator > (const Edge& e1, const Edge& e2) {
	if (e1.enemy < e2.enemy) return true;
	else if (e1.to < e2.to) return true;
	return e1.dist < e2.dist;
}
bool operator == (const Edge& e1, const Edge& e2) {
	if (e1.enemy == e2.enemy && e1.to==e2.to && e1.dist == e2.dist) return true;
	return false;
}
bool operator != (const Edge& e1, const Edge& e2) { return !(e1 == e2); }
bool operator < (const Edge& e1, const Edge& e2) { return !(e1 > e2) && (e1 != e2); }
bool operator >= (const Edge& e1, const Edge& e2) { return (e1 > e2) && (e1 == e2); }
bool operator <= (const Edge& e1, const Edge& e2) { return (e1 < e2) && (e1 == e2); }

const int INF = 1e9;
int d[110][110];

int main() {
	while (1) {
		cin >> N >> M >> L; if (N==0 && M==0 && L==0) break;
		vector< vector<Edge> > G(N+1, vector<Edge>());
		
		for (int i=0; i<M; i++) {
			int a, b, d, e; cin >> a >> b >> d >> e;
			G[a].push_back(Edge(b, d, e));
			G[b].push_back(Edge(a, d, e));
		}
		
		for (int i=0; i<=N; i++) fill(d[i], d[i] + L + 1, INF);
		
		d[1][0] = 0;
		
		priority_queue<Edge, vector<Edge>, greater<Edge> > q;
		q.push( Edge(1, 0, 0) );
		
		while (!q.empty()) {
			Edge e = q.top(); q.pop();
			
			for (int i=0; i<(int)G[e.to].size(); i++) {
				Edge ne = G[e.to][i];
				
				if (e.dist + ne.dist <= L) {
					if (d[ne.to][e.dist + ne.dist] > e.enemy) {
						d[ne.to][e.dist + ne.dist] = e.enemy;
						q.push(Edge(ne.to, e.dist + ne.dist, e.enemy));
					}
				}
				
				if (d[ne.to][e.dist] > e.enemy + ne.enemy) {
					d[ne.to][e.dist] = e.enemy + ne.enemy;
					q.push(Edge(ne.to, e.dist, e.enemy + ne.enemy));
				}
			}
		}
		
		int ans = INF;
		for (int i=0; i<=L; i++) ans = min(ans, d[N][i]);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	//write here
	string s,t;
	cin>>s>>t;
	int ans = 0;
	rep(i,0,sz(s)){
		if (s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
//	int t;
//	cin>>t;
//	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 5e3 + 10;
const int inf = 1e9;

char c[maxn];
int a[maxn], per_w[maxn], per_b[maxn];
int dp[maxn][maxn];
int fen[maxn + 100];

int get (int idx) {
	int ret = 0;
	for (; idx; idx -= idx & -idx)
		ret += fen[idx];
	return ret;
}

int get (int l, int r) {
	return get (r) - get (l - 1);
}


void change (int idx, int x) {
	for (; idx < maxn; idx += idx & -idx)
		fen[idx] += x;
}

int main () {
	ios_base::sync_with_stdio (false);
	int n;
	cin >> n;
	for (int i = 1; i <= 2 * n; i++) {
		cin >> c[i] >> a[i];
		if (c[i] == 'W')
			per_w[a[i]] = i;
		else
			per_b[a[i]] = i;
	}
	for (int i = 0; i <= n; i++) {
		if (i != 0)
			change (per_w[i], 1);
		for (int j = 0; j <= n; j++) {
			if (i == 0 and j == 0)
				continue;
			if (j != 0)
				change (per_b[j], 1);
			
			if (i == 0) {
				int idx = per_b[j];
				dp[i][j] = dp[i][j - 1] + get (idx + 1, 2 * n);
			}
			else if (j == 0) {
				int idx = per_w[i];
				dp[i][j] = dp[i - 1][j] + get (idx + 1, 2 * n);
			}
			else {
				int idx = per_b[j];
				dp[i][j] = dp[i][j - 1] + get (idx + 1, 2 * n);
				idx = per_w[i];
				dp[i][j] = min (dp[i][j], dp[i - 1][j] + get (idx + 1, 2 * n));
			}
		}
		for (int j = 1; j <= n; j++)
			change (per_b[j], -1);
	}
	cout << dp[n][n] << endl;
	return 0;
}


Measured memory_bytes: 40448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N;
  cin >> X >> N;
  if(N == 0){
	cout << X << endl;
    return 0;
  }
  vector<int> P(N);
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    P[i] = x;
  }
  sort(P.begin(), P.end());
  int min = 101,ans = 0;
  for(int i = 0; i <= 101; i++){
    if((find(P.begin(), P.end(), i) == P.end()) && (min > abs(X-i))){
      min = abs(X-i);
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int D,G;
	cin>>D>>G;
	vint P,C;
	for(int i=0;i<D;i++){
		int p,c;
		cin>>p>>c;
		P.pb(p);
		C.pb(c);
	}
	int ans=INF;
	for(int state=0;state<(1<<D);state++){
		int score=0,num=0;
		for(int i=0;i<D;i++)
			if(state&(1<<i)){
				score+=C[i];
				score+=P[i]*(i+1)*100;
				num+=P[i];
			}
		for(int i=D-1;i>=0;i--){
			int s=(i+1)*100;
			if(score<G && !(state&(1<<i))){
				int temp=min(P[i],(G-score+s-1)/s);
				num+=temp;
				score+=s*temp+(temp==P[i]?C[i]:0);
			}
		}
		ans=min(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  lli x;
  scanf("%lld", &x);

  int judge = 0;
  int num;
  while ( judge == 0 ) {
    judge = 1;
    for (int i = 2; i < x; i++) {
      if ( x % i == 0 ) {
        judge = 0;
        break;
      }
    }
    x++;
  }
  printf("%lld\n", x - 1);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<double> S(N+1);
    double p;
    for(int i=1;i<N+1;++i){
        cin >> p;
        S[i] = (1 + p) / 2;
    }
    for(int i=0;i<N;++i){
        S[i+1] += S[i];
    }
    double sum = 0, ans = -1;
    for(int i=K;i<N+1;++i){
        sum = S[i] - S[i-K];
        if(ans < sum){
            ans = sum;
        }
    }
    printf("%.12lf\n", ans);
}


Measured memory_bytes: 1792
n=int(input())
i=0
x=[]
y=[]
def linked_merge_sort(lst):
    if len(lst) == 1:
        return
    
    #
    # 1. 分割
    #
    q, r = divmod(len(lst), 2)
    left = [lst.pop() for _ in range(q)]
    right = [lst.pop() for _ in range(q + r)]
    
    #
    # 2. ソート
    #
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    #
    # 3. 統合
    #
    left.reverse()  # 補足
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            lst.append(left.pop())
        else:
            lst.append(right.pop())
    while left:
        lst.append(left.pop())
    while right:
        lst.append(right.pop())
while i<n:
    a=list(map(int,input().split()))
    x.append(a[0])
    y.append(a[1])
    i+=1
linked_merge_sort(x)
linked_merge_sort(y)
if n%2==0:
    p=(x[n//2]+x[(n//2)-1])/2
    q=(y[n//2]+y[(n//2)-1])/2
    ans=(q-p)*2+1
else:
    p=x[(n-1)//2]
    q=y[(n-1)//2]
    ans=q-p+1
print(int(ans))


Measured memory_bytes: 155360
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
y1 = x//2
y2 = x//2 + 1
sa1, sa2 = float("inf"), float("inf")
z1, z2 = 0, 0
for i in range(n-1):
    if sa1 > abs(y1 - a[i]):
        sa1 = abs(y1-a[i])
        z1 = a[i]
    if sa2 > abs(y2 - a[i]):
        sa2 = abs(y2 - a[i])
        z2 = a[i]

if sa1 > sa2:
    print(x, z2)
else:
    print(x, z1)




Measured memory_bytes: 62704
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;
using ll = long long;

int dist[1001][1001];

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m),c(m);
    for(int i=0;i<m;i++) cin >> a[i] >> b[i] >> c[i];
    
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)    dist[i][j] = 9999999;
        dist[i][i] = 0;
    }
    for(int i=0;i<m;i++){
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[j][k]);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<m;i++){
        if(dist[a[i]][b[i]]<c[i]) ans++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640