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

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

struct Node{
  int id,val,parent,size,in,out;
  vector<int> children;
  Node(){}
  Node(int id,int v,vector<int>ch):id(id),val(v),children(ch){}
};

typedef vector<Node> Tree;

struct HeavyLight {
  int pathCount,n;
  vector<int>path,pathSize,pathPos,pathRoot;
  Tree tree;//, len;
  
  HeavyLight(Tree tree)
    :pathCount(0),n(tree.size()),path(n),pathSize(n),pathPos(n),pathRoot(n),tree(tree){
    int time=0;
    dfs(0,-1,time);
    buildPaths(0,newPath(0));
    /*
    len=vector<vector<int> >(pathCount);

    REP(i,pathCount){
      int m=pathSize[i];
      len[i].resize(2*m);
      fill(ALL(len[i]),0);
      fill(len[i].begin()+m,len[i].begin()+2*m,1);
      for(int j=2*m-1;j>1;j-=2)len[i][j>>1]=len[i][j]+len[i][j^1];
    }
    */
  }

  void dfs(int u, int p, int &k){
    tree[u].in=k++, tree[u].parent=p, tree[u].size=1;
    EACH(v,tree[u].children)if(*v!=p)dfs(*v, u, k),tree[u].size+=tree[*v].size;
    tree[u].out=k++;
  }

  int newPath(int u){ pathRoot[pathCount]=u; return pathCount++; }

  void buildPaths(int u, int pt){
    path[u]=pt, pathPos[u]=pathSize[pt]++;
    EACH(v,tree[u].children)if(*v != tree[u].parent)
      buildPaths(*v, 2* tree[*v].size >= tree[u].size ? pt : newPath(*v));
  }

  bool isAncestor(int p, int ch){
    return tree[p].in <= tree[ch].in && tree[ch].out <= tree[p].out;
  }

  int lca(int a,int b){
    for(int root; !isAncestor(root=pathRoot[path[a]],b);a=tree[root].parent);
    for(int root; !isAncestor(root=pathRoot[path[b]],a);b=tree[root].parent);
    return isAncestor(a,b)?a:b;
  }
};


