akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    ll n,m;
    cin >> n >> m;
    
    vector<ll> v[m];
    rep(i,0,n){
	ll a,b;
	cin >> a >> b;
	if(a-1 < m)v[a-1].pb(b);
    }
    p_queue(ll) pq;
    ll ans = 0;
    
    rep(i,0,m){
	for(auto j : v[i])pq.push(j);
	if(!pq.empty()){
	    ans += pq.top();
	    pq.pop();
	}
    }
    P(ans);
    return  0;
}


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

int main() {
  int N;
  cin >> N;
  
  int a, b, c, d;
  a = N/1000;
  b = (N-1000*a)/100;
  c = (N-1000*a-100*b)/10;
  d = (N-1000*a-100*b-10*c);
   
  if ((a == b && b ==c) || (b == c && c == d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<int> H;

    for (int i = 0; i < N; ++i)
    {
        ll temp;
        cin >> temp;
        H.push_back(temp);
    }
    vector<bool> A(N, true);
    for (int i = 0; i < M; ++i)
    {
        ll a, b;
        cin >> a >> b;
        if (H[a - 1] == H[b - 1])
        {
            A[b - 1] = false;
            A[a - 1] = false;
            continue;
        }
        if (H[a - 1] > H[b - 1])
        {
            A[b - 1] = false;
        }
        else

        {
            A[a - 1] = false;
        }
    }
    ll ans = 0;
    for (int i = 0; i < A.size(); ++i)
    {
        if (A[i])
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3868
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<cstring>
#include <math.h>
using namespace std;
char a[300000];
char a1[100000];
int x,y;
typedef long long ll;
int main()
{
    x=100000;

    char q;
    int k,b,t,n;
    t=0;
    cin>>a1;
    int m=strlen(a1);
    for(int i=x;i<x+m;i++)
    {
        a[i]=a1[i-x];
    }
    y=x+m;
    cin>>n;
    while(n--)
    {
        cin>>k;
        if(k==1)
        {
            if(t==0)
            {
                t=1;
            }
            else
            {
                t=0;
            }
        }
        else if(k==2)
        {
            cin>>b>>q;
            if(b==1)
            {
                if(t==0)
                {
                    a[x-1]=q;
                    x=x-1;
                }
                else
                {
                    a[y]=q;
                    y=y+1;
                }
            }
            else
            {
                if(t==1)
                {
                    a[x-1]=q;
                    x=x-1;
                }
                else
                {
                    a[y]=q;
                    y=y+1;
                }
            }
        }
    }
    if(t==0)
    {
        for(int i=x; i<y; i++)
        {
            cout<<a[i];
        }
    }
    else
    {
         for(int i=y-1; i>=x; i--)
        {
            cout<<a[i];
        }
    }
    return 0;
}



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

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

	int a,b,c;
	cin>>a>>b>>c;
	if((a==b and a!=c )or(a==c and a!=b) or(b==c and b!=a))	cout<<"Yes";
	else cout<<"No";
	
	return 0;	
}

Measured memory_bytes: 256
N = list(map(int, input().split()))
N=N[0]
d={}
def dad(d,a,b):
    if a not in d:
        d[a]=[]
    d[a].append(b)

for x in range(N):
    A,B = list(map(int, input().split()))
    dad(d,B,A)

time=0
flag=0
for item in sorted(d.items()):
    for x in item[1]:
        time+=x
    if not time<=item[0]:
        flag=-1
        break
if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 76472
#include<bits/stdc++.h>
using namespace std;
#define debug 1

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	double n;
	cin>>n;
	
	long left=0,right=51000,mid;
	while(left<=right) {
//		cout<<left<<" "<<right<<endl;
		mid=(left+right)/2;
		if((long)((double)mid*1.08)>n)
			right=mid-1;
		else if((long)((double)mid*1.08)<n)
			left=mid+1;
		else {
			cout<<mid<<endl;
			return 0;
		}
	}
	cout<<":("<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int i, a, b, c;
  int d[3];
  scanf("%d %d %d", &a, &b, &c);
  d[0] = a, d[1] = b, d[2] = c;
  for(i = 0; i < 3; i++)
  {
    if(d[i] < -100 || d[i] > 100)
    {
      printf("wrong input\n");
      return 0;
    }
  }
  if(a <= c && b >= c)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    if (n < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (n < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int cnt = 0;
    REP (i, n - 1) {
        cnt += s[i] == s[i + 1];
    }
    cout << min(n - 1, cnt + 2 * k) << endl;
}


Measured memory_bytes: 512
a,b,c=map(int,input().split())
if a%c==0:
	l=a 
else:
	l=(a//c+1)*c 
if b%c==0:
	u=b 
else:
	u=(b//c)*c 
#print(l,u)
print(max(0,(u-l)//c+1))

Measured memory_bytes: 9184
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
struct Edge
{
	int to;
	int nxt;
	ll len;
}e[4005];
struct edge
{
	int from,to;
	ll len;
}_e[2005];
int n,m,edgenum,head[1005],pa[1005];
ll x,maxx[1005];
bool flag[2005];
bool cmp(edge a,edge b)
{
	return a.len<b.len;
}
int find(int x)
{
	return x==pa[x]?x:pa[x]=find(pa[x]);
}
void add(int u,int v,ll l)
{
	e[++edgenum].len=l;
	e[edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
void dfs(int node)
{
	for(int hd=head[node];hd;hd=e[hd].nxt)
	{
		int to=e[hd].to;
		if(to==pa[node])continue;
		pa[to]=node;
		maxx[to]=max(maxx[node],e[hd].len);
		dfs(to);
	}
}
int main()
{
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=1;i<=m;i++)scanf("%d%d%lld",&_e[i].from,&_e[i].to,&_e[i].len);
	sort(_e+1,_e+m+1,cmp);
	for(int i=1;i<=n;i++)pa[i]=i;
	ll tot=0;
	for(int i=1;i<=m;i++)
	{
		int u=find(_e[i].from);
		int v=find(_e[i].to);
		if(u!=v)
		{
			pa[u]=v;
			tot+=_e[i].len;
			add(_e[i].from,_e[i].to,_e[i].len);
			add(_e[i].to,_e[i].from,_e[i].len);
			flag[i]=1;
		}
	}
	if(tot>x)return puts("0"),0;
	int n1=tot==x?m:m-n+2,n2=m-n+2;
	for(int i=1;i<=m;i++)
	{
		if(!flag[i])
		{
			maxx[_e[i].from]=pa[_e[i].from]=0;
			dfs(_e[i].from);
			if(tot+_e[i].len-maxx[_e[i].to]<x)n1--;
			if(tot+_e[i].len-maxx[_e[i].to]<=x)n2--;
		}
	}
	ll v1=1,v2=1;
	for(int i=1;i<=n1;i++)v1=v1*2%MOD;
	for(int i=1;i<=n2;i++)v2=v2*2%MOD;
	printf("%lld\n",(v1-v2+MOD)%MOD);
	return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    for (int i=0;i<s.length();i++)
    {
        if (s[i]!=t[i]) {cout<<"No";return 0;};
    }
    if (t.length()-1==s.length())cout<<"Yes";
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,x;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&f);
	if(a<=40){
		a=40;
	}
	if(b<=40){
		b=40;
	}
	if(c<=40){
		c=40;
	}
	if(d<=40){
		d=40;
	}
	if(f<=40){
		f=40;
	}
	x=(a+b+c+d+f)/5;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 2728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	ll n; cin >> n;

	vector<ll>l(n + 1);
	l[0] = 2;
	l[1] = 1;
	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 2] + l[i - 1];
	}
	cout << l[n] << endl;
}


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s[1000];
	int n;
	cin>>n;
	unordered_map<string,bool> mp;
	cin>>str;
	mp[str]=1;
	n--;
	int i=1;
	s[0]=str;
	while(n--)
	{
	    cin>>s[i++];
	    if(mp[s[i-1]])
	    {cout<<"No";return 0;}
	    if(s[i-1][0]!=s[i-2][s[i-2].size()-1])
	    {cout<<"No";return 0;}
	    mp[s[i-1]]=1;
	    
	}
	cout<<"Yes";
	
	
	
	
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,j,k,block[500000][5],hhh,max[5],left,from,time;
int n,d,l,x;

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int main(){
	while(scanf("%d",&n)*n){
		hhh=0;left=0;
		for(i=0;i<5;i++)max[i]=0;

		for(;n>0;n--){

			scanf("%d %d %d",&d,&l,&x); x--;
			left+=l;

			if(d==1){
				k=0;j=0;
				for(i=0;i<l;i++){if(max[x+i]>k){k=max[x+i];j=x+i;}}
				for(i=0;i<l;i++){max[x+i]=k+1;block[k][x+i]=1;}
				from=k;time=1;
			}
			else{
				for(i=0;i<l;i++)block[max[x]+i][x]=1;
				from=max[x];
				max[x]+=l;
				time=l;
				j=x;
			}

			if(hhh<max[j])hhh=max[j];

			for(i=0;i<time;i++){
				if(block[from][0]==1 && block[from][1]==1 && block[from][2]==1 && block[from][3]==1 && block[from][4]==1){
					for(j=0;j<5;j++){block[from][j]=0;}
					for(k=from+1;k<hhh;k++){
						for(j=0;j<5;j++){
							swap(&block[k][j],&block[k-1][j]);
						}
					}
					left-=5;hhh--;
				}
				else from++;
			}

			for(j=0;j<5;j++){
				for(k=max[j];k>=0;k--){
					if(block[k][j]==1)break;
				}
				max[j]=k+1;
			}
			/*
			for(i=hhh-1;i>=0;i--){
				for(j=0;j<5;j++){
					printf("%c",block[i][j]==1 ? '*' : ' ');
				}
				printf("\n");
			}
			for(j=0;j<5;j++){printf("%d",max[j]);}printf("\n");
			printf("height:%d\n",hhh);
			*/
		}

		for(i=0;i<hhh;i++){
			for(j=0;j<5;j++){
				block[i][j]=0;
			}
		}

		printf("%d\n",left);
	}
	return 0;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m >> k;
    if(n+m+k>=22){
        cout << "bust" << endl;
    }else{
        cout << "win"<< endl;
    }
    return 0;
}

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

int main() {
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a);
    vector<int> q(b);
    vector<int> r(c);
    rep(i,a) cin >> p.at(i);
    rep(i,b) cin >> q.at(i);
    rep(i,c) cin >> r.at(i);
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    vector<int> sub(x+y+c);
    rep(i,x) sub.at(i) = p.at(i);
    rep(i,y) sub.at(x+i) = q.at(i);
    rep(i,c) sub.at(x+y+i) = r.at(i);
    sort(sub.begin(), sub.end());
    reverse(sub.begin(), sub.end());
    ll ans = 0;
    rep(i,x+y) ans += sub.at(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  if(x<r||x>(w-r)){
    printf("No\n");
  }
  else if(y<r||y>(h-r)){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long d[N];
  for (int i = 0; i < N; i++) cin >> d[i];
  long long ans = 0;
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) ans += d[i] * d[j];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3616
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var minv = int.MaxValue;
        var maxv = int.MinValue;
        for (var i = 0; i < n; i++)
        {
            var p = int.Parse(Console.ReadLine());
            maxv = Math.Max(maxv, p - minv);
            minv = Math.Min(minv, p);
        }
        Console.WriteLine("{0}", maxv);
    }
}


Measured memory_bytes: 9244
#include <cstdlib>
#include <iostream>
#include <cassert>

using namespace std;

class Stack {
    public:
        bool push(int num)
        {
            if(isFull())
            {
                return false;
            }
            _buffer[_stack_top] = num;
            ++_stack_top;
            return true;
        }

        int pop()
        {
            if(isEmpty())
            {
                assert(false);
                return 0;
            }
            --_stack_top;
            int value = _buffer[_stack_top];
            return value;
        }

        bool isEmpty() const
        {
            if(_stack_top <= 0)
            {
                return true;
            }
            return false;
        }

        bool isFull() const
        {
            if(_stack_top >= MAX_SIZE)
            {
                return true;        
            }
            return false;
        }

        Stack()
        {
            _stack_top = 0;
        }

        ~Stack()
        {

        }

    private:
        static const int MAX_SIZE = 100;

        int _buffer[MAX_SIZE];
        int _stack_top;
};

bool isOperator(char* str)
{
    if(str[0] == '+' || str[0] == '-' || str[0] == '*' )
    {
        return true;
    }
    return false;
}

int main()
{
    Stack numbers;

    char input[7];
    while(cin >> input)
    {
        if(isOperator(input))
        {      
            int num_back = numbers.pop();
            int num_front = numbers.pop();

            switch(input[0])
            {
                case '+':
                {
                    numbers.push(num_front + num_back);
                    break;
                }
                case '-':
                {
                    numbers.push(num_front - num_back);
                    break;
                }
                case '*':
                {
                    numbers.push(num_front * num_back);
                    break;
                }
                default:
                {
                    assert(false);
                    break;
                }
            }
        }
        else
        {
            int num = atoi(input);
            numbers.push(num);
        }
    }

    if(!numbers.isEmpty())
    {
        cout << numbers.pop() << endl;
    }

    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define pb push_back
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

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*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

int a[maxn];

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    int n; cin >>n;
    for (int i = 0; i<n; i++) cin>>a[i];
    for (int i = 0; i < n; i++){
        int s = 0;
        for (int j = 0; j <n; j++) {
            if (j == i)continue;
            s += a[j];
        }
        if (s <= a[i]) {
            puts("No");return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
import math
MOD = int(1e9+7)


def main():
    N, K = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    x = int(math.log(K, 2))
    dp = [[[0] * N for _ in range(N)] for _ in range(x+1)]
    dp[0] = A
    for d in range(x):
        for i in range(N):
            for j in range(N):
                for k in range(N):
                    dp[d+1][i][j] = (dp[d+1][i][j] +
                                     dp[d][i][k] * dp[d][k][j]) % MOD
    ans = [1] * N
    for d in range(x+1):
        if K & (2 ** d) == 0:
            continue
        prev = list(ans)
        ans = [0] * N
        for i in range(N):
            for j in range(N):
                ans[j] = (ans[j] + dp[d][i][j] * prev[i]) % MOD

    print(sum(ans) % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42604
#include<iostream>
#include<deque>
using namespace std;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}else return false;}
int n,m;
deque<int> dp(n);
deque<deque<int>> G;
int rec(int num){
	if(dp[num] != -1) return dp[num];
	int k = -1;
	for(auto v : G[num]) chmax(k, rec(v));
	k++;
	return dp[num] = k;
	}
int main(){
	cin >> n >> m;
	G.assign(n, deque<int> ());
	for(int i = 0; i < m; i++){
		int a,b;cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		}
	dp.assign(n, -1);
	int x = 0;
	for(int i = 0; i < n; i++) chmax(x, rec(i));
	cout << x << "\n";
	}

Measured memory_bytes: 70912
n = gets.to_i
n.times do
  ans = 0
  b = []
  5.times{ b << gets.split.map(&:to_i) }
  5.times do |i|
    5.times do |j|
      if b[i][j] == 1
        (1..5).each do |k|
          (1..5).each do |m|
            f = nil
            k.times do |p|
              m.times do |q|
                f = true if i + p > 4 || j + q > 4 || b[i+p][j+q] == 0
              end
            end
            ans = k * m if f.nil? && ans < k * m
          end
        end
      end
    end
  end
  p ans
  gets
end

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  int n;
  cin >> n;
  int x[n];
  rep(i,n){
    cin >> x[i];
  }
  sort(x,x+n);
  ll nmin = 1e9;
  for(int i = x[0];i < x[n-1]+1;i++){
    ll total = 0;
    rep(j,n){
      total += pow(abs(x[j]-i),2);
    }
    nmin = min(total,nmin);
  }
  cout << nmin << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

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

  int ball_num = 10;
  for(int i=0;i<n;i++){
    vector<int> a;
    bool flag = true;
    for(int j=0;j<ball_num;j++){ 
      int tmp;
      cin >> tmp;
      a.push_back(tmp);
    }

    int b=0;
    int c=0;
    for(int i=0;i<ball_num;i++){
      if(b<=c){
	swap(b, c);
      }
      
      // b > c

      if(b < a[i]){
	b = a[i];
      }else{
	if(c < a[i]){
	  c = a[i];
	}else{
	  flag = false;
	}
      }

      if(flag==false){
	break;
      }
    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
    
  }

  

}

Measured memory_bytes: 1204
a,b,c = map(int,input().split())
ans = 0
while a%2==b%2==c%2==0:
    a,b,c = (b+c)//2, (a+c)//2, (a+b)//2
    ans += 1
    if ans > 100:
        ans = -1
        break
print(ans)

Measured memory_bytes: 3064
#include<iostream>
int main()
{
 int a,b,c,k,i;
 scanf("%d %d %d %d",&a ,&b ,&c ,&k);
  if(k<=a){
    printf("%d",k);}
  else if(k<=a+b){
    printf("%d",a);}
  else{
    c=k-(a+b);
    i=a-c;
    printf("%d",i);}
}


Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main(void){
    int m,n;
    cin >> m;
    while(m!=0){
       n = 1000 - m;
       cout << n/500 + (n%500)/100 +(n%100)/50+ (n%50)/10 +(n%10)/5 + (n%5) << endl;
       cin >> m;
    }
}


Measured memory_bytes: 3012
#include<stdio.h>
int main(){
  int i;
  int n;
  int s;
  int t[2];
  int m1,m2,m3,m4,s1,s2,s3,s4;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    int b[2][2]={{0,100000},{0,100000}};
    int w[2][2]={{-1,-1},{-1,-1}};
    for(i=0;i<n;i++){
      scanf("%d %d %d %d %d %d %d %d %d",
	    &t[0],&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
      t[1]=(m1+m2+m3+m4)*60;
      s=s1+s2+s3+s4;
      t[1]+=s;
      if(b[1][1]>t[1]){
	b[1][1]=t[1];
	b[1][0]=t[0];
	if(b[0][1]>b[1][1]){
	  b[1][1]=b[0][1];
	  b[1][0]=b[0][0];
	  b[0][1]=t[1];
	  b[0][0]=t[0];
	}
      }
      if(w[1][1]<t[1]){
	w[1][1]=t[1];
	w[1][0]=t[0];
	if(w[0][1]<w[1][1]){
	  w[1][1]=w[0][1];
	  w[1][0]=w[0][0];
	  w[0][1]=t[1];
	  w[0][0]=t[0];
	}	
      }
    }
    printf("%d\n%d\n%d\n",b[0][0],b[1][0],w[1][0]);
  }
  return 0;
}

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

using namespace std;

int main(){
  long long n,W,w[109],v[109],base;
  long long dp[109][309];
  cin >> n >> W;
  cin >> w[0] >> v[0];
  base=w[0];
  for(int i=1;i<n;i++){
    cin >> w[i] >> v[i];
    w[i]-=base;
  }
  w[0]=0;
  memset(dp, 0, sizeof(dp));  
  long long mx=0;
  for(long long i=0;i<n;i++){
    for(long long j=100LL;j>=1;j--){
      for(long long k=300LL;k>=w[i];k--){
        dp[j][k]=max(dp[j][k], dp[j-1][k-w[i]]+v[i]);
      }
    }
  }
  int m=W/base, r=W%base;
  for(int i=0;m-i>=0;i++){
    mx=max(mx,dp[m-i][min(r+base*i, 300LL)]);
  }
  cout << mx << endl;
}



Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int N, X; cin >> N >> X;
  vector<int> m;
  for (int i = 0; i < N; i++) {
    int t; cin >> t;
    m.push_back(t); X -= t;
  }
  cout << N+(X/(*min_element(m.begin(),m.end()))) << endl;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

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

	int A[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout << A[N] << endl;

	return 0;
}


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



int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for( int i = 0; i < N; ++i ) cin >> A[i];
    for( int i = 0; i < N; ++i ) cin >> B[i]; 


    long long sumA = 0, sumB = 0;
    for( int i = 0; i < N; ++i ){
        sumA += A[i];
        sumB += B[i];
    } 

    if( sumA < sumB ) cout << -1 << endl;
    else
    {
        vector<int> diff(N);
        long long diffSum = 0;
        int ans = 0;
        for( int i = 0; i < N; ++i ){
            diff[i] = A[i] - B[i];
            if( diff[i] < 0 ){
                diffSum += - diff[i];
                ++ans;
            }
        } 
        
        sort( diff.begin(), diff.end(), greater<long long>() );

        int i = 0;
        while( diffSum > 0 ){
            diffSum -= diff[i];
            ++i, ++ans;
        }
        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
    
    public static class Edge {
      int idx;
      int node;
      public Edge(int n, int i) {
        this.idx = i;
        this.node = n;
      }
    }

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      
      Map<Integer, List<Edge>> graph = new HashMap<>();
      Map<Integer, Set<Integer>> usedColor = new HashMap<>();
      for(int i = 1; i <= n; i++) {
          graph.put(i, new ArrayList<>());
          usedColor.put(i, new HashSet<>());
      }

      for(int i = 0; i < n - 1; i++) {
          int v = sc.nextInt();
          int u = sc.nextInt();
          graph.get(v).add(new Edge(u, i));
          graph.get(u).add(new Edge(v, i));
      }

      int cnt = 0;
      for(List<Edge> adjs : graph.values())
          cnt = Math.max(cnt, adjs.size());

      System.out.println(cnt);
      
      int[] colors = new int[n-1];
      Queue<Integer> queue = new LinkedList<>();
      Set<Integer> visited = new HashSet<>();
      queue.offer(1);
      visited.add(1);
      while(!queue.isEmpty()) {
        int node = queue.poll();
        int c = 1;
        for(Edge e : graph.get(node)) {
          if(visited.contains(e.node)) continue;
          while(usedColor.get(node).contains(c) || usedColor.get(e.node).contains(c)) c++;
          if(colors[e.idx] == 0)
              colors[e.idx] = c;
          usedColor.get(node).add(c);
          usedColor.get(e.node).add(c);
          queue.offer(e.node);
          visited.add(e.node);
          c++;
        }
      }
      for(int c : colors)
        System.out.println(c);
  }
}

Measured memory_bytes: 153892
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    char[][] map = new char[h][w];
    int count = 0;
    int[][] dist = new int[h][w];
    for(int i=0;i<h;i++){
      map[i] = sc.next().toCharArray();
      for(int j=0;j<w;j++){
        if(map[i][j] == '.')count++;
        dist[i][j] = -1;
      }
    }
    int[][] vec = {{1,0},{-1,0},{0,1},{0,-1}};
    Queue<Integer> yQueue = new ArrayDeque<Integer>();
    Queue<Integer> xQueue = new ArrayDeque<Integer>();
    int now_dist = 1;
    dist[0][0] = 0;
    yQueue.add(0);
    xQueue.add(0);
    int ytmp,xtmp,size,yto,xto;
    while(!yQueue.isEmpty()){
      size = yQueue.size();
      for(int j=0;j<size;j++){
        ytmp = yQueue.poll();
        xtmp = xQueue.poll();
        
        for(int i=0;i<4;i++){
          yto = ytmp + vec[i][0];
          xto = xtmp + vec[i][1];
          if(yto>=0 && yto < h && xto >=0 && xto < w &&
             dist[yto][xto]==-1 && map[yto][xto]=='.'){
            dist[yto][xto] = now_dist;
            yQueue.add(yto);
            xQueue.add(xto);
          }
        }
      }
      now_dist++;
    }
    if(dist[h-1][w-1]!=-1){
      System.out.print(count-dist[h-1][w-1]-1);
    }else{
      System.out.print(-1);
    }
    System.out.flush();
  }
}

Measured memory_bytes: 23124
import collections
import math
n = int(input())
a = [0]*n
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(input())
    t.sort()
    m = " ".join(t)
    a[j] = m
c = collections.Counter(a)
d = list(c)
for k in range(len(d)):
    if c[d[k]] > 1:
        b += combinations_count(c[d[k]], 2)
    else:
        continue
print(b)

Measured memory_bytes: 20584
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int>p(n);
  REP(i, n) cin >> p[i];
  int ans =0;
  REP(i, n-2){
    if(p[i]<p[i+1]&&p[i+1]<p[i+2]) ans++;
    else if(p[i]>p[i+1]&&p[i+1]>p[i+2]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
S=list(input())
l=0
r=S[1:].count('E')
ans=l+r
for i in range(N-1):
    if S[i]=='W':
        l+=1
    if S[i+1]=='E':
        r-=1
    ans=min(ans,l+r)
print(ans)


Measured memory_bytes: 8268
import java.io.IOException;

public class Main {
	
		
		public static void main(String[] args) throws IOException {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
			
//			BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
//			String str = br.readLine();
//			int x = Integer.parseInt(str);
//			
		if(1<=x && x<=100){;
		System.out.println(x*x*x);// TODO ?????????????????????????????????????????????
		}
		}	
			
		
	
	}
	

Measured memory_bytes: 26308
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define pai 3.14159265359
#define mod 1000000007
 
vector<vector<int> > road(2001);
int n, k;

int solve_even()
{
    int ans = 2000;
    for(int i = 1; i <= n; i++){
        vector<int> depth(n + 1, -1);
        depth[i] = 0;
        queue<int> qu;
        qu.push(i);
        int nowans = 1;
        while(!qu.empty()){
            int now = qu.front();
            qu.pop();
            if(depth[now] >= k / 2) continue;
            for(int j = 0; j < road[now].size(); j++){
                int next = road[now][j];
                if(depth[next] == -1){
                    depth[next] = depth[now] + 1;
                    qu.push(next);
                    nowans++;
                }
            }
        }
        ans = min(ans, n - nowans);
    }
    return ans;
}

int solve_odd()
{
    int ans = 2000;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < road[i].size(); j++){
            vector<int> depth(n + 1, -1);
            depth[i] = 0;
            depth[road[i][j]] = 0;
            queue<int> qu;
            qu.push(i);
            qu.push(road[i][j]);
            int nowans = 2;
            while(!qu.empty()){
                int now = qu.front();
                qu.pop();
                if(depth[now] >= (k - 1) / 2) continue;
                for(int k = 0; k < road[now].size(); k++){
                    int next = road[now][k];
                    if(depth[next] == -1){
                        depth[next] = depth[now] + 1;
                        qu.push(next);
                        nowans++;
                    }
                }
            }
            ans = min(ans, n - nowans);
        }
    }
    return ans;
}

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    if(k % 2 == 0) cout << solve_even() << endl;
    else cout << solve_odd() << endl;
    return 0;
}

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

int main()
{
  int N, a = 0, b = 1;
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++)
    cin >> H[i];
  for (int i = 1; i < N; i++)
  {
    for (int j = 0; j < i; j++)
    {
      if (H[i] - H[j] < 0)
        a++;
    }
    if (a == 0)
      b++;
    a = 0;
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
int main() {
  int N; std::cin >> N;
  int s = 0, s2 = 0;
  for(int i = 0; i < N; ++i) {
    int d; std::cin >> d;
    s += d; s2 += d*d;
  }
  fin((s*s - s2)/2);
  return 0;
}


Measured memory_bytes: 256
def resolve():
    n,x,y = map(int, input().split())
    ans = {}
    for i in range(1, n):
        for j in range(i+1, n+1):
            dist1 = j-i
            dist2 = abs(x-i)+1+abs(y-j)
            dist =min (dist1, dist2)
            if dist in ans:
                ans[dist] += 1
            else:
                ans[dist] = 1
    for i in range(1,n):
        if i not in ans:
            ans[i] =0
        print(ans[i])
resolve()

Measured memory_bytes: 3676
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
N = I()
S = str(input())
ans = int(0)
count = int(0)

for i in range(N-1):
    if S[i]==S[i+1]:
        count += 1

ans = N -count

print(ans)

Measured memory_bytes: 3316
// https://atcoder.jp/contests/dp/tasks/dp_a
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    ll height[n];
    for(int i=0 ; i<n ; i++)
        cin >> height[i];
    ll dp[n]={0};
    dp[0] = 0;
    dp[1] = abs(height[0] - height[1]);

    for(int i=2 ; i<n ; i++)
        dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]) , dp[i-2]+abs(height[i]-height[i-2]));
    cout << dp[n-1];
    return 0;
}


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

