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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010


//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll red[a],green[b],ans=0;
    vector<ll > color(c,0);
    for(int i=0;i<a;i++)
        cin>>red[i];
    for(int i=0;i<b;i++)
        cin>>green[i];
    for(int i=0;i<c;i++)
        cin>>color[i];
    sort(red,red+a,greater<ll>());
    sort(green,green+b,greater<ll>());
    for(int i=0;i<x;i++)
        color.pb(red[i]);
    for(int i=0;i<y;i++)
        color.pb(green[i]);
    sort(color.begin(),color.end(),greater<ll>());
    for(int i=0;i<x+y;i++)
        ans+=color[i];
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 6000
# 優先度付きキューとか言うものが使えるかどうかが鍵になる
# pythonでは標準でheapqが使える．要するにヒープのこと．ただしヒープでは最小値しか取り出せないのでそこに注意する必要がある.
# 計算量はO(log(N))になる
N,M = map(int,input().split())
A = list(map(int,input().split()))
# 解法 bisectとsort(最初だけ)を使う
# dequeでbisectって使えんのかなぁ？
#A.sort()
#from collections import deque
#A = deque(A)
A = [-a for a in A]
import heapq
heapq.heapify(A)
import bisect
for i in range(M):
    a = heapq.heappop(A)
    new = a/2
    # listに挿入する．ただしpythonのlistは可変長配列なので，linked-listではない.それゆえ末尾や先頭以外への要素の挿入はO(N)かかる
    #bisect.insort_left(A,new)   # やってることはA.sort(bisect.bisect_left(A,new),new)．
    heapq.heappush(A,new)
import numpy as np
A = np.array(A,dtype=np.int64)
print(-A.sum())



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