int main(void){
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  Tree tree(n);
  
  REP(i,n){
    tree[i].id=i;
    int k;
    cin >> k;
    REP(j,k){
      int ch;
      cin >> ch;
      tree[i].children.push_back(ch);
    }
  }

  HeavyLight hl = HeavyLight(tree);

  int q;
  cin >> q;
  while(q--){
    int u,v;
    cin >> u >> v;
    cout << hl.lca(u,v) << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 29244
while True:
	dict = {}
	n = input()
	if n == 0:break
	for x in xrange(n):
		a, b = raw_input().split()
		dict[a] = b
	res = ""
	for x in xrange(input()):
		a = raw_input()[0]
		if a in dict:
			res += dict[a]
		else:
			res += a
	print res

Measured memory_bytes: 4308
N, A, B = map(int, input().split())
ans = 0
for i in range(N+1):
	sum = i % 10 + (i % 100)//10 + (i % 1000)//100 + (i % 10000)//1000 + i//10000
	if A <= sum <= B:
		ans += i
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int x[201],y[201];
const int mod = 998244353;

long long int mypow(long long int x,long long int b){
	long long int res=1;
	while(b){
		if(b&1)
			res=res*x%mod;
		x=x*x%mod;
		b>>=1;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>y[i];
	long long int ans=mypow(2,n);
	ans=((ans-1-n-n*(n-1)/2)%mod+mod)%mod;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int cnt=2;
			for(int k=1;k<=n;k++){
				if(k==i||k==j)	continue;
				if((x[i]-x[j])*(y[k]-y[j])!=(x[k]-x[j])*(y[i]-y[j]))
					continue;
				if(k<i||k<j)	break;
				cnt++;
			}
			ans=(ans-mypow(2,cnt)+mod+1+cnt+cnt*(cnt-1)/2)%mod;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n%x==0)cout << t*n/x << endl;
    else cout << t*(n/x)+t << endl;
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Console.ReadLine();
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		int c = 0, M = h.Max();
		for (int k = 0; k < M; k++)
		{
			var t = false;
			for (int i = 0; i < h.Length; h[i]--, i++)
			{
				if (h[i] > 0 && !t) c++;
				t = h[i] > 0;
			}
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 13268
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

int d2c[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int dd[8];
int qu[9], aa[9], aa_[9];
int k_, l_;
int c_;

void update(int k, int l) {
	if (l_ > l)
		return;
	for (int h = 0; h < k; h++)
		aa[h] = dd[qu[h]];
	int m = min(l, 9);
	for (int h = k; h < m; h++)
		aa[h] = dd[c_];
	sort(aa, aa + m, greater<>());
	bool better = false;
	if (l_ < l)
		better = true;
	else
		for (int h = 0; h < l; h++)
			if (aa_[h] != aa[h]) {
				if (aa_[h] < aa[h])
					better = true;
				break;
			}
	if (better) {
		k_ = k;
		l_ = l;
		for (int h = 0; h < m; h++)
			aa_[h] = aa[h];
	}
}

void solve(int c, int n, int k) {
	while (c > c_ && dd[c] == 0)
		c--;
	if (c == c_) {
		if (n % c == 0) {
			int l = k + n / c;
			update(k, l);
		}
		return;
	}
	for (int h = 0; h < c_; h++) {
		solve(c - 1, n, k);
		if (n < c || k == 9)
			break;
		n -= c;
		qu[k++] = c;
	}
}

int main() {
	int n, m; cin >> n >> m;
	while (m--) {
		int d; cin >> d;
		int c = d2c[d];
		dd[c] = max(dd[c], d);
	}
	c_ = 2;
	while (dd[c_] == 0)
		c_++;
	solve(7, n, 0);
	m = min(l_, 9);
	for (int h = 0; h < m; h++)
		if (aa_[h] > dd[c_])
			cout << aa_[h];
	for (int h = k_; h < l_; h++)
		cout << dd[c_];
	for (int h = 0; h < m; h++)
		if (aa_[h] < dd[c_])
			cout << aa_[h];
	cout << '\n';
	return 0;
}


Measured memory_bytes: 3588
N, M = map(int, input().split())
r = [set() for _ in range(N+1)]
for _ in range(M):
    n1, n2 = map(int, input().split())
    r[n1].add(n2)
    r[n2].add(n1)

from itertools import permutations as p
c = 0
kumis = p(range(2, N+1))
for kumi in kumis:
    prev = 1
    for k in kumi:
        if k not in r[prev]:
            break
        prev = k
    else:
        c += 1
print(c)

Measured memory_bytes: 39152
# include"stdio.h"
int main(){
    char a[11],b[11],c[11];
    scanf("%s %s %s",a,b,c);
    int c1=0,c2=0;
    while(a[c1]!='\0') c1++;
    while(b[c2]!='\0') c2++;
    if(a[c1-1]==b[0]&&b[c2-1]==c[0])
        printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 1632
def subtract_lst (lst1, lst2):
    ans = 0
    for i in range(len(lst1)):
        e1 = lst1[i]
        e2 = lst2[i]
        if e1 != e2:
            ans += 1
    return ans

if __name__ == '__main__':
    s = input()
    lenS = len(s)
    a = ""
    b = ""
    for i in range(lenS // 2):
      a = a + "10"
      b = b + "01"
    if lenS % 2 == 1:
        a = a + "1"
        b = b + "0"
    aAns = subtract_lst (a, s)
    bAns = subtract_lst (b, s)
    print (min(aAns, bAns))


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, a, b;

    cin>> n>> a>> b;

    for(int i=a; i<=b; i++)
    {
        if(i% n== 0)
        {
            cout<< "OK\n";
            return 0;
        }
    }

 cout<< "NG\n";

    return 0;
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];

    sort(d.begin(), d.end());
    
    cout << (d[n/2] - d[n/2-1]) << endl;

    return 0;
}


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

int selectionSort(int A[], int N){ // N個の要素を含む0-オリジンの配列A
  int count=0,k;
  for(int i=0;i<N-1;i++){
    int minj = i;
     for(k=i+1;k<N;k++)
       if(A[k] < A[minj])
         {minj = k;}
    if(i!=minj){swap(A[i],A[minj]);count++;}
  }
  return count;
}

int main() {
  int n,temp;
  cin>>n;
  int A[1000];
  for(int i=0;i<n;i++){
    scanf("%d",&temp);
    A[i]=temp;
  }
  int ans=selectionSort(A,n);
  cout << A[0];
  for(int i=1;i<n;i++)
    cout<<" "<<A[i];
  cout<<endl<<ans<<endl;
}



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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, M;
vector<ll> H;
vector<vector<int>> AB(100100);
vector<bool> used(100100, false);

void rec(int i) {
    if (used.at(i)) return;
    used.at(i) = true;
    for (int j = 0; j < AB.at(i).size(); j++) {
        rec(AB.at(i).at(j));
    }
    return;
}

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

    cin >> N >> M;

    H.resize(N);
    REP(i, N) {
        cin >> H.at(i);
    }

    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        AB.at(a).push_back(b);
        AB.at(b).push_back(a);
    }

    ll ans = 0;

    REP(i, N) {
        ll h = H.at(i);
        bool flag = true;
        for (auto x:AB.at(i)) {
            if (h <= H.at(x)) {
                flag = false;
                break;
            }
        }
        if (flag) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 100100

string A[MAXN];
int mem[MAXN][26][26];
int offset[MAXN];

struct trie{
	trie* V[30];
	int n,num,v;

	trie(int i){
		n=i;
		for (int j=0;j<26;++j)V[j] = nullptr;
		num=0;v=0;
	}

	void insert(int ind){
		num += 1;
		if (SZ(A[ind]) == n){++v;return;}
		int t = A[ind][n] - 'a';
		if (V[t] == nullptr)V[t] = new trie(n+1);
		V[t]->insert(ind);
	}

	void compute(int ind){
		if (SZ(A[ind]) == n)return;
		offset[ind] += v;
		int t = A[ind][n] - 'a';
		for (int i=0;i<26;++i)if(i!=t){
			if (V[i] == nullptr)continue;
			mem[ind][t][i] += V[i]->num;
			// for (int k=0;k<V[i]->num;++k)cout<<(char)('a' + t)<<' '<<(char)('a' + i)<<'\n';
		}
		V[t]->compute(ind);
	}
}*root;

int N,Q,a;
string S;

int main(){
	cin>>N;
	for (int i=1;i<=N;++i)cin>>A[i];
	root = new trie(0);
	for (int i=1;i<=N;++i)root->insert(i);
	for (int i=1;i<=N;++i)root->compute(i);
	// root->compute(3);
	// for (int i=1;i<=N;++i)cout<<offset[i]<<' ';cout<<'\n';
	cin>>Q;
	while (Q--){
		cin>>a>>S;
		// for (int i=0;i<26;++i){
		// 	for (int j=0;j<26;++j)cout<<mem[a][i][j]<<' ';cout<<'\n';
		// }
		int ans =0 ;
		for (int i=0;i<26;++i){
			for (int j=i+1;j<26;++j){
				// You lose out mem[a][S[i]][S[j]] if i > j
				ans += mem[a][S[j] - 'a'][S[i] - 'a'];
			}
		}
		cout<<ans+offset[a]+1<<'\n';
		// return 0;
	}
}

Measured memory_bytes: 302208
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 3050
#define INF 1<<28
vector<int> G[MAX_V];
int match[MAX_V],V;
bool used[MAX_V];
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}
bool dfs(int v){
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}
int bipartite_matching(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v)){
	res++;
      }
    }
  }
  return res;
}
typedef pair<int,int> P;
int main(){
  int n,m,l;
  while(cin>>n>>m>>l,n||m||l){
    for(int i=0;i<MAX_V;i++) G[i].clear();
    int e[n][n];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) e[i][j]=(i!=j)*INF;
    for(int i=0;i<m;i++){
      int u,v,d;
      cin>>u>>v>>d;
      e[u][v]=e[v][u]=d;
    }
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
    vector<P> p(l);
    for(int i=0;i<l;i++) cin>>p[i].first>>p[i].second;
    for(int i=0;i<l;i++){
      for(int j=0;j<l;j++){
	if(i==j) continue;
	int u=p[i].first,v=p[j].first;
	if(p[j].second-p[i].second>=e[u][v]) add_edge(i,l+j);
      }
    }
    V=l*2;
    cout<<l-bipartite_matching()<<endl;
  }
  return 0;
}