using namespace std;

int main()
{
    int x,n;
    set <string> s;
    string a;
    cin >> n;


    for(int i =0;i<n;i++)
    {
        cin >> a;
        s.insert(a);



    }
    cout << s.size();


    return 0;
}

Measured memory_bytes: 19200
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end

class Pos
  attr_reader :value
  
  def initialize(g)
    @used = Array.new(N, false)
    @value = Array.new(N, 0)
    @g = g
  end
  def dfs(i, cnt=0)
    return if @used[i]
    @used[i] = true
    @g[i].each do |j|
      dfs(j, cnt+1)
    end
    @value[i] = cnt
  end
end

def max(a, b)
  a > b ? a : b
end

N, U, V = gets.split.map(&:to_i)
AB = (N-1).times.map{gets.split.map(&:to_i)}

=begin
N = 10 ** 5
U, V =  1, N-1
ab=Array.new(N-1)
(N-1).times do |i|
  ab[i] = [i+1,i+2]
end
AB=ab
=end

g = Array.new(N){[]}
AB.each do |a, b|
  g[a-1] << b-1
  g[b-1] << a-1
end

takahashi = Pos.new(g)
aoki = Pos.new(g)
takahashi.dfs(U-1)
aoki.dfs(V-1)
ta = takahashi.value
ao = aoki.value