int main() {
  int M, D;
  cin >> M >> D;

  int ans = 0;
  for (int i = 2; i <= M; i++) {
    for (int j = 1; j <= D; j++) {
      if (j >= 10) {
        int d1 = j % 10;
        int d10 = (j / 10) % 10;
        if (d1 >= 2 && d10 >= 2 && d1 * d10 == i)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
a = []
for i in range(n):
    a.append(int(input()))

dp = [[] for _ in range(n)]
#dp
dp[1].append(0)
M = 1
for i in range(1, n):
    m = M
    flg = 0
    while m > 0:
        for p in dp[m]:
            if abs(a[i]-a[p]) <= k:
                dp[m+1].append(i)
                flg = 1
                if m + 1 > M:
                    M = m+1
                break
        if flg == 1:
            break
        m -= 1
    if flg == 0:
        dp[1].append(i) #i
        
print(M)

Measured memory_bytes: 123304
#include <iostream>
#include <algorithm>
using namespace std;
int main(){	
	int a[4];
	cin >> a[0]>>a[1]>>a[2];
	for (int i=0;i<3;i++){
		for (int j=3;j>i;j--){
			if(a[j-1]<a[i])	{
			int d= a[j-1];
			a[j-1]=a[i];
			a[i]=d;	
			}
		}
	}
	cout << a[2]*10+a[1]+a[0]<<endl;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  vector<int> b(1e5+2);
  for(int i = 0; i < b.size(); i++){
    b[i] = 0;
  }
  for(int i = 0; i < N; i++){
    if(a[i] > 0){
      b[a[i]-1]++;
    }
    b[a[i]]++;
    b[a[i]+1]++;
  }

  int ans = 0;
  for(int i = 0; i < b.size(); i++){
    chmax(ans, b[i]);
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i > b; --i)
#define REP(i, n)    for(uint i = 0; i < n; ++i)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

ul min2(ul a, ul b){
    return a < b? a : b;
}
ul max2(ul a, ul b){
    return a > b? a : b;
}

ul min(ul a, ul b, ul c){
    return min2(min2(a, b), c);
}
ul max(ul a, ul b, ul c){
    return max2(max2(a, b), c);
}

ul shapeT(ul H, ul W){
   ul x, y;
    x = W / 2;
    y = H / 3;
    ul a = W * y, b = x * (H - y), c = (W - x) * (H - y);
    ul d1 = max(a, b, c) - min(a, b, c);

    y++;
    a = W * y, b = x * (H - y), c = (W - x) * (H - y);
    ul d2 = max(a, b, c) - min(a, b, c);

    y++;
    a = W * y, b = x * (H - y), c = (W - x) * (H - y);
    ul d3 = max(a, b, c) - min(a, b, c);

    return min(d1, d2, d3);
}

ul shape3(ul H, ul W){
    ul h = H / 3;
    ul h1 = (H - h) / 2;
    ul a = h * W, b = h1 * W, c = (H - h1 - h) * W;
    ul d1 = max(a, b, c) - min(a, b, c);

    h++;
    h1 = (H - h) / 2;
    a = h * W, b = h1 * W, c = (H - h1 - h) * W;
    ul d2 = max(a, b, c) - min(a, b, c);

    h++;
    h1 = (H - h) / 2;
    a = h * W, b = h1 * W, c = (H - h1 - h) * W;
    ul d3 = max(a, b, c) - min(a, b, c);

    return min(d1, d2, d3);
}

int main(){
    ul H, W; cin >> H >> W;
    ul ans = -1;
    if(H % 3 == 0 || W % 3 == 0){
        ans = 0;
    }else{
        ans = min2(shapeT(H, W), shapeT(W, H));
        if(H >= 3){
            ans = min2(ans, shape3(H, W));
        }
        if(W >= 3){
            ans = min2(ans, shape3(W, H));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
L=[]
x=1
L.append(input())
for i in range(N-1):
    W=input()
    if W in L:
        x=0
    L.append(W)
    if L[i][-1]!=L[i+1][0]:
        x=0
if x==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61676
#include <stdio.h>
#include <inttypes.h>
#include <string.h>

int x[4], y[4];

uint64_t memo[1 << 16];

uint64_t search(int current) {
	int i, j, k;
	if (current == (1 << 16) - 1) return 1;
	if (memo[current]) return ~memo[current];
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (!((current >> (i * 4 + j)) & 1)) {
				uint64_t ret = 0;
				int next = current | (1 << (i * 4 + j));
				for (k = 0; k < 8; k++) {
					int ni, nj;
					if (k % 2 == 0) {
						ni = i + y[k / 2];
						nj = j + x[k / 2];
					} else {
						ni = i - y[k / 2];
						nj = j - x[k / 2];
					}
					if (0 <= ni && ni < 4 && 0 <= nj && nj < 4 && !((current >> (ni * 4 + nj)) & 1)) {
						ret += search(next | (1 << (ni * 4 + nj)));
					}
				}
				return ~(memo[current] = ~ret);
			}
		}
	}
	return 0; /* will not come here */
}

int main(void) {
	while (scanf("%d", &x[0]) == 1 && x[0] <= 4) {
		int i;
		if (scanf("%d", &y[0]) != 1) return 1;
		for (i = 1; i < 4; i++) {
			if (scanf("%d%d", &x[i], &y[i]) != 2) return 1;
		}
		memset(memo, 0, sizeof(memo));
		printf("%"PRIu64"\n", search(0));
	}
	return 0;
}

Measured memory_bytes: 1124
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>
#include <stack>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli mod197 = 1000000007LL;
constexpr lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}



int main(void) {

	lli N, K, X , Y;
	cin >> N >> K >> X >> Y;

	if (N > K) {
		COUT(X * K + (N - K) * Y);
	}
	else {
		COUT(X * N);
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = null;
        List<String> scanList = new ArrayList<String>();

        try {
            scan = new Scanner(System.in);
            while(scan.hasNext()){
                String str = scan.nextLine();
                scanList.add(str);
            }


        } finally {
            scan.close();
        }

        String strN = null;
        //N人リスト
        List<Integer> nList = new ArrayList<Integer>();

        // 読込
        int i = 0;
        for(String str : scanList) {
        // for(int i=0; i < scanList.size(); i++) {
            
            if(i == 0) {
                strN = str.substring(0, str.indexOf(" "));
                for(int k=0; k<Integer.valueOf(strN); k++) {
                    nList.add(k+1);
                }
            } else if (i != 0 && 0 == i % 2) {
                String[] sList = str.split(" ");
                for(int j=0; j<sList.length; j++) {
                    int targetInt = Integer.valueOf(sList[j]);
                    if(nList.contains(targetInt)) {
                        nList.remove(nList.indexOf(targetInt));
                    }
                }
            }
            i++;
        }

        //結果
        System.out.println(nList.size());

    }
}


Measured memory_bytes: 37188
// Solution of Problem : https://www.hackerrank.com/contests/hourrank-21/challenges/sams-numbers
// Change value of mod

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000009// Change mod value
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define space printf(" ")
#define endl printf("\n")
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define slld(x) scanf("%lld", &(x))
#define plld(x) printf("%lld", (x))
#define plldn(x) printf("%lld\n", (x))
#define sllf(x) scanf("%llf", &(x))
#define pllf(x) printf("%.9llf", (x))
#define pllfn(x) printf("%.9llf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin);freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp()//true for a before b
{
	bool ans = 0;
	return ans;
}

struct ST_Node
{
	ST_Node()
	{

	}
	void assign_value_()
	{

	}
	void merge_nodes_()
	{

	}
};

const int N = (1e5) + 9;
const int M = (1e5) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;

ll a[N];

bool func(int v, int n, ll A, ll B)
{
	int i;
	ll val = (ll)v, sum = 0LL;
	fo(i,1,n+1)
	{
		if(a[i] >= val*B)
		{
			sum += ((a[i]-val*B)/(A-B));
			if((a[i]-val*B) % (A-B) != 0)
				sum++;
		}
	}
	if(sum <= val)
		return 1;
	return 0;
}

int binsea(int l, int r, int n, ll A, ll B)
{
	if(l > r)
		return INF;
	int mid = (l+r)>>1;
	if(l == r)
	{
		if(func(mid,n,A,B))
			return mid;
		return INF;
	}
	if(func(mid,n,A,B))
		return min(mid, binsea(l,mid-1,n,A,B));
	return binsea(mid+1,r,n,A,B);
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int n, i, ans;
	ll A, B;
	cin >> n >> A >> B;
	fo(i,1,n+1)
		cin >> a[i];
	ans = binsea(0,INF,n,A,B);
	cout << ans;
	// Code ends here

	// clk = clock() - clk;
	// cout << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> v[n];
	for(int i=0;i<m;i++)
	{
		int x, y;
		cin >>x >> y;
		x--;
		//y--;
		v[x].pb({y, i});
	}	
	for(int i=0;i<n;i++)
		sort(v[i].begin(), v[i].end());
	char ans[m][12];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			int index = v[i][j].second;
			int first = i+1;
			char s[6];
			for(int k=5;k>=0;k--)
			{
				s[k] = first%10+ '0';
				first/=10;
			}
			int second = j+1;
			char z[6];
			for(int k=5;k>=0;k--)
			{
				z[k] = second%10 +'0';
				second/=10;
			}
			for(int k=0;k<6;k++)
				ans[index][k] = s[k];
			for(int k=6;k<12;k++)
				ans[index][k] = z[k-6];
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<12;j++)
			cout << ans[i][j];
		cout << "\n";
	}

	return 0;
}

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

using namespace std;

string naming(string s,int k){
  int len=s.length();
  string res="";
  bool flag=true;//?????????
  for(int i=0;i<len;i++){
    if(flag) res+=s[i];
    if(s[i]=='a'||s[i]=='i'||s[i]=='u'||s[i]=='e'||s[i]=='o')flag=true;
    else flag=false;
  }
  string memo="";
  for(int i=0;i<k;i++) memo+=res[i];
  if((int)res.length()<k)return res;
  else return memo;
}

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

  while(true){
    int n;cin>>n;
    if(n==0) break;
    int ma=-1;
    string ports[n];
    for(int i=0;i<n;i++){
      cin>>ports[i];
      ma=max((int)ports[i].length(),ma);
    }
    bool flag=false;
    for(int k=1;k<=ma;k++){
      set<string> st;
      bool judge=true;
      for(int i=0;i<n;i++){
        string kouho=naming(ports[i],k);
        //cout <<kouho<<endl;
        if(st.find(kouho)!=st.end()){
          judge=false;
          break;
        }
        st.insert(kouho);
      }
      if(judge){
        cout << k <<endl;
        flag=true;
        break;
      }
    }
    if(!flag) cout <<-1<<endl;
  }
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,i,j,n;
    cin>>n>>k;
    long long int A[n],p=0;
    for(i=0;i<n;i++)
        cin>>A[i];
    if(k>=n)
        cout<<"0";
    else
    {
      sort(A,A+n);
      for(i=0;i<n-k;i++)
        p=p+A[i];
      cout<<p;
    }
}


Measured memory_bytes: 1792
#include<cstdio>  
#include<cstring>  
#include<vector>  
#include<map>  
#include<algorithm>  
using namespace std;  
const int maxn=10000+10;  
const int maxm=100000+10;  
int n,m;  
struct node  
{  
    char s[20];  
    bool operator <(const node& rhs)const  
    {  
        return strcmp(s,rhs.s)<0;  
    }  
};  
map<node,int> mp;
struct Edge  
{  
    node u,v;  
    bool flag;
}e[maxm];  
vector<int> G[maxn];  
int pre[maxn],low[maxn];  
int dfs_clock;  
void tarjan(int u,int fa)  
{  
    low[u]=pre[u]=++dfs_clock;  
    for(int i=0;i<G[u].size();i++)  
    {  
        int v=G[u][i];  
        if(v==fa) continue;  
        if(!pre[v])  
        {  
            tarjan(v,u);  
            low[u]=min(low[u],low[v]);  
        }  
        else low[u] = min(low[u],pre[v]);  
    }  
}  
int main()  
{  
   
   
        int id=0;  
        scanf("%d%d",&n,&m);  
        mp.clear();  
        dfs_clock=0;  
        memset(pre,0,sizeof(pre));  
        for(int i=1;i<=n;i++) G[i].clear();  
        for(int i=0;i<m;i++)  
        {  
            e[i].flag=false;  
            scanf("%s%s",e[i].u.s,e[i].v.s);  
            if(mp.find(e[i].u)==mp.end()) mp[e[i].u]= ++id;  
            if(mp.find(e[i].v)==mp.end()) mp[e[i].v]= ++id;  
            int x = mp[e[i].u], y=mp[e[i].v];  
            G[x].push_back(y);  
            G[y].push_back(x);  
        }  
        tarjan(1,-1);  
        bool ok=true;
        for(int i=1;i<=n;i++)if(!pre[i])  
        {  
            ok=false;  
            break;  
        }  
        if(!ok) printf("0\n");  
        else  
        {  
            int ans=0;
            for(int i=0;i<m;i++)  
            {  
                int u=mp[e[i].u], v=mp[e[i].v];  
                if(low[u]>pre[v]||low[v]>pre[u]) e[i].flag=true,ans++;  
            }  
            printf("%d\n",ans);  
        }  
 
    return 0;  
} 

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define pb push_back
#define LN 30
#define P(x) (100+(x))//2^x
#define P_B(x) (200+(x))//(2^x)*B
using namespace std;
vector<string> ans;
I void Mul1(CI x,CI p)//a[8]=a[x]*(2^i)
{
	cout<<"+ 1000 "<<x<<" 8\n";for(int i=1;i<=p;++i) puts("+ 8 8 8");
}
I void Mul2(CI x,CI y)//a[9]=a[x]*a[y]
{
	//15:a[y]+1 10:now_mul 11:new_mul 12:check 13:AND
	cout<<"+ 4 "<<y<<" 15\n",puts("+ 1000 1000 9"),puts("+ 1000 1000 10");
	for(RI i=2*LN;~i;--i) cout<<"+ 10 "<<P(i)<<" 11\n",puts("< 11 15 12"),
		Mul1(12,i),puts("+ 10 8 10"),cout<<"+ "<<x<<" 12 13\n",puts("< 4 13 13"),Mul1(13,i),puts("+ 9 8 9");
}
int main()
{
	//0:A 1:B 3:A+1 4:1 1000:0
	RI i;puts("129398"),puts("+ 0 1 4"),puts("+ 0 4 4"),puts("+ 1 4 4"),puts("< 0 4 4"),puts("+ 0 4 3");
	for(puts("+ 4 100 100"),i=1;i<=2*LN;++i) cout<<"+ "<<P(i)-1<<" "<<P(i)-1<<" "<<P(i)<<endl;//Init 2^x
	for(puts("+ 1 200 200"),i=1;i<=LN;++i) cout<<"+ "<<P_B(i)-1<<" "<<P_B(i)-1<<" "<<P_B(i)<<endl;//Init (2^x)*B
	//2:ans 5:now_mul 6:new_mul 7:check 8,9:tmp
	for(i=LN;~i;--i) cout<<"+ 5 "<<P(i)<<" 6\n",puts("< 6 3 7"),//Try:now_mul+=2^i
		Mul1(7,i),puts("+ 5 8 5"),Mul2(7,P_B(i)),puts("+ 2 9 2");//Update ans and now_mul
	return 0;
}

Measured memory_bytes: 3476
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef long double LD;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 200005;
const LD INF = 1e18;

int A[N];
long double vals[N];
LL SUF[N], PRE[N], UPD[N];
vi st;
int n;

LD getVal(int idx) {
  if(idx == n + 1 || idx == 0) {
    return INF;
  }
  return vals[idx] + UPD[idx];
}

int main() {
  S(n);
  rep(i,1,n+1) {
    S(A[i]);
    vals[i] = log2(A[i]);
  }

  SUF[n + 1] = 0;
  st.pb(n + 1);
  for(int i = n; i >= 1; i--) {
    SUF[i] = SUF[i + 1];
    if(vals[i] <= getVal(i + 1)) {
      st.pb(i);
      continue;
    }
    long double cur = vals[i];
    while(st.size()) {
      int idx = st.back();
      long double nxt = getVal(idx);
      if(cur <= nxt) break;
      int upds = 0;
      while(cur > nxt) {
        nxt += 2.0;
        UPD[idx] += 2;
        upds += 2;
      }
      st.pop_back();
      assert(st.size() >= 1);
      int idx2 = st.back();
      SUF[i] += (idx2 - idx) * 1LL * upds;
      if(idx2 - 1 != idx) {
        UPD[idx2 - 1] += upds;
      }
      cur = getVal(idx2 - 1);
    }
    st.pb(i);
  }

  st.clear();
  PRE[0] = 0;
  st.pb(0);
  memset(UPD, 0, sizeof(UPD));
  rep(i,1,n+1) {
    vals[i] += 1.0; // Multiply atleast once first
    PRE[i] = PRE[i - 1] + 1;
    if(vals[i] <= getVal(i - 1)) {
      st.pb(i);
      continue;
    }
    long double cur = vals[i];
    while(st.size()) {
      int idx = st.back();
      long double nxt = getVal(idx);
      if(cur <= nxt) break;
      int upds = 0;
      while(cur > nxt) {
        nxt += 2.0;
        UPD[idx] += 2;
        upds += 2;
      }
      st.pop_back();
      assert(st.size() >= 1);
      int idx2 = st.back();
      PRE[i] += (idx - idx2) * 1LL * upds;
      if(idx2 + 1 != idx) {
        UPD[idx2 + 1] += upds;
      }
      cur = getVal(idx2 + 1);
    }
    st.pb(i);
  }

  LL ans = SUF[1];
  rep(i,1,n+1) {
    ans = min(ans, PRE[i] + SUF[i + 1]);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 9976
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
ll H,W,N;
set<pair<int,int>>M;
vector<ll>res(10,0);

vector<vector<P>> gmvs(9);
set<tuple<int,int,int,int>>flg;


int main()
{
	gmvs[0]=vector<P>{make_pair(0,0),make_pair(0,1),make_pair(0,2),make_pair(1,0),make_pair(1,1),make_pair(1,2),make_pair(2,0),make_pair(2,1),make_pair(2,2)};
	gmvs[1]=vector<P>{make_pair(0,-1),make_pair(0,0),make_pair(0,1),make_pair(1,-1),make_pair(1,0),make_pair(1,1),make_pair(2,-1),make_pair(2,0),make_pair(2,1)};
	gmvs[2]=vector<P>{make_pair(0,-2),make_pair(0,-1),make_pair(0,0),make_pair(1,-2),make_pair(1,-1),make_pair(1,0),make_pair(2,-2),make_pair(2,-1),make_pair(2,0)};
	gmvs[3]=vector<P>{make_pair(-1,0),make_pair(-1,1),make_pair(-1,2),make_pair(0,0),make_pair(0,1),make_pair(0,2),make_pair(1,0),make_pair(1,1),make_pair(1,2)};
	gmvs[4]=vector<P>{make_pair(-1,-1),make_pair(-1,0),make_pair(-1,1),make_pair(0,-1),make_pair(0,0),make_pair(0,1),make_pair(1,-1),make_pair(1,0),make_pair(1,1)};
	gmvs[5]=vector<P>{make_pair(-1,-2),make_pair(-1,-1),make_pair(-1,0),make_pair(0,-2),make_pair(0,-1),make_pair(0,0),make_pair(1,-2),make_pair(1,-1),make_pair(1,0)};
	gmvs[6]=vector<P>{make_pair(-2,0),make_pair(-2,1),make_pair(-2,2),make_pair(-1,0),make_pair(-1,1),make_pair(-1,2),make_pair(0,0),make_pair(0,1),make_pair(0,2)};
	gmvs[7]=vector<P>{make_pair(-2,-1),make_pair(-2,0),make_pair(-2,1),make_pair(-1,-1),make_pair(-1,0),make_pair(-1,1),make_pair(0,-1),make_pair(0,0),make_pair(0,1)};
	gmvs[8]=vector<P>{make_pair(-2,-2),make_pair(-2,-1),make_pair(-2,0),make_pair(-1,-2),make_pair(-1,-1),make_pair(-1,0),make_pair(0,-2),make_pair(0,-1),make_pair(0,0)};


	cin>>H>>W>>N;
	res[0]=(H-2)*(W-2);
	for(int i=0;i<N;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		M.insert(make_pair(a,b));
	}

	for(auto i=M.begin();i!=M.end();i++)
	{
		for(int gm=0;gm<9;gm++)
		{
			vector<P> mm=gmvs[gm];
			P lu=make_pair((*i).first+mm[0].first,(*i).second+mm[0].second);
			P rd=make_pair((*i).first+mm[8].first,(*i).second+mm[8].second);

			if(lu.first<0||lu.second<0||rd.first>=H||rd.second>=W||
				flg.find(make_tuple(lu.first,lu.second,rd.first,rd.second))!=flg.end())
				continue;

			int t=0;
			for(auto mv:mm)
			{
				if(M.find(make_pair((*i).first+(mv).first,(*i).second+(mv).second))!=M.end())
					t++;
			}
			res[t]++;
			flg.insert(make_tuple(lu.first,lu.second,rd.first,rd.second));
		}
	}


	for(int i=1;i<10;i++)res[0]-=res[i];
	for(int i=0;i<10;i++)
		cout<<res[i]<<endl;
	return 0;
}

Measured memory_bytes: 61184
import java.util.*;class Main{public static void main(String[] args){Scanner c=new Scanner(System.in);long[] s=new long[5];int n=c.nextInt();int a;for(int i=0;i<n;i++){a=0;switch(c.next().charAt(0)){case 'M':a++;case 'A':a++;case 'R':a++;case 'C':a++;case 'H':s[a]++;}}long m=0;for(int i=0;i<3;i++)for(int j=i+1;j<4;j++)for(int k=j+1;k<5;k++)m+=s[i]*s[j]*s[k];System.out.println(m);}}

Measured memory_bytes: 45120
#include <stdio.h>
#include <math.h>

int main(void){
  int x,y;
  while(scanf("%d %d",&x,&y)!=EOF){
    if(x==0 && y==0) break;
    printf("%d %d\n",x<y ? x : y,x<y ? y : x);
  }
  return 0;
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 105;

int n, m, Cnt[27];
char str[maxn][maxn];
int s1, s2, s4;

int main()
{
	sf("%d%d",&n,&m);
	fo(i,1,n) sf("%s",str[i]+1);
	fo(i,1,n) fo(j,1,m) Cnt[str[i][j]-'a'] ++;
	if(n%2&&m%2) s1=1;else s1=0;
	if(n%2) s2+=m-s1;
	if(m%2) s2+=n-s1;
	s4 =n*m-s1-s2;
	fo(i,0,25)
	{
		while(Cnt[i]>=4&&s4>=4) Cnt[i]-=4, s4-=4;
		while(Cnt[i]>=2&&s2>=2) Cnt[i]-=2, s2-=2;
		while(Cnt[i]&&s1) Cnt[i]--,s1--;
		if(Cnt[i])
		{
			pf("No\n");
			return 0;
		}
	}
	if(s4 > 0 || s2 > 0 || s1 > 0) return 0*pf("No");
	pf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
//const long long int pl=1000000;

long long int C[100][100]={};
long long int N,res=0,A,B,v[55],sum=0,cou=0,cou2=0;
bool AllSame=true;

string S[105];
int main(){
    cout << fixed << setprecision(18);
    cin>>N;
    cout<<1-N<<endl;
}



Measured memory_bytes: 3592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        var nk = longa();
        long n = nk[0], k = nk[1];
        long ans = 0;
        long ct = ((k - 1) * n - (k - 1) * (k - 2));
        for(long i = k; i <= n+1 ; i++)
        {            
            ct = ct + n - 2 * i + 2;
            ans += ct + 1;
            ans %= mod;
        }
        Write(ans);
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;

    string t;
    cin>>t;
    rep(i,t.size()){
        if(t[i]=='?')t[i]='D';
    }
    cout<<t<<endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 nibab
#define y1 kebab

int n,t,k,x,y,xd=1;

string s;

vector <int> a,b;

int dp[8005][16005],pp[8005][16005];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> s >> x >> y;
    for(int i=0;i<s.lg;i++){
        if(s[i]=='T'){
            if(xd){
                xd=0;
                x-=k;
                k=0;
            }
            else if(t==0) a.pb(k),k=0;
            else b.pb(k),k=0;
            t=!t;
        }
        else k++;
    }
    if(xd){
        xd=0;
        x-=k;
        k=0;
    }
    else if(t==0) a.pb(k),k=0;
    else b.pb(k),k=0;
    dp[0][8000]=1;
    for(int i=1;i<=a.sz;i++){
        int nibab=s.lg;
        for(int j=0;j<=16000;j++){
            if(j+a[i-1]<=16000) dp[i][j]=max(dp[i-1][j+a[i-1]],dp[i][j]);
            if(j-a[i-1]>=0) dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i][j]);
        }
    }
    pp[0][8000]=1;
    for(int i=1;i<=b.sz;i++){
        int nibab=s.lg;
        for(int j=0;j<=16000;j++){
            if(j+b[i-1]<=16000) pp[i][j]=max(pp[i-1][j+b[i-1]],pp[i][j]);
            if(j-b[i-1]>=0) pp[i][j]=max(pp[i-1][j-b[i-1]],pp[i][j]);
        }
    }
    if(dp[a.sz][x+8000] && pp[b.sz][y+8000]) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 499968
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << *max_element(A, &A[N]) - *min_element(A, &A[N]) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<list>
#include<set>
using namespace std;
#define fr first
#define sc second
#define INFTY 1000000
typedef pair< int,int > iiP;
typedef pair< int,iiP > P;
int main(){
  int N,P;
  bool Prime[INFTY + 1]={0};
  vector<int> Matsuzaki;
  vector<int> Prime_No;
  for(int i=2;i<INFTY;i++){
    if(!Prime[i]){
      Prime_No.push_back(i);
      for(int j=2;i*j<INFTY;j++) Prime[i*j] = true;
    }
  } 
  while(cin >> N >> P) {
    if(N == -1 && P == -1) break;
    int s =  upper_bound(Prime_No.begin(),Prime_No.end(),N) - Prime_No.begin();
    for(int i=0;i<=100;i++){
      for(int j=i;j<=i + 100;j++){
	Matsuzaki.push_back(Prime_No[s + i] + Prime_No[s + j]);
      }
    }
    sort(Matsuzaki.begin(),Matsuzaki.end());
    cout << Matsuzaki[P - 1] << endl;
    Matsuzaki.clear();
  }
}

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

using namespace std;
#define ll long long int
vector<ll> v;
map<pair<int,int>, ll> mp;
int n;
ll solve(int st, int en, int cnt){
    if(cnt==0){
        return 0;
    }
    if((en-st+1)<(2*cnt-1) || en<st){
        return -(1ll<<60);
    }
    if(mp.count({st,cnt})) return mp[{st,cnt}];
    mp[{st,cnt}] = max(solve(st+1,en,cnt), v[st]+solve(st+2,en,cnt-1));
    return mp[{st,cnt}];
}
int main()
{
    cin >> n;
    v.resize(n);
    for(int i=0;i<n;i++) {cin >> v[i];}
    ll f = solve(0,n-1,n/2);
    cout << f << endl;
}


Measured memory_bytes: 34336
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
a, b = map(int, input().split())

d = b - a
print(d * (d - 1) // 2 - a)

Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    int n, d, a;
    vector<P> monster;
    int x, h;
    int i, j;
    int tx, th;
    int mid;
    ll count;
    ll ans = 0;
    queue<P> bomb; //位置、ダメージ
    ll damage = 0;

    cin >> n >> d >> a;

    monster.emplace_back(0, 0);

    rep(i, 1, n + 1)
    {
        cin >> x >> h;
        monster.emplace_back(x, h);
    }

    sort(monster.begin(), monster.end());

    rep(i, 1, n + 1)
    {
        tx = monster[i].first;
        th = monster[i].second;

        while (bomb.size() && monster[i].first > bomb.front().first + d * 2)
        {
            damage -= bomb.front().second;
            bomb.pop();
        }

        if (th - damage > 0)
        {
            th -= damage;
            count = (th + a - 1) / a;

            bomb.push(P(tx, count * a));

            damage += count * a;

            ans += count;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6384
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    x,n = mi()
    p = mi()

    for d in range(x+1):
        for o in [-1,1]:
            val = x + o*d
            if val not in p:
                print(val)
                return

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9216
s = int(input())
ans = [s]
judge = True
count = 0 
while judge:
    if ans[count]%2 == 0: 
        ans.append(ans[count]/2)
    else:
        ans.append(3 * ans[count] + 1)
    if ans[count+1] in ans[:count]:
        judge = False
        print(count+2)
        exit()
    count += 1

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define NUM_DATA 10000

int compare(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}

int main(void) {
	size_t i, n;
	int data[NUM_DATA];
	int64_t answer;

	while (1) {
		scanf("%d", &n);
		if (!n)
			break;

		for (i = 0; i < n; i++) {
			scanf("%d", data+i);
		}
		qsort(data, n, sizeof(int), compare);

		n--;
		answer = 0;
		for (i = 0; i < n; i++) {
			answer += data[i] * (n-i);
		}
		printf("%lld\n", answer);
	}
	return 0;
}

Measured memory_bytes: 724
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;

    if ((a < b) && (b < c)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


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

int main(){
  int n;
  
  cin >> n ;
  
  int d1 = n%10;
  int d2 = n/10%10;
  int d3 = n/100%10;
  int d4 = n/1000%10;
  
  if((d2==d3&&d2==d4)||(d1==d2&&d1==d3))
     cout << "Yes" << endl;
  else
     cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  if(s[0]=='A'&&s[1]=='A'&&s[2]=='A'){
    cout<<"No"<<endl;
  }
  else if(s[0]=='B'&&s[1]=='B'&&s[2]=='B'){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  int x = n%500;
  cout << ( x<=a ? "Yes" : "No" ) << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

n, m, q = map(int, input().split())
con = list()
ans = 0

for _ in range(q):
    con.append(list(map(int, input().split())))

A_li = list(itertools.combinations_with_replacement(range(1,m+1),n))

for A in A_li:
    now_score = 0
    for a,b,c,d in con:
        a-=1
        b-=1
        if A[b]-A[a] == c:
            now_score += d
    ans = max(ans, now_score)

print(ans)


Measured memory_bytes: 21628
#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N;
  char v = N[N.size() - 1];
  if (v == '2' || v == '4' || v == '5' || v == '7' || v == '9') {
    cout << "hon" << endl;
  } else if (v == '0' || v == '1' || v == '6' || v == '8') {
    cout << "pon" << endl;
  } else if (v == '3') {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>

int main(){

  int i,n,a[250];


  scanf("%d",&n);

  for(i = 1; i <= n; i++){

    scanf("%d",&a[i]);
  }

  for(i = 1; i <= n; i++){

    printf("node %d: key = %d, ",i,a[i]);

    if(i/2 <= n && i/2 > 0)
      printf("parent key = %d, ", a[i/2]);

    if(i*2 <= n)
      printf("left key = %d, ",a[i*2]);

    if(i*2+1 <= n)
      printf("right key = %d, ",a[i*2+1]);

    printf("\n");
  }


  return 0;
}

      
      



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m,x;cin>>n>>m>>x;
	ll c[n];
	ll a[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m+1;j++){
			if(j==0){cin>>c[i];}
			else{cin>>a[i][j-1];}
		}
	}
	for(int j=0;j<m;j++){
		int c=0;
		for(int i=0;i<n;i++){
			c+=a[i][j];
		}
		if(c<x){
			cout<<-1;return;
		}
	}
	int ans=INT_MAX;
	for(int i=0;i<(1<<n);i++){
		set<int>s;int y=0;
		for(int j=0;j<n;j++){
			if((1<<j)&(i)){s.insert(j);y+=c[j];}
		}
		int arr[m]={0};
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(s.count(i)){
					arr[j]+=a[i][j];
				}
			}
		}
		bool ck=true;
		for(int i=0;i<m;i++){
			if(arr[i]<x){ck=false;break;}
		}
		if(ck){ans=min(ans,y);}
	}
	cout<<((ans==INT_MAX)?-1:ans);
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


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

int main(){
  int H,W;
  queue<pair<int,int>> search;
  cin>>H>>W;
  int a[1010][1010]; //距離
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        char tmp;
        cin>>tmp;
        if(tmp=='#') {
          a[i][j]=0;
          search.push({i,j});
        }
        else a[i][j]=10e6;
    }
  }
  int dr[]={-1,1,0,0};
  int dc[]={0,0,-1,1};
  while(!search.empty()){
    int r=search.front().first,c=search.front().second; 
    search.pop();
    for(int i=0;i<4;i++){
      int newr=r+dr[i],newc=c+dc[i];
      if(newr>=0&&newr<H&&newc>=0&&newc<W&&a[newr][newc]>a[r][c]+1){
        a[newr][newc]=a[r][c]+1;
        search.push({newr,newc});
      }
    }
  }
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        ans=max(ans,a[i][j]);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  long n,ans=0;
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<n;i++) b[a[i]-1]=i;
  set<long> aaa={-1,n};
  for(long i=0;i<n;i++) {
    auto itr=aaa.upper_bound(b[i]);
    long x=*itr-b[i];
    itr--;
    long y=b[i]-*itr;
    ans+=x*y*(i+1);
    aaa.insert(b[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 12800
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//NIL is NULL
#define NIL NULL
//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;
 
//root        
Nodepointer root;
 
//function insert
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  //make memory
  z=new struct Node();
 
  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  }
 
  z->parent=y;
 
  if(y==NIL) root=z;
 
  else if(z->key<y->key) y->leftc=z;
 
  else y->rightc=z;
 
 
}
 
//function search
Nodepointer find(Nodepointer now,int data){
  if(now==NIL||data==now->key) return now;
  if(data<now->key) return find(now->leftc,data);
  else return find(now->rightc,data);
}
 
//function treeminimum
Nodepointer treeminimum(Nodepointer x){
  while(x->leftc!=NIL){
    x=x->leftc;
  }
  return x;
}
//function treesuccerssor
Nodepointer treesuccessor(Nodepointer x){
  Nodepointer y;
  if(x->rightc!=NIL) return treeminimum(x->rightc);
  y=x->parent;
  while(y!=NIL && x==x->rightc){
    x=y;
    y=y->parent;
  }
  return y;
}
//function treedelete
void treedelete(Nodepointer z){
  Nodepointer x,y;
  if(z->leftc==NIL ||z->rightc==NIL)y=z;
  else y=treesuccessor(z);
 
  if(y->leftc!=NIL)x=y->leftc;
  else x=y->rightc;
  
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->leftc) y->parent->leftc=x;
  else y->parent->rightc=x;
  if(y!=z) z->key=y->key;
}
 
//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}
 
void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}
 
 
int main(){
 
  int n,i,j,data;
  Nodepointer del;
  char str[10];
  //load n
  scanf("%d",&n);
  //load commnad and key
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //find
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    //delete
    else if(strcmp(str,"delete")==0){
      scanf("%d",&data);
      del=find(root,data);
      treedelete(del);
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }
 
  return 0;
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rep(i, a, b) for(ll i = a; i < b; ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	FIO;
    ll n;
    cin >> n;
    ll total = 0;
    vll arr(n);
    for(ll& i : arr)  {
        cin >> i;
        total ^= i;
    }
    for(ll i : arr) {
        cout << (total ^ i) << ' ';
    }
	return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=a) cout<<0<<endl;
	else if(c<=a+b) cout<<c-a<<endl;
	else cout<<"NA"<<endl;
	
	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n;cin>>n;
    cout<<(n+1)/2<<endl;
    return 0;
}

Measured memory_bytes: 3604