Measured memory_bytes: 11432
// B - Cut and Count
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; string S; cin>>N>>S;
	int maxi = 0;
	rp(sep, 1, N){
		set<char> l,r;
		rp(i, 0, sep) l.insert(S[i]);
		rp(i, sep, N) r.insert(S[i]);
		int count = 0; for(auto a:l) if(r.find(a)!=r.end()) count++;
		maxi = max(maxi, count);
	}
	cout<< maxi <<endl;
}

Measured memory_bytes: 256
import math
N=int(input())
x=[list(map(int, input().split())) for i in range(N)]

#必要な掛け算の数字を出す
k=math.factorial(N) #k通り
w=0
for i in range(0,N):
    w=w+(N-i-1)
#必要な数
t=(k*(N-1))/(w)
#それぞれの辺の長さを総当たりで求めていく
p=0
q=0
for i in range(0,N):
    for j in range(i+1,N):
        p=(x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2
        q=q+math.sqrt(p)
print(q*t/k)

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
using namespace std;
char a[1000000+5];
string st;
int js;
int main()
{
	cin>>st;
	js=1;
	for (int i=0;i<=st.size()-1;i++)
	  if (st[i]=='B') js=max(1,js-1); else a[js]=st[i],js++;
	for (int i=1;i<=js-1;i++) cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,C,D,E,F,x=1,y=1;
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    for(int i=0; i<=F/(100*A); i++)
    {
        int a=i*100*A;
        if(a>F) break;
        for(int j=0; j<=F/(100*B); j++)
        {
            int b=j*100*B;
            if(a+b>F) break;
            for(int k=0; k<F/C; k++)
            {
                int c=k*C;
                if(a+b+c>F) break;
                for(int l=0; l<F/D; l++)
                {
                    int d=l*D;
                    if((a+b+c+d)>F||(c+d)>(a+b)/100*E) break;
                    int tz=(c+d);
                    int tm=(a+b);
                    if(x*(tm+tz)<=tz*(y+x))
                    {
                        x=tz;
                        y=tm;
                    }
                }
            }
        }
    }
    printf("%d %d",x+y,x);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,k;
    cin >> n >> k;
    double ans = 0;
    rep(i,n){
        double now = 1.0/(n);
        int poi = i+1;
        while(poi<k){
            now/=2.0;
            poi*=2;
        }
        ans += now;
    }
    printf("%.15lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL,LL>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL n;
    cin >> n;
    LL a[n+5];
    for (LL i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    LL ans = a[1];
    for (LL i=2;i<=n/2;i++) {
        ans += a[i] * 2;
    }
    if (n%2 == 1) {
        ans += a[(n+1)/2];
    }
    cout << ans << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  cin >> n;

  ll res = 0;
  rep (i, 1, n) {
    res += i;
  }

  cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdlib.h>
#include <ctype.h>
#include <stack>
#include <bitset>
#include <iterator>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ls k<<1
#define rs k<<1|1
#define lson l,mid,k<<1
#define rson mid+1,r,k<<1|1
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
int lowbit(int x){return x&(-x);}
const int maxn=15;
ll a,b;
int main(void){
    scanf("%lld%lld",&a,&b);
    if(b-a>=2030) puts("0");
    else{
            vector<int> v;
            for(ll i=a;i<=b;++i) v.push_back(i%2019);
            int ans=2e9;
            for(int i=0;i<v.size();++i)
                for(int j=i+1;j<v.size();++j) ans=min(ans,v[i]*v[j]%2019);
            printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0){
        cout<<"1";
    }
    

    if(b==0){
        cout<<"2";
    }
    

    if(c==0){
        cout<<"3";
    }
    

    if(d==0){
        cout<<"4";
    }
    

    if(e==0){
        cout<<"5";
    }
    

}

Measured memory_bytes: 3640
def breaking(a,x,y,n):
    a[x][y] = 0;
    answer = n
    if a[x-1][y]:
        answer = max(breaking(a,x-1,y,n+1),answer)
    if a[x][y-1]:
        answer = max(breaking(a,x,y-1,n+1),answer)
    if a[x+1][y]:
        answer = max(breaking(a,x+1,y,n+1),answer)
    if a[x][y+1]:
        answer = max(breaking(a,x,y+1,n+1),answer)
    a[x][y] = 1
    return answer

while True:
    n = int(input())
    if n==0: break
    m = int(input())

    mapp = [[0]*(n+2) for i in range(m+2)]
    for i in range(m):
        ainarray = list(map(int,input().split()))
        for j in range(n):
            mapp[i+1][j+1] = ainarray[j]

    res = 0
    for i in range(m):
        for j in range(n):
            if mapp[i+1][j+1]:
                res = max(res,breaking(mapp,i+1,j+1,1))

    print(res)

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

int main() {
	int n,i;
	long long a,min,max,all;
	cin >> n >> a;
	min = a;
	max = a;
	all = a;
	i = 1;
	while(i < n){
		cin >> a;
		all = all + a;
		if(a < min){
			min = a;
		}
		if(a > max){
			max = a;
		}
		i++;
	}
	cout << min << " " << max << " " << all << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
ll c[2010][2010];
const int mod = 1e9+7;

//Resolução da questão: https://www.youtube.com/watch?v=Ee8UtXL8pjY&t=2162s

//Monta o triângulo de Pascal
void initPascal() {
    c[0][0] = 1;
    c[1][0] = 1;
    c[1][1] = 1;

    for (int i = 2; i < 2010; i++) {
        c[i][0] = 1;
        for (int j = 1; j < 2010; j++) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j])%mod;
        }
    }
}

int main(int argc, char const *argv[])
{
    int n, k;

    initPascal();

    cin >> n >> k;

    int b = k;
    int r = n-k;

    for (int i = 1; i < k+1; i++) {
        ll prob = (c[b-1][i-1]*c[r+1][i])%mod;
        cout << prob << endl;
    }

    return 0;
}

Measured memory_bytes: 35172
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>

using namespace std;

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


Measured memory_bytes: 3620
a = int(input())
if 400 <= a and a <= 599:
    print(8)
elif 600 <= a and a <= 799:
    print(7)
elif 800 <= a and a <= 999:
    print(6)
elif 1000 <= a and a <= 1199:
    print(5)
elif 1200 <= a and a <= 1399:
    print(4)
elif 1400 <= a and a <= 1599:
    print(3)
elif 1600 <= a and a <= 1799:
    print(2)
elif 1800 <= a and a <= 1999:
    print(1)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[23][23];
ll dp[(1<<22)];
ll mod=1000000007;
ll bt(ll id,ll mask){
	if(id==n)return 1;
	ll &ret=dp[mask];
	if(ret!=-1)return ret;
	ret=0;
	for(int i=0;i<n;i++){
		if((mask&(1<<i))==0 && a[id][i]){
			ret=(ret+bt(id+1,(mask|(1<<i))))%mod;
		}
	}
	return ret%mod;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)cin>>a[i][j];
	}
	cout<<bt(0,0)<<endl;
}


