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

int main(){
    string w;
    cin >> w;
    int A = 0;
    int B = 0;
    int C = 0;
    int D = 0;
    int E = 0;
    int F = 0;
    int G = 0;
    int H = 0;
    int I = 0;
    int J = 0;
    int K = 0;    
    int L = 0;
    int M = 0;
    int N = 0;
    int O = 0;
    int P = 0;
    int Q = 0;
    int R = 0;
    int S = 0;
    int T = 0;
    int U = 0;
    int V = 0;
    int W = 0;
    int X = 0;
    int Y = 0;
    int Z = 0;
    int len = w.length();
    while (len > 0){
        string chara = w.substr(0,1);
        if (chara == "a"){
            A++;
        }
        else if (chara == "b"){
            B++;
        }
        else if (chara == "c"){
            C++;
        }
        else if (chara == "d"){
            D++;
        }
        else if (chara == "e"){
            E++;
        }
        else if (chara == "f"){
            F++;
        }
        else if (chara == "g"){
            G++;
        }
        else if (chara == "h"){
            H++;
        }
        else if (chara == "i"){
            I++;
        }
        else if (chara == "j"){
            J++;
        }
        else if (chara == "k"){
            K++;
        }
        else if (chara == "l"){
            L++;
        }
        else if (chara == "m"){
            M++;
        }
        else if (chara == "n"){
            N++;
        }
        else if (chara == "o"){
            O++;
        }
        else if (chara == "p"){
            P++;
        }
        else if (chara == "q"){
            Q++;
        }
        else if (chara == "r"){
            R++;
        }
        else if (chara == "s"){
            S++;
        }
        else if (chara == "t"){
            T++;
        }
        else if (chara == "u"){
            U++;
        }
        else if (chara == "v"){
            V++;
        }
        else if (chara == "w"){
            W++;
        }
        else if (chara == "x"){
            X++;
        }
        else if (chara == "y"){
            Y++;
        }
        else if (chara == "Z"){
            Z++;
        }
        w = w.substr(1,len);
        len = w.length();
    }
    if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0 && D % 2 == 0 && E % 2 == 0 && F % 2 == 0 && G % 2 == 0 && H % 2 == 0 && I % 2 == 0 && J % 2 == 0 && K % 2 == 0 && L % 2 == 0 && M % 2 == 0 && N % 2 == 0 && O % 2 == 0 && P % 2 == 0 && Q % 2 == 0 && R % 2 == 0 && S % 2 == 0 && T % 2 == 0 && U % 2 == 0 && V % 2 == 0 && W % 2 == 0 && X % 2 == 0 && Y % 2 == 0 && Z % 2 == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int bubbleSort(int N, int A[]){
  int flag = 1;
  int sum = 0;
  int v;
  while(flag){
    flag = 0;
    for(int j = N - 1; j > 0; j--){
      if(A[j] < A[j-1]){
        v = A[j];
        A[j] = A[j - 1];
        A[j - 1] = v;
        flag = 1;
        sum++;
      }
    }
  }
  for(int j = 0; N > j; j++){
    cout << A[j];
    if(N == j + 1){
      cout << endl;
    } else {
      cout << " ";
    }
  }
  cout << sum << endl;
}
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; N > i; i++) cin >> A[i];
  bubbleSort(N,A);
}


Measured memory_bytes: 3120
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main()
{
    int n, q, quer, t, x;
    cin >> n >> q;
    vector<stack<int>> sta(n);
    while (q--) {
        cin >> quer;
        if (quer == 0) {
            cin >> t >> x;
            sta[t].push(x);
        }
        else if (quer == 1) {
            cin >> t;
            if (!sta[t].empty())
                cout << sta[t].top() << endl;
        }
        else if (quer == 2) {
            cin >> t;
            if (!sta[t].empty())
                sta[t].pop();
        }
    }
}


Measured memory_bytes: 4224
N=int(input())
D,X=map(int,input().split())
A=[]
for I in range(N):
	A.append(int(input()))
SUM=sum(A)
ANS=0
for K in range(N):
	W=0
	E=1
	while(E<=D):
		W+=1
		E=1+W*A[K]
		ANS+=1
print(ANS+X)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846

