akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main() {
	int n, m;
	cin >> n;
	vector <string> red(n),small;
	vector <int> point;
	for (int i = 0; i < n; i++) {
		cin >> red.at(i);
		if (i == 0) { 
			small.push_back(red.at(0)); 
			point.push_back(1);
		}
		else {
			int a = small.size();
			for (int j = 0; j < a; j++) {
				if (red.at(i) == small.at(j)) {
					point.at(j)++;
					break;
				}
				else if (j == small.size() - 1){
					small.push_back(red.at(i));
					point.push_back(1);
				}
			}
		}
	}
	cin >> m;
	vector <string> blue(m);
	for (int i = 0; i < m; i++) {
		cin >> blue.at(i);
		for(int j = 0; j < small.size();j++)
			if (blue.at(i) == small.at(j)) {
				point.at(j)--;
			}
	}
	int max = 0;
	for (int i = 0; i < point.size();i++) {
		if (max < point.at(i)) max = point.at(i);
	}
	cout << max << endl;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int,int> ii;

int n,f[100005],up[100005];
long long ans[100005],sum[100005],cnt[100005];

vector<ii> graph[100005];
bool vis[100005];
vector<int> all;
vector<ii> tree[100005];

void dfs(int u,int p){
    f[u] = 1;
    for(int i = 0;i<graph[u].size();i++){
        int v = graph[u][i].fi;
        if(!vis[v] && v!=p){
            dfs(v,u);
            f[u]+=f[v];
        }
    }
}

int fin(int u,int p,int sz){
    for(int i = 0;i<graph[u].size();i++){
        int v = graph[u][i].fi;
        if(!vis[v] && v!=p){
            if(2*f[v]>sz) return fin(v,u,sz);
        }
    }
    return u;
}

void dist(int u,int p,int id,int val){
    all.pb(val); tree[id].pb(mp(val,u)); up[u] = val;
    for(int i = 0;i<graph[u].size();i++){
        int v = graph[u][i].fi,w = graph[u][i].se;
        if(!vis[v] && v!=p)
            dist(v,u,id,min(w,val));
    }
}
void centroid(int cen){
    dfs(cen,cen);
    int u = fin(cen,cen,f[cen]);
    vis[u] = 1;
    all.clear();
    for(int i = 0;i<graph[u].size();i++){
        int v = graph[u][i].fi,w = graph[u][i].se;
        if(vis[v]) continue;
        tree[v].clear();
        dist(v,u,v,w);
        sort(tree[v].begin(),tree[v].end());
    }
    sort(all.begin(),all.end());
    for(int i = 0 ;i<all.size();i++)
        ans[u]+=all[i];
    sum[all.size()] = 0;
    for(int i = 0 ;i<all.size();i++){
        sum[i] = all[i];
        if(i == 0) continue;
        sum[i]+=sum[i-1];
    }
    for(int i = 0 ;i<graph[u].size();i++){
        int v = graph[u][i].fi;
        if(vis[v]) continue;
        cnt[tree[v].size()] = 0;
        for(int j = 0;j<tree[v].size();j++){
            cnt[j] = tree[v][j].fi;
            if(j == 0) continue;
            cnt[j]+=cnt[j-1];
        }
        for(int j = 0;j<tree[v].size();j++){
            //cout<<tree[v][j].fi<<" "<<tree[v][j].se<<"\n";
            int node = tree[v][j].se,val = up[node],it;
            ans[node]+=val;
            it = upper_bound(all.begin(),all.end(),val)-all.begin();
            if(it-1>=0)
            ans[node]+=sum[it-1];
            ans[node]+=val*(all.size()-it);
            it = lower_bound(tree[v].begin(),tree[v].end(),ii(val+1,-1))-tree[v].begin();
            if(it-1>=0)
            ans[node]-=cnt[it-1];
            ans[node]-=val*(tree[v].size()-it);
        }
    }
    for(int i = 0;i<graph[u].size();i++){
        int v = graph[u][i].fi;
        if(!vis[v])
            centroid(v);
    }
}

int main(){
    cin.tie(0),ios::sync_with_stdio(0);
    cin>>n;
    int u,v,w;
    for(int i = 1;i<=n-1;i++){
        cin>>u>>v>>w;
        graph[u].pb(mp(v,w));
        graph[v].pb(mp(u,w));
    }
    centroid(1);
    for(int i = 1;i<=n;i++)
        cout<<ans[i]<<"\n";
}


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

int main() {

  double n;
  while( cin >> n ) {

    if ( n <= 48.00 ) {
      cout << "light fly";
    }else if ( n <= 51.00 ) {
      cout << "fly";
    }else if ( n <= 54.00 ) {
      cout << "bantam";
    }else if ( n <= 57.00 ) {
      cout << "feather";
    }else if ( n <= 60.00 ) {
      cout << "light";
    }else if ( n <= 64.00 ) {
      cout << "light welter";
    }else if ( n <= 69.00 ) {
      cout << "welter";
    }else if ( n <= 75.00 ) {
      cout << "light middle";
    }else if ( n <= 81.00 ) {
      cout << "middle";
    }else if ( n <= 91.00 ) {
      cout << "light heavy";
    }else {
      cout << "heavy";
    }
    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1220
// 2013/06/28 Tazoe

#include <iostream>
using namespace std;

struct square{
	int x;
	int y;
};

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

		if(N==0)
			break;

		struct square S[200];
		S[0].x = 0;
		S[0].y = 0;

		int x_max = S[0].x;
		int x_min = S[0].x;
		int y_max = S[0].y;
		int y_min = S[0].y;

		for(int i=1; i<N; i++){
			int n, d;
			cin >> n >> d;

			switch(d){
				case 0:
					S[i].x = S[n].x-1;
					S[i].y = S[n].y;
					if(S[i].x<x_min){
						x_min = S[i].x;
					}
					break;
				case 1:
					S[i].x = S[n].x;
					S[i].y = S[n].y+1;
					if(S[i].y>y_max){
						y_max = S[i].y;
					}
					break;
				case 2:
					S[i].x = S[n].x+1;
					S[i].y = S[n].y;
					if(S[i].x>x_max){
						x_max = S[i].x;
					}
					break;
				case 3:
					S[i].x = S[n].x;
					S[i].y = S[n].y-1;
					if(S[i].y<y_min){
						y_min = S[i].y;
					}
					break;
				default:
					break;
			}
		}

		cout << x_max-x_min+1 << ' ' << y_max-y_min+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int k,x;
    cin >> k >> x;
    
    if((k*500) >= x)
    cout <<"Yes" ;
    else
    cout <<"No";
    
    
	return 0;
    
}

Measured memory_bytes: 8832
S=input()
N=len(S)
ans=[0]*N

S+="R"

RL=0
LR=0
for i in range(1,N+1):
    if S[i-1]=="R" and S[i]=="L":
        RL=i
    elif S[i-1]=="L" and S[i]=="R":
        LR_next=i
        length=LR_next-LR
        if length%2==0:
            ans[RL-1]=length//2
            ans[RL]=length//2
        else:
            if (RL-LR)%2==1:
                ans[RL-1]=length//2+1
                ans[RL]=length//2
            else:
                ans[RL-1]=length//2
                ans[RL]=length//2+1
        LR=LR_next
                
print(' '.join(map(str, ans)))

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

int main()
{
    string s;
    int k;
    int num = 0;
    int pivot = 1;
    cin >> s >> k;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
        {
            num++;
        }
        else
        {
            pivot = s[i] - '0';
            break;
        }
    }

    // output
    if (k <= num)
    {
        cout << 1;
    }
    else
    {
        cout << pivot;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

template<typename T>
struct BIT{
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1){}

  T sum(int k){
    T ret = 0;
    for(++k; k>0; k -= k&-k) ret += d[k];
    return ret;
  }
  void add(int k, T x=1){
    for(++k; k<=n; k += k&-k) d[k] += x;
  }
};

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  ++N;
  vector<ll> v(N);
  v[0] = 0;
  rep(i,N-1)cin >> v[i+1];
  rep(i,N-1) v[i+1] += v[i];
  rep(i,N) v[i] -= (ll)i*K;

  map<ll,int> mp;
  rep(i,N) mp[v[i]] = 0;
  int n = 0;
  for(pair<const ll,int> & p : mp) p.second = n++;

  BIT< int > bit(N);
  ll ans = 0;
  rep(i,N){
    ans += bit.sum(mp[v[i]]);
    bit.add(mp[v[i]]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15104
using System;

namespace A___Day_of_Takahashi
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var ans = 0;
            if (a <= b)
            {
                ans = a;
            }
            else
                ans = a - 1;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int par[100010]; //親
int Rank[100010]; //木の深さ

//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) {
		return ;
	}
	if (Rank[x] < Rank[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (Rank[x] == Rank[y]) {
			Rank[x]++;
		}
	}
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	int n, m;
	cin >> n >> m;
	init(n);
	int p[n], ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int x[m], y[m];
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
		unite(x[i], y[i]);
	}
	for (int i = 0; i < n; i++) {
		if (same(i + 1, p[i])) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
    public static final double EPS = 0.001f;

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

        try {
            while (true) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                int d = sc.nextInt();
                int e = sc.nextInt();
                int f = sc.nextInt();

                double x = (double)(c*e-b*f)/(a*e-b*d);
                double y = (double)(c*d-f*a)/(b*d-a*e);

                if (x < EPS && x > -EPS) x = 0;
                if (y < EPS && y > -EPS) y = 0;

                System.out.printf("%.3f %.3f\n", x, y); 
            }
        } catch (Exception e) {
        }
    }
}

Measured memory_bytes: 26452
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

struct para
{
    ll a, b;
};

int Szukajpref(vector<ll>& a, vector<ll>& pref, int i)
{
    int l = 0, p = i, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (2 * pref[s] <= pref[i])
        {
            r = s;
            l = s + 1;
        }
        else
            p = s - 1;
    }
    return r;
}

