akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;


int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    ll r;
    cin>>r;
    ll n=r%2;
    ll v=r/2;
    ll total=0,ans=0,sec=0;
    ll q=0;
    //cout<<v<<endl;
   ans=d*(v);
    
   total=ans;
    ans=((c*v)*2);
    
    if(total>ans)total=ans;
    ans=((b*v)*4);
   
    if(total>ans)total=ans;
     ans=((a*v)*8);
    if(total>ans)total=ans;
    
    if(n!=0){
    ans=c;
    if(sec==0)sec=ans;
        ans=b*2;
    if(sec>ans)sec=ans;
    ans=a*4;
    if(sec>ans)sec=ans;}
    cout<<(total+sec)<<endl;
   
}


Measured memory_bytes: 256
N=gets.to_i
as=gets.split.map(&:to_i)
dam=Array.new(N+1)
fall=Array.new(N+1)
for i in 1..N
    dam[i]=as.shift
end
fall[1]=(1..N).to_a.map{|x|dam[x]*(x.odd? ? 1 : -1)}.inject(:+)
for i in 2..N
    fall[i]=2*dam[i-1]-fall[i-1]
end
puts fall[1..-1].join(" ")


Measured memory_bytes: 16268
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 0x3f3f3f3f
#define pll pair<long long , long long>
const int MAX=1e6+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int prime[MAX];
int main() 
{
	
	string s;
	cin>>s;
	int n = s.size();
	if(s[n-1]=='s')
	{
		s.push_back('e');
		s.push_back('s');
	}
	else
		s.push_back('s');
	cout<<s;

}


Measured memory_bytes: 27072
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int W, H, N;
int X[1000], Y[1000];

int main()
{
	scanf( "%d%d%d", &W, &H, &N );
	rep( i, N )
		scanf( "%d%d", X+i, Y+i );

	int ans = 0;
	rep( i, N-1 )
	{
		int dx = X[i+1] - X[i], dy = Y[i+1] - Y[i];
		ans += dx*dy > 0 ? std::max( abs(dx), abs(dy) ) : abs(dx)+abs(dy);
	}

	printf( "%d\n", ans );

	return 0;
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif
#define mp make_pair

namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
	out << '(' << a.fi << ", " << a.se << ')';
	return out;
}
}


int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) break;
		vi s(m), v(n), u(n);
		rep(i, m) {
			int k, a;
			cin >> s[i] >> k;
			rep(j, k) {
				cin >> a;
				v[a - 1] += s[i];
				if (k == 1) u[a - 1] += s[i];
			}
		}
		vi idxV(n), idxU(n);
		rep(i, n) idxV[i] = idxU[i] = i;
		sort(all(idxV), [&](int a, int b) {return v[a] < v[b];});
		sort(all(idxU), [&](int a, int b) {return u[a] < u[b];});
		int ans = 0;
		if (idxV[n - 1] != idxU[0]) ans = max(ans, v[idxV[n - 1]] - u[idxU[0]]);
		else ans = max(ans, v[idxV[n - 1]] - u[idxU[1]]);
		if (idxV[n - 2] != idxU[0]) ans = max(ans, v[idxV[n - 2]] - u[idxU[0]]);
		else ans = max(ans, v[idxV[n - 2]] - u[idxU[1]]);
		cout << ans+1 << endl;
		dumpV(v);
		dumpV(u);
	}
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>

int main(void)
{
	char map[101][102];
	int Flag;
	int flag[101][102];
	int w, h;
	int i, j;
	
	while (1){
		scanf("%d%d",&h,&w);
		
		if (h == 0 && w == 0){
			break;
		}
		
		for(i = 0; i < 102; i++){
			for(j = 0; j < 102;j++){
				flag[i][j] = 0;
			}
		}
		
		for (i = 0; i < h; i++){
			scanf("%s", map[i]);
		}
		
		i = 0;
		j = 0;
		
		while (1){
			
			if (flag[i][j] == 1){
				Flag = 1;
				break;
			}
			
			else if (map[i][j] == '.'){
				Flag = 2;
				break;
			}
			
			if (map[i][j] == '^'){
				flag[i][j] = 1;
				i--;
			}
			
			else if (map[i][j] == 'v'){
				flag[i][j] = 1;
				i++;
			}
			
			else if (map[i][j] == '>'){
				flag[i][j] = 1;
				j++;
			}
			
			else if (map[i][j] == '<'){
				flag[i][j] = 1;
				j--;
			}
		}
		
		if (Flag == 1){
			printf("LOOP\n");
		}
		
		else if (Flag == 2){
			printf("%d %d\n",j,i);
		}
		
	}
	
	return (0);
}

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