void solve()
{
    int s,w;cin>>s>>w;
    if(w>=s)
        cout<<"unsafe"<<nl;
    else
        cout<<"safe"<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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


Measured memory_bytes: 3640
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int insd;
const int N = 100001;
ll a[N], dp[2][N];

ll s1[N], smax[N], c1;
ll s2[N], s2max, c2;

void reset() {
	c1 = c2 = s2max = 0;
}

void push(ll x) {
	s2[c2++] = x;
	if (x > s2max) s2max = x;

	while (c1 + c2 > m) {
		if (c1) c1--;
		else {
			for (int i = c2 - 1; i >= 0; i--) {
				smax[c1] = s1[c1] = s2[i];
				if (c1 > 0 && smax[c1 - 1] > smax[c1]) smax[c1] = smax[c1 - 1];
				c1++;
			}
			c2 = 0;
			s2max = 0;
		}
	}
}

ll get_max() {
	if (c1 == 0) return s2max;
	return max(s2max, smax[c1 - 1]);
}

int main() {
	//freopen("x.in", "r", stdin);
	cin >> n >> m >> k;
	F1(i, n) cin >> a[i];

	F1(i, n) dp[0][i] = a[i];

	for (int kk = 2; kk <= k; kk++) {
		reset();
		int i1 = kk % 2;
		int i2 = 1 - i1;

		insd = kk - 1;
		for (int i = kk; i <= n; i++) {
			while (insd < i) {
				push(dp[i1][insd]);
				insd++;
			}
			dp[i2][i] = kk * a[i] + get_max();
		}

		if (kk == k) {
			ll ans = 0;
			for (int i = k; i <= n; i++) {
				ans = max(ans, dp[i2][i]);
			}
			cout << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4864
s = input()
k = int(input())



# S = []
# for i in range(len(s)+1):
#     for j in range(i+1,len(s)+1):
#         if not(s[i:j] in S):
#             S.append(s[i:j])
#         # print(s[i:j])

S = set()

for i in range(1, k+1):
    for j in range(len(s)-i+1):
            S.add(s[j:j+i])

T = sorted([x for x in S])

print(T[k-1])








Measured memory_bytes: 4592
#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 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 main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> in(n);
    ll i;
    rep(i, n) {
        cin >> in[i];
    }
    xrep(i, k, n) {
        if (in[i] > in[i-k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int j=0; j<n; j++) cin >> v[j];


    int count = 0;

    for(;;) {
        for(int i = 0; i<n; i++) {
            if(v[i] % 2 != 0) {
                cout << count << endl;
                return 0;
            }
            else v[i] = v[i] / 2;
        }
        count++;
    }
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x;
		String c;
		boolean data[][] = new boolean[4][13];
		
		n = stdIn.nextInt();
		
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 13; j++) {
				data[i][j] = false;
			}
		}
		
		for( int i = 1; i <= n; i++) {
			c = stdIn.next();
			x = stdIn.nextInt();
			
			switch(c) {
			case "S":
				data[0][x - 1] = true;
				break;
			case "H":
				data[1][x - 1] = true;
				break;
			case "C":
				data[2][x - 1] = true;
				break;
			case "D":
				data[3][x - 1] = true;
				break;
			default:
				break;
			}
		}
		
		for(int i = 0; i < 4; i++) {
			for(int j = 1; j <= 13; j ++) {
				switch(i) {
				case 0:
					if(data[i][j - 1] == false) {
						System.out.println("S " + j);
					}
					break;
				case 1:
					if(data[i][j - 1] == false) {
						System.out.println("H " + j);
					}
					break;
				case 2:
					if(data[i][j - 1] == false) {
						System.out.println("C " + j);
					}
					break;
				case 3:
					if(data[i][j - 1] == false) {
						System.out.println("D " + j);
					}
					break;
				default:
					break;
				}
			}
			
		}
		
	}
}


Measured memory_bytes: 26340
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define itn int
using namespace std;
typedef pair<int, int> P;
signed main() {
	int w, h, n, x[100][100]={},a;
	cin >> w >> h >> n;
	for (int i = 0; i < n;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		if (c == 1) {
			for (int j = 0; j < a; j++) {
				for (int k = 0; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 2) {
			for (int j = a; j < w; j++) {
				for (int k = 0; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 3) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < b; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 4) {
			for (int j = 0; j < w; j++) {
				for (int k = b; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (x[i][j] == 0) {
				a++;
			}
		}
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A > C) {
        swap(A, C);
        swap(B, D);
    }

    if (B <= C) {
        cout << 0 << endl;
    } else {
        cout << min(B, D) - C << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> price(n);
for(int i = 0; i < n; i++){
cin >>  price.at(i);
}
sort(price.begin(), price.end());
price.at(n-1) = price.at(n-1) / 2;
int sum = 0;
for(int i; i < n; i++){
sum = sum + price.at(i);
}
cout << sum <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
vector<ll> kaijo;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
void kaijo_set(ll n){
  kaijo.push_back(1);
  for(ll i=1;i<=n;i++) kaijo.push_back(kaijo[i-1]*i%mod);
}
ll nCr(ll n,ll r){
  if(n==0||r==0) return 1;
  ll res=kaijo[n];
  res*=pow(kaijo[r],mod-2);
  res%=mod;
  res*=pow(kaijo[n-r],mod-2);
  return res%mod;
}
int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  kaijo_set(n*m);
  ll ans=0;
  for(ll d=1;d<n;d++){
    ll kans=(n-d)*m;
    kans%=mod;
    kans*=m;
    kans%=mod;
    kans*=nCr(n*m-2,k-2);
    kans%=mod;
    kans*=d;
    kans%=mod;
    ans+=kans;
    ans%=mod;
  }
  swap(n,m);
  for(ll d=1;d<n;d++){
    ll kans=(n-d)*m;
    kans%=mod;
    kans*=m;
    kans%=mod;
    kans*=nCr(n*m-2,k-2);
    kans%=mod;
    kans*=d;
    kans%=mod;
    ans+=kans;
    ans%=mod;
  }
  cout<<ans<<endl;
}


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

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

using namespace std;
using lint=long long;

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

	vector<pair<lint,int>> p(n);
	rep(i,n) p[i]={a[i],i};
	sort(p.rbegin(),p.rend());

	static lint dp[2001][2001];
	rep(i,n){
		int idx=p[i].second;

		rep(j,i+1){
			// a[idx] を左から j 番目に置く
			dp[j+1][i-j]=max(dp[j+1][i-j],dp[j][i-j]+a[idx]*abs(idx-j));
			// a[idx] を右から i-j 番目に置く
			dp[j][i-j+1]=max(dp[j][i-j+1],dp[j][i-j]+a[idx]*abs(n-(i-j)-1-idx));
		}
	}

	lint ans=0;
	rep(i,n+1) ans=max(ans,dp[i][n-i]);
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 26440
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$b=array_count_values($a);
if($b[0]==$n){
  echo "Yes";
}elseif($n%3!=0){
  echo "No";
}else{
  $c=array_count_values($b);
  if($c[$n/3]!=3){
    echo ($b[0]==$n/3&&count($b)==2)?"Yes":"No";
    exit;
  }
  $xor=0;
  foreach($b as $k=>$v){
    $xor^=$k;
  }
  echo ($xor==0)?"Yes":"No";
}

Measured memory_bytes: 19188
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/

int main() {
  ll n,sum=0;
  cin >> n;
  REP(i,1,n+1){
    if(i%3!=0 && i%5!= 0){
      sum+=i;
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n],b[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  b[0] = 0;
  b[1] = abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
  	b[i] = INT_MAX;
  	for(int j=max(0,i-k);j<i;j++)
  		b[i] = min(b[i],b[j]+abs(a[j]-a[i]));
  }
  cout<<b[n-1];
}

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

typedef long long int ll;
typedef unsigned long long int ull;

#define test(t)		int t; cin>>t; while(t--)
#define all(a)		a.begin(), a.end()
#define f(i, a, b)	for(int i = a; i < b; ++i)
#define endl 		"\n"
#define deb(x)		cout << #x << "--" << x << "--" << endl;
#define deb2(x,y)	cout << #x << "--" << x << "--" << endl <<  #y << "--" << y << "--" << endl;
#define fast 		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007

void solve()
{
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	ll sum = 0;

	if(k <= a){
		sum += k;
		cout << sum << endl;
		return;
	}
	else{	//k > a
		sum += a;
		k -= a;
	}

	if(k <= b){
		cout << sum << endl;
		return;
	}
	else{	//k > b
		k -= b;
	}

	if(k <= c){
		sum -= k;
		cout << sum << endl;
		return;
	}
	else{	//k > c
		sum -= c;
		k -= c;
	}
	cout << sum << endl;
}

int main()
{
     fast;
     //test(t)
          solve();
     return 0;
}

Measured memory_bytes: 3184
#include <cstdio>
long long c[][16] = {{0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286},{539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286}}, n, u, md=1e9+7, ans, t;
int main(){
	scanf("%lld", &t);
	for(int i=0; i<t; i++){
		scanf("%lld", &n);
		ans=0; u=1;
		for(auto e: c[n%2]){
			ans += e*u%md;
			u = u*n%md;
		}
		printf("%lld\n", ans%md);
	}
}

Measured memory_bytes: 1700
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int N; cin >> N;
    ll dp[N + 1];
    dp[0] = 2;
    dp[1] = 1;
    for (int i = 2; i <= N; ++i) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    out(dp[N]);


    
    return 0;
}






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

int lis(vector<int> a){
    int n = a.size();
	int dp[n];
	fill(dp, dp + n, INT_MAX);
	rep(i,n) *lower_bound(dp, dp+n, a[i]) = a[i];
	return lower_bound(dp, dp+n, INT_MAX) - dp;
}
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)scanf("%d", &a[i]);
    cout << lis(a) << endl;
}


Measured memory_bytes: 4008
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
int a[10];

int main() {
    #ifndef ONLINE_JUDGE
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    if(n==1&&!m){
        cout << 0 << endl;
        return 0;
    }
    memset(a,-1,sizeof(a));
    bool f = 0;
    for(int i = 1;i <= m;i++){
        int s,c;
        cin >> s >> c;
        if(n!=1&&s==1&&c==0){
            f = 1;
        }else if(a[s]==-1){
            a[s] = c;
        }else{
            //if(a[s]==0)a[s] = c;
            f = a[s] == c ? 0 : 1;
        }
    }
    if(f){
        cout << "-1\n";
        return 0;
    }
    string ans = "";
    for(int i = 1;i <= n;i++){
        if(a[i]==-1&&i==1)a[i] = 1;
        else if(a[i]==-1)a[i] = 0;
        ans += a[i] + '0';
    }
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
#include<set>
//#include<map>
//#include<list>

/**/

using namespace std;
using LLI = long long int;

const int MAX_N = 25;
int n, W;
int w[MAX_N], v[MAX_N];

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//int gcd(int x, int y) {
//	int tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}

int main(void) {
	int N, K,res = 1;
	cin >> N >> K;
	for (int i = 0; i < N;i++) {
		if (res > K) {
			res += K;
		}
		else {
			res *= 2;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin>>n;
  
  ll sum=0;
  vector<int> A(100010);
  ll x;
  rep(i,n){
    cin>>x;
    sum+=x;
    A[x]++;
  }
  
  ll q;
  cin>>q;
  
  ll b,c;
  rep(i,q){
    cin>>b>>c;
    A[c]+=A[b];
    sum+=A[b]*(c-b);
    A[b]=0;
    cout<<sum<<endl;
  }
  
  return 0;
}

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

int main()
{
    int n,m,ans,flg;

    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
    }

    for (ans = 0;ans <= 999;++ans) {
        string sans = to_string(ans);
        flg = 0;
        if ((int)sans.size()==n) {
            rep(i, m) {
                if (s[i] <= (int)sans.size()) {
                    if (sans[s[i] - 1] != c[i]) {
                        ++flg;
                        break;
                    }
                }
            }
            if (flg == 0)
                break;
        }
    }
    if (ans>999 || flg != 0)
        ans = -1;

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


Measured memory_bytes: 3700
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	vector<int>a;
	rep(i, 3) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	sort(All(a));
	int ans = a.at(2) - a.at(1);
	ans += a.at(1) - a.at(0);
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {

		Scanner sysin = new Scanner(System.in);
		final int n = sysin.nextInt();
		int[] p = IntStream.range(0, n)
					.map(i -> sysin.nextInt())
					.boxed()
					.mapToInt(Integer::intValue)
					.toArray();
		sysin.close();

		int answer = 0;
		for (int i = 1; i < p.length - 1; i++) {
			if ((p[i] < p[i - 1] && p[i] > p[i + 1]) || (p[i] > p[i - 1] && p[i] < p[i + 1])) {
				answer++;
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 27476
#include<bits/stdc++.h>
using namespace std;
char mm[1005][1005];
int dp[1005][1005];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",&mm[i][1]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==1&&j==1&&mm[i][j]=='.')
			{
				dp[i][j]=1;
			}
			else if(mm[i][j]=='.') dp[i][j]=dp[i-1][j]+dp[i][j-1],dp[i][j]%=1000000007;
			else dp[i][j]=0;
		}
	}
	printf("%d",dp[n][m]);
}

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

int main() {
  int x,y;
  cin >> x >> y;
  vector<int>a={0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(a.at(x)==a.at(y))
    cout << "Yes" <<endl;
  else
    cout << "No"<<endl;
  
}


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

string kiyaku(int a, int b){

  string ret;

  while(true){
    if(b==1){
      ret = to_string(a);
      break;
    }
    if(a%2!=0){
      ret = to_string(a);
      ret.append("/");
      ret.append(to_string(b));
      break;
    }

    a /= 2; b /= 2;
  }

  return ret;
}

int main(){

  while(true){
    string s; cin>>s;
    if(s=="#") break;

    int a = 0, b = 1;

    if(s.size()<=5){
      s == "north" ? a = 0 : a = 90 ;
      cout<<a<<endl;
    }else{
      for(int i=s.size()-1,cnt=0;i>0;++cnt){
        if(s.substr(i,1)=="h"){
          i -= 5;

          if(cnt>0){
            a = a*2 - 90;
            b *= 2;
          }

        }else{
          i -= 4;

          if(cnt>0){
            a = a*2 + 90;
            b *= 2;
          }else{
            a = 90;
          }
        }
      }

      cout<<kiyaku(a,b)<<endl;
    }

  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
 
using namespace std;
 
 
 
int main(){
 
        double a;
        scanf("%lf", &a);
        double b = a/3.0;
        double c = a-b-b;
        // cout<<b<<" "<<c<<" ";
        double ans = b*b*b;
        // cout<<b*b*b<< " ";
        printf("%.7f",ans);
 
        return 0;
 
}

Measured memory_bytes: 256
/*
Vim shortcuts:
  :pc -> close scratch window
*/
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORR(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;

int N,M;
string s;
vector<set<int> > G;
vector<bool> bad;
vector<int> dA;
vector<int> dB;
void dfsUpdate(int c) {
  if (bad[c])return;
  if (dA[c]>0&&dB[c]>0)return;
  bad[c] = true;
  FOR(it,G[c]) {
    if (s[c]=='A'){
      dA[*it]--;
    } else {
      dB[*it]--;
    }
    dfsUpdate(*it);
  }
}
int main(int argc, char **argv, char **envp) {
  cin >> N >> M;
  G.resize(N);
  dA.resize(N,0);
  dB.resize(N,0);
  bad.resize(N,false);
  cin >> s;
  REP(i,M) {
    int a,b;
    scanf("%d%d",&a,&b);--a;--b;
    if (G[a].find(b)!=G[a].end())continue;
    if (s[a]=='A') dA[b]++;
    if (s[a]=='B') dB[b]++;
    if (s[b]=='A') dA[a]++;
    if (s[b]=='B') dB[a]++;
    G[a].insert(b);
    G[b].insert(a);
  }
  REP(i,N) {
    dfsUpdate(i);
  }
  bool ok=false;
  REP(i,N) {
    if(bad[i] == false) ok=true;
  }
  if (ok)
    cout << "Yes"<<endl;
  else
    cout << "No"<<endl;
  return 0;
}


Measured memory_bytes: 28548
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	int N;
	cin >> N;
	vi a(N);
	rep(i, N) {
		cin >> a[i];
	}
	vi b = a;
	ll ansp = 0;
	ll ansm = 0;

	if (a[0] <= 0) {
		ansp = 1 - a[0];
		a[0] = 1;
	}

	ll now = a[0];
	repl(i, 1, N) {
		if (now > 0) {
			if (now + a[i] < 0) {
				now += a[i];
			}
			else {
				ansp += now + a[i] + 1;
				now = -1;
			}
		}
		else {
			if (now + a[i] > 0) {
				now += a[i];
			}
			else {
				ansp += 1 - (now + a[i]);
				now = 1;
			}
		}
	}

	a = b;

	if (a[0] >= 0) {
		ansm = a[0] + 1;
		a[0] = -1;
	}

	now = a[0];
	repl(i, 1, N) {
		if (now > 0) {
			if (now + a[i] < 0) {
				now += a[i];
			}
			else {
				ansm += now + a[i] + 1;
				now = -1;
			}
		}
		else {
			if (now + a[i] > 0) {
				now += a[i];
			}
			else {
				ansm += 1 - (now + a[i]);
				now = 1;
			}
		}
	}

	cout << min(ansp, ansm) << endl;

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

bool getBond(char c){
  if(c == 'A') return true;
  if(c == 'T') return true;
  if(c == 'G') return true;
  if(c == 'C') return true;
  return false;
}

bool isGood(string s){
  F0R(i,s.length())
    if(!getBond(s[i]))
      return false;
  return true;
}

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

    string s;
    ll n,q;
    cin >> n >> q;
    cin >> s;
    ll l[q],r[q];
    F0R(i,q){
      cin >> l[i] >> r[i];
    }
    ll st[n];
    st[0] = 0;
    bool edged[n];
    F0R(i,n) edged[i] = false;
    bool almost = false;
    FOR(i,0,n){
      if(almost && s[i] == 'C') {
        st[i] = st[i-1]+1;
        edged[i-1] = true;
      }
      else if(i!=0)
        st[i] = st[i-1];
      if(s[i] == 'A') almost = true;
      else almost = false;
    }


    F0R(i,q){
      if(l[i] == 1){ cout << st[r[i]-1] << endl; continue;}

      if(!edged[l[i]-2]){
        cout << st[r[i]-1] -st[l[i]-2]<<endl;
        // cout << r[i] << " - " << l[i] << endl  ;
        // cout << st[r[i]-1] << " - " << st[l[i]-2] << endl;
      }
      else
        cout << st[r[i]-1] - st[l[i]-2] - 1 << endl;
        // cout << r[i] << " - " << l[i] << endl  ;
        // cout << st[r[i]-1] << " - " << st[l[i]-2] << endl;
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 3536
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



fn is_needed(ns: &[i64], i: usize,  k: i64) -> bool {
    let lb = k - ns[i];
    if lb < 0 {
        return true;
    }

    let mut dp = vec![vec![0; (k+1) as usize]; ns.len() + 1];
    dp[0][0] = 1;

    for j in 0..ns.len() {
        for k2 in 0..k+1 {
            if i == j {
                dp[j+1][k2 as usize] += dp[j][k2 as usize];
                continue;
            }

            dp[j+1][k2 as usize] += dp[j][k2 as usize];
            if k2 + ns[j] > k {
                continue;
            }
            dp[j+1][(k2 + ns[j]) as usize] += dp[j][k2 as usize];
        }
    }

    for k2 in lb..k {
        if dp[ns.len()][k2 as usize] != 0 {
            return true;
        }
    }

    false
}


fn solve(mut ns: Vec<i64>, k: i64) -> i64 {
    ns.sort();

    if is_needed(&ns, 0 as usize, k) {
        return 0;
    }

    let mut lb = 0;
    let mut ub = ns.len() as i64;
    while ub - lb > 1 {
        let med = (lb + ub) / 2;
        if is_needed(&ns, med as usize, k) {
            ub = med;
        } else {
            lb = med;
        }
    }
    lb + 1
}


fn main() {
    input! {
        n: usize,
        k: i64,
        ns: [i64; n]
    }
     println!("{}", solve(ns, k));
}


Measured memory_bytes: 127228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

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

  vector<ll> a(n);
  rep (i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll sum = a[0];
  int i = 1;
  int remain = n - 2;
  while (remain > 0) {
    if (remain - 2 >= 0) {
      sum += a[i] * 2;
      remain -= 2;
    } else {
      sum += a[i];
      remain -= 1;
    }
    i++;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

vector<pair<lli, lli> > factoring(lli n){
    vector<pair<lli, lli> > res;
    for(lli i=2; i*i<=n; i++){
        if(n%i == 0){
            res.emplace_back(i, 0);
            while(n%i == 0){
                n /= i;
                res.back().second++;
            }
        }
    }
    if(n != 1){
        res.emplace_back(n, 1);
    }
    return res;
}

int main(){
    lli n;
    cin >> n;
    auto factor = factoring(n);
    lli ans = 0;
    for(auto p: factor){
        int z = 1;
        lli siz = p.second;
        while(z <= siz){
            ans++;
            siz -= z;
            z++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
int deg[87];

int main() {
    for (int i = 0; i < 3; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        deg[a]++;
        deg[b]++;
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= 4; i++) {
        if (deg[i] == 1) cnt1++;
        else if (deg[i] == 2) cnt2++;
    }
    if (cnt1 == 2 && cnt2 == 2) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int fx(int ex,int ans){
	if(ex!=0){
		ans=ans*fx(ex-1,ans);
		return ans*2;
	}
	else if(ex==0)return 1;
}

int main(){
	int left,right=0,ex=9,i=0,j,num=1,ans=0,buntin[10000]={0};
	
	while(scanf("%d",&left)!=EOF){
		while(ex>=0){
			ans=fx(ex,num);
			if(left>=(ans+right)){
				right+=ans;
				buntin[i]=ans;
				i++;
				ex--;
			}
			else ex--;
		}
		for(j=i-1;j>=0;j--){
			printf("%d",buntin[j]);
			if(j>0)printf(" ");
		}
		printf("\n");
		ex=9;
		right=0;
		i=0;
		num=1;
		ans=0;
	}
	
	return 0;
}

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

int main() {
  
  int k,s;
  cin >> k >> s;
  
  int count = 0;
  
  for ( int a = 0; a <= k; a++){
    for ( int b = 0; b <= k; b++){
      int c = s - a - b;
      if ( a + b + c == s && c >= 0 && c <= k ){
        count++;
      }
    }
  }
  
  cout << count << endl;
  
}

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

using namespace std;

#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 each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) cout << "+" << endl;
	else if (a * b == 15) cout << "*" << endl;
	else cout << "x" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define irep(i, n) for (ll i = n-1; i >= 0; i--)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll T;
    cin >> T;
    rep(_, T) {
        ll N;
        cin >> N;
        vll K(N), L(N), R(N);
        vvll VL(N+1), VR(N+1);
        ll ans = 0;
        rep(i, N) {
            cin >> K[i] >> L[i] >> R[i];
            K[i]--;
            if(L[i] > R[i]) {
                ans += R[i];
                VL[K[i]].push_back(L[i]-R[i]);
            }
            else {
                ans += L[i];
                VR[K[i]].push_back(R[i]-L[i]);
            }
        }

        priority_queue<ll, vll, greater<ll>> pq1;
        rep(i, N) {
            for(auto x : VL[i]) pq1.push(x);
            while(i+1 < pq1.size()) pq1.pop();
        }
        while(!pq1.empty()) {
            ans += pq1.top();
            pq1.pop();
        }

        priority_queue<ll, vll, greater<ll>> pq2;
        irep(i, N) {
            for(auto x : VR[i]) pq2.push(x);
            while(N-1-i < pq2.size()) pq2.pop();
        }
        while(!pq2.empty()) {
            ans += pq2.top();
            pq2.pop();
        }

        cout << ans << endl;
    }
}


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

//WA

int main(void){
	int N,dp[300010]={},dpi[300010]={},s=0;
	char S[300010];
	scanf("%d%s",&N,S);
	dp[0]=0;
	rep(i,N-1){
		dp[i+1]=dp[i];
		if(S[i]=='W')dp[i+1]++;
	}
	dpi[N-1]=0;
	ireg(i,1,N-1){
		dpi[i-1]=dpi[i];
		if(S[i]=='E')dpi[i-1]++;
	}
	rep(i,N){
		// printf("%c\n",S[i]);
		if(dp[s]+dpi[s]>dp[i]+dpi[i])s=i;
	}
	printf("%d\n",dp[s]+dpi[s]);
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec a(N);
    REP(i,0,N) cin >> a[i];

    ll avg = 0, m = 0;
    REP(i,0,N) avg += a[i];
    if(2*(avg-N*(avg/N)) < N) avg = avg / N;
    else avg = avg / N + 1;
    REP(i,0,N) m += (a[i] - avg) * (a[i] - avg);
    PR(m);


    return 0;
}

/*



*/

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>

using namespace std;
typedef long long LL;

int main()
{
    int STRLEN = 10;
    char buff[STRLEN+1];
    buff[STRLEN] = 0;

    int N;
    cin >> N;

    map<string, LL> anaCounts;

    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        memcpy(buff, s.c_str(), STRLEN);
        sort(buff, buff+STRLEN);
        ++(anaCounts[buff]);
    }

    LL ans = 0;
    for (auto it = anaCounts.begin(); it != anaCounts.end(); ++it) {
        LL count = it->second;
        ans += count * (count-1) / 2;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 11136
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Maybe (fromJust)
import Control.Monad (forM, replicateM)

getInts :: IO [Int]
getInts = map (fst . fromJust . C.readInt) <$> C.words <$> B.getLine

main :: IO ()
main = do
    [n, m] <- getInts
    xs <- replicateM m getInts
    let [lb,ub] = foldl1 intersect xs
    print $ max 0 (ub - lb + 1)
    where
        intersect [l1,r1] [l2,r2] = [max l1 l2, min r1 r2]

Measured memory_bytes: 52988
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>


#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>
#include<ctime>

#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int, int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph;


signed main(){
	ll n , m ;
	cin >> n >> m ;
	ll sum = 0;
	for (int a ,  i = 0; i < m; i++){
		cin >> a;
		sum += a;

	}
	if (sum > n){
		cout << -1;

	}else{
		cout << n - sum;
	}




	return 0; 
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,ans=0,sum=0;
	cin>>N;
	int a[2][N];
	for(int i=0;i<2;i++){
		for(int j=0;j<N;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<N;i++){
		sum=0;
		for(int j=0;j<=i;j++){
			sum=sum+a[0][j];
		}
		for(int j=i;j<N;j++){
			sum=sum+a[1][j];
		} 
		ans=max(ans,sum);
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
      long nam = in.nextLong();
      int cnt = String.valueOf( nam ).length();
      int sum = 0;
      
      long memo = nam;
      for(int i = 0;i < cnt;i++){
      		sum += memo%10;
        	memo /=10;
      }
      
      if(nam%sum==0){
         System.out.print("Yes"); 
      }else{
         System.out.print("No");
      }
      

      

	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>

using namespace std;

int n,a[200][200]={0};
void prim(){
	int d[200]={0};
	priority_queue<pair<int,pa> >  PQ; 
	pair<int,pa> q;
	pa r;
	int wei=0;
	int w=6;
	int u=w,z=0;
	d[w]=1;
	while(z!=n-1){
		for(int j=n-1;j>-1;j--){
			if(a[u][j]<=0 && d[j]==0 && u!=j) PQ.push(make_pair(a[u][j],make_pair(u,j)));
		}
	while(1){
		if(PQ.size()==0) {
			cout<<"dv"<<endl;
		break;
		}
		q=PQ.top();
		PQ.pop();
		r=q.second;
	//	cout<<"rsec"<<r.second<<endl;
		if(d[r.second]==0) break;
		
		}
	u=r.second;
//	cout<<"a" <<u<<endl;
	d[u]=1;
	wei=wei+q.first;
	z++;
//	cout<<z<<" "<<-q.first<<" "<<u<<" "<<r.first<<endl;
	
	}
	cout<<-wei<<endl;
}



int main(){
	// your code goes here
	int m;
	cin>>n;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
		cin>>m;
		a[i][j]=-m;
		}
	}
	prim();

	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a==0 | b==0){
        cout << "Zero";
    }else if(a>0 && b>0){
        cout << "Positive";
    }else if(a<0 && b>0){
        cout << "Zero";
    }else{
        if((a+b)%2==0){
            cout << "Negative";
        }else{
            cout << "Positive";
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int multi(int ar[3])
{
  int i;
  for( i=0; i<3; i++ ){
    ar[i]=ar[i]*ar[i];
  }
}

int main()
{
  int cnt=0,cnt_a=0,cnt_b=0,cnt_c=0; 
  while(1){
    int array[3];
    int temp,i,j;

    for( i=0; i<3; i++ ){
      scanf("%d",&array[i]);
    }

    for( i=0; i<2; i++ ){
      for( j=i+1; j<3; j++ ){
	if( array[i]<array[j] ){
	  temp=array[i];
	  array[i]=array[j];
	  array[j]=temp;
	}
      }
    }
    /*for( i=0; i<3; i++ ){
      printf("%d",array[i]);
    }
    */
    if( array[0]>=array[1]+array[2] || array[0]<=array[1]-array[2] )break;

    cnt++;
    multi(array);
   
    /*for( i=0; i<3; i++ ){
      printf("%d",array[i]);
      }*/

    if( array[0]<array[1]+array[2] )cnt_a++;
    if( array[0]==array[1]+array[2] )cnt_b++;
    if( array[0]>array[1]+array[2] )cnt_c++;
    
  }
  printf("%d %d %d %d\n",cnt,cnt_b,cnt_a,cnt_c);
  return 0;
}

Measured memory_bytes: 596