Measured memory_bytes: 33024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
XYZ = [LIST() for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(N)

for X, Y, Z in XYZ:
	uf.union(X-1, Y-1)

print(uf.group_count())


Measured memory_bytes: 32952
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
    int n,count;
    string s;
    cin >> s;
    n = s.length();
    count = 0;
    for (int i = 0; i <= n/4; i++){
        
        if(s[i] != s[n - 1 - i] || s[i] != s[n/2 -1-i] || s[n/2 +1+i] != s[n-1-i]){
            count = 1;
            break;
        }

    }

    if(count == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
        int N = int.Parse(str[0]);
        int K = int.Parse(str[1]);

        string[] strHeight = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得

        int count = 0;
        for( int i = 0; i < N; i++ )
        {
            int each = int.Parse(strHeight[i]);
            if( each >= K )
            {
                count++;
            }
        }
        Console.WriteLine(count.ToString());
        // Console.Read();
    }
}

Measured memory_bytes: 15584
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

#define INF 100000000
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;


int main(){
    int n ; cin >> n;
    vector<pair<int, int>> tasks(n);
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        tasks[i].first = b;
        tasks[i].second = a;
        
    }
    sort(tasks.begin(), tasks.end());
    
    ll sum = 0;
    bool isYes = true;
    for(auto v : tasks){
        sum += v.second;
        if (sum > v.first) {
            isYes = false;
            break;
        }
    }
    if (isYes) {
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0 ;
    }
    
}


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