int Szukajsuf(vector<ll>& a, vector<ll>& suf, int i)
{
    int l = i, p = a.size() - 1, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (2 * suf[s] <= suf[i])
        {
            r = s;
            p = s - 1;
        }
        else
            l = s + 1;
    }
    return r;
}


int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<ll> pref(n);
    pref[0] = a[0];
    for (int i = 1; i < n; ++i)
        pref[i] = pref[i - 1] + a[i];
    vector< vector<para> > prefopt(n);
    for (int i = 1; i < n; ++i)
    {
        int nr = Szukajpref(a, pref, i);
        if (nr != -1)
        {
            prefopt[i].push_back({pref[nr], pref[i] - pref[nr]});
            if (nr + 1 < i)
            {
                ++nr;
                prefopt[i].push_back({pref[nr], pref[i] - pref[nr]});
            }
        }
        else
            prefopt[i].push_back({pref[0], pref[i] - pref[0]});
    }
    vector<ll> suf(n);
    suf[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i)
        suf[i] = suf[i + 1] + a[i];
    vector< vector<para> > sufopt(n);
    for (int i = n - 2; i >= 0; --i)
    {
        int nr = Szukajsuf(a, suf, i);
        if (nr != -1)
        {
            sufopt[i].push_back({suf[nr], suf[i] - suf[nr]});
            if (nr - 1 > i)
            {
                --nr;
                sufopt[i].push_back({suf[nr], suf[i] - suf[nr]});
            }
        }
        else
            sufopt[i].push_back({suf[n - 1], suf[i] - suf[n - 1]});
    }
    ll odp = 100000000000000000;
    for (int i = 1; i <= n - 3; ++i)
    {
        for (int j = 0; j < prefopt[i].size(); ++j)
        {
            for (int k = 0; k < sufopt[i + 1].size(); ++k)
            {
                vector<ll> t;
                t.push_back(prefopt[i][j].a);
                t.push_back(prefopt[i][j].b);
                t.push_back(sufopt[i + 1][k].a);
                t.push_back(sufopt[i + 1][k].b);
                sort(t.begin(), t.end());
                odp = min(odp, t[3] - t[0]);
            }
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 33152
#include <iostream>
using namespace std;
int main(){
    // int n;
    // cin >> n;
    // if(n%2==0){
    //     cout<<n*n/4<<endl;
    // }else{
    //     cout<<(n*n-1)/4<<endl;
    // }

    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2-y2+y1;
    int y3 = y2+x2-x1;
    int x4 = x3-y3+y2;
    int y4 = y3+x3-x2;
    cout <<x3<<" "<<y3<<" "<<x4<<" "<<y4<<" "<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#define SIZE 200005
#define BT 1005
#define ALP 26

using namespace std;
typedef long long int ll;

char str[SIZE];
int KMP[SIZE];
ll len[BT];
ll cnt[BT][ALP];
ll ans[ALP];
ll query[ALP];

void solve(ll L)//[0,L-1]
{
	int n=strlen(str);
	for(int i=0;i<n;i++)
	{
		if(i==0) KMP[i]=-1;
		else
		{
			KMP[i]=KMP[i-1];
			while(1)
			{
				if(str[KMP[i]+1]==str[i])
				{
					KMP[i]++;
					break;
				}
				if(KMP[i]==-1) break;
				KMP[i]=KMP[KMP[i]];
			}
		}
	}
	int add=KMP[n-1];
	while((add+1)*2>=n) add=KMP[add];
	string T="";
	for(int i=0;i<n-(add+1);i++) T+=str[i];
	for(int i=0;i<T.size();i++)
	{
		if(i==0) KMP[i]=-1;
		else
		{
			KMP[i]=KMP[i-1];
			while(1)
			{
				if(T[KMP[i]+1]==T[i])
				{
					KMP[i]++;
					break;
				}
				if(KMP[i]==-1) break;
				KMP[i]=KMP[KMP[i]];
			}
		}
	}
	add=KMP[T.size()-1];
	while((add+1)*2>T.size()) add=KMP[add];
	add++;
	//printf("%s %d\n",T.c_str(),add);
	int sz=0;
	memset(cnt,0,sizeof(cnt));
	memset(len,0,sizeof(len));
	for(int i=add;i<T.size()-add;i++)
	{
		len[sz]++;
		cnt[sz][T[i]-'a']++;
	}
	sz++;
	for(int i=0;i<add;i++)
	{
		len[sz]++;
		cnt[sz][T[i]-'a']++;
	}
	sz++;
	while(len[sz-1]<=L)
	{
		len[sz]=len[sz-1]+len[sz-2];
		for(int i=0;i<ALP;i++)
		{
			cnt[sz][i]=cnt[sz-1][i]+cnt[sz-2][i];
		}
		//printf("%lld\n",len[sz]);
		sz++;
	}
	memset(query,0,sizeof(query));
	for(int i=sz-1;i>=2;i--)
	{
		if(L>=len[i])
		{
			L-=len[i];
			for(int j=0;j<ALP;j++) query[j]+=cnt[i][j];
		}
	}
	for(int i=0;i<L;i++)
	{
		query[T[i]-'a']++;
	}
}
int main()
{
	scanf("%s",&str);
	ll L,R;
	scanf("%lld %lld",&L,&R);
	solve(R);
	for(int i=0;i<ALP;i++) ans[i]=query[i];
	solve(L-1);
	for(int i=0;i<ALP;i++) ans[i]-=query[i];
	for(int i=0;i<ALP;i++)
	{
		if(i!=0) printf(" ");
		printf("%lld",ans[i]);
	}puts("");
	return 0;
}


Measured memory_bytes: 1856
n = int(input())

# いくつあるかわからないときのスペース区切りの整数の入力
v = input().split()
v = list(map(int,v))

# いくつあるかわからないときのスペース区切りの整数の入力
c = input().split()
c = list(map(int,c))

k = [0] * n

for i in range(0,n):
    k[i] = v[i] - c[i]

#print(k)
k.sort(reverse=True)
#print(k)

for i in range(0,n):
    if k[i] < 0:
        k[i] = 0

print(sum(k))


Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define angle(a) (atan2((a).imag(), (a).real()))
#define vec(a, b) ((b) - (a))
#define length(a) (hypot((a).imag(), (a).real()))
#define dot(a, b) ((conj(a) * (b)).real())
#define cross(a, b) ((conj(a) * (b)).imag())
#define lengthSqr(p) dot(p, p)
#define rotateO(p, ang) ((p) * exp(point(0, ang)))
#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)
#define reflectO(v, m) (conj((v) / (m)) * (m))
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define X() real()
#define Y() imag()
using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
typedef complex<double> point;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
	FAST_IO
	int k, s, count = 0;
	cin >> k >> s;
	for(int x = 0; x <= k; ++x){
		for(int y = 0; y <= k; ++y){
			int z = s - x - y;
			if(z >= 0 && z <= k) count++;
		}
	}
	
	cout << count << "\n";
	
}


Measured memory_bytes: 256
n = int(input())
mod = 10**9+7
L = list(map(int,input().split()))
from collections import Counter
L = Counter(L)
#print(L)
cnt_2 = 0
cnt_0 = 0
else1 = 0
for k,v in L.items():
    if v == 2:
        cnt_2 +=1
    elif k == 0 :
        cnt_0 +=v
    else:
        else1 +=1
#print(cnt_2,cnt_0)
if else1 != 0:
    print(0)
elif n%2 == 1 and cnt_0 == 1:
    print(2**cnt_2%mod)
elif n%2 == 1 and cnt_0 != 1:
    print(0)
elif n%2 == 0 and cnt_0 != 0:
    print(0)
elif n%2 == 0 and cnt_0 == 0:
    print(2**cnt_2%mod)


Measured memory_bytes: 14820
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	bool ok = true;
	int x, y, t;
	int x_now = 0;
	int y_now = 0;
	int t_now = 0;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		int dist = abs(x - x_now) + abs(y - y_now);
		int diff_t = t - t_now;
		if (dist > diff_t || abs(dist - diff_t) % 2 == 1) {
			ok = false;
			break;
		}

		x_now = x;
		y_now = y;
		t_now = t;
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n;
ll dp[maxn] , a[maxn],h[maxn];
void update(int x , ll val)
{
    for( ; x <= n ; x += x & -x)
        dp[x] = max(dp[x],val);
}
ll query(int x)
{
    ll res = 0;
    for( ; x > 0 ; x &= x - 1)
        res = max(res , dp[x]);
    return res;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> h[i];
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n ; ++i)
    {
        update(h[i],query(h[i] - 1)+a[i]);
    }
    cout << query(n);
}


Measured memory_bytes: 4992
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var n int 
  fmt.Scan(&n)
  res := make(map[string]int)
  for i := 0; i < n; i++ {
    var s string 
    fmt.Scan(&s)
    res[s]++
  }
  var m int 
  fmt.Scan(&m)
  for i := 0; i < m; i++ {
    var t string 
    fmt.Scan(&t)
    res[t]--
  }
  ans := 0
  for _, c := range res {
    ans = maxInt(ans, c)
  }
  fmt.Println(ans)
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if (ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for(i = 0; i < strlen(str); i++){
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M - 1));}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i = 0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str)==0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for(i = 0; i<M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", com, str);
        if(com[0] == 'i'){
            insert(str);
        } else {
            if (find(str)){
                printf("yes\n");
            } else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 17076
#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  double E[N];
  double P[N];
  double ans = 0.0;
  double tmp = 0.0;

  for (int i = 0; i < N; i++) {
    cin >> E[i];
    E[i] = (E[i] + 1) / 2;

    tmp += E[i];
    if (i - K >= 0) tmp -= E[i-K];
    
    ans = max(ans, tmp);
  }
       
  cout<<fixed<<setprecision(12)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
string s;
int n,m,a[100005],ok,ans,sum;
int main(){
	in(n);in(m);
    cin>>s;
    if(s[n]=='1'){
        puts("-1");
        return 0;
    }
    sum=n;
    while(1){
        ok=0;
        int tot=max(0,sum-m);
        for(int i=tot;i<sum;i++){
            if(s[i]=='0'){
                a[++ans]=sum-i;
                sum=i;
                ok=1;
                break;
            }
        }
        if(sum==0||ok==0)break;
    }
    if(ok){
		for(int i=ans;i>=1;i--)printf("%d ",a[i]);
		puts("");
	}
    else puts("-1");
    return 0;
}


Measured memory_bytes: 1024
import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


def readList():
    return list(map(int, input().strip().split()))


def solve(s, t):
    M, N = len(s), len(t)
    ans = N

    for i in range(M-N+1):
        curr = N

        for j in range(N):
            if s[i+j] == t[j]:
                curr -= 1

        ans = min(ans, curr)

    return ans


s = read()
t = read()

print(solve(s, t))


Measured memory_bytes: 74284
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	ll z;

	while(cin >> z, z) {
		ll x, y;
		ll min = 1111*1111*1111;
		ll z3 = z*z*z;
	
		for(x = 1; x < z; x++) {
			for(y = 1; y < z; y++) {
				if(x*x*x+y*y*y < z3) {
					if(min > z3-x*x*x-y*y*y) {
						min = z3-x*x*x-y*y*y;
					}
				}
			}
		}

		cout << min << endl;
	}
}

Measured memory_bytes: 1156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))


