akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main() {
  int a, b, c, d, e;
  int sum = 0;
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  scanf("%d\n", &c);
  scanf("%d\n", &d);
  scanf("%d\n", &e);
  if(a >= 40) {
    sum = sum + a;
  } else {
    sum = sum + 40;
  }
  if(b >= 40) {
    sum = sum + b;
  } else {
    sum = sum + 40;
  }
  if(c >= 40) {
    sum = sum + c;
  } else {
    sum = sum + 40;
  }
  if(d >= 40) {
    sum = sum + d;
  } else {
    sum = sum + 40;
  }
  if(e >= 40) {
    sum = sum + e;
  } else {
    sum = sum + 40;
  }
  printf("%d\n", sum / 5);
  return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
			a.add(d);
		}
		Collections.sort(a);	
		int half = a.size()/2;

		System.out.println(a.get(half)-a.get(half-1));
   
        }
		
	}

Measured memory_bytes: 61580
#include <bits/stdc++.h>
#define M_PI           3.14159265358979323846  /* pi */
using namespace std;
using  ll = long long;

int main() {
	ll n;
	cin >> n;

	vector<ll>t(n + 1);
	vector<ll>x(n + 1);
	vector<ll>y(n + 1);

	for (ll i = 1; i <= n; i++) {
		cin >> t.at(i) >> x.at(i) >> y.at(i);
	}
	ll tnow;
	ll xynow;
	bool result = true;

	for (ll i = 1; i <= n; i++) {
		tnow = (t.at(i) - t.at(i - 1));
		xynow = fabs(x.at(i) - x.at(i - 1) + (y.at(i) - (y.at(i - 1))));

		if (tnow < xynow)result = false;
		if (xynow % 2 != tnow % 2)result = false;
	}
	if (result == true)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 5568
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        lld h,w;
        cin>>h>>w>>m;
        set<pair<lld,lld>> st;
        lld row[h+1];
        lld col[w+1];
        for(i=0;i<=h;i++) row[i]=0;
        for(i=0;i<=w;i++) col[i]=0;
        for(i=0;i<m;i++){
            cin>>x>>y;
            row[x]++;
            col[y]++;
            st.insert(mp(x,y));
        }
        vec v1;
        pair<lld,lld> pp;
        lld mx1=0,mx2=0;
        for(i=0;i<=h;i++){
            if(row[i]>mx1)
            {
                v1.clear();
                mx1 = row[i];
                v1.pb(i);
            }
            else if(row[i]==mx1)
                v1.pb(i);
        }
        vec v2;
        for(i=0;i<=w;i++)
        {
            if(col[i]>mx2)
            {
                v2.clear();
                mx2 = col[i];
                v2.pb(i);
            }
            else if(col[i]==mx2)
                v2.pb(i);
        }
        for(auto u:v1)
        {
            for(j=0;j<v2.size();j++)
            {
                x = u; y = v2[j];
                cnt = mx1+mx2;
                pp.ff = x; pp.ss=y;
                if(st.find(pp)!=st.end())
                    cnt--;
                else
                {
                    ans = max(ans,cnt);
                    flag=true;
                    break;
                }
                ans = max(ans,cnt);
            }
            if(flag)
                break;
        }
        op(ans);
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 34984
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf=1000000007;

inline 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<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int pre[200005], n, ran[200005], se[200005];

void inti()
{
    for(int i=0;i<=n;i++)
    {
        pre[i]=i;
        ran[i]=1;
        se[i]=1;
    }
}

int find(int x)
{
    if(pre[x]==x)
    {
        return x;
    }
    return pre[x]=find(pre[x]);
}

void unite(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x!=y)
    {
        if(ran[x]<ran[y])
        {
            pre[x]=y;
            se[y]=se[x]+se[y];
        }
        else
        {
            if(ran[x]==ran[y])
            {
                ran[x]++;
            }
            pre[y]=x;
            se[x]=se[y]+se[x];
        }
    }
}

bool same(int x,int y)
{
    return find(x)==find(y);
}

