akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll N;cin >> N;
    vector<ll> csum(N);
    for(int i=0;i<N;i++) cin >> csum[i];
    /* 
    multiset<ll> mse;
    set<ll> se;
    mse.insert(0);
    se.insert(0);
    mse.insert(csum[0]);
    se.insert(csum[0]);
    */
   map<ll,ll> ma;
   ma[0]++;
   ma[csum[0]]++;
    for(int i=1;i<N;i++){
        csum[i]+=csum[i-1];
        //mse.insert(csum[i]);
        //se.insert(csum[i]);
        ma[csum[i]]++;
    }
    ll ans=0;
    for(auto e : ma){
        ll tmp=e.second;
        ans+=tmp*(tmp-1)/2;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	if(b%a==0)cout<<a+b;
	else cout<<b-a;
	
	return 0;
}

Measured memory_bytes: 3572
N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N

first = sorted(A)[-1]
second = sorted(A)[-2]

for i in range(N):
    if A[i]==first:
        ans[i] = second
    else:
        ans[i] = first

print(*ans, sep="\n")

Measured memory_bytes: 70332
#include <stdio.h>

int main(){
	int a, b, c, d, e, f;
	float det;
	float inv_mat[2][2];
	float x, y;

	while( scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF ){
		/*Calc Inverse Matrix*/
		det = a*e - b*d;
		inv_mat[0][0] = e/det;
		inv_mat[1][1] = a/det;
		inv_mat[0][1] = -b/det;
		inv_mat[1][0] = -d/det;
		/*Calc Answer x, y*/
		x = inv_mat[0][0]*c + inv_mat[0][1]*f;
		y = inv_mat[1][0]*c + inv_mat[1][1]*f;
		/*Output*/
		printf("%.3f %.3f\n", x, y);
	}

	return 0;
}

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