void Main() {
    // input
    int x;
    cin >> x;

    // process


    // output
    if (x == 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3588
x,y,z= map(int,input().split())
A = []
ans = 0
A.append([x,y,z])
while True:
    if x%2==0 and y%2==0 and z%2==0:
        ans+=1
        x,y,z=((y+z)//2),((z+x)//2),((y+x)//2)
        
        if [x,y,z] in A:
        	ans = -1
        	break
        
    
    A.append([x,y,z])
    if x%2==0 and y%2==0 and z%2==0:
        continue
    else:
      break
    
print(ans)

Measured memory_bytes: 3064
/*Author: Qaseem Hasan alias Mikepayne14(Codeforces,SPOJ) 
                           qaseem_hasan_ (HackerEarth,Codechef,HackerRank)
*/
 
 
//---------------------------------------------------------
//#pragma GCC optimize "trapv"
 
#include<bits/stdc++.h>
using namespace std;
//---------------------------------------------------------
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; } //x=min,y=item
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
 
template<typename ForwardIterator,typename T>
T first_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::lower_bound(first,last,value);
    return (it!=last)?(it - first) : -1;
}
 
template<typename ForwardIterator,typename T>
T last_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::upper_bound(first,last,value);
    return ((it!=last)?(it - first) : -1) - 1;
}
//--------------------------------------------------------
#define acc accumulate
#define eb emplace_back
#define ll long long int
#define lld long long double
#define mii map <int,int>
#define vi vector <int>
#define vll vector <ll>
#define vvi vector <vi>
#define pii pair <int,int>
#define vpii vector <pii>
#define seti set <int>
#define F first
#define S second
#define fil(v,x) fill(all(v),x)
#define filcon(v,x) iota(all(v),x)
#define rep(n) for(int i=0;i<n;++i)
#define repr(n) for(int i=n-1;i>=0;--i)
#define erase(v,e) v.erase(std::remove(v.begin(), v.end(), e), v.end())
#define sqr(x) ((x)*(x))
#define MEM(a, b) memset(a, b, sizeof(a))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define inrange(i,a,b) ((i>=min(a,b)) && (i<=max(a,b))) 
#define FLSH fflush(stdout)
// #define min_all(a,b,c,d,...) min({a,b,c,d,...})
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define make_unique(v) sort(all(v)); v.erase(unique(all(v)), v.end());
#define INF (int)1e9
#define EPS 1e-8
#define MOD 1e9 + 7
#define tr(x) cout<<#x<<" = { "<<x<<" }\n";
#define khatam '\n'
#define PI acos(-1);
 
//--------------------------------------------------------
 
//int ar[40001][40001];
 
//ll ar[10001];
 
//--------------------------------------------------------
/*bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.F < j.F;
}*/
 
void solve()
{
    int n,k;
    cin >> k >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    int maxa = 0;
    for(int i=1;i<n;i++)
    {
        maxa = max(maxa,v[i]-v[i-1]);
    }
    maxa = max(maxa,k-v[n-1]+v[0]);
    cout << k - maxa << khatam;
}