int main()
{
    int m, ans=1;
    scanf("%d%d",&n,&m);
    inti();
    for(int i=1;i<=m;i++)
    {
        int u, v;
        scanf("%d%d",&u,&v);
        if(same(u,v))
        {
            continue;
        }
        else
        {
            unite(u,v);
            ans=max(ans,se[find(u)]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5988
#include <iostream>
using namespace std;
#define ll long long
const ll N = 2e5+107;
ll n,i,a[N],xr;
int main ()
{
    cin>>n;
    for (i=1; i<=n; ++i)
    {
        cin>>a[i];
        xr=xr^a[i];
    }
    for (i=1;i<=n;++i)
        cout<<(xr^a[i])<<" ";
    cout<<"\n";
}



Measured memory_bytes: 5060
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

int main()
{
	int n;
	vector<int> a;

	cin >> n;
	a.reserve(n);

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

	for(int i = n - 1; i >= 0; --i) {
		cout << a[i];
		(i == 0)? cout << endl : cout << ' ';
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl a(n); REP(i, n) cin >> a[i];
	
	map<ll, ll> first, num;
	for (ll i = n - 1; i >= 0; i--) {
		first[a[i]] = i;
		num[a[i]]++;
	}
	vl ans(n, 0);
	auto cur = first.rbegin();
	while (true) {
		auto nxt = next(cur);
		if (nxt == first.rend()) {
			ans[cur->second] += num[cur->first] * cur->first;
			break;
		}
		ans[cur->second] += (cur->first - nxt->first) * num[cur->first];

		num[nxt->first] += num[cur->first];
		if (cur->second < nxt->second) nxt->second = cur->second;
		swap(nxt, cur);
	}

	REP(i, n) cout << ans[i] << "\n";
	cout << flush;
}

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

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  string S;
  ll K;
  cin >> S >> K;
  ll i;
  ll ans=0;
  ll t=1;
  if(S[0] != S[S.length()-1]){
    for(i=1;i<S.length();i++){
      if(S[i-1]==S[i]){
        t++;
      }else{
        ans += t/2;
        t=1;
      }
    }
    ans += t/2;
    cout << ans*K;
  }else{
    ll mae, ushiro;
    for(i=1;i<S.length();i++) if(S[i]!=S[0]) break;
    if(i==S.length()){
      cout<<S.length()*K/2; return 0;
    }
    mae = i;
    for(i=S.length()-1;i>=0;i--) if(S[i]!=S[0]) break;
    ushiro = i;
    for(i=mae+1;i<=ushiro;i++){
      if(S[i-1]==S[i]){
        t++;
      }else{
        ans += t/2;
        t=1;
      }
    }
    ans *= K;
    ans += t/2*K;
    //cout << t/2*K << endl;
    ans += (mae + S.length() - ushiro -1)/2 * (K-1);
    //cout << (mae + S.length() - ushiro -1)/2 * (K-1) << endl;
    ans += mae / 2 + (S.length() - ushiro -1 )/2;
    //cout << mae / 2 + (S.length() - ushiro -1 )/2 << endl;
    cout << ans;
  }
}


Measured memory_bytes: 256
#include<iostream>

int main() {

	int input;
	int sevenCount = 0;
	int fiveCount = 0;

		for (int i = 0; i < 3; i++) {
			std::cin >> input;
			if (input == 7)sevenCount++; 
			if (input == 5)fiveCount++;
}
	
		if ((sevenCount == 1) && (fiveCount == 2))std::cout << "YES";
		else std::cout << "NO";
		


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  li n,x,m; cin >>n >>x >>m;
  vector<li> v(m,0);
  li a=x,t,c=1;
  while(1){
    (a*=a)%=m;
    if(v[a]){
      t=c-v[a];
      break;
    }else{
      v[a]=c++;
    }
  }
  li tail=c-t,q=(n-tail)/t,r=(n-tail)%t;
  li ans=0;
  a=x;
  rep(i,tail+r){
    ans+=a;
    a=a*a%m;
  }
  li period=0;
  rep(i,t){
    period+=a;
    a=a*a%m;
  }
  ans+=period*q;
  print(ans);
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define ll long long
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=1e6+6; const ll INF=1e18;
vector< pr > G[N];
int st[N],tp;
ll f[N];
int main(){
    int n,m; cin>>n>>m;
    rep(i,1,m){
        int l,r,c; cin>>l>>r>>c;
        G[r].push_back(mp(l,c));
    }
    f[0]=INF,f[1]=0; st[tp=1]=1;
    rep(i,2,n){
        f[i]=INF;
        rep(j,0,G[i].size()-1){
            int l=G[i][j].fi,v=G[i][j].se;
            f[i]=min(f[i],v+f[*lower_bound(st+1,st+1+tp,l)]);
        }
        while (tp&&f[i]<f[st[tp]]) --tp;
        st[++tp]=i;
    }
    cout<<(f[n]==INF?-1:f[n])<<endl;
    return 0;
}


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

int main() {
  std::string S;
  std::cin >> S;
  int mm;
  if (S[5] == '0')
    mm = std::stoi(S.substr(6, 1));
  else
    mm = std::stoi(S.substr(5, 2));

  if (mm <= 4)
    std::cout << "Heisei" << std::endl;
  else
    std::cout << "TBD" << std::endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,K;
ll w[1010][1010];
ll b[1010][1010];

void sets(ll x, ll y, char c){
    int f = 1;
    if(c == 'B') f *= -1;
    if((x / K)%2 == 1) f *= -1;
    x %= K;
    if((y / K)%2 == 1) f *= -1;
    y %= K;
    if(f > 0) w[x][y]++;
    else b[x][y]++;
}

ll W(ll a, ll bb, ll c, ll d){
    if(a > c || bb > d) return 0;
    ll ret = w[c][d];
    if(a > 0) ret -= w[a-1][d];
    if(bb > 0) ret -= w[c][bb-1];
    if(a>0 && bb>0) ret += w[a-1][bb-1];
    return ret;
}

ll B(ll a, ll bb, ll c, ll d){
    if(a > c || bb > d) return 0;
    ll ret = b[c][d];
    if(a > 0) ret -= b[a-1][d];
    if(bb > 0) ret -= b[c][bb-1];
    if(a>0 && bb>0) ret += b[a-1][bb-1];
    return ret;
}

ll get(ll x, ll y){
    ll a = W(0,0,x-1,y-1) + W(x,y,K-1,K-1) + B(0,y,x-1,K-1) + B(x,0,K-1,y-1);
    ll b = B(0,0,x-1,y-1) + B(x,y,K-1,K-1) + W(0,y,x-1,K-1) + W(x,0,K-1,y-1);
    return max(a,b);
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++){
        ll x,y;
        char c;
        cin >> x >> y >> c;
        sets(x,y,c);
    }

    for(int i=0;i<K;i++){
        for(int j=0;j<K;j++){
            if(i>0){
                w[i][j] += w[i-1][j];
                b[i][j] += b[i-1][j];
            }
            if(j>0){
                w[i][j] += w[i][j-1];
                b[i][j] += b[i][j-1];
            }
            if(i>0 && j>0){
                w[i][j] -= w[i-1][j-1];
                b[i][j] -= b[i-1][j-1];
            }
        }
    }

    ll max_v = 0;
    for(int i=0;i<K;i++){
        for(int j=0;j<K;j++){
            max_v = max(max_v, get(i,j));
        }
    }
    cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<numeric>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;

int gcd(int a,int b){
	//aとbの最大公約数
	//a>bにしたい
	if (a<b) return gcd(b,a);
	if (a%b==0) return b;
	return gcd(b,a%b);
}

int main(){
	 int n,k;
	 cin >> n>>k;
	 int a,ma,b;
	 cin >> a;
	 ma = b = a;
	 rep(i,n-1){
		cin >> a;
		b = gcd(a,b);
		ma = max(ma,a);
	 }
	 if (k%b!=0 || k>ma){
		 cout << "IMPOSSIBLE" << endl;
	 }
	 else {
		 cout << "POSSIBLE" << endl;
	 }

	 return 0;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
import static java.lang.Long.bitCount;

public class Main {

	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		int h,w,k; 
		h=in.nextInt();
		w=in.nextInt();
		k=in.nextInt();
		String []a=new String[h];
		String []d=new String[h];
		for(int i=0; i<h; ++i) {
			a[i]=in.next();
			d[i]=a[i];
		}
		ArrayList<Integer> b=new ArrayList<>();
		ArrayList<Integer> c=new ArrayList<>();
		for(int i=0; i<(1<<h); ++i) {
			int init=0;
			for(int j=0; j<h; ++j) {
				if(((1<<j)&i)>0) init+=(1<<j); 
			}
			b.add(init);
		}
		for(int i=0; i<(1<<w); ++i) {
			int init=0;
			for(int j=0; j<w; ++j) {
				if(((1<<j)&i)>0) init+=(1<<j); 
			}
			c.add(init);
		}
		int ans=0;
		for(int u:b) {
			for(int v:c) {
				d=a;
				if(check(d,u,v,h,w)==k) ++ans;
			}
		}
		
		System.out.println(ans);
	}
	
	static int check(String []a, int u, int v, int h, int w) {
		int total=0, rem_black=0;
		for(int i=0; i<h; ++i) {
			for(int j=0; j<w; ++j) {
				char c=a[i].charAt(j);
				if(c=='.') continue;
				if(c=='#') ++total;
				if(((1<<i)&u)>0 || ((1<<j)&v)>0) ++rem_black;
			}
		}
		return total-rem_black;
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 33436
#include <iostream>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

typedef struct _node {
	int depth;
	int parent;
	int num;
	int * adj;
} NODE;

int main () {
	int N, u, v;
	cin >> N >> u >> v;

	NODE tree[100001];

	for (int i=1; i<=N; i++) {
		tree[i].depth = -1;
		tree[i].parent = -1;
		tree[i].num = 0;
		tree[i].adj = NULL;
	}

	for (int i=0; i<N-1; i++) {
		int a, b;
		cin >> a >> b;
		tree[a].num ++;
		tree[b].num ++;
		if (tree[a].num==1) {
			if ((tree[a].adj = (int *)malloc(sizeof(int))) == NULL) {
				cerr << "malloc" << endl;
				return -1;
			}
		} else {
			if ((tree[a].adj = (int *)realloc(tree[a].adj, tree[a].num*sizeof(int))) == NULL) {
				cerr << "realloc" << endl;
				free (tree[a].adj);
				return -1;

			}
		}
		if (tree[b].num==1) {
			if ((tree[b].adj = (int *)malloc(sizeof(int))) == NULL) {
				cerr << "malloc" << endl;
				return -1;
			}
		} else {
			if ((tree[b].adj = (int *)realloc(tree[b].adj, tree[b].num*sizeof(int))) == NULL) {
				cerr << "realloc" << endl;
				free (tree[b].adj);
				return -1;

			}
		}
		tree[a].adj[tree[a].num-1] = b;
		tree[b].adj[tree[b].num-1] = a;
	}


	tree[v].depth = 0;
	queue<int> que;
	que.push (v);
	while (!que.empty ()) {
		int n = que.front ();
		que.pop ();
		for (int i=0; i<tree[n].num; i++) {
			int idx = tree[n].adj[i];
			if (tree[idx].depth == -1) {
				tree[idx].depth = tree[n].depth + 1;
				tree[idx].parent = n;
				que.push (idx);
			}
		}
	}

	// 中間を探す
	int med = tree[u].depth/2 + 1;
	int mnode = u;
	while (tree[mnode].depth!=med)
		mnode = tree[mnode].parent;

	// 深いところを探す
	int max = med;
	int n = mnode;
	stack<int> st;
	st.push (n);
	while (!st.empty ()) {
		n = st.top ();
		st.pop ();
		if (tree[n].num==1) {
			if (tree[n].depth>max)
				max = tree[n].depth;
		} else {
			for (int i=0; i<tree[n].num; i++) {
				if (tree[n].adj[i] != tree[n].parent) {
					st.push (tree[n].adj[i]);
				}
			}
		}
	}

	cout << max-1 << endl;

	for (int i=0; i<N; i++)
		free (tree[i].adj);

	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  string S,T;
  cin>>S>>T;
  int ans=1;
  if(S.size()!=T.size()-1) ans=0;
  rep(i,S.size()){
    if(S[i]!=T[i]) ans=0;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>T(N);
    vector<int>A(N);
    vector<int>cnt(N,-1);
    vector<int>ika(N,-1);
    int sum = -1;
    for(int i = 0; i < N; i++) {
        cin >> T[i];
        if(T[i] > sum) {
            cnt[i] = T[i];
            sum = T[i];
        }
        else {
            ika[i] = T[i];
        }
    }
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i+1 == N) {
            if(cnt[i] != A[i] && cnt[i] != -1) {
                cout << 0 << endl;
                return 0;
            }
            else {
                cnt[i] = A[i];
            }
        }
        if(i != 0){
            if(A[i-1] > A[i]) {
                if(cnt[i-1] != A[i-1] && cnt[i-1] != -1) {
                    cout << 0 << endl;
                    return 0;
                }
                else {
                    cnt[i-1] = A[i-1];
                }
            }
            if(cnt[i-1] == -1) {
                ika[i-1] = min(ika[i-1],A[i-1]);
            }
            if(cnt[i-1] != -1 && ika[i-1] != -1 && cnt[i-1] > ika[i-1]) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    int ans = 1;
    for(int i = 0; i < N; i++) {
        if(cnt[i] == -1) {
            ans*=ika[i];
            ans%=INF;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200005] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = n; i > 0; i--, i--) cout << a[i] << ' ';
    if (n % 2) for (int i = 2; i <= n; i++, i++) cout << a[i] << ' ';
    else for (int i = 1; i <= n; i++, i++) cout << a[i] << ' ';
}


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

bitset<1000001> bs;
vector<long long> primes;

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

void sieve() {
  bs.set();
  bs[0] = bs[1] = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (bs[i]) {
      primes.push_back(i);
      for (int j = i*2; j <= 1000000; j+=i) {
        bs[j] = 0;
      }
    }
  }
}

int main() {
  long long a, b, c;
  cin >> a >> b;
  c = gcd(a, b);
  sieve();

// prime facotize gcd(a, b)
  long long ans = 1;
  for (long long i : primes) {
    if (c % i == 0) {
      ans++;
      while (c % i == 0) {
        c /= i;
      }
    }
  }

  ans += (c != 1) ? 1 : 0;
  cout << ans;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  long x;
  cin >> x;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
  long count = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + a.at(i + 1) > x) {
      long count_plus = min(a.at(i) + a.at(i + 1) - x, a.at(i + 1));
      count += count_plus;
      a.at(i + 1) -= count_plus;
      if (a.at(i + 1) == 0) {
        long count_plus = a.at(i) - x;
        count += count_plus;
        a.at(i) -= count_plus;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; i++)
	{
		for (int j = x - i; j + i <= x; j++)
		{
			if ((i * 4 + j * 2) == y)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3632
def myAnswer(N:int,M:int,A:list,B:list,C:list,D:list) ->int:
   for a,b in zip(A,B):
      ans = 10**10
      no = 0
      for n in range(M):
         c = C[n]
         d = D[n]
         distance = abs(a - c) + abs(b - d)
         if(ans > distance):
            ans = distance
            no = n+1
      print(no)


def modelAnswer():
   return
def main():
   N, M = map(int,input().split())
   A = []
   B = []
   C = []
   D = []
   for _ in range(N):
      a,b = map(int,input().split())
      A.append(a)
      B.append(b)
   for _ in range(M):
      c,d = map(int,input().split())
      C.append(c)
      D.append(d)
   myAnswer(N,M,A[:],B[:],C[:],D[:])

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))

cnt = 0
for i in range(1, 101):
    flg = False
    for j in range(N):
        if H[j] < i and flg:
            cnt += 1
        flg = H[j] >= i
    if flg:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (map read . words) >>= print

solve :: [Int] -> Int
solve [x, y]
  | (abs x) <= (abs y) = if x >= 0 && y >= 0 then d
                         else if x < 0 && y < 0 then d + 2
                              else d + 1
  | otherwise = if x < 0 && y <= 0 then d
                else if x >= 0 && y > 0 then d + 2
                     else d + 1
    
  where
    d = abs ((abs x) - (abs y))

getl :: (String -> a) -> IO a
getl f = f <$> getLine


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  std::string s;
  std::cin >> s;
  if (s == "ABC") {
    std::cout << "ARC" << std::endl;
  } else {
    std::cout << "ABC" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

int N;
string S;

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

  int white = 0;
  int black = 0;
  rep(i, N) {
    if (S[i] == '.') {
      white++;
    }
  }

  int ans = white;
  rep(i, N) {
    if (S[i] == '#') {
      black++;
    }
    if (S[i] == '.') {
      white--;
    }
    ans = min(black + white, ans);
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


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

int N;
string S[1111];
int C[1111];
int main(){
  while(  cin >> N && N ){
    memset(C,0,sizeof(C));
    for(int i=0;i<N;i++){
      cin >> S[i];
      for(int j=0;j<(int)S[i].size();j++)
	if( S[i][j]== '.' )
	  C[i]++;      
    }

    for(int i=0;i<N;i++){
      if( C[i] ){
	S[i][C[i]-1] = '+';
	for(int j=i-1;j>-1;j--){
	  if( C[j] > C[i] ) 
	    S[j][C[i]-1] = '|';
	  else
	    break;
	}
      }
    }

    for(int i=0;i<N;i++){
      for(int j=0;j<(int)S[i].size();j++){
	if( S[i][j] == '.' ) cout << " ";
	else cout << S[i][j];
      }
      cout << endl;
    }

  }
}

Measured memory_bytes: 1984
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 xx, yy, aa, bb, cc;
	cin >> xx >> yy >> aa >> bb >> cc;
	vector<int64> av(aa), bv(bb), cv(cc);
	for(int64 ii = 0;ii < aa;ii++)
	{
		cin >> av[ii];
	}
	for(int64 ii = 0;ii < bb;ii++)
	{
		cin >> bv[ii];
	}
	for(int64 ii = 0;ii < cc;ii++)
	{
		cin >> cv[ii];
	}
	sort(av.begin(), av.end());
	reverse(av.begin(), av.end());
	sort(bv.begin(), bv.end());
	reverse(bv.begin(), bv.end());
	sort(cv.begin(), cv.end());
	reverse(cv.begin(), cv.end());
	int64 ans = 0;
	for(int64 ii = 0;ii < xx;ii++)
	{
		ans += av[ii];
	}
	for(int64 ii = 0;ii < yy;ii++)
	{
		ans += bv[ii];
	}
	xx--;
	yy--;
	for(int64 ii = 0;ii < cc;ii++)
	{
		if(xx == -1 && yy == -1)
		{
			break;
		}
		else if(xx == -1)
		{
			if(bv[yy] >= cv[ii])
			{
				break;
			}
			else
			{
				ans -= bv[yy];
				ans += cv[ii];
				yy--;
				continue;
			}
		}
		else if(yy == -1)
		{
			if(av[xx] >= cv[ii])
			{
				break;
			}
			else
			{
				ans -= av[xx];
				ans += cv[ii];
				xx--;
				continue;
			}
		}
		else if(av[xx] < bv[yy])
		{
			if(av[xx] >= cv[ii])
			{
				break;
			}
			else
			{
				ans -= av[xx];
				ans += cv[ii];
				xx--;
			}
		}
		else
		{
			if(bv[yy] >= cv[ii])
			{
				break;
			}
			else
			{
				ans -= bv[yy];
				ans += cv[ii];
				yy--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5588
N, M = map(int, input().split())
H = list(map(int, input().split()))
t = [1] * N
for i in range(M):
  a, b = map(int, input().split())
  if H[a-1] >= H[b-1]:
    t[b-1] = 0
  if H[a-1] <= H[b-1]:
    t[a-1] = 0
print(sum(t))

Measured memory_bytes: 19976
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

int N;

int main() {

	scanf("%d", &N);



	printf("%d\n", 180 * (N - 2));

	return 0;
}


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

using namespace std;

int n, m;

string s;

char a[51][51];

int dl[] = {1, -1, 0, 0};
int dc[] = {0, 0, 1, -1};

int main()
{
    cin >> n >> m;

    int i, j;
    for(i = 1; i <= n; i ++)
    {
        cin >> s;
        for(j = 1; j <= m; j ++)
            a[i][j] = s[j - 1];
    }

    int rez = 1;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
        {
            if(a[i][j] == '#')
            {
                int cate = 0;
                for(int d = 0; d <= 3; d ++)
                {
                    int nl = i + dl[d];
                    int nc = j + dc[d];
                    if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                        cate += (a[nl][nc] == '#');
                }

                if(cate == 0)
                    rez = 0;
            }
        }
    }

    cout << (rez == 1 ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
        final Scanner lineScanner = new Scanner(System.in);
        final int A = lineScanner.nextInt();
        final int B = lineScanner.nextInt();
        final int needIndex = lineScanner.nextInt();
 
        List<Integer> numList = new ArrayList<>();
        for (int i = 1; i <= A && i <= B; i++) {
            if (A % i == 0 && B % i == 0) {
                numList.add(i);
            }
        }
        Collections.sort(numList, Collections.reverseOrder());
        System.out.println(numList.get(needIndex - 1));
    }
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010


int main(){
	IOS;
	ll l,r;cin>>l>>r;
	vll v;
	ll ans=inf;
	rep(i,l,min(r+1ll,l+4039ll))v.pb(i%2019);
	rep(i,0,sz(v))rep(j,i+1,sz(v))ans=min(ans,(v[i]*v[j])%2019);
	cout<<ans;
	return 0;
}



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

int main()
{
    int x=1; 
    int i=0;
    while(x!=0){
        cin >> x;
        i++;
        if(x==0){
            break;
        }
        cout << "Case " << i << ": " << x << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  cin>>n;
  int arr[n];
  for(int i =0; i < n; i++){
  	cin>>arr[i];
  }
  int co = 1;
  int ma = arr[0];
  for(int i =1; i < n; i++){
	ma = max(arr[i],ma);
	if(arr[i] >= ma) co++;
    }
  cout<<co<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(W>=(x+r) && H>=(y+r) && 0<=(x-r) && 0<=(y-r)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

int main(){
  int A,B;
  cin >>A>>B;
  
  int ans = 0;
  rep(i,A,B+1){
    string s = to_string(i);
    string t = s;
    reverse(t.begin(),t.end());
    if(s==t) ans++;
  }
  cout <<ans<< endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int h,w,i,j;
    char a[101][101],x[101] = {0},y[101] = {0};

    scanf("%d %d",&h,&w);

    for (i = 0; i < h; i++)
    {
        scanf("%s",a[i]);
    }

    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if(a[i][j] == '#')break;
        }
        if(j == w)y[i] = 1;
    }

    for (i = 0; i < w; i++)
    {
        for (j = 0; j < h; j++)
        {
            if(a[j][i] == '#')break;
        }
        if(j == h)x[i] = 1;
    }

    for (i = 0; i < h; i++)
    {
        if(y[i] == 1)continue;
        for (j = 0; j < w; j++)
        {
            if(x[j] == 1)continue;
            else printf("%c",a[i][j]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;

template<typename T> struct edge
{
    int to; T cost;
    edge(int to, T cost) : to(to), cost(cost) {}
};
template<typename T>
using Gragh = vector<vector<edge<T>>>;

template<typename T> T MST(Gragh<T> &G)
{
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> used(G.size(), 0);
    T res = 0;
    que.push(make_pair(0, 0));
    while(que.size())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        if(used[v]) continue;
        used[v] = 1;
        res += p.first;
        for(auto &u : G[v])
        {
            if(used[u.to]) continue;
            que.push(make_pair(u.cost, u.to));
        }
    }
    return res;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E; cin >> V >> E;
    Gragh<int> G(V);
    for(int i = 0; i < E; i++)
    {
        int s, t, w; cin >> s >> t >> w;
        G[s].emplace_back(t, w);
        G[t].emplace_back(s, w);
    }
    cout << MST(G) << endl;
    return 0;
}




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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    int count = 0;
    bool ok = false;
    for(int i=0;i<n;++i){
        int x,y;
        cin>>x>>y;
        if(x == y){
            count++;
        }else count=0;
        if(count == 3)ok = true;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}

/////////////////////////////////////////////////////////////
bool diffSign(int a,int b) {
	return ((a>0 && b<0) || (a<0 && b>0));
}  

int main() 
{ 
	int i,n,m,x;
	cin>>n>>m;
	priority_queue<int> A;
	rep(i,n) {
		cin>>x;
		A.push(x);
	}
	while(m--) {
		x = A.top();
		A.pop();
		x = x/2;
		A.push(x);
	}
	LL cnt=0;
	while(!A.empty()) {
		cnt += A.top();
		A.pop();
	}
	cout<<cnt;
	return 0; 
} 


Measured memory_bytes: 892
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) a[i] = in.nextLong();

            long[][] dp = new long[n + 1][n + 1];
            for (int left = n - 1; left >= 0; left--) {
                for (int right = left; right < n; right++) {
                    if (left == right) {
                        dp[left][right] = a[left];
                    } else {
                        dp[left][right] = Math.max(a[left] - dp[left + 1][right], a[right] - dp[left][right - 1]);
                    }
                }
            }
            out.println(dp[0][n - 1]);
        }

    }
}



Measured memory_bytes: 129632
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME:
int main() {
    int n;
    cin >> n;
    vector<int> a;
    for(int t=1; t<=n; t*=6) a.push_back(t);
    for(int t=9; t<=n; t*=9) a.push_back(t);
    sort(a.begin(), a.end());
    int dp[20][100010];     // dp[i][j] := i番目まで使用して、合計がjになる時の最小の操作数
    int m = a.size();

    rep(i, m+1)rep(j, n+1) dp[i][j] = inf;
    rep(i, m+1) dp[i][0] = 0;
    rep(i, m+1)rep(j, n+1){
        if(i==0) continue;
        if(j-a[i-1]>=0){
            dp[i][j] = min(dp[i][j-a[i-1]]+1, dp[i-1][j]);
        }else{
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
    }

    cout << dp[m][n] << endl;
    return 0;
}

Measured memory_bytes: 6656
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int n ,arr[N] ;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    sort(arr,arr+n);
    if(n%2) return cout << 0,0 ;
    cout << arr[n/2] - arr[n/2-1] ;
    return 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n, m;
    cin >> n >> m;
    int x[n] = {};
    int y[m] = {};
    int numX, numY;
    cin >> numX >> numY;
    rep(i, n) { cin >> x[i]; }
    rep(i, m) { cin >> y[i]; }

    // 処理
    sort(x, x + n);
    sort(y, y + m);

    int maxX = x[n - 1];
    int minY = y[0];

    // 出力
    cout << (maxX < minY && maxX < numY && numX < minY ? "No War" : "War")
         << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    char a[3];
    int b = 700;
    for( int i = 0; i < 3; i++ ){
        cin >> a[i] ;
        if(a[i]=='o'){
            b = b + 100;

        }
    }

    cout << b << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];
 
int times = 1;
int n;
int graph[101][101];
 
void bfs(int now){
 
  T[now].f = true;
  T[now].begin = times++;
 
  for( int i = 1 ; i <= n; i++ ){
    if( graph[now][i] == 1 && !T[i].f ) bfs(i);
  }
  T[now].end = times++;
 
}
 
int main(void){
 
  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  for( int i = 1 ; i <= n ; i++ ){
    if( !T[i].f ) bfs(i);
  }
 
  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }
 
 
  return 0;
}


Measured memory_bytes: 3108
# Here your code !
H, W = gets.split

S = Array.new
H.to_i.times do
    S << gets.chomp.split("")
end
answer = Array.new(H.to_i).map{Array.new(W.to_i,0)}

H.to_i.times do |i|
    j = 0
    S[i].each {
        if S[i][j] != "#"
            if j != W.to_i-1 && S[i][j+1] == "#"
                answer[i][j] += 1
            end
            if j != 0 && S[i][j-1] == "#"
                answer[i][j] += 1
            end
            if i != 0 && S[i-1][j] == "#"
                answer[i][j] += 1
            end
            if i != H.to_i-1 && S[i+1][j] == "#"
                answer[i][j] += 1
            end
            if i != 0 && j != 0 && S[i-1][j-1] == "#"
                answer[i][j] += 1
            end
            if i != 0 && j != W.to_i-1 && S[i-1][j+1] == "#"
                answer[i][j] += 1
            end
            if j != 0 && i != H.to_i-1 && S[i+1][j-1] == "#"
                answer[i][j] += 1
            end
            if j != W.to_i-1 && i != H.to_i-1 && S[i+1][j+1] == "#"
                answer[i][j] += 1
            end
        else
            answer[i][j] = "#"
        end
        j += 1;
    }
end

H.to_i.times do |i|
  answer[i].each { |s|
    print s
  }
  puts ""
end

Measured memory_bytes: 2172
n = int(input())
 
s = 0
p = 0
for _ in range(n):
  t,x,y = map(int, input().split())
  s = t - s
  p = abs((x+y)-p)
  if s < p:
    print("No")
    exit()
  elif s%2 != p%2:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 9064
a=[]
for i in range(5):
    a.append(int(input()))
ans=0
min=10
minn=0
for i in range(5):
    if (a[i]%10<=min and a[i]%10!=0):
        min=a[i]%10
        minn=i
for i in range(5):
    if a[i]%10!=0:
        b=(a[i]//10)
        ans=ans+b*10+10
    elif a[i]==0:
        ans+=10
    else:
        ans=ans+a[i]
if min!=10:
    print(ans-(10-a[minn]%10))
else:
    print(ans)

Measured memory_bytes: 3064
use strict;
use warnings;

my $in = <>;
chomp $in;
my ($n, $m) = split(/ /, $in);

my %input;
while(my $in = <>){
	chomp $in;
	my @data = split(/ /, $in);
	
	my $top = $data[0];
	my $tail = $data[1];
	
	if (!exists $input{$top}){
		$input{$top} = [];
	}
	if (!exists $input{$tail}){
		$input{$tail} = [];
	}
	push(@{$input{$top}}, $tail);
	push(@{$input{$tail}}, $top);
}

my @select;
my @used;
my $idx = (keys %input)[0];
$select[0] = $idx;
$select[1] = $input{$idx}->[0];
$used[$idx-1] = 1;
$used[($input{$idx}->[0])-1] = 1;

while(1){
	$idx = $select[0];
	my $head_flag = 0;
	foreach (@{$input{$idx}}){
		if (!$used[$_-1]){
			unshift(@select, $_);
			$used[$_-1] = 1;
			$head_flag = 1;
			last;
		}
	}
	
	$idx = $select[-1];
	my $tail_flag = 0;
	foreach (@{$input{$idx}}){
		if (!$used[$_-1]){
			push(@select, $_);
			$used[$_-1] = 1;
			$tail_flag = 1;
			last;
		}
	}
	
	if(($head_flag == 0) && ($tail_flag == 0)){
		last;
	}
}


print scalar(@select)."\n";
print join(" ", @select)."\n";
exit;


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

#define MAXD 300001
using pii = pair<int,int>;
unordered_set<int> rows[MAXD],cols[MAXD];
int h,w,m;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>h>>w>>m;
    for (int i = 0,hi,wi; i < m; ++i) {
        cin>>hi>>wi;
        rows[hi].insert(wi);
        cols[wi].insert(hi);
    }
    vector<pii> brows, bcols;
    for (int i = 1; i <= h; ++i) brows.emplace_back(rows[i].size(),i);
    for (int i = 1; i <= w; ++i) bcols.emplace_back(cols[i].size(),i);
    sort(brows.rbegin(), brows.rend());
    sort(bcols.rbegin(), bcols.rend());

    while (brows.back().first != brows.front().first) brows.pop_back();
    while (bcols.back().first != bcols.front().first) bcols.pop_back();

    for (pii r: brows) {
        for (pii c: bcols) {
            if (!rows[r.second].count(c.second)) {
                cout << brows[0].first + bcols[0].first;
                return 0;
            }
        }
    }

    cout << brows[0].first + bcols[0].first - 1;
}

Measured memory_bytes: 81908