akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
 
    vector<int> box(n, 0);
    for(int i = n-1; i >= 0; --i){
        int sm = 0;
        int ptr = i;
        while(ptr < n){
            sm += box[ptr];
            ptr += i+1;
        }
 
        if(sm%2 ^ a[i]) box[i] = 1;
    }

    vector<int> res;
    rep(i, n){
        if(box[i]) res.push_back(i+1);
    }

    cout << res.size() << endl;
    rep(i, res.size()) cout << res[i] << " ";
    cout << endl;
  
    return 0;
}

Measured memory_bytes: 5312
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,q,l,r,cnt=0;
  cin>>n>>q;
  string S;
  vector<int>C(n+1,0);
  for(int i=0;i<n;i++){char aux; cin>>aux; S+=aux;}

  for(int i=0;i<n-1;i++){if (S[i] == 'A' && S[i+1] == 'C') C[i+1]++;}
  
  for(int i=0;i<n-1;i++){C[i+1]+=C[i];}
  
  for(int i=0;i<q;i++){
    cin>>l>>r;
    cnt=C[r-1]-C[l-1];
	cout<<cnt<<endl;}}

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

int main(void){
	int n;
	cin >> n;
	vector<int>c,s,f;
	c.resize(n+1);	s.resize(n+1);	f.resize(n+1);
	for(int i = 1; i <= n-1; ++i){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 1; i <= n; ++i){
		int t = 0, pos = i;
		while(pos < n){
			if(t <= s[pos]){
				t = s[pos];
			}
			if(t%f[pos]!=0){
				t += f[pos] - (t % f[pos]);
			}
			t += c[pos];
			++pos;
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 888
<?php
fscanf(STDIN,'%d',$N);
$H = fgets(STDIN);
$arrayH = explode(' ',$H);
$resultArray = array();
$resultArray[] = 0;
$resultArray[] = abs($arrayH[1]-$arrayH[0]);
for($i=2;$i<$N;$i++){
  if($resultArray[$i-1]+abs($arrayH[$i]-$arrayH[$i-1])>=$resultArray[$i-2]+abs($arrayH[$i]-$arrayH[$i-2])){
    $resultArray[] = $resultArray[$i-2]+abs($arrayH[$i]-$arrayH[$i-2]);
  }else{
    $resultArray[] = $resultArray[$i-1]+abs($arrayH[$i]-$arrayH[$i-1]);
  }
}

echo $resultArray[$N-1];

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

using namespace std;

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

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

    double ans = v[0];
    for (int i = 1; i < N; i++) {
        ans = (ans + v[i])/2.0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    A.at(i) = make_pair(a, i);
  }
  
  sort(A.begin(), A.end(), greater<pair<int, int>>());

  for (int i = 0; i < N; i++)
  {
    int ans;
    if (i == A.at(0).second) ans = A.at(1).first;
    else ans = A.at(0).first;
    cout << ans << endl;
  }
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

int main()
{
    int M[100][100];
    int n, u, k, v;

    cin >> n;

    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            M[i][j] = 0;
        }
    }

    rep(i, 0, n)
    {
        cin >> u >> k;
        u--;
        rep(j, 0, k)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            if (j)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3160
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;



inline long long f(long long x) {
    if (x < 0) return 0;
    ++x;
    long long res = 0;
    for (long long i = 0; i <= 50; ++i) {
        long long len = (1ll << i);
        long long bl = (x + len - 1ll) / len;
        if (bl & 1ll) {
            long long z = len * (bl / 2ll);
            if (z & 1ll) res ^= (1ll << i);
        } else {
            --bl;
            long long z = len * (bl / 2ll);
            if (x % len == 0) z += len;
            else z += x % len;
            if (z & 1ll) res ^= (1ll << i);
        }
    }
    return res;
}

int main(int argc, const char * argv[]) {
//    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long a, b;
    cin >> a >> b;
    a = f(a - 1ll);
    b = f(b);
    a ^= b;
    cout << a << '\n';
}



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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    int a, b = 0;
    long long int ans = 0;
    rep(i,n) {
        cin >> a;
        if (a>b) b = a;
        else ans += b-a;
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll gcd(ll x,ll y)
{
	return y ? gcd(y,x % y) : x;
}

ll lcm(ll x,ll y)
{
	return x / gcd(x,y) * y;
}

int N;

int main()
{
	scanf("%d",&N);
	ll ans = 1;
	FOR(i,0,N){
		ll x;
		scanf("%lld",&x);
		ans = lcm(x,ans);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a) memset(a,0,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
ll a[1005];
int main()
{
	ll n;cin>>n;
	ll flag=0;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%2==0){
			if(a[i]%3==0||a[i]%5==0){
				continue;
			}else{
				flag=1;
			}
		}else{
			continue;
		}
	}
	if(flag) cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 384
// If you want something you've never had, you must be willing to do s
// something you've never done
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)

#define pb push_back
#define ft first
#define sd second
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int N = 1e5 + 5;
const ll mod = 1e9+7;
int n, m;
const int INF = 2e9;

int getParity(string &s, int n) {
    int sum = 0;
    for(int i=0; i<n; i++) {
        if(s[i] == '0') continue;
        sum += (((n-1)&i) == i);
    }
    return sum % 2;
}

signed main() {
    int n;
    cin >> n;
    int two = 0;
    string s;
    cin >> s;
    for(int i=0; i<n; i++) {
       two += (s[i] == '2');
    }
    two = !!two;
    if(two) {
        for(int i=0; i<n; i++) {
            if(s[i] == '2') s[i] = '0';
            else s[i] = '1';
        }
        int par = getParity(s, n);
        if(!par) cout << "0\n";
        else cout << "1\n";
    }
    else {
        for(int i=0; i<n; i++) {
            if(s[i] == '1') s[i] = '0';
            else s[i] = '1';
        }
        int par = getParity(s, n);
        if(!par) cout << "0\n";
        else cout << "2\n";
    }

    return 0;
}



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

#define int long long
#define ll long long
#define F first 
#define S second 
#define pb push_back
#define ld double

using namespace std ; 

const int MAXN = 1001 * 1001 , MOD =  1e9 + 7 ;

int dp[MAXN] ; 

int32_t main()
{
	ios::sync_with_stdio(0) ;
	int n ; 
	cin >> n ; 
	int ans = 0 ; 
	dp[0] = 1 ; 
	dp[1] = 1 ; 
	dp[2] = 1 ; 
	dp[3] = 2 ; 
	int s = 2 ; 
	for(int i = 4 ; i < MAXN ; i ++ ) 
	{
		dp[i] = dp[i-1] + s ;
		s += dp[i-2] ; 
		dp[i] %= MOD ; 
		s %= MOD ; 
	}
	ans ++ ; 

	for(int i = 0 ; i < n - 1 ; i ++ ) ans += dp[i] * (n-1) , ans %= MOD ; 
	
	for(int i = 0 ; i < n ; i ++ ) ans += dp[i] * (n-1) , ans %= MOD ; 

	for(int i = 0 ; i < n - 1 ; i ++ ) ans += dp[i] * (n-1) % MOD * (n-2) % MOD , ans %= MOD ;

	cout << ans << endl ; 	

}



Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int N, maxK, K;
    cin >> N >> maxK;
    
    if(N<maxK) {
        K=N;
    } else {
        K = maxK;
    }
    
    vector<long long int> V(N);
    vector<long long int> cal_V(N*2);
    for(int n=0; n<N; n++) {
        cin >> V[n];
        cal_V[n] = V[n];
        cal_V[n+N] = V[n];
    }
    
    long long int ans=0;
    // cout << "calc ans" << endl;
    for(int k=0; k<((K+1)/2); k++) {
        // cout << k << "th ";
        // cout << "calc sum" << endl;
        for(int n=N-(K-k); n<N+1; n++) {
            long long int sum=0;
            priority_queue<long long int, vector<long long int>, greater<long long int> > que;
            for(int i=0; i<(K-k); i++) {
                sum += cal_V[n+i];
                if(cal_V[n+i]<0) {
                    que.push(cal_V[n+i]);
                }
            }
            
            if(!que.empty()) {
                for(int i=0; i<k+(maxK-K); i++) {
                    // cout << sum << " -> ";
                    sum -= que.top();
                    que.pop();
                    if(que.empty()) break;
                    // cout << sum << endl;
                }
            }
            
            // cout << "compare ans and sum" << endl;
            if(ans<sum) {
                ans = sum;
            }
        }
        // cout << "calc sum end" << endl;
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int n, m;
ll mod = 1000000007;

int main() {
	cin >> n >> m;
	vector<int> dp(n+2);
	vector<bool> broken(n+1,false);
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		broken.at(t) = true;
	}
	dp.at(n) = 1;
	dp.at(n + 1) = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (broken.at(i)) {
			dp.at(i) = 0;
			continue;
		}
		dp.at(i) = (dp.at(i + 1) + dp.at(i + 2)) % mod;
	}
	cout << dp.at(0);
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>

int pivot(int a[],int i,int j){
	int k=i+1;
    while(k<=j && a[i]==a[k]) k++;
    if(k>j) return -1;
    if(a[i]>=a[k]) return i;
    return k;
}

int partition(int a[],int i,int j,int x){
   int l=i,r=j;

    // 検索が交差するまで繰り返します
    while(l<=r){

      // 軸要素以上のデータを探します
      while(l<=j && a[l]<x)  l++;

      // 軸要素未満のデータを探します
      while(r>=i && a[r]>=x) r--;

      if(l>r) break;
      int t=a[l];
      a[l]=a[r];
      a[r]=t;
      l++; r--;
    }
    return l;
}

void quickSort(int a[],int i,int j){
    if(i==j) return;
    int p=pivot(a,i,j);
    if(p!=-1){
      int k=partition(a,i,j,a[p]);
      quickSort(a,i,k-1);
      quickSort(a,k,j);
    }
}

void sort(int a[],int N){
    quickSort(a,0,N-1);
}


int main(){
	int N;
	std::cin >> N;
	int d[N];
	for(int i = 0;i < N;i++){
		std::cin >> d[i];
	}

	int ceilN = ceil(N/2);

	sort(d,N);

	int separate = 0;
	if(N%2 == 0){
		separate = d[ceilN] -d[ceilN-1];
	}
	std::cout << separate;
	return 0;
}

Measured memory_bytes: 640
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    a=[(int(input()),i) for i in range(n)]
    a.sort(reverse=True)
    m,mi=a[0][0],a[0][1]
    for i in range(n):
        if mi==i:
            print(a[1][0])
        else:
            print(m)
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 31652
#include <iostream>
#include <stdio.h>

using namespace std;

struct Dice{

	int u;	int w;	int s;	int e;	int n;	int d;
	
	Dice (int d1, int d2, int d3, int d4, int d5, int d6)
		{u = d1; s = d2; e = d3; w = d4; n = d5; d = d6;}
	
	Dice (int *num){
		u = num[0]; s = num[1]; e = num[2];
		w = num[3]; n = num[4]; d = num[5];}
	
	Dice ()
		{u = 1; s = 2; e = 3; w = 4; n = 5; d = 6;}

	void rotate(char *direction){
		int dam = 0;
		for (int i = 0; direction[i] != '\0'; i++){
			switch (direction[i]){
			case 'E':
				dam = e;
				e = u; u = w; w = d; d = dam;
				break;
			case 'N':
				dam = n;
				n = u; u = s; s = d; d = dam;
				break;
			case 'S':
				dam = s;
				s = u; u = n; n = d; d = dam;
				break;
			case 'W':
				dam = w;
				w = u; u = e; e = d; d = dam;
				break;
			case 'X'://???????????¢
				dam = w;
				w = s; s = e; e = n; n = dam;
				break;
			default:
				break;
			}
		}
	}	
	
	void display(char direction){
		switch (direction){
			case 'E': printf("%d\n",e); break;
			case 'N': printf("%d\n",n); break;
			case 'S': printf("%d\n",s); break;
			case 'W': printf("%d\n",w); break;
			case 'U': printf("%d\n",u); break;
			case 'D': printf("%d\n",d); break;
			default: break;
		}
	}
};


int main(){

	int num[6];
	
	for (int i = 0; i < 6; i++) cin >> num[i];
	Dice d0 = num;
	for (int i = 0; i < 6; i++) cin >> num[i];
	Dice d1 = num;
	
		//d0.u??¨?????????d1???u???
		int a = d0.u;
		int b = d0.s;
		if (d1.n == a) d1.rotate("S");
		else if(d1.e == a) d1.rotate("W");
		else if(d1.s == a) d1.rotate("N");
		else if(d1.w == a) d1.rotate("E");
		else if(d1.d == a) d1.rotate("EE");
		for (int j = 0; j < 4; j++){
			if (d1.s == b) {
				if (d1.e == d0.e){
					cout << "Yes" << endl;
					break;
				}
				else {
					cout << "No" << endl;
					break;
				}
			}
			if ( j == 3 ){
				cout << "No" << endl;
				break;
			}
			d1.rotate("X");
		}
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans;
  if(n%1000 == 0) {
    ans = 0;
  } else {
    ans = 1000-n%1000;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
s = int(input())
MOD = 10**9+7

dp = [0]*2001
dp[0] = 1
dp[1] = 0
dp[2] = 0
for i in range(3, 2001):
    for j in range(3, i+1):
        dp[i] += dp[i-j]
        dp[i] %= MOD

print(dp[s])

Measured memory_bytes: 64916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX = 1000005;
const ll MOD = 1000000007;
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;}

int main(){
  string s;
  cin >> s;
  int l = s.length();
  int res = 0;
  for(int i=0;i<l;i++){
    if(s[2*i+1] == 'L'||s[2*i+1] == 'U'||s[2*i+1] == 'D') res++;
    if(s[2*i] =='R'||s[2*i] =='U'||s[2*i] =='D') res++;
  }
  if(res == l) cout << "Yes";
  else cout << "No";
  return 0;
}

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

using namespace std;

int n;
long long x, a[6969], b[6969], c[6969];

int main() {
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
  	cin >> a[i];
  	b[i] = a[i];
  }
  long long ans = LLONG_MAX;
  for (int k = 0; k < n; ++k) {
  	long long cur = k * x;
  	for (int i = 0; i < n; ++i) cur += b[i];
  	ans = min(ans, cur);
  	for (int i = 0; i < n; ++i) c[i] = min(b[i], a[(i - k - 1 + n) % n]);
  	for (int i = 0; i < n; ++i) b[i] = c[i];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
const ll inf=1e16;
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int n,x,y,z;
ll mx[100050],ans=-inf;
inline ll Max(ll a,ll b){
  return a>b?a:b;
}
struct date{
  int a,b,c,s;
  bool operator < (const date &c) const {
    return s<c.s;
  }
}t[100050];
priority_queue<int>a,b;
int main(){
  x=gi(),y=gi(),z=gi(),n=x+y+z;
  ll sum=0,op=0;
  for (int i=1; i<=n; ++i){
    t[i]=(date){gi(),gi(),gi()};
    t[i].s=t[i].a-t[i].b;
    op+=t[i].c;
  }
  sort(t+1,t+n+1);
  for (int i=1; i<=y; ++i)
    a.push(t[i].c-t[i].b),mx[y]+=t[i].b-t[i].c;
  for (int i=y+1; i<=n; ++i){
    a.push(t[i].c-t[i].b),mx[i]=mx[i-1]+t[i].b-t[i].c;
    mx[i]+=a.top(),a.pop();
  }
  for (int i=n; i>n-x; --i)
    b.push(t[i].c-t[i].a),sum+=t[i].a-t[i].c;
  ans=Max(ans,sum+mx[n-x]);
  for (int i=n-x; i>y; --i){
    b.push(t[i].c-t[i].a),sum+=t[i].a-t[i].c;
    sum+=b.top(),b.pop();
    ans=Max(ans,sum+mx[i-1]);
  }
  cout<<ans+op;
  return 0;
}


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

public class Program
{
	public static void Main()
	{
		int[] NT = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int ans = 0;
		int max = int.MinValue;
		int min = A[0];
		foreach (var item in A)
		{
			if (item - min > max)
			{
				max = item - min;
				ans = 1;
			}
			else if (item - min == max)
			{
				++ans;
			}
			min = Math.Min(min, item);
		}
		Console.WriteLine(ans);
	}
}

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

int main()
{
	ll a;
	double b;
	scanf("%lld %lf",&a,&b);
	b=b+1e-7;
	ll c=b*100;
	ll d=c*a/100;
	printf("%lld",d);
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

int main(){
    int N;
    vector<ll> A;
    ll sub;
    int negative_cnt = 0;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> sub;
        A.push_back(sub);
        if(A[i] < 0){
            negative_cnt++;
        }
    }
    
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ans += abs(A[i]);
    }
    
    if(negative_cnt % 2 != 0){
        ll min_element = LONG_MAX;
        for(int i = 0; i < N; i++){
            min_element = min(min_element, abs(A[i]));
        }
        
        ans -= 2 * min_element;
    }
    
    cout << ans << endl;
}

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

string LCS(string s1, string s2)
{
    int n1=s1.length(),n2=s2.length();
    
     vector<vector<int>>dp(n1+1,vector<int>(n2+1));
    
    for(int i=0;i<=n1;i++)
    {
        for(int j=0;j<=n2;j++)
        {
           
            if(i==0||j==0)dp[i][j]=0;
            else if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else
              dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
        
    }
   
    string s3="";
    int i=n1,j=n2;
    while(i>0&&j>0)
    {
        
        if(s1[i-1]==s2[j-1])
        {
            s3+=s1[i-1];
            i--;
            j--;
        }
       else if(dp[i-1][j]>dp[i][j-1])i--;
        else j--;
    }reverse(s3.begin(),s3.end());
    return s3;
}

int main() {
    string s1, s2;
    cin>>s1>>s2;
    
    
	cout<<LCS(s1,s2);
	return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H;
    cin >> H;
    ll answer = 0;
    ll currentNum = 1;
    ll currentHp = H;
    while(currentHp)
    {
        answer += currentNum;
        currentNum *= 2;
        currentHp /= 2;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
c=Array.new(40,0)
n.times do
  k,*a=gets.split.map(&:to_i)
  k.times do |i|
   c[a[i]]+=1
  end
end  
cnt=0
c.each do |ce|
  if ce==n
    cnt+=1
  end
end
p cnt

Measured memory_bytes: 1788
n, m = [ int(v) for v in input().split() ]
l1, r1 = [ int(v) for v in input().split() ]

def connect(a,b,c,d):
	x = max(a,c)
	y = min(b,d)
	if y < x:
		return 0
	else:
		return (x,y)
ans2 = 1
ans = (l1, r1)
for i in range(m-1):
	l, r = [ int(v) for v in input().split() ]
	if connect(l,r,l1,r1) != 0:
		l1, r1 = connect(l,r,l1,r1)
		ans = (l1, r1)
	else:
		ans2 = 0
		break

if ans2 == 0:
	ans = 0
else:
	ans = ans[1] - ans[0] +1
print(ans)


Measured memory_bytes: 3064
/* Simplicity and Goodness */

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

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;


void solve()
{
    int x;
    scn(x);

    if(x >= 400 and x <= 599) prin(8);
    else if(x >= 600 and x <= 799) prin(7);
    else if(x >= 800 and x <= 999) prin(6);
    else if(x >= 1000 and x <= 1199) prin(5);
    else if(x >= 1200 and x <= 1399) prin(4);
    else if(x >= 1400 and x <= 1599) prin(3);
    else if(x >= 1600 and x <= 1799) prin(2);
    else prin(1);
}

int main()
{
    int t = 1;
    // scn(t);
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var a = ReadLongs();

            if (N == 1)
            {
                return $"1 1";
            }

            var count = 0L;
            if (a.Any(x => 1 <= x && x <= 399)) count++;
            if (a.Any(x => 400 <= x && x <= 799)) count++;
            if (a.Any(x => 800 <= x && x <= 1199)) count++;
            if (a.Any(x => 1200 <= x && x <= 1599)) count++;
            if (a.Any(x => 1600 <= x && x <= 1999)) count++;
            if (a.Any(x => 2000 <= x && x <= 2399)) count++;
            if (a.Any(x => 2400 <= x && x <= 2799)) count++;
            if (a.Any(x => 2800 <= x && x <= 3199)) count++;

            var xCount = a.Count(x => x >= 3200);
            /*
            レート 1-399：灰色
            レート 400-799：茶色
            レート 800-1199：緑色
            レート 1200-1599：水色
            レート 1600-1999：青色
            レート 2000-2399：黄色
            レート 2400-2799：橙色
            レート 2800-3199：赤色
             */
            return $"{(count == 0 ? 1 : count)} {count + xCount}";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28264
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N, A[101010];
int dp[101][10101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    
    dp[0][0] = 1;
    rep(i, 0, N) rep(j, 0, 10001) if(dp[i][j]) {
        dp[i + 1][j] = 1;
        dp[i + 1][j + A[i]] = 1;
    }

    int ans = 0;
    rep(j, 0, 10001) if (j % 10 && dp[N][j]) ans = max(ans, j);
    cout << ans << endl;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;


vector<int64_t> f(300000,1);
vector<bool> seen(300000,false);
int64_t aa;

void dfs(const vector<vector<int64_t> >& A, int64_t v) {
  queue<int64_t> q;
    seen[v] = true; // v を訪問済にする
    for (int i=0; i<A[v].size(); i++) {
        if (seen[A[v][i]]) continue; // next_v が探索済だったらスルー
        // q.push(A[v][i]);
        f[aa]++;
      // cout<<v<<" "<<A[v][i]<<endl;
        dfs(A, A[v][i]); // 再帰的に探索
    }
      //  while(q.size()>0){
      //    int64_t tmp= q.front();
      //    q.pop();
      //  } 
}

int main() {
  map<pair<int,int>,int> g;
 
  int64_t N,M,m=-1;
  cin>>N>>M;
  vector<vector<int64_t> > A(N+1,vector<int64_t>(0));
  // vector<vector<int64_t> > A(N,vector<inint64_t>(M));
  for(int i=0; i<M; i++){
    int64_t a,b,t;
    cin>>a>>b;
    if(a>b){
      t=a;
      a=b;
      b=t;
    }
    if(!g.count(make_pair(a,b))){
      A[a].push_back(b);
      A[b].push_back(a); //無効グラフやからどっちも
      g[make_pair(a,b)]=1;
    }
  }
  for(int i=1; i<N+1; i++){
    aa=i;
    dfs(A,i);
    // m=max(m,f[i]);
  }

  for(int i=1; i<N+1; i++){
    // cout<<f[i]<<endl;
    m=max(m,f[i]);
  }
  //for(int i=0; i<N; i++){
  //   for(int j=0; j<M; j++){
  //       cin>>A[i][j];
  //   }
  // }
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << m << endl;
}

Measured memory_bytes: 175856
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, res;

int cnt(int a) {
	int ret = 0;
	reps(i,1,a+1) if (a%i==0) ret++;
	return ret;
}

signed main() {
	cin >> n;
	reps(i,1,n+1) if (i%2 && cnt(i)==8) res++;
	cout << res << ln;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int sum=0;
  rep(i,5){
    int tmp;
    cin>>tmp;
    if(tmp<40)tmp=40;
    sum+=tmp;
  }
  cout<<sum/5<<endl;

}
/*int main(){
  int sum=0;
  int tmp;
  rep(i,5){
    cin>>tmp;
    if(tmp>=40)sum+=tmp;
    else sum+=40;
  }
  cout<<sum/5<<endl;


}
*/

Measured memory_bytes: 1160
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
priority_queue<int> pq;
int n;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int x;
		cin >>x;
		pq.push(-x);
	}
	while (pq.size()>1)
	{
		int x=-pq.top();
		pq.pop();
		int y=-pq.top();
		//cout <<x<<" "<<y<<" \n";
		pq.pop();
		pq.push(-x);
		if (y>x && y%x) pq.push(-(y%x));
	}
	cout <<-pq.top();
	return 0;
}

Measured memory_bytes: 892
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		boolean north = false;
		boolean south = false;
		boolean west = false;
		boolean east = false;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'N') {
				north = true;
			} else if(s.charAt(i) == 'S') {
				south = true;
			} else if(s.charAt(i) == 'W') {
				west = true;
			} else {
				east = true;
			}
		}
		if((north && south && !east && !west) || (east && west && !north && !south) || (east && west && north && south)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35764
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <limits>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p));
#define mp make_pair;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);}

long double retpow(long double a) {
	long double ans=1;
	for (long double i = 0; ;++i)
	{
		if (ans>=a) return i;
		ans*=2; 
	}
	cout<<"error"<<endl;
	return -1;
}

int main() {
	fast();
	long double n,k,temp;
	long double ans=0;
	cin>>n>>k;
	for (int i = 1; i <= n; ++i)
	{
		temp = retpow(k/i);
		ans+=1/pow(2,temp);
	}
	ans/=n;
	cout.precision(40);
	cout<<fixed<<ans<<endl;
}

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

int N;

int main() {
    cin >> N;
    vector<long long> A(N + 1), B(N + 1);
    for (int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    B[N] = 0;
    long long rest = 0;
    long long ans = 0;
    for (int i = 0; i < N + 1; i++) {
        ans += min(rest, A[i]);
        A[i] -= min(rest, A[i]);
        ans += min(B[i], A[i]);
        rest = B[i] - min(B[i], A[i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import re
while 1:
    n,m=map(int,input().split())
    if n==0:break
    p=[];s=0
    for _ in [0]*n:
        n,M=input().replace('*','[0-9]').split()
        p.append([re.compile(n),int(M)])
    for _ in [0]*m:
        l=input()
        for n,M in p:
            if n.search(l):
                s+=M;break
    print(s)

Measured memory_bytes: 8144
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
string s; int n, u, v;

int main(void)
{
	cin>>s; n=s.length(); u=n%2;
	if(s[0]==s[n-1]) v=1;
	if(u==v) cout<<"Second";
	else cout<<"First";
	return 0;
}

// it may be easier than you think
// it may be harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = ReadIntArray();
            if ((r[0] == r[1] || r[1] == r[2] || r[0] == r[2]) && !(r[0] == r[1] && r[1] == r[2]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int pos[2][2005],c[4005],dp[2005][2005],w,n;
void add(int x,int p){
	for(int i=x;i<=w;i+=i&-i)c[i]+=p;
}
int sum(int x){
	int ans=0;
	for(int i=x;i>=1;i-=i&-i)ans+=c[i];
	return ans;
}
int main(){
	scanf("%d",&n);
	w=2*n;
	for(int i=1;i<=w;i++){
		char s[2];int x;
		scanf("%s%d",s,&x);
		pos[s[0]=='W'][x]=i;
		add(i,1);
	}
	pos[0][0]=pos[1][0]=w+1;
	for(int i=0;i<=n;i++){
		add(pos[0][i],-1);
		for(int j=0;j<=n;j++){
			add(pos[1][j],-1);
			if(i||j){
				dp[i][j]=1e9;
				if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+sum(pos[0][i]-1));
				if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+sum(pos[1][j]-1));	
			}
		}
		for(int j=0;j<=n;j++)add(pos[1][j],1);
	}
	printf("%d\n",dp[n][n]);
}

Measured memory_bytes: 19528
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
using namespace std;


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

  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

  vector<int> dpA(N, -1), dpB(N, -1), dpC(N, -1);
  dpA[0] = a[0]; dpB[0] = b[0]; dpC[0] = c[0];

  for (int i = 1; i < N; i++) {
    dpA[i] = max(dpB[i-1], dpC[i-1]) + a[i];
    dpB[i] = max(dpC[i-1], dpA[i-1]) + b[i];
    dpC[i] = max(dpA[i-1], dpB[i-1]) + c[i];
  }

  cout << max(dpA[N-1], max(dpB[N-1], dpC[N-1])) << endl;

  return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,k,x,y;
	scanf("%lld%lld%lld%lld",&n,&k,&x,&y);
	if(n<=k)printf("%lld",x*n);
	else printf("%lld",x*k+y*(n-k));
}

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

struct Node {
    int idx, parent;
};

map<int, vector<int>> Edges;
int parent[200001];
int64_t ret[200001];


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

    int N, Q;
    cin >> N >> Q;
    for (int i = 1; i <= N - 1; i++) {
        int a, b;
        cin >> a >> b;
        Edges[a].push_back(b);
        Edges[b].push_back(a);
    }
    map<int, int> Add;
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        if (Add[p]) Add[p] += x;
        else
            Add[p] = x;
    }

    queue<int> que;
    que.push(1);
    parent[1] = -1;
    while (!que.empty()) {
        int i = que.front();
        que.pop();
        if (Add[i]) ret[i] += Add[i];
        for (auto &j : Edges[i]) {
            if (parent[j] != 0) continue;
            parent[j] = i;
            ret[j] += ret[i];
            que.push(j);
        }
    }

    for (int i = 1; i <= N; i++) {
        if (i > 1) cout << " ";
        cout << ret[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 36600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);


struct P{
  double x;
  double y;

  P(){
	x = 0, y = 0;
  }

  P(const double &s , const double &e)
  { x=s; y=e;}

  P operator - (const P &t) const
  { return P(x-t.x , y-t.y); }

  P operator + (const P &t) const
  { return P(x+t.x , y+t.y); }

  P operator * (const double &d) const
  { return P(x*d , y*d); }

};

P rotate(P t , P p , double r){
  double ta=cos(r)*(t.x-p.x)-sin(r)*(t.y-p.y)+p.x;
  double tb=sin(r)*(t.x-p.x)+cos(r)*(t.y-p.y)+p.y;
  return P(ta , tb);
}

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

  int N; cin >> N;
  vector<P> ps[2];
  int crt = 0, nxt = 1;
  ps[crt].PB(P(0,0));
  ps[crt].PB(P(100,0));
  while(N--){
	ps[nxt].clear();
	ps[nxt].PB(ps[crt][0]);
	REP(i,SZ(ps[crt])-1){
	  P p1 = ps[crt][i], p2 = ps[crt][i+1];
	  P q1 = (p1*2 + p2) * (1. / 3);
	  P q2 = (p1 + p2*2) * (1. / 3);
	  P q3 = rotate(q1, q2, -PI / 3.);
	  ps[nxt].PB(q1);
	  ps[nxt].PB(q3);
	  ps[nxt].PB(q2);
	  ps[nxt].PB(p2);
	}
	swap(crt, nxt);
  }

  REP(i,SZ(ps[crt]))
	cout << fixed << setprecision(9) << ps[crt][i].x << " " << ps[crt][i].y << endl;
  
  return 0;
}

Measured memory_bytes: 1392
from functools import reduce
from math import ceil

n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[0], reverse=True)
max_a = ab[0][0]
ab = list(filter(lambda x: x[1] >= max_a, ab))

ab.sort(key=lambda x: x[1], reverse=True)
for i, v in enumerate(ab):
    h -= v[1]
    if h <= 0:
        print(i+1)
        exit()

res = ceil(h / max_a) + len(ab)
print(res)



Measured memory_bytes: 29520
"""
https://abc058.contest.atcoder.jp/tasks/abc058_b
"""
o=input()
e=input()
p=""
if len(o)-len(e)==0:
    for i in range(len(o)):
        p=p+o[i]+e[i]
    print(p)
else:
    for i in range(len(e)):
        p=p=p+o[i]+e[i]
    p=p+o[len(o)-1]
    print(p)


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

template <typename T>
class fenwick_tree {
	const int n;
	vector<T> data;
public:
	fenwick_tree(int n_) : n(n_), data(n + 1) {}
	T find(int p) const {
		T res = 0;
		while (p > 0) {
			res += data[p];
			p -= p & -p;
		}
		return res;
	}
	void add(int p, T val) {
		++p;
		while (p <= n) {
			data[p] += val;
			p += p & -p;
		}
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<int> a(N), xs;
	for (int i = 0; i < N; i++) {
		cin >> a[i]; xs.push_back(a[i]);
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < N; i++) {
		a[i] = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
	}
	ll k = (ll)N * (N + 1) / 2;
	int lb = -1, ub = xs.size() - 1;
	while (ub - lb > 1) {
		int c = (lb + ub) >> 1;
		vector<int> sum(N + 1); sum[0] = N;
		for (int i = 0; i < N; i++) {
			sum[i + 1] = sum[i] + (a[i] <= c ? 1 : -1);
		}
		ll cnt = 0;
		fenwick_tree<int> ft(N + N + 1);
		for (int i = 0; i <= N; i++) {
			cnt += ft.find(sum[i]);
			ft.add(sum[i], 1);
		}
		((cnt << 1LL) > k ? ub : lb) = c;
	}
	cout << xs[ub] << endl;
	return 0;
}


Measured memory_bytes: 2296
<?php

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

//最大公約数
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}
 
//最小公倍数
function lcm($m, $n){
    return $m * $n / gcd($m, $n);
}

$lcmnm = lcm($n, $m);

$l = [];

for ($i = 0; $i < $n; $i++) {
    $l[$lcmnm / $n * $i] = $s[$i];
}

$result = true;
for ($i = 0; $i < $m; $i++) {
    if (isset($l[$lcmnm / $m * $i]) && $l[$lcmnm / $m * $i] != $t[$i]) {
        $result = false;
        break;
    }
}

if ($result) {
    echo $lcmnm . "\n";
} else {
    echo "-1\n";
}

Measured memory_bytes: 13048