ans = 0
N.times do |i|
  if ao[i] - ta[i] > 0
    ans = max(ans, ao[i])
  end
end
p ans - 1

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++)
    cin >> a.at(i);
  
  int cost;
  int min = 1000000;
  for (int i=-100; i<=100; i++) { // 書き換える先の整数
    cost = 0;
    for (int j=0; j<n; j++) {
      cost += (a.at(j)-i)*(a.at(j)-i);
    }
    if (cost < min) min = cost;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 150
int graph[MAX][MAX];
int d[MAX],f[MAX];
int time=0,n;

void dfs(i){
  int j;
  time++;
  d[i]=time;
  for(j=0;j<n;j++){
    if(graph[i][j]!=0 && d[j]==0){
      dfs(j);
    }
  }
  time++;
  f[i]=time;
}

int main(){
  int u,k,v;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      graph[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==0) dfs(i);
  }

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

Measured memory_bytes: 656
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        m: usize,
        l: usize,
        roads:[(usize1,usize1,usize);m],
        q: usize,
        query: [(usize1,usize1);q]
    }

    let mut dists = vec![vec![999_987_654_321; n]; n];
    for &r in &roads {
        dists[r.0][r.1] = r.2;
        dists[r.1][r.0] = r.2;
    }
    for m in 0..n {
        for i in 0..n {
            for j in 0..n {
                dists[i][j] = cmp::min(dists[i][j], dists[i][m] + dists[m][j]);
            }
        }
    }

    let mut dists2: Vec<Vec<usize>> = vec![vec![999_987_654_321; n]; n];
    for i in 0..n {
        for j in 0..n {
            if dists[i][j] <= l {
                dists2[i][j] = 1;
                dists2[j][i] = 1;
            }
        }
    }
    for m in 0..n {
        for i in 0..n {
            for j in 0..n {
                dists2[i][j] = cmp::min(dists2[i][j], dists2[i][m] + dists2[m][j]);
            }
        }
    }

    for &(from, to) in &query {
        if dists2[from][to] >= 999_987_654_321 {
            println!("{}", -1);
        } else {
            println!("{}", dists2[from][to] - 1);
        }
    }

    let mut ans = 0;
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 4748
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[2525];
int over,just;
int dfs(int v,int u,int d){
	if(d==1) just++;
	if(d<1) over++;
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(u!=w) dfs(w,v,d-2);
	}
}
int main()
{
	int n,k,a,b,out=114514;
	cin>>n>>k;
	rep(i,n-1){
		cin>>a>>b;a--;b--;gr[a].pb(b);gr[b].pb(a);
	}
	rep(i,n){
		over=0;
		vector<int> js;
		rep(j,gr[i].size()){
			just=0;
			dfs(gr[i][j],i,k);
			js.pb(just);
		}
		sort(All(js));
		rep(j,js.size()-1) over+=js[j];
		out=min(out,over);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
}

Measured memory_bytes: 31664
using System;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int p = int.Parse(input[1]);
			p += 3 * a;
			int pie = p / 2;
			Console.WriteLine(pie);
		}
	}
}


Measured memory_bytes: 11220
x,y = map(int,input().split())
ans = 0
if x == 3:
    ans += 100000
elif x == 2:
    ans += 200000
elif x == 1:
    ans += 300000
if y == 3:
    ans += 100000
elif y == 2:
    ans += 200000
elif y == 1:
    ans += 300000
if x == 1 and y == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 38388