int main()
{
    FAST_IO;
/*    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
//--------------------------------------------------------
    solve();
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> M(H, vector<int>(W));
  for (int k = 0; k < N; k++) {
    int x, y, a;
    cin >> x >> y >> a;
    int sx = 0, sy = 0, tx = W, ty = H;
    if (a == 1) {
      tx = x;
    } else if (a == 2) {
      sx = x;
    } else if (a == 3) {
      ty = y;
    } else {
      sy = y;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (sy <= i && i < ty && sx <= j && j < tx) {
          M[i][j] = 1;
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (!M[i][j]) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define Rep(i,a,b) for(ll i=a;i<b;i++)
#define pb emplace_back
#define allv v.begin(),v.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<(#x)<<" "<<x<<endl
ll mod=1e9+7;
template<typename t>
ll Max(ll a,ll b)
{
    return (a>b)?a:b;
    
}
ll Min(ll a,ll b)
{
    return (a>b)?b:a;
}
ll Power(ll a,ll b)
{
    ll p=1;
    a=a;
    b=b;
    while(b)
    {
        if(b&1)
        {
            p=((p)*(a));
        }
        a=((a)*(a));
        b=(b/2);
    }
    return p;
}
ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    ll p=power(a,b/2)%mod;
    p=(p*p)%mod;
    if(b&1)
    p=(p*a)%mod;
    return p;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
/*void dfs(ll i)
{
    visited[i]=true;
   // provinces.pb(i);
    for(auto it:adj[i])
    {
        if(!visited[it] && choices[it])
        dfs(it);
    }
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    cin>>t;

    if(t==0)
    cout<<1<<endl;
    else 
    cout<<0<<endl;
    
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	double x;
	string s;
	double ans=0;
	rep(i,n){
		cin>>x>>s;
		if(s=="BTC")x*=380000;
		ans+=x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mxn 100005
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
int main(){
	int n,w; cin>>n>>w;
	ll wt[n],val[n];
	for(int i=0; i<n; i++){
		cin>>wt[i]>>val[i];
	}
	ll dp[n+1][w+1];
	for(int i=0; i<=n; i++){
		for(int j=0; j<=w; j++){
			if(i==0 || j==0) dp[i][j] = 0;
			else{
				if(j <wt[i-1]){
					dp[i][j] = dp[i-1][j];
				}
				else{
					dp[i][j] = max(dp[i-1][j], dp[i-1][j-wt[i-1]] + val[i-1]);
				}
			}
		}
	}
	cout<<dp[n][w];
}

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

int main()
{
  int n,k;
  cin >> n>>k;
  int x[n];
  for(int i=0; i<n; i++)
  {
    cin >> x[i];
  }
  int d=0;
  for(int i=0; i<n; i++)
  {
    if (x[i]<abs(k-x[i])) d+=2*x[i];
    else d+=2*abs(k-x[i]);
  }
  cout << d << endl;  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<ostream>
using namespace std;
char lalalala[1000006];
int acacacac[1000006][2];
int min(int n,int m) {
	return n<m?n:m;
}
int main() {
	cin>>lalalala+1;
	acacacac[0][0]=0;
	acacacac[0][1]=1;
	int len=1;
	for(int i=1;lalalala[i];len=i++) {
		acacacac[i][0]=min(acacacac[i-1][0]+min(lalalala[i]-'0',11-(lalalala[i]-'0')),acacacac[i-1][1]+10-(lalalala[i]-'0'));
		acacacac[i][1]=min(acacacac[i-1][0]+min(lalalala[i]-'0'+1,10-(lalalala[i]-'0')),acacacac[i-1][1]+9-(lalalala[i]-'0'));
	}
	cout<<acacacac[len][0]<<endl;
  	return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <math.h>
 
int s[1002];
 
#define gc() getchar_unlocked()
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc();
    while (c >= '0');
    return n;
}
 
int main()
{
    int n, i, is;
    double m, fs, a;
     
    while (n = in()) {
        is = 0; for (i = 0; i < n; i++) is += s[i] = in();
        m = (double)is/n;
        fs = 0; for (i = 0; i < n; i++) {
            a = s[i]-m;
            fs += a*a;
        }
        printf("%.8lf\n", sqrt(fs/n));
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <vector>

constexpr unsigned long MOD = 1000000007;

// 素因数分解する
auto factorize( unsigned long long x )
{
	std::vector<std::pair<unsigned long, unsigned long> > result;

	for ( int i = 2; i * i <= x; i++ )
	{
		if ( x % i != 0 )
		{
			continue;
		}

		int counter = 0;
		while ( x % i == 0 )
		{
			// i^pを約数に持つので、割り切れる回数をカウント
			counter++;
			x /= i;
		}
		result.emplace_back( std::make_pair( i, counter ) );
	}

	if ( x != 1 )
	{
		// どのiでも割り切れなかったので、x自身を追加（xが素数のとき）
		result.emplace_back( std::make_pair( x, 1 ) );
	}

	return ( result );
}

// nCrを計算する
#define FACTMAX ( 200000 )
unsigned long long fact[FACTMAX];
unsigned long long finv[FACTMAX];
unsigned long long inv[FACTMAX];

void combinationInit()
{
	fact[0] = fact[1] = 1;
	for ( unsigned long long i = 2; i < FACTMAX; i++ )
	{
		fact[i] = ( fact[i - 1] * i ) % MOD;
	}
	inv[1] = 1;
	for ( unsigned long long i = 2; i < FACTMAX; i++ )
	{
		inv[i] = ( MOD - MOD / i ) * inv[MOD % i] % MOD;
	}
	finv[0] = finv[1] = 1;
	for ( int i = 2; i < FACTMAX; i++ )
	{
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

unsigned long long combination( unsigned long long n, unsigned long long r )
{
	return ( ( fact[n] * ( finv[r] * finv[n - r] % MOD ) % MOD ) );
}

int main()
{
	unsigned long N, M;
	std::cin >> N >> M;

	// M = a1^b1 * a2^b2 * a3^b3 ... であり、
	// a1もまた a^c1 * a^c2 * a^c3 ... なので、
	// c1 + c2 + c3 ... = b1, 以下同様にbnまで求めるのと同じ

	// Mを素因数分解する
	auto f = factorize( M );

	// f.size()が数列bの要素数nであり、f[i].secondがbiの値である
	combinationInit();
	unsigned long long result = 1;
	for ( auto &&it : f )
	{
		result *= combination( it.second + N - 1, it.second );
		result %= MOD;
	}

	std::cout << result << std::endl;

	return ( 0 );
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(100010, vector<int>());
  vector<P> ve(m);
  rep(i,m) {
    int p, y;
    scanf("%d%d", &p, &y);
    ve[i].first = p;
    ve[i].second = y;
    vec[p].push_back(y);
  }
  rep(i,100010) sort(vec[i].begin(), vec[i].end());
  rep(i,m) printf("%012lld\n", ll(ve[i].first)*1000000+int(lower_bound(vec[ve[i].first].begin(), vec[ve[i].first].end(), ve[i].second) - vec[ve[i].first].begin())+1);
  return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a + b + c;
	if (sum >= 22) {
		cout << "bust" << endl;
		return 0;
	} else {
		cout << "win" << endl;
		return 0;
	}

}


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

using namespace std;

typedef long long ll;
const ll maxn = 5010,mod = 1e9 + 7;
ll n,head[maxn],to[maxn * 2],nextt[maxn * 2],tot = 1;
ll f[maxn][maxn],sizee[maxn],g[maxn];

void add(ll x,ll y)
{
    to[tot] = y;
    nextt[tot] = head[x];
    head[x] = tot++;
}

void dfs(ll u,ll fa)
{
    sizee[u] = 1;
    f[u][1] = 1;
    ll tmp[5010];
    for (ll i = head[u]; i; i = nextt[i])
    {
        ll v = to[i];
        if (v == fa)
            continue;
        dfs(v,u);
        memset(tmp,0,sizeof(tmp));
        for (ll j = 0; j <= sizee[u]; j++)
            for (ll k = 0; k <= sizee[v]; k++)
            {
                tmp[j + k] = (tmp[j + k] + 1LL * f[u][j] * f[v][k] % mod) % mod;
                tmp[j + k] = (tmp[j + k] + mod) % mod;
            }
        sizee[u] += sizee[v];
        for (ll j = 0; j <= sizee[u]; j++)
            f[u][j] = tmp[j];
    }
    for (ll i = 2; i <= sizee[u]; i += 2)
    {
        f[u][0] = (f[u][0] + 1LL * g[i] * (-f[u][i]) % mod) % mod;
        f[u][0] = (f[u][0] + mod) % mod;
    }
}

int main()
{
    scanf("%lld",&n);
    for (ll i = 1; i < n; i++)
    {
        ll x,y;
        scanf("%lld%lld",&x,&y);
        add(x,y);
        add(y,x);
    }
    g[2] = 1;
    for (ll i = 4; i <= n; i += 2)
        g[i] = 1LL * g[i - 2] * (i - 1) % mod;
    dfs(1,0);
    printf("%lld\n",mod - f[1][0]);

    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

	int n,a;cin>>n>>a;cout<<n*n-a<<endl;

	return 0;
}


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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int next = 0; int cnt = 0;
  vector<int> visited(n);
  for (;;) {
    if (next == 1) {
      cout << cnt << "\n";
      break;
    }
    if (visited[next]) {
      cout << -1 << "\n";
      break;
    }
    visited[next] = 1;
    ++cnt;
    next = a[next] - 1;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int c = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] != i + 1) {
      c++;
    }
  }
  if (c <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

const int N = 2e5 + 7;

vector <int> adj[N];


int l[N], r[N], t[N], ans[N];

int f(int lx, int rx, int v) {
	if(!t[v]) {
		t[v] = 1;
		l[v] = lx;
		r[v] = rx;
	} else {
		if((l[v] - lx) & 1) {
			return 0;
		}
		if(lx > r[v] || rx < l[v]) {
			return 0;
		}
		l[v] = max(l[v], lx);
		r[v] = min(r[v], rx);
	}
	return 1;
}


void dfs(int v, int p) {
	for(int u: adj[v]) if(u ^ p) {
		dfs(u, v);
		if(t[u] && !f(l[u] - 1, r[u] + 1, v)) {
			cout << "No" << endl;
			exit(0);
		}
	}
}

void push(int v, int p) {
	if(!t[v]) {
		ans[v] = ans[p] + 1;
	} else {
		if(ans[p] + 1 >= l[v] && ans[p] + 1 <= r[v]) {
			ans[v] = ans[p] + 1;
		} else {
			assert(ans[p] - 1 >= l[v] && ans[p] - 1 <= r[v]);
			ans[v] = ans[p] - 1;
		}
	}
	for(int u: adj[v]) if(u ^ p) {
		push(u, v);
	}
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;

	for(int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}


	int k; cin >> k;

	for(int i = 1; i <= k; i++) {
		int v, p; cin >> v >> p;
		l[v] = r[v] = p; t[v] = 1;
	}

	dfs(1, 0);

	cout << "Yes" << endl;

	ans[1] = l[1];
	for(int v: adj[1]) {
		push(v, 1);
	}

	for(int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
} 

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, a, b) for (int i = (a); i < (int)(b); i++)
#define PYMOD(A, M) ((((A) % (M)) + (M)) % (M))
using ll = long long;

using namespace std;

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

    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    forn(i, n)
        cin >> x[i] >> y[i];

    bool w0 = false, w1 = false;
    for (int i = 0; i < n; i++) {
        if ((x[i] + y[i]) % 2 == 0)
            w0 = true;
        else
            w1 = true;
    }

    if (w0 && w1) {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> d;
    vector<string> answer(n);

    if (w0) {
        d.pb(1);
        forn(i, n) {
            answer[i].pb('L');
            x[i]++;
        }
    }

    for (ll j = 31; j >= 0; j--) {
        d.pb(1ll << j);
        forn(i, n) {
            ll nx = x[i] - y[i];
            ll ny = x[i] + y[i];
            if (nx > 0 && ny > 0) {
                answer[i].pb('R');
                x[i] -= 1ll << j;
            } else if (nx > 0 && ny < 0) {
                answer[i].pb('D');
                y[i] += 1ll << j;
            } else if (nx < 0 && ny > 0) {
                answer[i].pb('U');
                y[i] -= 1ll << j;
            } else {
                answer[i].pb('L');
                x[i] += 1ll << j;
            }
        }
    }

    forn(i, n)
        assert(x[i] == 0 && y[i] == 0);

    cout << d.size() << endl;
    for (ll df : d)
        cout << df << " ";
    cout << endl;
    forn(i, n)
        cout << answer[i] << endl;

    return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if (A >= 13)
    cout << B << endl;
  else if (A <= 5) 
    cout << 0 << endl;
  else
    cout << B/2 << endl;
    
 
}

Measured memory_bytes: 3536
N=int(input())
A=list(map(int, input().split()))

from collections import defaultdict
cnt=defaultdict(int)
for i in range(N):
  cnt[A[i]]+=1
  
keys=cnt.keys()
out='YES'
for i in keys:
  if cnt[i]>1:
    out='NO'
    
print(out)

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

struct DisjointSet{
    vector<int> p;
    DisjointSet(int n) : p(n){
        rep(i,n) p[i] = -1;
    }

    int root(int x){
        if(p[x] < 0) return x;
        return p[x] = root(p[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(rx > ry) swap(rx,ry);
        p[rx] += p[ry];
        p[ry] = rx;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m; cin >> n >> m;
    int a[m], b[m];
    rep(i,m){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }

    int ans = 0;
    rep(i,m){
        DisjointSet dis = DisjointSet(n);
        rep(j,m){
            if(i == j) continue;
            dis.unite(a[j], b[j]);
        }
        bool isok = true;
        rep(j,n){
            rep(k,n){
                if(!dis.same(j,k)) isok = false;
            }
        }
        if(!isok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

int a,b[110],c,d,e[110];
   cin >> a;
   for(int i=0;i<a;i++)
     cin >> b[i];
  
  
  
  for(int i=0;i<a;i++){
    c =0,d=0;
    for(int j=0;j<i;j++){
       c += b[j];
    }
    
    for(int k=i;k<a;k++){
      d+= b[k];
    }
    e[i] = abs(c-d);
  }
  
  sort(e,e+a);
  
  cout << e[0] << endl;
}
  
      
       

  


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        mut time: [(usize, usize); n]
    }
    time.sort_by(|a, b| a.1.cmp(&b.1));
    let mut a = 0;
    for i in 0..n {
        a += time[i].0;
        if a > time[i].1 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main() {
  int n;
  cin >> n;
  char s[n];
  
  int ans = 1;
  cin >> s[0];
  for(int i=1; i<n; i++){
    cin >> s[i];
    if(s[i] != s[i-1]){
      ans++;
    }
  }
  cout << ans << endl;
}
      
  

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

int main() {
	ios_base::sync_with_stdio( false );

	int N, Y;
	cin >> N >> Y;

	int x = -1;
	int y = -1;
	int z = -1;

	for( int i = 0; i <= N; ++i ) {
		for( int j = 0; i+j <= N; ++j ) {
			int k = (Y - 10000*i - 5000*j) / 1000;
			if( k >= 0 && i+j+k == N ) {
				x = i;
				y = j;
				z = k;
				break;
			}
		}
	}

	cout << x << ' ' << y << ' ' << z << ' ' << endl;

	return 0;
}


Measured memory_bytes: 256
fn main() {
    let n = read::<u32>();
    let v = read_vec2::<u32>(n-1);
    for i in 0..(n-1) {
        let mut k = 0;
        for e in v.iter().skip(i as usize) {
            let c = e[0];
            let s = e[1];
            let f = e[2];
            let t = (0..).map(|n|s+f*n).skip_while(|&n|{
                k>n
            }).take(1).nth(0).unwrap();
            k = t;
            k += c;
        }
        println!("{}", k);
    }
    println!("{}", 0);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 4476
import math

def resolve():
    
    R,G,B=map(int,input().split())
    K=int(input())
    # A=list(map(int,input().split()))

    for i in range(K):
        if(G<=R):
            G*=2
        else:
            if(B<=G):
                B*=2
    
    ans="No"
    if(B>G and G>R):
        ans="Yes"

    print(ans)        


resolve()

Measured memory_bytes: 9176
#include "bits/stdc++.h"
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	int d=0;
	while(cin>>d){
		int sum=0;

		for (int i = 0; i < 600; i=i+d) {
		sum+=i*i*d;
	}
	cout<<sum<<endl;
	}
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll h,w,sh,sw,gh,gw;
  cin >> h >> w >> sh >> sw >> gh >> gw;

  vector<vector<char>> e(h,vector<char>(w));
  mat d(h,vec(w,0));
  mat t(h,vec(w,0));

  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      cin >> e[i][j];
      d[i][j]=-1;
    }
  }

  queue<vector<ll>> que,que2,que3;

  d[sh-1][sw-1]=0;
  que2.push({sh-1,sw-1});
  t[sh-1][sw-1]=1;
  ll l=0;

  while(!que2.empty()){
    while(!que2.empty()){
      vec u=que2.front();
      d[u[0]][u[1]]=l;
      que.push(u);
      que3.push(u);
      que2.pop();
    }
    l++;
    vector<ll> v=que.front();
    while(!que.empty()){
      vector<ll> v =que.front();
      que.pop();
      for(int i=0;i<4;i++){
        if(v[0]+dx[i]<0 || v[0]+dx[i] >h-1 || v[1]+dy[i] <0 || v[1]+dy[i]>w-1)continue;
        if(d[v[0]+dx[i]][v[1]+dy[i]]== -1 && e[v[0]+dx[i]][v[1]+dy[i]]=='.'){
          d[v[0]+dx[i]][v[1]+dy[i]]=d[v[0]][v[1]];
          que.push({v[0]+dx[i],v[1]+dy[i]});
          que3.push({v[0]+dx[i],v[1]+dy[i]});
        }
      }
      // for(ll i=-5;i<=5;i++){
      //   for(ll j=-5;j<=5;j++){
      //     if(v[0]+i<0 || v[0]+i >h-1 || v[1]+j <0 || v[1]+j>w-1)continue;
      //       if(e[v[0]+i][v[1]+j]=='.'){
      //         d[v[0]+i][v[1]+j]=min(d[v[0]][v[1]],d[v[0]+i][v[1]+j]);
      //       if(t[v[0]+i][v[1]+j]==0){
      //         que.push({v[0]+i,v[1]+j});
      //         t[v[0]+i][v[1]+j]=1;
      //       }
      //     }
      //   }
      // }
    }
    //cout << que3.size() << endl;;

    while(!que3.empty()){
      vec v=que3.front();
      que3.pop();

      for(ll i=-2;i<=2;i++){
        for(ll j=-2;j<=2;j++){
          if(v[0]+i<0 || v[0]+i >h-1 || v[1]+j <0 || v[1]+j>w-1)continue;
          if(d[v[0]+i][v[1]+j]==-1 && e[v[0]+i][v[1]+j]=='.' && t[v[0]+i][v[1]+j]==0){
            //cout << i << " " << j << " " << v[0]+i << " " <<v[1]+j<< endl;
            que2.push({v[0]+i,v[1]+j});
            t[v[0]+i][v[1]+j]=1;
            //cout << v[0]+i << " " << v[1]+j<< " " <<d[v[0]+i][v[1]+j] <<  endl;
          }
        }
      }
    }
    //cout << que2.size() << endl;
    
  }

  cout << d[gh-1][gw-1] << endl; 


}

Measured memory_bytes: 20740
#include <stdio.h>
#include <string.h>

char str [100005];
char dr[10]="dream";
char er[10]="erase";

int main()
{
    while (scanf("%s",&str)!=EOF)
    {
        int len = strlen (str);
        int i,ok=1;
        for (i=0;i<len;i++)//dreameraser
        {
            if (str[i]=='d')
            {
                int j;
                for (j=i;j<=i+4;j++)
                {
                    if (j>=len||dr[j-i]!=str[j])
                    {
                        ok=0;
                        break;
                    }
                }
                if (j==i+5)//是dream
                {
                    i=j-1;
                    if (str[j]=='e'&&str[j+1]=='r'&&str[j+2]!='a')
                    {
                        i=j+1;
                    }
                }
            }
            else if (str[i]=='e')
            {
                int j;
                for (j=i;j<=i+4;j++)
                {
                    if (j>=len||er[j-i]!=str[j])
                    {
                        ok=0;
                        break;
                    }
                }
                if (j==i+5) //是erase
                {
                    i=j-1;
                    if (str[j]=='r') i=j;
                    else i=j-1;
                }
            }
            else ok=0;
            if (ok==0) break;
        }
        if (ok==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main(){
    int H,W;scanf("%d %d\n",&H,&W);
    int a=0;
    char c;
    while (std::cin>>c) {
        if(c=='#')++a;
    }
    if(a==H+W-1)printf("Possible");
    else printf("Impossible");
}


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

#define ll long long
const ll hell = 1e9+7;
string s[1005];
ll dp[1005][1005];

int main()
{
	ll h,w;
	cin>>h>>w;
	dp[0][0]=1;
	
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='#')
			{
				dp[i][j]=0;
				continue;
			}
			
			if(j>0) dp[i][j] += dp[i][j-1];
			dp[i][j]%=hell;
			if(i>0) dp[i][j] += dp[i-1][j];	
			dp[i][j]%=hell;		
			
		}
		
	}
	
	cout<<dp[h-1][w-1]%hell<<endl;
}


Measured memory_bytes: 13336
public class Main 
{
	public static void main(String[] args) 
	{
		for(int i = 1; i < 10; ++i)
		{
			for(int j = 1; j < 10; ++j)
			{
				System.out.println(i + "x" + j + "=" + i * j);
			}
		}
	}
}

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

int n, x;
vector<int> l;
int ans = 1;

int main(){
  cin >> n >> x ;
  rep(i, n){
    int tmp;
    cin >> tmp;
    l.push_back(tmp);
  } 
  int d = 0;
  
  rep(i, n){
     d += l.at(i); 
    if(d <= x){
      ans++; 
    }
    else break;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN=100000+100;
int h[MAXN],f[MAXN];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>h[i];
	for(int i=1;i<n;i++)
	{
		f[i]=f[i-1]+abs(h[i-1]-h[i]);
		if(i>1)
		{
			f[i]=min(f[i],f[i-2]+abs(h[i-2]-h[i]));
		}
	}
	cout<<f[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
int n,c[200009],dp[200009],c2[200009],num,pn[200009];
vector<int>pos[200009];
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",c+i);
	for(int i=0;i<n;) {
		c2[num++]=c[i];
		pos[c[i]].push_back(num-1);
		int j;
		for(j=i+1;j<n&&c[j]==c[i];j++);
		i=j;
	}
	dp[0]=1;
	pn[c2[0]]++;
	for(int i=1;i<num;i++) {
		dp[i]=dp[i-1];
		if(pn[c2[i]]-1>=0) {
			dp[i]=(dp[i]+dp[pos[c2[i]][pn[c2[i]]-1]])%mod;
		}
		pn[c2[i]]++;
	}
	printf("%d\n",dp[num-1]);
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
vector <int> vec;
int a, b, c;
int ans;

int main() {
	scanf("%d %d %d", &a, &b, &c);
	ans += b;
	if(c <= b) ans += c;
	else {
		ans += b + 1;
		c -= b + 1;
		ans += min(a, c);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,sum,i;
int main(){
    cin>>n;
    int a[n+2]={};
    for(i=1;i<=n;i++){cin>>a[i];sum+=abs(a[i]-a[i-1]);}
    sum+=abs(0-a[n]);
    for(i=1;i<=n;i++)cout<<sum-(a[i-1]<a[i]&&a[i+1]<a[i]?a[i]-max(a[i-1],a[i+1]):a[i]<a[i-1]&&a[i]<a[i+1]?min(a[i-1],a[i+1])-a[i]:0)*2<<endl;
    return 0;
}

Measured memory_bytes: 1664
n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort()
F.reverse()
t = sum(A)
ok = 10**12
ng = -1
if t <= k:
    print(0)
else:
    while abs(ok-ng) > 1:
        cur = 0
        mid = (ok+ng)//2
        for i in range(n):
            temp = mid/F[i]
            if int(temp) == temp:
                cur += max(0, int(A[i]-temp))
            else:
                if A[i]-temp > 0:
                    cur += int(A[i]-temp)+1
        if cur > k:
            ng = mid
        else:
            ok = mid
    print(ok)


Measured memory_bytes: 120268
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}

fn main() {
     let l = read_line();
    let n = to_i(&l);
    for x in n..1000 {
        let a = x / 100;
        let b = (x / 10)%10;
        let c = x % 10;
        //println!("{} {} {} {}", x, a, b ,c); 
        if a==b && b==c {
            print!("{}", x);
            return;
        }
    }
    
    

    print!("{}", 0);


}   

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	string str; cin >> str;
	vector<string> word;
	int c = 0;

	for (int i = 0; i < str.length(); i++) {
		string w=str.substr(i, 1);
		word.push_back(w);
		if (isupper(str[i])) c++;
			
	}
	int count;
	if (word[0] == "A") {
		count = 0;
		for (int i = 2; i < str.length()-1; i++) {
			if (word[i] == "C") {
				count++;
				//cout << word[i] << ":" << i << endl;
			}
		}

		if (count == 1 && c == 2) cout << "AC" << endl;
		else cout << "WA" << endl;

	}
	else cout << "WA" << endl;
	//cout << c;

	return 0;
}

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

int main(){
    int k;
    int i[32] = { 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 };
    cin >> k;
    cout << i[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
d = defaultdict(int)
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            a = i*i+j*j+k*k+i*j+j*k+k*i
            d[a] += 1
N = int(input())
for i in range(1,N+1):
    print(d[i])

Measured memory_bytes: 13024
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: i64,
    }

    let mut q: i64 = 0; //辺を引く分
    let mut p: i64 = 0; //頂点を足す分

    for i in 1..=n {
        p += i * (n - i + 1) as i64;
    }

    for _ in 1..n {
        input! {
            u: i64,
            v: i64,
        }
        if u < v {
            q += (n - v + 1) * u;
        } else {
            q += (n - u + 1) * v;
        }
    }

    println!("{}", p - q);
}


Measured memory_bytes: 4860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using ll = long long;
ll H, W;
ll h, w;

bool is_ok(std::vector< std::string >& grid, std::vector< std::string > temp)
{
  for (ll Y = 0; Y < H-h+1; Y++) {
    for (ll X = 0; X < W-w+1; X++) {
      bool was_found = true;
      for (ll y = 0; y < h; y++) {
	for (ll x = 0; x < w; x++) {
	  if (grid[Y+y][X+x] == temp[y][x]) {
	    ;
	  } else {
	    was_found = false;
	  }
	}
      }
      if (was_found) return true;
    }
  }

  return false;
}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, M;
  std::cin >> N >> M;
  H = N;
  W = N;
  h = M;
  w = M;
  std::vector< std::string > grid(H, std::string(W, 'x'));
  std::vector< std::string > temp(h, std::string(w, 'x'));
  for (ll y = 0; y < H; y++) {
    std::cin >> grid[y];
  }
  for (ll y = 0; y < h; y++) {
    std::cin >> temp[y];
  }

  std::string judge = is_ok(grid, temp) ? "Yes" : "No";
  std::cout << judge << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define rep(i,n) for(register int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
//const int MOD=998244353;
//const int N=2e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

int n;
LL ans;

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	ans=(LL)n*(LL)(n-1)/2;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
unsigned MAXXXX = 233333333;
unsigned long long dsb;
string s;
int main()
{
  cin>>s;
  for(int i=0; i<s.size()-1; i++)
  {
    if(s[i]!=s[i+1])dsb++;
  }
  cout<<dsb<<endl;
  return 0;
}


Measured memory_bytes: 512
from sys import stdin
N,A, B, C = map(int, input().split())

S = stdin.read().split()


if (A and B or B and C or C and A) and A+B+C >= 3:
    ans = []
    ans.append('Yes')
    for s in S:
        if s == 'AB':
            if A < B:
                A += 1
                B -= 1
                ans.append('A')
            else:
                A -= 1
                B += 1
                ans.append('B')
        elif s == 'AC':
            if A < C:
                C -= 1
                A += 1
                ans.append('A')
            else:
                A -= 1
                C += 1
                ans.append('C')
        else:
            if B < C:
                C -= 1
                B += 1
                ans.append('B')
            else:
                B -= 1
                C += 1
                ans.append('C')
    print('\n'.join(ans))
    exit()

ans = []
for i, s in enumerate(S):
    if s == 'AB':
        if A==B==1 and C==0 and i < N-1:
            if S[i+1] == 'AC':
                A += 1
                B -= 1
                ans.append('A')
                continue
            elif S[i+1] == 'BC':
                A -= 1
                B += 1
                ans.append('B')
                continue
        if A < B:
            A += 1
            B -= 1
            ans.append('A')
        else:
            A -= 1
            B += 1
            ans.append('B')

    elif s == 'AC':
        if A==C==1 and B==0 and i < N-1:
            if S[i+1] == 'AB':
                A += 1
                C -= 1
                ans.append('A')
                continue
            elif S[i+1] == 'BC':
                A -= 1
                C += 1
                ans.append('C')
                continue
        if A < C:
            A += 1
            C -= 1
            ans.append('A')
        else:
            A -= 1
            C += 1
            ans.append('C')
    else:
        if B==C==1 and A==0 and i < N-1:
            if S[i+1] == 'AB':
                B += 1
                C -= 1
                ans.append('B')
                continue
            elif S[i+1] == 'AC':
                B -= 1
                C += 1
                ans.append('C')
                continue
        if B < C:
            B += 1
            C -= 1
            ans.append('B')
        else:
            B -= 1
            C += 1
            ans.append('C')

    if A < 0 or B < 0 or C < 0:
        print('No')
        exit()

print('Yes')
print('\n'.join(ans))


Measured memory_bytes: 84872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  static int[] array1 = new int[2001];

  static int[] array2 = new int[4001];

  public static void main(String[] args) throws NumberFormatException, IOException
  {
    init();
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      int num = Integer.valueOf(input.readLine());

      System.out.println(array2[num]);
    }

  }

  private static void init()
  {

    for (int i = 0; i <= 1000; i++)
    {
      for (int j = 0; j <= 1000; j++)
      {
        array1[i + j]++;
      }
    }

    for (int i = 0; i <= 2000; i++)
    {
      for (int j = 0; j <= 2000; j++)
      {
        array2[i + j] += array1[i] * array1[j];
      }
    }
  }
}

Measured memory_bytes: 25068
while True:
    try:
        a,b,c,d,e,f = (float(x) for x in input().split())
        x = (c * e - b * f) / (a * e - b * d)
        y = (c * d - a * f) / (b * d - a * e)
    except:
        break

    x = round(x, 3)
    y = round(y, 3)

    if x == -0.000:
        x = 0.000
    elif y == -0.000:
        y = 0.000

    print("{0:.3f} {1:.3f}" . format(x, y))


Measured memory_bytes: 5584
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	int H, W, h, w;
	gi4(H, W, h, w);

	int cnt = H * W;
	cnt -= W * h;
	H -= h;
	cnt -= H * w;
	   
	ans(cnt);

	wait();

	return 0;
}

Measured memory_bytes: 256
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  string temp="YAKI";
  
  string str;

  cin>>str;

  int j=0;
  
  for(int i=0;i<4;i++){
    if(str[i]==temp[i]){
      j++;
    }
  }

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




Measured memory_bytes: 256