int main(){
    int N, a = 0;
    bool ans = false;
    cin >> N;
    if(N > 3){
        for(int i=0; i <= N/4; i++){
            for(int j=0; j <= N/7; j++){
                a = 4*i + 7*j;
              if(a == N) ans = true; 
            }
        }
    }
    cout << (ans ? "Yes": "No") << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    string s;
    cin>>n>>s;
    int len=s.size();
    if(len%2==1) cout<<"No";
    else{
        rep(i,len/2){
            if(s[i]!=s[i+len/2]){
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
    }
}

Measured memory_bytes: 3604
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++ i) {
        if(i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}



int main(void) {
	string s;
	int a, i, j, k, tmp;

	scanf("%d", &a);
	cin >> s;
	if (a >= 3200) {
		cout << s;
	}
	else {
		printf("red\n");
	}


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n, cnt=1;
  	scanf("%d",&n);
  	char s[n];
  	scanf("%s",s);
  	for(int i=1; i<n; i++){
		if(s[i] != s[i-1]) cnt++;
    }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
#define P 1000000007
ll fact[200010];

ll choose(n,r){
	return fact[n]*invp(fact[r]*fact[n-r],P)%P;
}

int main(){
	int h,w,a,b;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	fact[0]=1;
	rep(i,1,200005)fact[i]=fact[i-1]*i%P;
	ll x=b-1,y=h-a;
	ll ans=0;
	while(x<w-1&&y>0){
		x++,y--;
		ans=(ans+choose(x+y,y)*choose((w-1-x)+(h-1-y),(h-1-y)))%P;
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

Measured memory_bytes: 3592
x,y,a,b,c = gets.chomp.split(' ').map(&:to_i)
pa = gets.chomp.split(' ').map(&:to_i).sort
qb = gets.chomp.split(' ').map(&:to_i).sort
rc = gets.chomp.split(' ').map(&:to_i).sort

pa = pa[(-x)..]
qb = qb[(-y)..]
ary = pa + qb + rc
ary = ary.sort
ans = 0
(x+y).times do 
    ans += ary.pop
end
puts ans

Measured memory_bytes: 35208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
ll gcd(ll x, ll y)
{
    if (y==0) return x;
    return gcd(y, x%y);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>> n;
    ll ary[n];
    rep(i,n) cin >> ary[i];

    ll lruiseki[n];
    ll rruiseki[n];

    lruiseki[0] = ary[0];
    rruiseki[n-1] = ary[n-1];
    REP(i,1,n)
    {
        lruiseki[i] = gcd(lruiseki[i-1], ary[i]);
    }
    for (int i=n-2;i>=0;i--)
    {
        rruiseki[i] = gcd(rruiseki[i+1], ary[i]);
    }

    ll ans = 0;
    rep(i,n)
    {
        if (i==0)
        {
            ans = max(ans, rruiseki[1]);
        }
        else if (i==n-1)
        {
            ans = max(ans, lruiseki[n-2]);
        }
        else
        {
            ans = max(gcd(lruiseki[i-1], rruiseki[i+1]), ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll dp[N];
int h[N];
int main(){
    int n,k;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",h+i);
    memset(dp,0x3f,sizeof(dp));
    dp[1]=0;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=1){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n];
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

void replace(string *field, char c, int sx, int sy, int w, int h)
{
    static const int dx[] = {-1,  0, 0, 1};
    static const int dy[] = { 0, -1, 1, 0};

    field[sy][sx] = '.';
    for (int i = 0; i < 4; i++) {
        if (((sx + dx[i] >= 0) && (sx + dx[i] < w)) &&
                ((sy + dy[i] >= 0) && (sy + dy[i] < h))) {
            if (field[sy + dy[i]][sx + dx[i]] == c) {
                replace(field, c, sx + dx[i], sy + dy[i], w, h);
            }
        }
    }
}


int main(int argc, char **argv)
{
    int w, h;
    string field[100];

    cin >> h >> w;
    while ((w != 0) && (h != 0)) {
        int num = 0;

        for (int i = 0; i < h; i++) {
            cin >> field[i];
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (field[i][j] != '.') {
                    num++;
                    replace(field, field[i][j], j, i, w, h);
                }
            }
        }
        cout << num << endl;
        cin >> h >> w;
    }

    return 0;
}

Measured memory_bytes: 2320
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define debug(x) cerr<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
ll power(ll x,ll y,ll z) {
	ll ret = 1;
	while(y > 0) {
		if(y & 1) ret = (ret*x)%z;
		x = (x*x)%z;
		y >>= 1;
	}
	return ret;
}
const ll N = 17, inf = 1e15;
ll dp[1<<N], A[N][N], best[1<<N];
int main() {
	
	ll n;
	sll(n);
	REP(i,1,n) REP(j,1,n) sll(A[i][j]);
	ll mx = 1<<n;
	REP(mask,0,mx - 1) {
		vector<ll> idx;
		REP(i,0,n - 1) {
			if(mask & (1 << i)) idx.pb(i + 1);
		}
		ll sz = idx.size();
		for(ll i = 0;i < sz;++i) {
			ll x = idx[i];
			for(ll j = i;j < sz;++j) {
				ll y = idx[j];
				best[mask] += A[x][y];
			}
		}
	}
	REP(mask,0,mx - 1) {
		for(ll submask = mask;submask > 0;submask = (submask - 1)&mask) {
			dp[mask] = max(dp[mask], best[submask] + dp[mask^submask]);
		}
	}
	printf("%lld\n",dp[mx - 1]);

	

	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {

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

        int ans = Integer.MAX_VALUE;
        for (int i = 1; i < n; i++) {
            int tmpA = i;
            int tmpB = n - tmpA;

            int tmpSum = digitsSum(tmpA) + digitsSum(tmpB);
            if (ans > tmpSum) ans = tmpSum;
        }

        System.out.println(ans);
    }

    private static int digitsSum(int num) {
        int ans = 0;
        while (num > 0) {
            ans = ans + (num % 10);
            num /= 10;
        }

        return ans;
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
const int N=100010;
int n,k;
LL ans;
//vector<int>e[N];
int Write[20],WRI;
void judge(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int read(){int d=0,f=1; char c=getchar(); while (c<'0'||c>'9'){if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') d=d*10+c-48,c=getchar(); return d*f;}
void write(int x){if (!x){putchar('0'); return;}if (x<0) putchar('-'),x=-x;for (WRI=1;x;x/=10,WRI++) Write[WRI]=x%10;for (int i=WRI-1;i;i--) putchar((char)(Write[i]+48));}
int main()
{
	//judge();
	n=read(); k=read();
	for (int b=k+1;b<=n;b++)
	{
		//ans+=n/b*(n-k+1);
		ans+=n/b*(b-k);
		if (n%b>=k)
			if (k>0) ans+=n%b-k+1;
			else ans+=n%b-k;
		//ans+=(n-k-1)/b+1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <ctime>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long ll;

int mod = 1000000007;

char a[2010][2010];
int v[2010][2010];
int e[2010][2010], ec[2010][2010], er[2010][2010];

int main() {
    ios::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    forn (i, n) {
        cin >> a[i];
        forn (j, m) {
            a[i][j] -= '0';
        }
    }
    forn (i, n) {
        forn (j, m) {
            v[i + 1][j + 1] = v[i + 1][j] + v[i][j + 1] - v[i][j] + a[i][j];
            e[i + 1][j + 1] = e[i + 1][j] + e[i][j + 1] - e[i][j] + (i && a[i][j] && a[i - 1][j])
                                                                  + (j && a[i][j] && a[i][j - 1]);
            er[i][j + 1] += er[i][j] + (i && a[i][j] && a[i - 1][j]);
            ec[i + 1][j] += ec[i][j] + (j && a[i][j] && a[i][j - 1]);
        }
    }
    forn (i, q) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        --x1;
        --y1;
        int ans = v[x2][y2] - v[x1][y2] - v[x2][y1] + v[x1][y1] - 
                 (e[x2][y2] - e[x1][y2] - e[x2][y1] + e[x1][y1]);
        cout << ans + (er[x1][y2] - er[x1][y1]) + (ec[x2][y1] - ec[x1][y1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 68864
#include<bits/stdc++.h>
using namespace std;
int n,m,a[210000],l[210000],t[210000],ans,cnt[210000],x,y;
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		l[i] = i - cnt[i] + 1;
		int ii = i;
		for (int j = max(1,l[i]); j <= i; j++) {
			t[j]++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (t[i] == 0) ans++;
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &x, &y);
		if (l[a[x]] > 0) {
	 		t[l[a[x]]]--;
			if (t[l[a[x]]] == 0) ans++;
		}
		l[a[x]]++;
		a[x] = y;
		l[y]--;
		if (l[y] > 0) {
			t[l[y]]++;
			if (t[l[y]] == 1) ans--;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4608
#include <stdio.h>
int main(void) {
int A,B,C,K;
scanf("%d%d%d%d",&A,&B,&C,&K);
if(K<=A){
printf("%d\n",K);
}else if(A<K&&K<=A+B){
printf("%d\n",A);
}else{
printf("%d\n",A-(K-(A+B)));
}
return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define mx 405
using namespace std;

int h, w, dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
bool used[mx][mx], sp[mx][mx];
string s[mx];
long long ans;

int main(){
	scanf("%d%d", &h, &w);
	for(int i = 0; i < h; i++){
		cin >> s[i];
		for(int j = 0; j < w; j++) sp[i][j] = ((s[i][j] == '#') + i + j)&1;
	}

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(used[i][j]) continue;
			used[i][j] = true;
			long long cnt = 1;
			long long cn = (s[i][j] == '#');
			stack< pair<int, int> > st;
			st.push(make_pair(i, j));
			while(!st.empty()){
				auto stt = st.top();
				st.pop();
				for(int k = 0; k < 4; k++){
					int di = stt.first + dx[k], dj = stt.second + dy[k];
					if(0 <= di && di < h && 0 <= dj && dj < w && !used[di][dj] && (sp[i][j] == sp[di][dj])){
						used[di][dj] = true;
						st.push(make_pair(di, dj));
						cnt++;
						if(s[di][dj] == '#') cn++;
					}
				}
			}
			ans += (cnt-cn)*cn;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
	double n,a;
	int i;
	while(scanf("%lf",&n)!=EOF)
	{
		a=n;
		for(i=2;i<11;i++)
		{
			if(i%2==0)
				n*=2;
			else
				n/=3;
			a+=n;
		}
		printf("%f\n",a);
	}
	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i,su=0;
    cin>>s;
    for(i=1;i<4;i++)
    {
        if(s[i]==s[i-1]&&s[i]==s[1])
            su++;
    }
    cout<<(su>=2?"Yes":"No")<<endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main()
{
	char S[100001];
	scanf("%s", S);
	
	int i, j, count[100001] = {}, sink = -1;
	for (i = 0; S[i] != 0; i++) {
		if (S[i] == 'L') count[sink + ((i - sink) % 2)]++;
		else {
			for (j = i; S[j+1] == 'R'; j++);
			count[j] += (j - i) / 2 + 1;
			count[j+1] += (j - i + 1) / 2;
			sink = j;
			i = j;
		}
	}
	
	for (i = 0; S[i] != 0; i++) printf("%d ", count[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,T;
  cin >> n >> T;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  vector<ll> b,d;
  ll sum=0;
  REP(i,n/2,n) sum+=a[i];
  b.pb(0);
  d.pb(sum);
  rep(k,n/2-(n%2==0)) {
    ll x=a[k*2+(n%2==0)];
    ll y=a[n/2+k];
    sum-=y;
    sum+=x;
    b.pb((y+x)/2+1);
    d.pb(sum);
  }
  while(T--) {
    ll x;
    R x;
    ll k=upper_bound(all(b),x)-b.begin();
    pr(d[k-1]);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3444
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let a=tn()+tn()+tn()
  to(a>=22?'bust':'win')
}
main()

Measured memory_bytes: 11468
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

map<int, int> mp;

ll fac(ll a) {
	ll cnt = 0,mem=0;
	bool flag = true;
	for (int i = 2; i <= a; i++) {
		flag = true;
		if (a%i == 0) {
			for (int j = 2; j <= sqrt(i); j++) {
				if (i%j == 0) flag = false;
			}

			if (flag) {
				mem = 0;
				while (a%i == 0) {
					a /= i;
					mem++;
				}
				mp[i] += mem;
			}
		}
	}
	return cnt;
}

int main() {
	ll n,cnt=0;
	ll nfact = 1;
	cin >> n;
	REP(i,2,n+1){
		fac(i);
	}

	for (const auto& x : mp) {
		nfact *= (x.second + 1);
		nfact %= NUM;
	}
	cout << nfact%NUM << "\n";
}



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

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            cin = new CommonInput();

            int x, y, s, yTotal;
            int xPrice1, xPrice2, tmpTotal;

            while (true)
            {
                xPrice1 = xPrice2 = yTotal = tmpTotal = 0;

                x = cin.GetNextToInt();
                y = cin.GetNextToInt();
                s = cin.GetNextToInt();

                if (x == 0 && y == 0 && s == 0)
                    break;

                for (int i = 1; i <= s / 2; i++)
                {
                    xPrice1 = i * (100 + x) / 100;

                    int j = i - 1;
                    do
                    {
                        j++;
                        xPrice2 = j * (100 + x) / 100;
                    } while (xPrice1 + xPrice2 < s + 1 && xPrice1 + xPrice2 != s);

                    tmpTotal = i * (100 + y) / 100 + j * (100 + y) / 100;

                    if (xPrice1 + xPrice2 == s && yTotal < tmpTotal)
                    {
                        yTotal = tmpTotal;
                    }
                }

                Console.WriteLine(yTotal);
            }
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 9116
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a<10 && b<10) cout << a*b << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	input := bufio.NewReader(os.Stdin)

	var k, x int
	fmt.Fscanf(input, "%d %d\n", &k, &x)
	minX := x - (k - 1)
	maxX := x + (k - 1)
	minX = max(minX, -1000000)
	maxX = min(maxX, 1000000)
	for i := minX; i < maxX; i++ {
		fmt.Printf("%d ", i)
	}
	fmt.Printf("%d", maxX)
}


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

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

    int M;
    cin >> M;
  	int S[M][2];
    for(int i = 0; i < M; i++){
        for(int j = 0; j < 2; j++){
            cin >> S[i][j];
        }
    }

    int A;
  	int B;
    for(int i = 0; i < M; i++){
        A = S[i][0];
        B = T[A-1] - S[i][1];
        cout << sum - B << endl;
    }
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]), a[i]--;

	int ans=0;
	rep(i,n) if(a[a[i]]==i) ans++;
	printf("%d\n",ans/2);

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    string n;
    cin>>n;
    string rn = n;
    reverse(n.begin(),n.end());
    string ans="No";
    if(n==rn)ans="Yes";
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();
    let y: i64 = input();

    let mut ans = (-1, -1, -1);
    for i in 0..n + 1 {
        for j in 0..n - i + 1 {
            if y == 10000 * i + 5000 * j + 1000 * (n - i - j) {
                ans = (i, j, n - i - j);
            }
        }
    }

    println!("{} {} {}", ans.0, ans.1, ans.2);
}


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

using namespace std;

int main(){
	int x;
	int y;
	cin >> x >> y;

	int tmp = x;

	if(y == 1){
		cout << 0;
		return 0;
	}
	
	int ans = 1;

	while(tmp < y){
		tmp--;
		tmp += x;
		ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1e9;


int main(void) {
    int n, i, j;
    string s;

    cin >> s;

    n = s.size();

    for (i = (n - 1) / 2; i > 0; i--) {
        for (j = 0; j < i; j++) {
            if (s[j] != s[i + j]) break;
        }
        if (j == i) {
            printf("%d\n", i * 2);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,K;
	char s[100];
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
		if(i==K-1)
		{
			if(s[i]>='A'&&s[i]<='Z')
			{
				s[i]=s[i]-'A'+'a';
			}
			else if(s[i]>='a'&&s[i]<='z')
			{
				s[i]=s[i]-'a'+'A';
			}
		}
	}	
	for(int i=0;i<N;i++)
	{
		cout<<s[i];
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
int MOD=1e9+7;
using namespace std;
int main(){
    int n;
    cin >> n;
    bool h=true;
    for(int i=0;i<n;i++){
        int x;
        cin>> x;
        if(x%2==1){
            h=false;
            break;
        }
    }
    if(h){
        cout<<"second"<<endl;
    }else{
        cout<<"first"<<endl;
    }
}


Measured memory_bytes: 256
# D - AtCoder Express 2 
import sys

N, M, Q = map(int, sys.stdin.readline().strip().split())

cusum = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, sys.stdin.readline().strip().split())
    cusum[L][R] += 1

# 累積和の計算
for i in range(N):
    for j in range(N):
        cusum[i + 1][j + 1] += cusum[i + 1][j] + cusum[i][j + 1] - cusum[i][j]


for _ in range(Q):
    p, q = map(int, sys.stdin.readline().strip().split())  # p <= q

    ans = cusum[q][q] - cusum[q][p - 1] - cusum[p - 1][q] + cusum[p- 1][p - 1]
    print(ans)


Measured memory_bytes: 18836
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int x = scanner.nextInt();

		double tan;

		if (x >= a * a * b / 2) {
			tan = (double) 2 * (a * a * b - x) / a / a / a;
		} else {
			tan = (double) a * b * b / 2 / x;
		}
		System.out.println(Math.atan(tan) * 180 / Math.PI);
	}
}

Measured memory_bytes: 23892
fun main(args: Array<String>) {
    val s= readLine()!!
    val b =
            s.first()=='A' &&
            s.drop(2).dropLast(1).count{ it=='C' }==1 &&
            s.count{ it.isUpperCase() }==2
    println(if(b) "AC" else "WA")
}

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

// i > 0
int parent(int i) { return ((i + 1) / 2) - 1; }

int left(int i) { return 2 * (i + 1) - 1; }

int right(int i) { return 2 * (i + 1); }

int n;

void percolate(vector<int> &v, int i) {
  if (i >= n)
    return;

  int max_ch = -1;
  if (left(i) < n and v[left(i)] > v[i])
    max_ch = left(i);
  if (right(i) < n and v[right(i)] > v[i]) {
    if (max_ch == -1 or v[right(i)] > v[left(i)])
      max_ch = right(i);
  }
  if (max_ch != -1) {
    swap(v[i], v[max_ch]);
    percolate(v, max_ch);
  }
}

int main() {
  cin >> n;
  vector<int> v;
  int val;
  while (cin >> val)
    v.push_back(val);

  for (int i = n / 2; i >= 0; --i) {
    percolate(v, i);
  }

  for (int i = 0; i < v.size(); ++i) {
    cout << " " << v[i];
  }
  cout << endl;
}


Measured memory_bytes: 4724
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;

    if (s.size() < 26)
    {
        vector<bool> used(26, false);
        rep(i, 0, s.size()) used[s[i] - 'a'] = true;

        char append_char;
        rep(i, 0, 26)
        if (not used[i])
        {
            append_char = 'a' + i;
            break;
        }
        
        cout << s << append_char << endl;
        return 0;
    }
    else
    {
        vector<bool> available(26, false);
        rrep(i, 26, 0)
        {
            rep(j, 0, 26)
            if (available[j] and s[i] < j + 'a')
            {
                cout << s.substr(0, i) << char(j + 'a') << endl;
                // cout << "abcdefghijklmnopqrstuvx" << endl;
                return 0;
            }
            available[s[i] - 'a'] = true;
        }
    }
    
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
n = input()
n = n[::-1]
kuriage = 0
sum = 0
for i in range(len(n)):
  intI = int(n[i]) + kuriage
  if intI < 5:
    kuriage = 0
    sum += intI
  elif intI > 5:
    kuriage = 1
    sum += (10 - intI)
  else: # intI == 5
    if len(n) != i+1 and int(n[i+1]) >= 5:
      kuriage = 1
      sum += (10 - intI)
    else:
      kuriage = 0
      sum += intI  
print(sum + kuriage)  

Measured memory_bytes: 5492
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<vector>
#include<cstddef>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

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

i64 n;
cin >> n;
vector<i64> a(n);
i64 sum_A = 0,sum_B = 0;
rep(i,n){
    cin >> a[i];
}
sort(rall(a));
rep(i,n){
    if(i % 2 == 0)sum_A += a[i];
    else sum_B += a[i];
}
cout << sum_A - sum_B << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int r[10];
int n, m, q;
int qq[55][4];
ll ans(0);

void go(int idx, int cnt) {
    if (idx == n) {
        ll t(0);
        int i;
        rep(i, q) {
            if (r[qq[i][1]-1]-r[qq[i][0]-1]==qq[i][2]) {
                t += qq[i][3];
            }
        }
        ans = max(ans, t);
        return;
    }
    int i;
    xrep(i, cnt, m + 1) {
        r[idx] = i;
        go(idx+1, i);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> m >> q;
    int i;
    rep(i, q) {
        int j;
        rep(j, 4) cin >> qq[i][j];
    }
    go(0, 1);
    cout << ans << endl;
}


Measured memory_bytes: 3656
import sys

input = sys.stdin.readline

def main():
  x, y = map(int, input().rstrip().split())
  
  for i in range(x + 1):
    if y == (2 * i) + (4 * (x - i)):
      print("Yes")
      sys.exit()
  print("No")
  
if __name__ == "__main__":
  main()

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
#define M map
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    string s; cin >> s;
    string t; cin >> t;

    int n = t.size();
    if(s + t[n - 1] == t) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 
int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n, x, t; cin >> n >> x >> t;
  cout << ((n+x-1)/x)*t << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
const int N=2e5+5;
int a[N],i,n,q;
ll ans;
map<int,int>cnt;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        ans+=a[i];
        cnt[a[i]]++;
    }
    //cout<<ans<<'\n';
    cin>>q;
    for(i=1;i<=q;i++){
        int x,y;
        cin>>x>>y;
        ans+=(y-x)*cnt[x];
        cnt[y]+=cnt[x];
        cnt[x]=0;
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 8372
#include <cstdio>
#include <utility>
#include <vector>
#include <stack>

using namespace std;

void count(stack<int> *s) {
    int find;
    int times = 0;

    if (s->empty()) return;

    find = s->top();

    while (!s->empty() && find == s->top()) {
        times++;
        s->pop();
    }

    if (times >= 4) return;

    for(;times;times--) s->push(find);
} 

int main() {
    while (1) {
        int i;
        int n;
        vector<int> characters;
        vector<pair<int, int> > var;
        int d[4];
        int save;
        int min_size;

        scanf("%d", &n);
        if (n == 0) return 0;

        min_size = n;

        for (i=0;i<4;i++) d[i] = -1-i;

        for (i=0;i<n;i++) {
            int j;
            int k;

            scanf("%d", &k);
            k--;

            characters.push_back(k);

            for (j=0;j<3;j++) {
                d[j] = d[j+1];
            }

            d[3] = k;

            if (d[0] == d[1] && d[1] == d[2]) {
                if (var.empty() || var.back() != make_pair(i, d[0]))
                    var.push_back(make_pair(i, d[0]));
            }

            if (d[0] == d[1] && d[1] == d[3]) {
                if (var.empty() || var.back() != make_pair(i-1, d[1]))
                    var.push_back(make_pair(i-1, d[1]));
            }

            if (d[0] == d[2] && d[2] == d[3]) {
                if (var.empty() || var.back() != make_pair(i-2, d[2]))
                    var.push_back(make_pair(i-2, d[2]));
            }

            if (d[1] == d[2] && d[2] == d[3]) {
                if (var.empty() || var.back() != make_pair(i-3, d[3]))
                    var.push_back(make_pair(i-3, d[3]));
            }
        }

        for (i=0;i<var.size();i++) {
            int j;
            stack<int> process;
            int now_color = -1;

            save = characters[var[i].first];
            characters[var[i].first] = var[i].second;

            for (j=0;j<characters.size();j++) {
                if (characters[j] != now_color) {
                    count(&process);
                    now_color = characters[j];
                }

                process.push(characters[j]);
            }

            count(&process);

            if (min_size > process.size()) min_size = process.size();
            characters[var[i].first] = save;
        }

        printf("%d\n", min_size);
    }
}

Measured memory_bytes: 1176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	int n,k;
	cin>>n>>k;
	vector<int>l;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		l.push_back(tmp);
	}
	sort(l.begin(),l.end(),greater<int>());
	int ans=0;
	for(int i=0;i<k;i++)
		ans+=l[i];

	cout<<ans<<endl;
	return 0;
	

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int left,right,mid,n1,n2,a[100000],b[100000],i,cnt=0;
  scanf("%d",&n1);
  for(i=0;i<n1;i++)
    {
      scanf("%d",&a[i]);
    }
  scanf("%d",&n2);
  for(i=0;i<n2;i++)
    {
      scanf("%d",&b[i]);
    }
  for(i=0;i<n2;i++)
    {
      left=0;
      right=n1;
      while(left<right)
	{
	  mid = (left+right)/2;
	  if(a[mid]==b[i])
	    {
	      cnt++;
	      break;
	    }
	  else if(b[i]<a[mid])
	    {
	      right = mid;
	    }
	  else left = mid+1;
	}
    }
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2376
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
	n <- readLn
	xs <- sort . map strToInt . words <$> getLine
	putStrLn . show $ (xs!!(n-1) - xs!!0)


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n, wt;
  cin>>n>>wt;
  vector<ll>w(n), v(n), knap(wt+1, 0);
  for(ll i=0;i<n;i++)	cin>>w[i]>>v[i];
  for(ll i=0;i<n;i++)
  {
    for(ll j=wt;j>=0;j--)
    {
      if(j>=w[i])
      {
        knap[j] = max(knap[j - w[i]] + v[i], knap[j]); 
      }
      //cout<<knap[j]<<" ";
    }
    //cout<<"\n";
  }
  cout<<knap[wt];
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, l = 0, r = 200005;
    ll m, b[100005] = {}, z = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i - 1];
    while (l + 1 < r) {
        int o = (l + r) / 2;
        ll c = 0;
        for (int i = 0; i < n; i++) {
            c += n - (int)(lower_bound(a, a + n, o - a[i]) - a);
        }
        //cout << o << ' ' << c << '\n';
        if (c >= m) l = o;
        else r = o;
    }
    ll c = 0;
    for (int i = 0; i < n; i++) {
        int d = (int)(lower_bound(a, a + n, l - a[i]) - a);
        c += n - d;
        z += b[n] - b[d] + 1ll * a[i] * (n - d);
    }
    cout << z - l * (c - m);
}


Measured memory_bytes: 4800
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
const int N = 3005;
lli dp[N][N];
lli nums[N];
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> nums[i];
	
	for(int l = n; l >= 1; l--) {
		dp[l][l] = nums[l];
		for(int r = l+1; r <= n; r++)
			dp[l][r] = max(nums[l] - dp[l+1][r], nums[r] - dp[l][r-1]);
	}
	cout << dp[1][n] << "\n";
	return 0;
}

Measured memory_bytes: 70016
#include<stdio.h>
int main()
{
	int N;
	scanf ("%d", &N);
		if (N%10==7)
		{
			printf("Yes");
		}else if (N/10 ==17 || N/10 ==27 || N/10 ==37 || N/10 ==47 || N/10 ==57 || N/10 ==67 || N/10 ==77 || N/10 ==87 || N/10 ==97)
		{
			printf("Yes");
		}else if(N/100 ==7)
		{
			printf("Yes");
		}else 
		{
			printf("No");
		}
	
	return 0;
}

Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,AB,BC,CA,ans;
  cin >>A>>B>>C;
  AB = abs(A-B);
  BC = abs(B-C);
  CA = abs(C-A);
  if(AB >= BC && AB >= CA){ans = BC + CA;}
  if(BC >= CA && BC > AB){ans = AB + CA;}
  if(CA > AB && CA > BC){ans = AB + BC;}
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
int main()
{
    int N,K;
    cin >> N >> K;
    vector<ll> H(N);
    REP(i,N)cin >> H[i];
    sort(H.begin(),H.end(),greater<ll>());
    ll count = 0;
    REP(i,N){
        if(i>=K)count += H[i];
    }
    cout << count << endl;
    return 0;
}

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

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

  return 0;
}


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

int main() {
    bool flag = false;
    std::string str;
    std::cin >> str;
    for(int i = 0;i < 3;i++){
        if(str.at(i) == '7'){
            flag = true;
            std::cout << "Yes" << std::endl;
            break;
        }
    }
    if(!flag){
        std::cout << "No" << std::endl;
    }

}


Measured memory_bytes: 3628