akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int AC[100010] = {0};
	int WA[100010] = {0};
	bool flg[100010] = {false};

	int N, M;

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int no;
		string S;

		cin >> no >> S;

		if (flg[no]) {
		} else {
			if (S == "AC") {
				flg[no] = true;
			} else {
				WA[no]++;
			}
		}
	}

	int ac = 0, wa = 0;

	for (int i = 0; i < N + 5; i++) {
		if (flg[i]) {
			ac++;
		}
	}

	for (int i = 0; i < N + 5; i++) {
		if (flg[i]) {
			wa += WA[i];
		}
	}

	cout << ac << " " << wa << endl;

	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void){

  int a,b,c,x;

  x=0;

  scanf("%d %d %d",&a,&b,&c);

  if(a>b){

    x=a;

    a=b;

    b=x;

}

   if(b>c){

    x=b;

    b=c;

    c=x;

}

      if(a>b){

        x=a;

       a=b;

      b=x;

}

  printf("%d %d %d\n",a,b,c);

return 0;

}

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

int main(){
  int n, m;
  cin >> n >> m;
  
  vector<int> a(m);
  for(int i=0; i<m; i++){
    cin >> a[i];
  }
  
  int s=0;
  for(int i=0; i<m; i++){
    s += a[i];
  }
  
  if(n>=s){
    cout << n-s << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

using namespace std;

class UnionFind {
private:
    vector<int> parent;

public:
    UnionFind(int n) {
        parent.resize(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        parent[y] = x;
    }

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

int main() {
    int n, q, x, y, com;

    cin >> n >> q;
    UnionFind tree(n);
    while (q--) {
        cin >> com >> x >> y;
        if (com == 0) {
            tree.unite(x, y);
        }
        else {
            cout << tree.same(x, y) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1240
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  ll L,R,ans=20108;
  cin>>L>>R;
  if(R-L>=2018){
    cout<<0<<endl;
    return 0;
  }else{
    L=L%2019; R=R%2019;
    for(ll i=L;i!=R;i=(i+1)%2019){
      for(ll j=(i+1)%2019;j!=(R+1)%2019;j=(j+1)%2019){
        ans=min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 1000000

int primes[MAX] = {0};

int main(void) {
	int num, i, j;
	num = 0;
	for (i = 2; i <= MAX; ++i) {
		for (j = 2; j * j <= i; ++j) {
			if ((i % j) == 0) break;
		}
		if (j * j > i) num++;
		primes[i] = num;
	}
	while(scanf("%d", &num) != EOF) {
		printf("%d\n", primes[num]);
	}
	
	return 0;
}

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

using namespace std;

int main(void){
    int N,i;
    double x,sum=0;
    string u;
    
    cin >> N;

    for(i=0;i<N;i++){
        cin >> x;
        cin >> u;
        if(u=="JPY"){
            sum += x;
        }else{
            sum += (x*380000.0);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 760
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll dp[606][303][303];
int main()
{
	int n;
	cin>>n;
	int a[606];
	for(int i=0; i<2*n; i++){
		cin>>a[i];
	}
	int b[606], c[606]={};
	fill(b+1, b+2*n+1, 1);
	int m=0;
	for(int i=0; i<n; i++){
		if(a[2*i]>=0 && a[2*i+1]>=0){
			b[a[2*i]]=b[a[2*i+1]]=0;
		}
	}
	for(int i=1; i<=2*n; i++){
		if(b[i]>0){
			m++;
			b[i]=m;
		}
	}
	if(m==0){
		cout<<1<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=0; i<n; i++){
		if(a[2*i]>=0 && a[2*i+1]>=0) continue;
		if(a[2*i]>=0) c[b[a[2*i]]]=1, cnt++;
		if(a[2*i+1]>=0) c[b[a[2*i+1]]]=1, cnt++;
	}
	dp[m+1][0][0]=1;
	for(int i=m+1; i>=2; i--){
		for(int j=0; j<=min(m/2, m+1-i); j++){
			for(int l=0; l<=min(m/2, m+1-i-j); l++){
				if(c[i-1]){
					(dp[i-1][j][l+1]+=dp[i][j][l])%=MOD;
					if(j) (dp[i-1][j-1][l]+=dp[i][j][l])%=MOD;
				}else{
					dp[i-1][j+1][l]+=dp[i][j][l];
					if(l) (dp[i-1][j][l-1]+=l*dp[i][j][l])%=MOD;
					if(j) (dp[i-1][j-1][l]+=dp[i][j][l])%=MOD;
				}
			}
		}
	}
	ll ans=dp[1][0][0];
	for(int i=1; i<=m/2-cnt; i++) (ans*=i)%=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 431744
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}

int32_t main()
{   
     IOS;
     
     ll n,m;
     cin>>n>>m;
     cout<<min((n%m),m-(n%m));
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

using E = pair<int, int>;  // to, weight

int main() {
  int L;
  while (cin >> L) {
    int N = 0;
    while ((1 << N) <= L) ++N;
    vec<E, 2> G(N);
    for (int i = 0; i + 1 < N; i++) {
      G[i].push_back(E(i + 1, 0));
      G[i].push_back(E(i + 1, 1 << i));
    }
    int K = 1 << (N - 1);
    for (int i = N - 2; i >= 0; i--) {
      if ((L >> i) & 1) {
        G[i].push_back(E(N - 1, K));
        K += 1 << i;
      }
    }
    int M = 0;
    for (int i = 0; i < N; i++) M += G[i].size();
    cout << N << " " << M << endl;
    for (int i = 0; i < N; i++) {
      for (auto e : G[i]) {
        int j = e.fst;
        int w = e.snd;
        cout << (i + 1) << " " << (j + 1) << " " << w << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
//const int maxn=2e5+10;
int n,a[200005],b[200005],sum=0;
signed main()
{
    //int n;
    cin >> n;
    //const int maxn=2e5+10;
   //int a[maxn], b[maxn];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        b[a[i]]++;
    }
    //int sum=0;
    for(int i=1;i<=n;i++)
    {
        int ss = (b[i]*(b[i]-1))/2;
        sum+=ss;
    }
   /* for(int i=0;i<n;i++)
    cout<<b[i]<<" ";
  cout<<endl;*/
    for (int c = 1; c <= n; c++)
    {
        int s,t;
        s=b[a[c]];
        int k=s-1;
        if(s>=2)
        {
            int a1 = (s*(s-1))/2;
            int a2= ((k-1)*k)/2;
            t = sum- a1 + a2;
        }
        else
        {
            t=sum;
        }
        cout<<t<<endl;
    }
}

Measured memory_bytes: 4736
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<double, double> P;

double dl2(P a, P b) {
  double dx = a.first - b.first, dy = a.second - b.second;
  return sqrt(dx * dx + dy * dy);
}

int fact(int n) {
  if(n == 0)
    return 1;
  return n * fact(n - 1);
}

int main(void) {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  vector<vector<double>> d(n, vector<double>(n));
  rep(i, n) rep(j, n) d[i][j] = dl2(p[i], p[j]);
  vector<int> a(n);
  rep(i, n) a[i] = i;
  double ans = 0.0;
  do {
    rep(i, n - 1) {
      ans += d[a[i]][a[i + 1]];
    }
  } while(next_permutation(a.begin(), a.end()));
  ans /= fact(n);
  printf("%.10f\n", ans);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  // ここにプログラムを追記

  int l, r;
  int count = 0;

  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    count += r - l + 1;
  }

  cout << count << endl;
}


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

int main(){
  ll x;
  cin >> x;
  ll p = 0, ans = 1;
  while(true) {
    p += ans;
    if(p >= x) break;
    ans++;
  }
  cout << ans << 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;
const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    string P,Q;
    rep(i,n) {
        string s;
        cin >> s;
        P += s;
    }
    rep(i,n) {
        string s;
        cin >> s;
        Q += s;
    }
    vector<int> v;
    for(int i = 1; i <= n;i++) v.push_back(i);
    int a=0,b=0;
    do{
        string tmp;
        for(auto x : v) tmp += to_string(x);
        if(tmp < P) a++;
        if(tmp < Q) b++; 

    }while(next_permutation(v.begin(),v.end()));
    int ans = abs((a+1)-(b+1));
    cout << ans << endl; 
    
}

Measured memory_bytes: 3644
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int x,a,b;
   cin >> x >> a >> b;

   int ans = (x-a)%b;

   cout << ans << endl;




   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

vector<int> s;

bool binarySearch(int left, int right, int t) {
  if (left >= right) return false;
  int mid = (left + right) / 2;
  if (s[mid] == t) return true;
  else if (s[mid] > t) {
    binarySearch(left, mid, t);
  }
  else {
    binarySearch(mid + 1, right, t);
  }
}

int main() {
  int n, q, t, c = 0;
  cin >> n;
  rep(i, n) {
    cin >> t;
    s.push_back(t);
  }
  
  
  cin >> q;
  rep(i, q) {
    cin >> t;
    c += binarySearch(0, n, t);
  }

  cout << c << endl;


  
  return 0;
}


Measured memory_bytes: 3468
//killer_R@$tog!
#include<bits/stdc++.h>
using namespace std;
#define hell 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define ll long long int
#define N 100009
#define all(b) b.begin(),b.end();
//int pr[N];
//int seg[N];
/*int query(int l,int r,int sl,int sr,int p)
{
    if(r<sl || l>sr)
        return 0;
    if(sr<=r && sl>=l)
        return seg[p];
    int m=sl+(sr-sl)/2;
    return (__gcd(query(l,r,sl,m,2*p+1),query(l,r,m+1,sr,2*p+2)));
}

int build(int l,int r,int p,int arr[])
{
    if(l==r)
    {
        seg[p]=arr[l];
        return seg[p];
    }
    int m=l+(r-l)/2;
    seg[p]=__gcd(build(l,m,2*p+1,arr),build(m+1,r,2*p+2,arr));
    return seg[p];
}
void isprime()
{
    memset(pr,1,sizeof(pr));
    pr[1]=0;
    for(int i=2;i*i<=N;i++)
    {
        if(pr[i])
        {
            for(j=i*i;j<=N;j+=i)
            {
                pr[j]=0;
            }
        }
    }
}*/
void killer()
{
    int n;cin>>n;int a[n+1][3],dp[n+1][3];memset(dp,0,sizeof(dp));memset(a,0,sizeof(a));
    rep(i,1,n+1)
    {
        rep(j,0,3)
        cin>>a[i][j];
    }
    rep(i,1,n+1)
    {
        dp[i][0]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]);
        dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]);
        dp[i][2]=max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    //int h=(int)ceil(log2(n));
    //h=2*(int)pow(2,h)-1;
    //build(0,n-1,0,a);

    ll t;
    //cin>>t;
    t=1;
    while(t--)
        killer();

    return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<ll> S(N);
    rep(i, N) cin >> S[i];

    // C = A - B
    // とおくと
    // 0C, A + 0C,
    // 1C, A + 1C,
    // 2C, A + 2C,
    // ...
    // kC, A + kC(= N - 1)
    
    // A = N - 1 - kC
    // として
    // 0C, N - 1 - (k - 0)C,
    // 1C, N - 1 - (k - 1)C,
    // 2C, N - 1 - (k - 2)C,
    // ...
    // kC, N - 1 - (k - k)C
    // すべての段で左 < 右
    
    // f(k) - f(k - 1) = S[kC] + S[N - 1 - kC]

    ll ans = 0;

    for (int C = 1; C < N; ++C) {
        ll sum = 0;

        for (int k = 1; k * C < N; ++k) {
            if ((N - 1) % C == 0 && k <= (N - 1) / C && (N - 1) / C <= 2 * k) {
                break;
            }
            else if ((k + 1) * C >= N - 1) {
                break;
            }
            else {
                sum += S[k * C] + S[N - 1 - k * C];

                ans = max(ans, sum);
            }
        }
    }

    write(ans);
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int t,n,i,j,up=0,down=0;
  int h[100][1000];

  scanf("%d", &t);
  for(i=0;i<t;i++){
    scanf("%d", &n);
    scanf("%d", &h[i][0]);
    for(j=1;j<n;j++){
      scanf("%d", &h[i][j]);
      if(h[i][j]-h[i][j-1]>up){
	up=h[i][j]-h[i][j-1];
      } else if(h[i][j-1]-h[i][j]>down){
	down=h[i][j-1]-h[i][j];
      }
    }
    printf("%d %d\n", up, down);
    up=0;
    down=0;
  }

  return 0;
}


Measured memory_bytes: 980
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>

using namespace std;

typedef long long LL;

int n,mx,mn;
int minn,maxx;
pair<int,int> a[210000];
LL ans;
int main()
{
	scanf("%d",&n);
	mx=-1e9,mn=1e9;
	for (int i=1;i<=n;i++)
	{
		scanf("%d %d",&a[i].first,&a[i].second);
		if (a[i].first>a[i].second) swap(a[i].first,a[i].second);
		mx=max(mx,a[i].second);
		mn=min(mn,a[i].second);
	}
	sort(a+1,a+1+n);
	ans=(LL)(a[n].first-a[1].first)*(LL)(mx-mn);
	minn=maxx=a[1].second;
	for (int i=2;i<=n;i++)
	{
		ans=min(ans,(LL)(mx-a[1].first)*(LL)(max(maxx,a[n].first)-min(minn,a[i].first)));
		minn=min(minn,a[i].second);
		maxx=max(maxx,a[i].second);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

using namespace std;

int main(){
	int r,c,sum,total_sum = 0;
	scanf("%d %d",&r,&c);
	int table[r+1][c+1];

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			table[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d",&table[i][j]);
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		total_sum += sum;
	}
	table[r][c] = total_sum;

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
			printf("%d ",table[i][j]);
		}
		printf("%d\n",table[i][c]);
	}
}



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

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] ary = new int[]{in.nextInt(), in.nextInt(), in.nextInt()};
            Arrays.sort(ary);

            out.append(Arrays.equals(ary, new int[]{5, 5, 7}) ? "YES" : "NO");
        }

    }
}



Measured memory_bytes: 25044
c = [[int(j) for j in input().split()] for i in range(3)]


def main():
    flg = True

    for i in range(2):
        for j in range(2):
            if c[i][j] + c[i + 1][j + 1] != c[i][j + 1] + c[i + 1][j]:
                flg = False
                break

        if not flg:
            break

    print("Yes" if flg else "No")
    return


main()


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
		int a,b,d,r;
		double f;
		scanf("%d %d",&a,&b);
		d=a/b;
		r=a%b;
		f=a;
		f=f/b;
		printf("%d %d %lf\n",d,r,f);
		return 0;
}



Measured memory_bytes: 2720
#include<stdio.h>
#define MAX 10000
#define NIL -1


typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[MAX];

int n,H[MAX];

int getDep(int u){

  int d=0;
  while(T[u].parent!=NIL){
    u=T[u].parent;
    d++;
  }
  return d;
}

int setH(int u){

  int h1,h2;
  h1=h2=0;

  if(T[u].right!=NIL) h1=setH(T[u].right)+1;
  if(T[u].left!=NIL) h2=setH(T[u].left)+1;

  return H[u] = (h1>h2?h1:h2);

}

int getS(int u){
  if(T[u].parent==NIL) return NIL;
  
  if(T[T[u].parent].left != u && T[T[u].parent].left!=NIL) return T[T[u].parent].left;

  if(T[T[u].parent].right != u && T[T[u].parent].right!=NIL) return T[T[u].parent].right;

  return NIL;
}


void print(int u){

  int i,c;

  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getS(u));

  int deg = 0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",getDep(u));
  printf("height = %d, ",H[u]);

  
  if(T[u].parent==NIL) printf("root\n");
  else if(T[u].left==NIL&&T[u].right==NIL) printf("leaf\n");
  else printf("internal node\n");

  
}


int main(){
  int i,j,l,r,v,root=0;
  
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].parent=NIL;
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);

    T[v].left=l;
    T[v].right=r;

    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL) root=i;
  }

  setH(root);
  
  for(i=0;i<n;i++){
    print(i);
  }

  return 0;
  
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int n;
map<string,int>M;
map<string,vector<string> >A;
int f(string s)
{
    int now=M[s];
    if(A[s].size()>0)
    {
        int a=0;
        for(int i=0;i<A[s].size();i++)a+=f(A[s][i]);
        now=min(now,a);
    }
    return now;
}
main()
{
	while(cin>>n,n)
	{
		M.clear();
		A.clear();
		for(int i=0;i<n;i++)
		{
			string s;int a;cin>>s>>a;M[s]=a;
		}
		int m;cin>>m;
		for(int i=0;i<m;i++)
		{
			string s;cin>>s;
			int k;cin>>k;
			for(;k--;)
			{
				string t;cin>>t;
				A[s].push_back(t);
			}
		}
		string s;cin>>s;
		cout<<f(s)<<endl;
	}
}



Measured memory_bytes: 3060
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string s; cin >> s;
    s[5] = ' '; s[13] = ' ';
    cout << s << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

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

    ll R, G, B, N;
    cin >> R >> G >> B >> N;

    ll sum = 0;
    for (int r = 0; r * R <= N; ++r) {
        for (int g = 0; g * G <= N; ++g) {
            ll x = N - r * R - g * G;
            if (0 <= x && x % B == 0) ++sum;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  lvec x(n);
  REP(i, n) cin >> x[i];
  lvec c = x;
  sort(ALL(c));
  ll l = c[n / 2 - 1];
  ll r = c[n / 2];

  REP(i, n) {
    if (x[i] <= l)
      print(r);
    else
      print(l);
  }
  return 0;
}

Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int N,W;
int w[205],imos[205];
ll dp[205][10010];
ll sum(int k,int a,int b)//(a,b]
{
	if(b==-1)return 0ll;
	if(a==-1)return dp[k][b];
	return (dp[k][b]-dp[k][a]+MOD)%MOD;
}
ll wsum(int a,int b)//[a,b]
{
	return (imos[b]-(a==0?0:imos[a-1])+MOD)%MOD;
}
int main()
{
	scanf("%d %d",&N,&W);
	for(int i=0;i<N;i++)scanf("%d",&w[i]);
	sort(w,w+N,greater<int>());
	for(int i=0;i<N;i++)imos[i]=w[i];
	for(int i=0;i<N;i++)imos[i+1]+=imos[i];
	dp[0][w[0]]=1;
	dp[0][0]=1;
	for(int i=1;i<N;i++)
	{
		for(int j=0;j<=W;j++)
		{
			if(j-w[i]>=0)dp[i][j]=(dp[i-1][j-w[i]]+dp[i-1][j])%MOD;
			else dp[i][j]=dp[i-1][j];
			//cout << dp[i][j] << ' ';
		}
		//cout << endl;
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<=W;j++)
		{
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
			//cout << dp[i][j] << ' ';
		}
		//cout << endl;
	}
	ll ans = 0;
	for(int i=0;i<N;i++)
	{
		int beg,end;
		beg = W - wsum(N-1-i,N-1);
		end = beg + w[N-1-i] - w[N-i];
		beg = max(beg,-1);
		end = max(end,-1);
		ans += sum(N-1-i,beg,end);
		//cout << beg  << ' '<< end << ' '  << sum(N-1-i,beg,end) << endl;
		ans %= MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
typedef long long LL;

int a[410];
LL dp[410][410];

int main() {
    int n;
    cin>>n;
    for (int i=0;i<n;i++) scanf("%d", &a[i]);
    memset(dp,-1,sizeof(dp));
    for (int i=0;i<n;i++) dp[i][i]=0;
    for (int i=0;i<n;i++) {
        LL sum=a[i];
        for (int j=i-1;j>=0;j--) {
            sum+=a[j];
            if (j==i-1) dp[j][i]=sum;
            else {
                for (int k=j;k<=i-1;k++) {
                    LL v=dp[j][k]+dp[k+1][i]+sum;
                    if (dp[j][i]==-1 || dp[j][i]>v) dp[j][i]=v;
                }
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}

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

int gcd(int p, int q){
    if(q == 0)return p;
    return gcd(q, p % q);
}

int main() {

    int k;
    cin>>k;
    long long sm;
    sm =0;

    for(int i=1; i<=k; i++) {
       for(int j=1; j<=k; j++) {
           for(int x=1; x<=k; x++) {  
            // cout<<gcd(gcd(i,j),x)<<"\n";
            sm+=gcd(gcd(i,j),x);
            }
        } 
    }

    printf("%lld",sm);

}



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

namespace AtCoder.ABC122.A
{
    class Program
    {
        public static void Main()
        {
            var b = Console.ReadLine();
            Console.WriteLine(b == "A" ? "T" : b == "T" ? "A" : b == "C" ? "G" : "C");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
ll solve(ll h)
{
    if(h==1)
    return 1;
    return 2*solve(h/2) + 1;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll h;
    cin>>h;
    cout<<solve(h);
  }  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd seocnd

using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    if(n % 2 == 0) cout << n << endl;
    else cout << n * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string solve(vector<int> & v,int k)
{
    bool dp[k+1];
    memset(dp,0,sizeof dp);
    for(int i=1 ;i<=k;i++)
    {
        for(int move:v)
        {
            if(move >i)
            {
                continue;
            }
            if(dp[i-move]==0)
            {
                dp[i]=1;
            }
        }
    }
    return dp[k]? "First" : "Second";
}
int main() 
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cout<<solve(v,k);
}


Measured memory_bytes: 3716
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] high = new int[N+1];
        for (int i = 1; i <= N; i++) {
            high[i] = sc.nextInt();
        }
        int tot = 0;
        int tmp = 0;
        for (int i = 1; i < N+1; i++) {
            if (tmp < high[i]) {
                tot += high[i]-tmp;
            }
            tmp = high[i];
        }
        System.out.println(tot);
    }
}

Measured memory_bytes: 35628
from math import gcd

n,k = map(int,input().split())
a = list(map(int,input().split()))

gcd_num = a[0]
for ai in a[1:]:
    gcd_num = gcd(gcd_num,ai)

if(k%gcd_num==0)&(k <= max(a)):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 85552
#include<bits/stdc++.h>
using namespace std;
string cmp(string a, string b){
    if(a<=b) return a;
    return b;
}
int main(){
    int a,b;
    cin>>a>>b;
    string x="",y="";
    for(int i=1;i<=b;i++) x=x+char(a+48);
    for(int i=1;i<=a;i++) y=y+char(b+48);
    cout<<cmp(x,y);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
typedef long double ld;
ll rec(ll n, ll x){
  if(n == 0) return 1;
  ll len = (1LL<<(n+1)) - 3;
  ll num = (1LL<<n) - 1;
  if(x == 1) return 0;
  else if(x <= len + 1) return rec(n-1, x-1);
  else if(x == len + 2) return num + 1;
  else if(x <= (len+1)*2) return num + 1 + rec(n-1, x-len-2);
  else return num*2 + 1;
}
int main(){
  ll n;  cin >> n;
  ll x; cin >> x;
  cout << rec(n, x) << endl;
  return 0;
}


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

int N, A, x[50];
long long dp[50][2501][51];

long long dfs(int i, int sum, int num)
{
  if (i == N){
    return num * A == sum && num;
  }

  if (dp[i][sum][num] != -1) return dp[i][sum][num];

  return dp[i][sum][num] = dfs(i + 1, sum + x[i], num + 1) + dfs(i + 1, sum, num);
}

int main()
{
  cin >> N >> A;
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << dfs(0, 0, 0) << endl;
}



Measured memory_bytes: 50048
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll bpow(ll a , ll b){
  if (b == 0) return 1;
  ll ret;
  if (b%2 == 0){
    ll  t = bpow(a, b/2);
    ret = t*t;
  }else{
    ll t = bpow(a, (b-1)/2);
    ret = a*t*t;
  }
  return ret;
}
int main(){
  ll N, K; cin >> N >> K;
  vector<ll> sum(N+1,0);
  REP(i,N){
    ll a; cin >> a;
    sum[i+1] = sum[i] + a;
  }
  map<ll,ll> cnt;
  FOR(l,1,N+1) FOR(r,l,N+1){
    cnt[sum[r]-sum[l-1]]++;
  }
  //桁数の最大値
  ll M = ceil(log2(sum[N]));
  ll ans = 0;
  IREP(i,M){
    ll t = ans + bpow(2,i);
    ll c = 0;
    FOREACH(x,cnt){
      if(t == (t&(x.first))) c++;
    }
    if(c>=K) ans = t;
  }
  cout << ans << endl;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#') break;
            if(j==w-1){
                for(int k=0;k<w;k++){
                    a[i][k]='n';
                }
            }
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(a[j][i]=='#') break;
            if(j==h-1){
                for(int k=0;k<h;k++){
                    a[k][i]='n';
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]!='n'){
                cout << a[i][j];
            }
        }
        cout << endl;
    }

}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using Yorukatsu044.Questions;
using Yorukatsu044.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu044.Questions
{
    /// <summary>
    /// ABC058 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var abc = inputStream.ReadIntArray();
            yield return abc[1] - abc[0] == abc[2] - abc[1] ? "YES" : "NO";
        }
    }
}


namespace Yorukatsu044
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu044.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu044.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
a,v=gets.split.map(&:to_i)
b,w=gets.split.map(&:to_i)
t=gets.to_i
if a<b
  if (b-a)*(b+w*t-a-v*t)<=0
    puts "YES"
  else
    puts "NO"
  end
else
  if (a-b)*(a-v*t-b+w*t)<=0
    puts "YES"
  else
    puts "NO"
  end
end



Measured memory_bytes: 14384
#include <iostream>
#include <algorithm>

using namespace std;

class Solver {
public:
	static void solve() {
		int n;
		cin >> n;

		char s[500];
		cin >> s;

		int cnts[26] = {};
		for (int i = 0; i < n; i+=2) {
			cnts[s[i] - 'a']++;
		}

		int res = 0;
		for (int i = 1; i <= 9; i++) {
			int cnt = 0;
			for (int j = 0; j < 26; j++) {
				if (cnts[j] == i)cnt++;
			}

			if (cnt == 0)continue;

			if (res > 0)res++;

			if (i == 1) {
				res += cnt + cnt - 1;
			}
			else {
				if (cnt == 1) {
					res += 3;
				}
				else {
					res += cnt + cnt - 1 + 2 + 2;
				}
			}
		}

		cout << res<<endl;
	}
};

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


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

using namespace std;
typedef pair<int, int> pii;

int main() {
    vector<pii> v;
    int p, s;
    while (scanf("%d,%d", &p, &s), p) {
        v.push_back(pii(s, p));
    }

    int rank[150], r = 1;
    sort(v.begin(), v.end(), greater<pii>());
    rank[v[0].second] = r;
    for (int i = 1; i < v.size(); i++) {
        if (v[i].first != v[i - 1].first) r++;
        rank[v[i].second] = r;
    }

    int q;
    while (scanf("%d", &q) != EOF)
        cout << rank[q] << endl;

    return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x[8] = {}, y[8] = {}, a[8] = {0, 1, 2, 3, 4, 5, 6, 7}, c = 0;
    double z = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    do {
        for (int j = 1; j < n; j++) z += hypot(x[a[j]] - x[a[j - 1]], y[a[j]] - y[a[j - 1]]);
        c++;
    } while (next_permutation(a, a + n));
    cout << setprecision(13) << z / c;
}


Measured memory_bytes: 3852
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    map<ll,ll> mp;
    int n; cin >> n;
    ll a[200005];
    ll sum = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        sum += mp[i]*(mp[i]-1)/2;
    }
    for(int k=0;k<n;k++){
        cout << sum - (mp[a[k]] - 1) << "\n";
    }
    return 0;
}

Measured memory_bytes: 16640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int Wcnt=0;
  rep(i,n){
    if(s[i]=='W') Wcnt++;
  }
  int Rcnt=n-Wcnt;
  int Rcnt2=0;
  rep(i,Rcnt){
    if(s[i]=='R') Rcnt2++;
  }
  int ans=Rcnt-Rcnt2;
  cout << ans << endl;
}

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

int main(){
  int num;
  double temp;
  double diff;
  double king_diff=1000;
  int ans;
  cin>>num;
  double T,target;
  cin>>T>>target;
  double array[num];
  for(int i=0;i<num;i++){
    cin>>array[i];
  }
  for(int i=0;i<num;i++){
    temp=T-array[i]*0.006;
    diff=target-temp;
    if(diff<0){
      diff=-diff;
    }
    if(king_diff>diff){
      king_diff=diff;
      ans=i+1;
    }
    
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
def decrement(*args):
  return [elm-1 for elm in args]

B,F,R = 4,3,10

a = [[[0 for _ in range(R)]for _ in range(F)]for _ in range(B)]

n = int(input())
for _ in range(n):
  b,f,r,v = map(int,input().split())
  b,f,r = decrement(b,f,r)
  a[b][f][r] += v

for x in a[0]:
  print('',end=' ')
  print(*x)
print("####################")
for x in a[1]:
  print('',end=' ')
  print(*x)
print("####################")
for x in a[2]:
  print('',end=' ')
  print(*x)
print("####################")
for x in a[3]:
  print('',end=' ')
  print(*x)



Measured memory_bytes: 5628
#include<cstdio>
using namespace std;
int main(){
 int w,h;
 int cnt=0;
 while(1){
  cnt=0;
  scanf("%d %d",&h,&w);
  if(w==0 && h==0){
   
   return 0;
  }
  for(int i=0;i<h;i++){

   for(int j=0;j<w;j++){

    if((i+j)%2==0){
     printf("#");
    }else{
     printf(".");
    }
    cnt++;

   }
   printf("\n");
  }
  printf("\n");
 }
}


Measured memory_bytes: 2604
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        var s = Console.ReadLine();
        SegmentTree<int> segtree = new SegmentTree<int>(n + 1, int.MaxValue / 2, Min);
        segtree.Operate(n, 0);
        for (int i = n; i >= 0; i--)
        {
            if (s[i] == '1') continue;
            var val = segtree[i];
            segtree.Operate(Max(0, i - m), i, val + 1);
        }
        if (segtree[0] == int.MaxValue / 2) { Console.WriteLine(-1); return; }
        var last = segtree[0];
        var lastPos = 0;
        List<int> res = new List<int>();
        for (int i = 0; i <= n; i++)
        {
            if (s[i] == '1' || last - 1 != segtree[i]) continue;
            res.Add(i - lastPos);
            last = segtree[i];
            lastPos = i;
        }
        Console.WriteLine(string.Join(" ", res));
    }
}


class SegmentTree<T>
{
    public readonly int Size;
    T[] Operators;
    Func<T, T, T> Merge;
    int LeafCount;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public SegmentTree(int size, T identity, Func<T, T, T> merge)
    {
        Size = size;
        Merge = merge;
        LeafCount = 1;
        while (LeafCount < size) LeafCount <<= 1;
        Operators = new T[LeafCount << 1];
        for (int i = 0; i < Operators.Length; i++)
            Operators[i] = identity;
    }
    public T this[int index]
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { return Query(index); }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int i, T x) { i += LeafCount; Operators[i] = Merge(Operators[i], x); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int l, int r, T x)
    {
        for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1)
        {
            if ((l & 1) == 1) Operators[l] = Merge(Operators[l], x);
            if ((r & 1) == 0) Operators[r] = Merge(Operators[r], x);
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int i)
    {
        i += LeafCount;
        T res = Operators[i];
        while (0 < (i >>= 1)) res = Merge(res, Operators[i]);
        return res;
    }
}


Measured memory_bytes: 16992
// solution is at the bottom

import kotlin.math.*

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }


fun main() {
    val n = readInt()
    val a = readIntArray(n)
    var res = 0L

    var min = a[0]
    for (x in a.slice(1 until n)) {
        if (x > min) {
            min = x
        } else {
            res += min - x
        }
    }

    println(res)
}


Measured memory_bytes: 54704