int main()
{
	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	long long int y=0;
	
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='g')
		{
			if(i%2==1)
				y++;
		}
		else
		{
			if(i%2==0)
				y--;
		}
	}
	
	cout<<y<<endl;
	return 0;
}

Measured memory_bytes: 512
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def f(t, c):
    res = ''
    for i in range(len(t)-1):
        if t[i] == c or t[i+1] == c:
            res += c
        else:
            res += t[i]
    return res

S = input()
ans = 1000
for c in 'qwertyuiopasdfghjklzxcvbnm':
    T = S[:]
    cnt = 0
    while not all(t == c for t in T):
        T = f(T, c)
        cnt += 1
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 9428
#include<bits/stdc++.h>
#define PLI pair<ll,int>
#define PII pair<int, int>
#define X first
#define Y second
#define MP make_pair
#define PLL pair<ll, ll>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define N 5010
#define M 1000100
const double eps = 1e-6;
using namespace std;

int Read()
{
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
ll ReadL()
{
    ll x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

const ll inf = 1000000000000000ll;
int n;
struct P
{
    ll h, p;
}a[N];
bool cmp(P a, P b)
{
    if(a.p == b.p) return a.h < b.h;
    return a.p < b.p;
}
set<PLI, greater<PLI> > b;
set<PLI, greater<PLI> > :: iterator it;
priority_queue <PLI> q;

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    printf("%lld\n", inf);
    while(scanf("%d", &n) != EOF)
    {
        for(int i = 1; i <= n; i ++) a[i].h = ReadL(), a[i].p = ReadL();
        sort(a + 1, a + n + 1, cmp);
        b.clear();
//        printf("a\n");
//        cnt = 0;
        ll sm = 0;
//        printf("1: %lld %lld\n", a[1].h, a[1].p);
        for(int i = 1; i <= n; i ++)
        {
            while(!q.empty()) q.pop();
            if(i == 1) sm += a[i].p, b.insert(MP(a[i].p + a[i].h, i));
            else
            {
                b.insert(MP(a[i].p + a[i].h, i));
                sm += a[i].p;
                it = b.begin();
                ll tsm = sm;
                while(it != b.end() && (it->X) >= tsm) q.push(MP(a[it->Y].p, it->Y)), it ++;
                while(!q.empty())
                {
                    PLI tmp = q.top(); q.pop();
                    tsm -= tmp.X;
                    while(it != b.end() && (it->X) >= tsm) q.push(MP(a[it->Y].p, it->Y)), it ++;
                }
//                printf("a\n");
//                if(it == b.end())
//                {
////                    b.insert(MP(a[i].p + a[i].h, i));
//                    printf("%d: %lld %lld\n", i, a[i].h, a[i].p);
//                }
                if(it != b.end()) b.erase(MP(a[i].p + a[i].h, i)), sm -= a[i].p;
            }
        }
        printf("%d\n", b.size());
    }
    return 0;
}


Measured memory_bytes: 640
#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;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,n;
	cin>>h>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	vector<int> dp(h+1,INT_MAX);
	for(int i=1;i<=h;i++){
		for(int j=0;j<n;j++){
			if(i-a[j]<=0){
				dp[i]=min(dp[i],b[j]);
			}
			else{
				dp[i]=min(dp[i],b[j]+dp[i-a[j]]);
			}
		}
	}
	cout<<dp[h]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<stack>
#include<algorithm>
#include<climits>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define vll vector<ll>
#define mii map<ll, ll>
#define debug(x) cerr << #x << " is " << x << "\n";
#define debug1(x, y) cerr << #x << " is " << x << "\n" << #y << " is " << y << "\n";
#define w(x) ll x; cin >> x; while(x--)
#define endl "\n"
#define f first 
#define s second 
#define fo(n) for(ll i = 0LL; i < n; ++i) 
#define setbits(n) __builtin_popcount(n)
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(x.begin(), x.end())
#define pb push_back
#define mk make_pair
#define PERMUTE next_permutation
#define RESET(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
using namespace std;
 
int main(){
    fast
    ll h, w;
    cin >> h >> w;
    vector<vector<bool>> grid(h, vector<bool>(w, true));
    fo(h) {
        for(int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if(c == '#')
                grid[i][j] = false;
        }
    }

    vector<vector<ll>> dp(h, vector<ll>(w, 0));
    dp[0][0] = 1;
    
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(grid[i][j]) {
                if(i != 0 && grid[i - 1][j]) 
                    dp[i][j] += (dp[i - 1][j] % MOD);
                if(j != 0 && grid[i][j - 1]) 
                    dp[i][j] += (dp[i][j - 1] % MOD);
            }
        }
    }

    cout << dp[h - 1][w - 1] % MOD << endl;
    
    return 0;
}