class BDigitalGifts {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      in >> n;
      vector<pair<double, string>> xu(n);
      REP(i, n) {
        double x;
        string y;
        in >> x >> y;
        xu[i] = pair<double, string>(x, y);
      }

      double ans = 0;
      REP(i, n) {
        ans += xu[i].first * (xu[i].second == "JPY" ? 1 : 380000);
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BDigitalGifts solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())

s=[['#']*(w+2)]
for i in range(h):
    s.append(['#']+list(input())+['#'])
s.append([['#']*(w+2)])

l=[[0]*(w+2) for _ in range(h+2)]
r=[[0]*(w+2) for _ in range(h+2)]
u=[[0]*(w+2) for _ in range(h+2)]
d=[[0]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j]=='.':
            l[i][j]=l[i][j-1]+1
            u[i][j]=u[i-1][j]+1
        if s[i][w+1-j]=='.':
            r[i][w+1-j]=r[i][w+2-j]+1
        if s[h+1-i][j]=='.':
            d[h+1-i][j]=d[h+2-i][j]+1

ans=0
for i in range(1, h+1):  # hはy座標
    for j in range(1, w+1):  # wはx座標
        tmp_ans=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
        ans=max(ans, tmp_ans)
print(ans)


Measured memory_bytes: 314248
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int a, b;
  while(cin >>a >>b && a) cout <<(a % 2 == 1 && b % 2 == 1 ? "no" : "yes") <<endl;
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#define nmax_def 110000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int N, d[nmax_def];
	int Nc, dL, dR;
	int ans;
	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> d[i];
	}
	sort(d, d + N, less<int>());
	Nc = N / 2;
	dL = d[Nc - 1];
	dR = d[Nc];
	ans = dR - dL;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
  cout << std::fixed << std::setprecision(10);
  int n,k;
  cin >> n >> k;
  vdouble p(n+1);
  p[0] = 0;
  erep1(i,n){
    int a;
    cin >> a;
    p[i] = p[i-1] + a;
  }
  double ans = 0;
  for(int i = 0;i < n - (k-1);i++){
    double temp = p[i + k] - p[i];
    ans = max(ans,temp);
  }
  cout << (ans + k)/2 << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int n, a[5] = {0}, count, i;

  count = 0;

  scanf("%d", &n);
  while (n > 0) {
    if (n % 10 == 1) {
      a[count] = 9;
    }
    else if (n % 10 == 9) {
      a[count] = 1;
    }
    count++;
    n = n / 10;
  }

  for (i = count-1; i >= 0; i--) {
    printf("%d", a[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;
string s;

int main(void){
    
    scanf("%d", &N);
    cin >> s;
    
    vector<bool> v(N);
    for(int p = 0; p < 4; ++p){
        
        if(p == 0) v[0] = true, v[1] = true;
        else if(p == 1) v[0] = true, v[1] = false;
        else if(p == 2) v[0] = false, v[1] = true;
        else v[0] = false, v[1] = false;
        
        for(int i = 1; i < N - 1; ++i){
            if(v[i]){
                if(s[i] == 'o') v[i + 1] = (v[i - 1]) ? true : false;
                else v[i + 1] = (v[i - 1]) ? false : true;
            }
            else{
                if(s[i] == 'o') v[i + 1] = (v[i - 1]) ? false : true;
                else v[i + 1] = (v[i - 1]) ? true : false;
            }
        }
        
        bool ans = false;
        if((v[0] && s[0] == 'o' && v[N - 1] && v[1]) || (v[0] && s[0] == 'o' && !v[N - 1] && !v[1])){
            if(v[N - 1] && s[N - 1] == 'o' && v[N - 2] && v[0]) ans = true;
            else if(v[N - 1] && s[N - 1] == 'x' && !v[N - 2] && v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'x' && v[N - 2] && v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'o' && !v[N - 2] && v[0]) ans = true;
        }
        else if((v[0] && s[0] == 'x' && !v[N - 1] && v[1]) || (v[0] && s[0] == 'x' && v[N - 1] && !v[1])){
            if(v[N - 1] && s[N - 1] == 'o' && v[N - 2] && v[0]) ans = true;
            else if(v[N - 1] && s[N - 1] == 'x' && !v[N - 2] && v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'x' && v[N - 2] && v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'o' && !v[N - 2] && v[0]) ans = true;
        }
        else if((!v[0] && s[0] == 'x' && v[N - 1] && v[1]) || (!v[0] && s[0] == 'x' && !v[N - 1] && !v[1])){
            if(v[N - 1] && s[N - 1] == 'o' && !v[N - 2] && !v[0]) ans = true;
            else if(v[N - 1] && s[N - 1] == 'x' && v[N - 2] && !v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'x' && !v[N - 2] && !v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'o' && v[N - 2] && !v[0]) ans = true;
        }
        else if((!v[0] && s[0] == 'o' && !v[N - 1] && v[1]) || (!v[0] && s[0] == 'o' && v[N - 1] && !v[1])){
            if(v[N - 1] && s[N - 1] == 'o' && !v[N - 2] && !v[0]) ans = true;
            else if(v[N - 1] && s[N - 1] == 'x' && v[N - 2] && !v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'x' && !v[N - 2] && !v[0]) ans = true;
            else if(!v[N - 1] && s[N - 1] == 'o' && v[N - 2] && !v[0]) ans = true;
        }
        
        if(ans){
            for(int i = 0; i < N; ++i) printf("%c", (v[i]) ? 'S' : 'W');
            printf("\n");
            return 0;
        }
        
    }
    printf("-1\n");
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
   string n;
   
   cin >> n;
  
    int l = n.size();
  
    int ll = n.size() - 2;
  
  
 
   string str;
   str=n[0];
   string str1;
  
   str1 = n[l-1];
  
   
   
    string str2 = to_string(ll);
  
   cout << str + str2 + str1 << endl;
  

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x;
    cin>>x;
    int y=0;
    if(x%10==1){y++;}
    if((x/10)%10==1) {y++;}
    if((x/100)%10==1){y++;}
  
    cout<<y;
 
    return 0;
}

Measured memory_bytes: 256
def main():
    l = [int(_) for _ in input().split()]
    n = l[0]
    m = l[1]
    x = l[2]
    a = [int(_) for _ in input().split()]

    cost_to_zero = 0
    cost_to_m = 0

    for i in range(len(a)):
        if a[i] > x:
            cost_to_m += 1
        else:
            cost_to_zero += 1

    answer = min([cost_to_zero, cost_to_m])
    print(answer)


if __name__ == "__main__":
    main()


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

int main() {
  int n;
  cin >> n;
  int m=n/2;
  int d[n];
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n);

  cout << d[m]-d[m-1] <<endl;
  return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

using std::cin;
using std::pair;
using std::cout;
using std::endl;
using std::vector;
using std::any_of;
using std::for_each;
using std::min_element;

using star_t = pair<int,int>; // type of star point

bool all_exist(vector<star_t> c1,vector<star_t> c2) {
	for (star_t s1 : c1) {
		if (any_of(c2.begin(),c2.end(),[s1](star_t s2){return s1 == s2;}) == false) {
			return false;
		}
	}
	return true;
}

int main() {
	while (true) {
		int m;
		cin >> m;
		if (m == 0) {
			break;
		}
		vector<star_t> c1(m); // constellation 1
		for_each(c1.begin(),c1.end(),[](star_t &s){cin >> s.first >> s.second;});
		int n;
		cin >> n;
		vector<star_t> c2(n); // constellation 2
		for_each(c2.begin(),c2.end(),[](star_t &s){cin >> s.first >> s.second;});
		// find star which has min x in constellation 1
		auto min_x1 = min_element(c1.begin(),c1.end(),[](star_t s1,star_t s2){return s1.first < s2.first;});
		// find star which has min x in constellation 2
		auto min_x2 = min_element(c2.begin(),c2.end(),[](star_t s1,star_t s2){return s1.first < s2.first;});
		int delta_x = min_x2->first - min_x1->first;
		int delta_y = min_x2->second - min_x1->second;
		for_each(c2.begin(),c2.end(),[delta_x,delta_y](star_t &s){s.first -= delta_x;s.second -= delta_y;});
		while (all_exist(c1,c2) == false) {
			c2.erase(min_x2);
			min_x2 = min_element(c2.begin(),c2.end(),[](star_t s1,star_t s2){return s1.first < s2.first;});
			int sub_delta_x = min_x2->first - min_x1->first;
			int sub_delta_y = min_x2->second - min_x1->second;
			for_each(c2.begin(),c2.end(),[sub_delta_x,sub_delta_y](star_t &s){s.first -= sub_delta_x;s.second -= sub_delta_y;});
			delta_x += sub_delta_x;
			delta_y += sub_delta_y;
		}
		cout << delta_x << " " << delta_y << endl;
	}
}

Measured memory_bytes: 3124
#include <iostream>
 
using namespace std;
 
int main(){
	long long n, m;
	cin >> n >> m;
	long long ans = min(n, m/2);
	n -= ans;
	m -= 2*ans;
	while(m>=4){
		ans++;
		m -= 4;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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



int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<int>> dist(h,vin(w,0));
  vector<string> a(h);
  rep(i,0,h)cin>>a[i];
  queue<pair<int, int>> que;
  rep(i,0,h){
   rep(j,0,w){
     if(a[i][j]=='#'){
      que.push(mp(i,j)); 
     }
   }
  }
  while (que.size() != 0) {              // キューの要素がなくなったら終了
        pair<int, int> now = que.front();  // 現在の状態
        que.pop();
        for (int i = 0; i < 4; i++) {
            int ny = now.first + dy[i];                            // 次の探索場所の行番号
            int nx = now.second + dx[i];                           // 次の探索場所の列番号
            if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;  // 迷路の外に出るならスルー
            if (a[ny][nx] == '#') continue;                     // 障害物があればスルー
            if (dist[ny][nx] != 0) continue;                     //探索済みならスルー
            que.push(make_pair(ny, nx));
            dist[ny][nx] = dist[now.first][now.second] + 1;
        }
    }
  
  int ans=0;
  rep(i,0,h){
   rep(j,0,w){
     chmax(ans,dist[i][j]);
   }
  }
  cout<<ans<<endl;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	vector<ll> a[26];
	ll n=s.length();
	ll m=t.length();
	for(ll i=0;i<n;i++)
	{
		a[s[i]-'a'].push_back(i+1);
	}
	ll ans=0;
	ll Ans=0;
	bool flg=true;
	for(ll i=0;i<m;)
	{
		ll idx = lower_bound(a[t[i]-'a'].begin(),a[t[i]-'a'].end(),Ans)-a[t[i]-'a'].begin();
		//cout<<a[t[i]-'a']<<endl;
		if (idx<a[t[i]-'a'].size() and idx>=0) 
		{
			Ans=a[t[i]-'a'][idx];
			//cout<<Ans<<" ";
			i++;
			if (i<m and i>=0 and t[i]==t[i-1])
				Ans++;
		}
		else
		{
			if (Ans==0)
			{
				flg=false;
				break;
			}
			else
			{
				Ans=0;
				ans+=n;
			}
		}

	}
	if (flg)
	cout<<ans+Ans;
	else
	cout<<-1;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

vec yakusu(int N){
    vec y(0);
    for(int i = 1; i * i <= N; i++) if(N % i == 0) y.push_back(i);
    vec y2 = y;
    IREP(i, y.size()) if(y[i] * y[i] < N) y2.push_back(N / y[i]);
    return y2;
}

signed main(){

    int S; cin >> S;
    vec y = yakusu(S);
    int mod = 1000000007;

    int ans1 = 0, ans2 = 0, ans3 = 0;

    //f(l)=f(r)の場合
    for(int t: y){
        int fl = S / t;
        // t <= 9*10^(fl-1)なら足す
        if(fl >= 9 || t <= 9 * fastpow(10, fl - 1, INF)){
            ans1 += 9 * fastpow(10, fl - 1, mod) - t + 1 + mod;
            ans1 %= mod;
        }
    }
    //cout << ans1 << endl;

    //f(l)<f(r)<=8の場合
    //l<10^7まで
    vec pow10(10, 1);
    FOR(i, 1, 10) pow10[i] = 10 * pow10[i - 1];
    int l = 1, r = 1, s = 1;
    int fl = 1, fr = 1;
    while(l < pow10[7] && r < pow10[8] && l <= r){
        while(s < S && r < pow10[8]){
            r += 1;
            fr = Upper_bound(pow10, r);
            s += fr;
        }
        if(s == S && fl != fr && r < pow10[8]){
            ans2 = (ans2 + 1) % mod;
        }
        s -= fl;
        l += 1;
        fl = Upper_bound(pow10, l);
    }
    //cout << ans2 << endl;

    //f(l)>=8 f(r)=f(l)+1
    //f(l)=8なるlは9*10^7個だから足りなくなることはない
    int tmax = S / 8;
    ans3 = tmax;
    for(int d: y) if(d <= tmax) ans3--;
    //cout << ans3 << endl;

    int ans = (ans1 + ans2 + ans3) % mod;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  set<int64_t> st;
  for (int i = 0; i < n; ++i)
  {
    int64_t tmp;
    cin>>tmp;
    a[i]=tmp-i-1;
  }
  vector<int64_t> b;
  sort(a.begin(), a.end());
  if(a.size()%2!=0){
    b.emplace_back(a[(a.size()-1)/2]);
  }
  else{
    b.emplace_back(a[a.size()/2]);
    b.emplace_back(a[a.size()/2-1]);
    b.emplace_back((a[a.size()/2]+a[a.size()/2-1])/2);
    b.emplace_back((a[a.size()/2]+a[a.size()/2-1])/2+1); 
  }
  vector<int64_t> ans; 
  for(auto&& e: b) {
    int64_t tmp=0;
    for(auto&& f: a) {
      tmp+=abs(f-e);
    }
    ans.emplace_back(tmp);
  }
  cout<<*min_element(ans.begin(), ans.end());
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

	cout << ceil(n / 2.0) << endl;

	return 0;
}

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

using namespace std;

int main(int argc, char* argv[]){
	vector<string> result;
	double x1,y1,x2,y2,x3,y3,x4,y4;
	int N = 0;
	cin >> N;
	for (int i=0; i<N; ++i){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		double inc1,inc2;
		inc1 = (y1 - y2) / (x1 - x2);
		inc2 = (y3 - y4) / (x3 - x4);
		if (inc1 == inc2){
			result.push_back("YES");
		}
		else{
			result.push_back("NO");
		}
	}
	vector<string>::iterator it = result.begin();
	while (it != result.end()){
		cout << *it << endl;
		++it;
	}
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x=a+b;
    int y=a-b;
    int z=a*b;
    if(x>=y && x>=z){
        cout<<x;
    }
    else if(y>=z && y>=x){
        cout<<y;
    }
    else if(z>=x && z>=y){
        cout<<z;
    }
}


Measured memory_bytes: 256
#include<cstdio>
int n,m,vis[100005],f[100005];
int main()
{
	scanf("%d%d",&n,&m);
	f[0]=1;
	for (int i=1;i<=m;i++)
	{
		int x;
		scanf("%d",&x);
		vis[x]=1;
	}
	if (!vis[1]) f[1]=1;
	for (int i=2;i<=n;i++) if (!vis[i]) f[i]=(f[i-1]+f[i-2])%1000000007;
	printf("%d\n",f[n]);
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int first = 0, second = 0, fi = -1;
    rep(i, n) {
        if (a[i] > first) {
            second = first;
            first = a[i];
            fi = i;
        }
        else if (a[i] > second) second = a[i];
    }
    rep(i, n) {
        cout << (i!=fi?first:second) << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
open System
open System.Linq;


let N=stdin.ReadLine()|>int
let L=stdin.ReadLine().Split()|>Array.map int |> Array.sort
[<EntryPoint>]
let sf argv =
    let mutable ans = 0
    for i in [0..N-3] do 
        for j in [i+1..N-2] do
            let sum =L.[i]+L.[j]
            let mutable l = -1
            let mutable r = N
            while r - l > 1 do
                let c=(l+r)/2
                match L.[c] < sum with
                | true -> l<-c
                | false -> r<-c
            ans <- ans + max 0 l-j
    printfn "%d" ans
    0 

Measured memory_bytes: 22560