Measured memory_bytes: 11332
import numpy as np

X, N= map(int,input().split())
P = list(map(int, input().split()))
P = list(set(P))

if N == 0:
    print(X)
else:
    A = [i for i in range(1,210)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    if (A[j] - X)**2 >= X**2:
        print(0)
    else:
        print(A[j])

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

int main(void){
    int alice=0,bob=0,n;

    cin >> n;
    vector<int> vec(n);

    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    for(int i=0;i<n;i++){
        if(i%2 == 0){
            alice+=vec.at(i);
        }else{
            bob+=vec.at(i);
        }
    }
    cout << alice - bob << endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  string S;cin>>S;
  ll ans = 0;
  int bcnt=0;
  repeat(i,S.length()){
    if(S[i]=='W'){
      ans += bcnt;
    }else{
      bcnt++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
    int n ;
    cin>>n; int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    long long ans=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1]) 
        {
            ans+=-a[i]+a[i-1];
            a[i]=a[i-1];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}


inline long long modo(long long a, long long m) {
    return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q);
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d);
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = modo(b1 + m1 * tmp, m);
  return make_pair(r, m);
}


int main() {
    ll n;
    cin >> n;
    vector<ll> d;
    for(auto x : prime_factor(2*n)){
        d.push_back(pow(x.first, x.second));
    }
    int s = d.size();
    ll ans = inf;
    rep(bit, (1<<s)){
        ll m1 = 1, m2 = 1;
        rep(i, s){
            if(bit & (1<<i)) m1 *= d[i];
            else m2 *= d[i];
        }
        pair<ll, ll> p = ChineseRem(m1-1, m1, 0, m2);
        if(m1 != 1)chmin(ans, p.first);
    }
    cout << ans << endl;
}


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

bool isPrime(int x); 
int gcd(int a, int b); 
vector<int> primeFactorization(int x); 
void printVector(vector<long> list, string str); 
void setPrecision(int n);

void exec(int hoge) {
  cout << hoge << endl;
}

int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
    return 0;
  }

  cout << (100 * (10 -n)) + r << endl;
}

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

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;

  double num = sqrt(x);
  for (int i = 3; i <= num; i+=2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// 素因数分解
// example: primeFactorization(12) = vector<int>{2, 2, 3}
vector<int> primeFactorization(int x) {
  vector<int> ans;
  int i = 2;
  while (i*i <= x) {
    if (x % i == 0) {
      ans.push_back(i);
      x /= i;
    } else {
      i++;
    }
  }
  ans.push_back(x);
  return ans;
}

void printVector(vector<long> list, string str) {
  for (int i = 0; i < list.size(); i++) {
    cout << str << ": " << list[i] << endl;
  }
}

void setPrecision(int n) {
  cout << fixed << setprecision(n);
}

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

void dfs(int p, vector<char> &op, vector<int> &num) {
    if (p == 3) {
        int sum = num[0];
        for (int i = 0; i < 3; ++i) {
            if (op[i] == '+')sum += num[i + 1];
            if (op[i] == '-')sum -= num[i + 1];
        }
        if (sum == 7) {
            cout << num[0];
            for (int i = 0; i < 3; i++)cout << op[i] << num[i + 1];
            cout << "=7" << endl;
            exit(0);
        }
        return;
    }

    //'+'の場合
    op[p] = '+';
    dfs(p + 1, op, num);

    //'-'の場合
    op[p] = '-';
    dfs(p + 1, op, num);

    op[p] = '?';
    return;
}

int main() {
    string t;
    cin >> t;
    vector<int> num(4);
    for (int i = 0; i < 4; i++)num[i] = t[i] - '0';
    vector<char> op(3, '?');

    dfs(0, op, num);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

template <typename T>
struct BellmanFord
{
    static constexpr T INF = numeric_limits<T>::max();

    struct edge
    {
        int u, v;
        T w;
        edge() {}
        edge(int u, int v, T w) : u(u), v(v), w(w) {}
    };

    int n;
    vector<vector<int>> G;
    vector<int> used, reach;
    BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 1) {}

    vector<edge> es;
    void add_edge(int u, int v, T c)
    {
        es.emplace_back(u, v, c);
        G[u].emplace_back(v);
    }

    vector<T> build(int from, int &neg_loop)
    {
        vector<T> ds(n, INF);
        ds[from] = 0;
        for (int j = 0; j < n; j++)
        {
            bool update = 0;
            for (auto e : es)
            {
                if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF)
                    continue;
                if (ds[e.v] > ds[e.u] + e.w)
                {
                    ds[e.v] = ds[e.u] + e.w;
                    update = 1;
                }
            }
            if (!update)
                break;
            if (j == n - 1)
            {
                neg_loop = 1;
                return ds;
            }
        }
        neg_loop = 0;
        return ds;
    }

    void dfs(int v)
    {
        if (used[v])
            return;
        used[v] = 1;
        for (int u : G[v])
            dfs(u);
    }

    T shortest_path(int from, int to, int &neg_loop)
    {
        for (int i = 0; i < n; i++)
        {
            fill(used.begin(), used.end(), 0);
            dfs(i);
            reach[i] = used[to];
        }
        return build(from, neg_loop)[to];
    }
};
template <typename T>
constexpr T BellmanFord<T>::INF;

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

    int n, m;
    cin >> n >> m;
    BellmanFord<int> G(n);
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        c *= -1;
        G.add_edge(a, b, c);
    }
    int neg_loop;
    int ans = -G.shortest_path(0, n - 1, neg_loop);
    if (neg_loop)
        cout << "inf" << endl;
    else
        cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int i,j,a,v[26];
    for(i=0;i<26;i++)
        v[i]=0;
    char s[100000];
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        a=(int)(s[i]-'a');
        v[a]++;
    }
    for(i=0;i<26;i++)
       {
           if(v[i]==0)
           {
               printf("%c",'a'+i);
               return 0;
           }
       }
       printf("None");
 return 0;   
}

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

#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF					INT_MAX
#define LLINF					LLONG_MAX
#define DEBUG					false

typedef long long				ll;
typedef pair <int, int> ii;

int main() {

	vector<int> in(3);
	rep(i, 3) cin >> in[i];
	
	SORT(in);
	
	if(in[0] == 5 && in[1] == 5 && in[2] == 7) cout << "YES" <<endl;
	else cout << "NO" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        System.out.println((H - h) * (W - w));
    }
}


Measured memory_bytes: 22868
N, M, X = STDIN.gets.split.map(&:to_i)

C, *A_algo= N.times.map { STDIN.gets.split.map(&:to_i) }.transpose
A_book = A_algo.transpose

def bits(int)
  int.bit_length.times.select { |b| int[b] === 1 }
end

if A_algo.map(&:sum).min < X
  puts -1
  return
end

min_cost = (1...2**N).map { |n| bits(n) }
  .select { |indexes| X <= A_book.values_at(*indexes).transpose.map(&:sum).min }
  .map { |indexes| C.values_at(*indexes).sum }
  .min

puts min_cost


Measured memory_bytes: 15996
#include <stdio.h>

int a,b,c;

int main() {
  
  scanf("%d %d",&a,&b);
  
  c=a*500;
  
  if(c>=b){
  printf("Yes\n");  
  }
  else{
  printf("No\n");  
  }
  
  
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
	
	int ans;
	/*void dfs(int c,int a,int n,int count){
		if(c>=2&&a>=1){
		//	cout<<"CCA"<<endl;
			dfs(c-2,a-1,n,count+1);
		}
		if(c>=3){
			//cout<<"CCC"<<endl;
			dfs(c-3,a,n,count+1);
		}
		if(c>=1&&a>=1&&n>=1){
			//cout<<"CAN"<<endl;
			dfs (c-1,a-1,n-1,count+1);
		}
		ans=max(ans,count);
		//return count;
	}*/

int main(){
	int Q;
	int c,a,n;
	cin>>Q;
	for(int i=0;i<Q;i++){
	cin>>c>>a>>n;
	//dfs(c,a,n,0);
		while(c>=1&&a>=1&&n>=1){
			ans++,c--,a--,n--;
		}
		while(c>=2&&a>=1){
			ans++,c-=2,a--;
		}
		while(c>=3){
			ans++,c-=3;
		}
	cout<<ans<<endl;
	ans=0;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <limits.h>
#include <tgmath.h>

using namespace std;

typedef uint16_t ui16;
typedef uint32_t ui32;
typedef uint64_t ui64;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef long double ld;
typedef pair<int, int> pr;

//template<typename T> inline T abs(T a) { return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a) { return a * a; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) {for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; return cout; }
void print() { cout << endl; }
template<typename T, typename... Ts> void print(T x, Ts... xs) { cout << x << " "; print(xs...); };
template<typename T> void read(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cin >> v[i]; };

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> board(H + 1, vector<char>(W + 1, '.'));
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin >> board[i][j];
        }
    }

    vector<vector<ui32>> dp(H + 1, vector<ui32>(W + 1, 0));
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (i == 1 && j == 1) {
                dp[1][1] = 1;
                continue;
            }

            if (board[i][j] == '#') {
                continue;
            }

            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]);
            if (dp[i][j] > 1000000007) {
                dp[i][j] %= 1000000007;
            }
        }
    }

//    for (int i = 0; i <= H; ++i) {
//        for (int j = 0; j <= W; ++j) {
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }

    cout << dp[H][W] << endl;

    return 0;
}









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

s = 0
i = 1

while s <= n:
    s += i
    if s == n:
        break
    i += 1
    
else:
    print('No')
    exit()

print('Yes')
print(i+1)
A = [[] for i in range(i+1)]
N = [i for i in range(n+1)]

m = i
j = 1

for a in range(i+1):
    A[a] += N[j:j+m]
    for k in range(a+1, i+1):
        A[k] += [j]
        j += 1
    print(i, *A[a])
    m -= 1

Measured memory_bytes: 13616
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long ans = 100000000;
  for(int i = -100; i <= 100; i++){
    long long int sum = 0;
    for(int j = 0; j < n; j++){
      sum += (i - a[j]) * (i - a[j]);
    }
    ans = min(sum, ans);
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

typedef long long ll;

#define INF 1LL<<60
#define REP(i, n) for(int i = 0; i < (int)n; ++i)

using namespace std;

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

    ll N;
    cin >> N;
    ll min_value = INF;
    for (ll i = 1; i <= sqrt(N); ++i) {
        if (N % i == 0) min_value = min(min_value, i + N / i - 2);
    }
    cout << min_value << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

int main() {

  int N, A;
  cin >> N >> A;
  if ((N % 500) <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256