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


using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	
	int n;
	cin >> n;
	vector<vector<pll>> tree(n);
	for (int i = 0; i < n - 1;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		tree[a].emplace_back(make_pair(b, c));
		tree[b].emplace_back(make_pair(a, c));
	}

	int q, k;
	cin >> q >> k;
	k--;
	vector<ll> d(n,BIG_NUM);
	d[k] = 0;
	vector<bool> isChecked(n);
	priority_queue<pll, vector<pll>, greater<pll>>pq;
	pq.push(make_pair(0,k));

	while (!pq.empty()) {
		ll v = pq.top().second;
		pq.pop();

		if (!isChecked[v]) {
			for (auto it = tree[v].begin();it != tree[v].end();it++) {
				if (d[it->first] > d[v] + it->second) {
					d[it->first] = d[v] + it->second;
					pq.push(make_pair(d[it->first], it->first));
				}
			}
			isChecked[v] = true;
		}
	}

	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;

		x--;
		y--;
		cout << d[x] + d[y] << endl;
	}
	
}


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

using namespace std;
typedef long long ll;
#define cc(x) cout << (x) << endl
#define FOR(az,c)   for ( int (az)=0; (az)<(c); (az)++)
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
typedef vector<int> vi;
#define endl '\n';
#define pb push_back
#define mp make_pair
#define X first
#define Y second
typedef pair<int, int> pii;
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

string trim(const string& str)
{
    size_t first=str.find_first_not_of(' ');
    if(string::npos == first)
    {
        return str;
    }
    size_t last=str.find_last_not_of(' ');
    return str.substr(first,(last-first+1));
}
//----------------------------------------------------------//


void solve()
{
   int n;
   cin>>n;
   n=n%1000;
   if(n==0)
   {
       cout<<0<<endl;
   }
   else
   {
       cout<<1000-(n%1000)<<endl;
   }
   
   

}
   



int main()
{
    IOS
    //int t=0;
    //cin>>t;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
   // while(t--){
    solve();
    //}
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  int r;
  cin >> r;
  cout << 3 * r * r << endl;

}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

s = input()

cnt = 0
for i in range(len(s) // 2):
    if s[i] != s[len(s)-i-1]:
        cnt += 1

print(cnt)

Measured memory_bytes: 31216
s = gets.chop
slength = s.length

for num in 0..slength-1 do
    if s[num] == 'C'
        for endnum in num+1..slength do
            if s[endnum] == 'F'
                puts "Yes"
                break
            elsif endnum == slength
                puts "No"
            end
        end
        break
    elsif num == slength-1
        puts "No"
    end
end

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

const int MAXN = 1e5 + 10;
bool isp[MAXN];
int n, ps[MAXN];

int main() {
	isp[1] = 1;
	for (int i = 2; i < MAXN; i++)
		if (!isp[i])
			for (int j = i + i; j < MAXN; j += i)
				isp[j] = 1;
	for (int i = 2; i < MAXN; i++)
		if (!isp[i] && !isp[(i + 1) / 2])
			ps[i]++;
	for (int i = 1; i < MAXN; i++)
		ps[i] += ps[i - 1];
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		cout << ps[r] - ps[l - 1] << '\n';
	}
}

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

int main(){
    int n,ans=0;
    cin>>n;n--;
    rep(i,n){
        ans+=n/i;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n,m;
priority_queue<ll> q;

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

    REP(i,n){
        ll a;
        cin>>a;
        q.push(a);
    }

    REP(i,m){
        ll qq = q.top();
        q.pop();
        q.push(qq/2LL);
    }

    ll ans = 0;
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
    return 0;
}

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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    int n;
    cin>>n;
    vector<pi> v;
    for (int i=0;i<n;i++) {
        int x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    int cnt = 0;
    bool ok = false;
    for (int i=0;i<n;i++) {
        if (v[i].first == v[i].second) {
            cnt++;
        }else {
            if (cnt >= 3) ok = true;
            cnt = 0;
        }
    }
    if (ok or cnt>=3) {
        cout << "Yes\n";
    }else {
        cout << "No\n";
    }
}

int32_t main(){
    fastio
    notc
    ret
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define INF 1<<29
#define LIMIT 1000000007 //10^9+7

namespace /* combination.cpp */{
  namespace /* modinv.cpp */{
    namespace /* extGCD.cpp */{
      //ax + by = gcd(a, b)を満たすx, yを参照渡しから入れる
      long long extGCD(long long a, long long b, long long &x, long long &y) {
          if (b == 0) {
              x = 1;
              y = 0;
              return a;
          }
          long long d = extGCD(b, a%b, y, x);
          y -= a/b * x;
          return d;
      }
    }

    /*
    mod pでの a の逆元 x
    ax = 1 mod p
    ax-1がpで割り切れるので
    ax + py = 1 の解 x をとる
    aとpは互いに素であること
    */
    long long modinv(long long a, long long p){
      long long x, y;
      extGCD(a, p, x, y);
      return (x>0? x: x+p);
    }
  }

  long long l_fac(long long n){
    if(n<0) return -1;
    long long ans = 1;
    for(long long i=1; i<=n; i++){
      ans *= i;
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nPr(long long n, long long r){
    long long ans = 1;
    for(long long i=0; i<r; i++){
      ans *= (n-i);
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nCr(long long n, long long r){
    if(r > n/2) r = n-r;
    return l_nPr(n, r) * modinv(l_fac(r), LIMIT) % LIMIT;
  }
}

long long modpow(long long a, long long n, long long p){
  if(n==1) return a % p;
  if(n%2 == 1) return (a * modpow(a, n-1, p)) % p;

  long long t = modpow(a, n/2, p);
  return t * t % p;
}

int main(){
    ll n, a, b;
    cin>>n>>a>>b;

    ll ans = modpow(2, n, LIMIT) - 1;
    ans -= l_nCr(n, a);
    if(ans<0)ans+=LIMIT;
    ans -= l_nCr(n, b);
    if(ans<0)ans+=LIMIT;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
// Aizu Vol-5 0502: Dice
// 2017.8.30 bal4u@uu

#include <stdio.h>

int t[7] = { 0, 'N', 'E', 'W', 'S', 'R', 'L' };

int rot[7][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,2,6,3,4,1,5 },{ 0,4,2,1,6,5,3 },{ 0,3,2,6,1,5,4 },
	{ 0,5,1,3,4,6,2 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 } };
	
int main()
{
	int n;
	int i, j, k1, k2, s;
	int dice[2][7];
	char b[10];

	while (scanf("%d", &n) && n) {
		s = 1; for (i = 1; i <= 6; i++) dice[0][i] = i;
		for (k1 = 0, k2 = 1; n-- > 0; k1 = k2, k2 = !k2) {
			scanf("%s", b);
			for (j = 0; *b != t[j]; j++);
			for (i = 1; i <= 6; i++) dice[k2][i] = dice[k1][rot[j][i]];
			s += dice[k2][1];
		}
		printf("%d\n", s);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class rolling_hash{
	static const long long base=10007,mod1=1e9+7,mod2=1e9+9;
	int len;
	vector<long long> pow1,pow2,h1,h2;
public:
	using hash_type=pair<long long,long long>;
	rolling_hash(){}
	rolling_hash(const string& s):len(s.length()),pow1(len+1),pow2(len+1),h1(len+1),h2(len+1){
		pow1[0]=pow2[0]=1;
		rep(i,len){
			pow1[i+1]=pow1[i]*base%mod1;
			pow2[i+1]=pow2[i]*base%mod2;
			h1[i+1]=(h1[i]*base+s[i])%mod1;
			h2[i+1]=(h2[i]*base+s[i])%mod2;
		}
	}
	template<class T>
	rolling_hash(const vector<T>& a):len(a.size()),pow1(len+1),pow2(len+1),h1(len+1),h2(len+1){
		pow1[0]=pow2[0]=1;
		rep(i,len){
			pow1[i+1]=pow1[i]*base%mod1;
			pow2[i+1]=pow2[i]*base%mod2;
			h1[i+1]=(h1[i]*base+a[i])%mod1;
			h2[i+1]=(h2[i]*base+a[i])%mod2;
		}
	}
	hash_type get_hash(int l,int r)const{
		assert(0<=l && l<=r && r<=len);
		auto res1=(h1[r]-h1[l]*pow1[r-l])%mod1; if(res1<0) res1+=mod1;
		auto res2=(h2[r]-h2[l]*pow2[r-l])%mod2; if(res2<0) res2+=mod2;
		return {res1,res2};
	}
	static hash_type get_hash(const string& s){
		long long res1=0,res2=0;
		rep(i,s.length()){
			res1=(res1*base+s[i])%mod1;
			res2=(res2*base+s[i])%mod2;
		}
		return {res1,res2};
	}
	template<class T>
	static hash_type get_hash(const vector<T>& a){
		long long res1=0,res2=0;
		rep(i,a.size()){
			res1=(res1*base+a[i])%mod1;
			res2=(res2*base+a[i])%mod2;
		}
		return {res1,res2};
	}

	hash_type f(int l,int r,char c){
		auto res1=(h1[r]-h1[l]*pow1[r-l])%mod1; if(res1<0) res1+=mod1;
		auto res2=(h2[r]-h2[l]*pow2[r-l])%mod2; if(res2<0) res2+=mod2;
		res1=(pow1[r-l]*c+res1)%mod1;
		res2=(pow2[r-l]*c+res2)%mod2;
		return {res1,res2};
	}
};

int main(){
	int n; cin>>n;
	vector<string> s(n);
	rep(i,n) cin>>s[i];

	int lmax=0;
	rep(i,n) lmax=max(lmax,int(s[i].length()));

	vector<bool> L(lmax+1);
	rep(i,n) L[s[i].length()]=true;

	vector H(lmax+1,vector<rolling_hash::hash_type>());
	rep(i,n){
		int len=s[i].length();

		int freq[128]={};
		rep(j,len) freq[s[i][j]]++;

		rolling_hash R(s[i]);
		for(int j=len;j>=0;j--){
			if(L[len-j+1]){
				for(int c='a';c<='z';c++) if(freq[c]) {
					H[len-j+1].emplace_back(R.f(j,len,c));
				}
			}
			if(j>0) freq[s[i][j-1]]--;
		}
	}

	rep(l,lmax+1) sort(H[l].begin(),H[l].end());

	lint ans=0;
	rep(i,n){
		auto p=equal_range(H[s[i].length()].begin(),H[s[i].length()].end(),rolling_hash::get_hash(s[i]));
		ans+=p.second-p.first-1;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 394532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<pair<int, int>> R(N), B(N);

    for(int i=0; i<N; i++){
        int x,y; cin >> x >> y;
        R[i] = {x, y};
    }
    for(int i=0; i<N; i++){
        int x, y; cin >> x >> y;
        B[i] = {y, x};
    }

    sort(R.begin(), R.end(), greater<pair<int, int>>());
    sort(B.begin(), B.end());

    int ans = 0;
    for(int i=0; i<N; i++){
        pair<int, int> r = R[i];
        for(int j=0; j<B.size(); j++){
            pair<int, int> b = B[j];
            if(r.first < b.second && r.second < b.first){
                ans++;
                B.erase(B.begin()+j);
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>

int main(void)
{

    int N;
    scanf("%d", &N);

    std::vector<int> A, B;
    std::queue<int> skipped, answer1, answer2;
    int x;
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &x);
        A.push_back(x);
    }
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &x);
        B.push_back(x);
    }

    for (int i = 0, j = N - 1; i < N; i++)
    {
        while (j >= 0 && B[j] == A[i])
        {
            skipped.push(B[j]);
            j--;
        }
        if (j < 0)
        {
            if (skipped.front() != A[i])
            {
                answer1.push(skipped.front());
                skipped.pop();
                continue;
            }
            else
            {
                break;
            }
        }
        answer1.push(B[j]);
        j--;
    }
    while(!skipped.empty()){
        skipped.pop();
    }
    for (int i = 0, j = 0; i < N; i++)
    {
        while (j < N && B[j] == A[i])
        {
            skipped.push(B[j]);
            j++;
        }
        if (j == N)
        {
            if (skipped.front() != A[i])
            {
                answer2.push(skipped.front());
                skipped.pop();
                continue;
            }
            else
            {
                break;
            }
        }
        answer2.push(B[j]);
        j++;
    }

    if (answer1.size() != N && answer2.size() != N)
    {
        printf("No\n");
    }
    else if (answer1.size() == N)
    {
        printf("Yes\n");
        while (!answer1.empty())
        {
            printf("%d ", answer1.front());
            answer1.pop();
        }
    }
    else
    {
        printf("Yes\n");
        while (!answer2.empty())
        {
            printf("%d ", answer2.front());
            answer2.pop();
        }
    }

    return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MX 100016
#define INF ((ll)1e15)

vpii wh[MX];
ll dist[MX];

int main()
{
    canhazfast();

    int n, m;
    priority_queue<pll, vpll, greater<pll>> q;

    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        wh[l].empb(r, c);
    }
    q.emp(0, 1);
    for (int i = 1; i <= n; ++i) {
        while (q.size() && q.top().sec < i) q.pop();
        retif(q.empty()) cout << "-1\n", 0;
        dist[i] = q.top().fir;
        for (const pii &p : wh[i]) q.emp(dist[i]+p.sec, p.fir);
    }
    cout << dist[n] << '\n';

    return 0;
}


Measured memory_bytes: 7032
#include <iostream>

using namespace std;

int W,H;
int posW, posH;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
bool tiles[21][21] = {};
bool v_tiles[21][21] = {};

void dfs(int x, int y) {
    if (!(0 <= x && x <= W-1 && 0 <= y && y <= H-1) || v_tiles[x][y] == true || tiles[x][y] == true)
        return;

    v_tiles[x][y] = true;
    for (int i = 0; i < 4; i++) {
        dfs(x+dx[i], y+dy[i]);
    }
}

int main() {
    while (cin>>W>>H && W != 0 && H != 0) {
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                v_tiles[w][h] = false;
                char tile;
                cin>>tile;
                switch (tile) {
                    case '.':
                        tiles[w][h] = false;
                        break;

                    case '#':
                        tiles[w][h] = true;
                        break;

                    case '@':
                        tiles[w][h] = false;
                        posW = w;
                        posH = h;
                        break;
                }
            }
        }

        dfs(posW, posH);

        int count = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (v_tiles[w][h] == true) count++;
            }
        }
        cout<<count<<endl;;
    }
}

Measured memory_bytes: 3072
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] lines = sc.nextLine().split(" ");
        long num1 = Integer.parseInt(lines[0]);
        long num2 = Integer.parseInt(lines[1]);

        long ans1 = num1 / num2;
        long ans2 = num1 % num2;
        double ans3 = (double)num1 / (double)num2;

        System.out.println(ans1 + " " + ans2 + " " + String.format("%.9f", ans3));


    }
}

Measured memory_bytes: 26456
n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]

import itertools
l = [i for i in range(1,n+1)]
ll = itertools.permutations(l)

for i,v in enumerate(ll):
    if list(v) == p:
        p_ind = i
    if list(v) == q:
        q_ind = i

print(abs(p_ind - q_ind))

Measured memory_bytes: 3064
#include <stdio.h>

typedef struct{
  int p;
  int l;
  int r;
}Tree;

int n;

void output(Tree *);
int makedepth(Tree *,int);
int makeheight(Tree *,int);
  
int main(){
  Tree a[25];
  int d[25];
  int b,i,id,l,r;

  scanf("%d",&n);
   for(i = 0; i < n; i++){
    a[i].p = a[i].l = a[i].r = -1;
   }
   
  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d%d",&a[id].l,&a[id].r);
    if(a[id].l != -1)a[a[id].l].p = id;
    if(a[id].r != -1)a[a[id].r].p = id;
  }
  
  for(i = 0; i < n; i++){
   if(a[i].p == -1){
   r = i;
   break;
   }
  }
 output(a);
  return 0;
}

void output(Tree a[]){
  int i,b,prev,degree = 0,sibling = 0;
  
  for(i = 0; i < n; i++){
    prev = a[i].p;
    degree = 0;
    
    if(a[i].p != -1){
      if(a[prev].l == i)sibling = a[prev].r;
      else sibling = a[prev].l;
    }
    else{
     sibling = -1;
    }
    if(a[i].l != -1)degree++;
    if(a[i].r != -1)degree++;
    
    printf("node %d: parent = %d, ",i,a[i].p);
    printf("sibling = %d, degree = %d, ",sibling,degree);
    printf("depth = %d, height = %d, ",makedepth(a,i),makeheight(a,i));
    
    if(a[i].p == -1)printf("root\n");
    else if(a[i].l == -1 && a[i].r == -1)printf("leaf\n");
    else printf("internal node\n");
	   
  }
}

int makedepth(Tree a[],int d){
  int prev,num = 0;

  prev = d;
  while(a[prev].p != -1){
    num++;
    prev = a[prev].p;
  }
  return num;
}
 
int makeheight(Tree a[],int h){
  int result,num1 = 0,num2 = 0;

  if(a[h].l != -1)num1 = makeheight(a,a[h].l) + 1;
  if(a[h].r != -1)num2 = makeheight(a,a[h].r) + 1;

  if(num1 >= num2)result = num1;
  else result = num2;

  num1 = 0;
  num2 = 0;
  
  return result;
}



Measured memory_bytes: 2128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
    int A, B, C, X, Y, money;
    scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);

    if((A+B)<=2*C){
        money=A*X+B*Y;
    }
    else{
        if(X>Y){
            if((2*C)<A){
                money = 2*C*X;
            }
            else{
                money = (2*C*Y)+(X-Y)*A;
            }
        }
        else{
            if((2*C)<B){
                money = 2*C*Y;
            }
            else{
                money = (2*C*X)+(Y-X)*B;
            }
        }
    }
    printf("%d", money);
    return 0;
}

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

int sumCalc(int A[],int N){
  int sum = 0;

  for (int i = 0; i < N; i++){
    sum += A[i];
  }

  return sum;
}

int main(){
  int N;
  double M;
  int A[100];
  double sum;
  double flag;
  int count = 0;

  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> A[i];

  sum = sumCalc(A, N);

  flag = sum / (4 * M);

  for (int i = 0; i < N; i++){
    if (A[i] >= flag){
      count++;
    }
  }

  if (count >= M){
    cout << "Yes" << endl;
  } else if (count < M){
    cout << "No" << endl;
  }

  return 0;
}

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

#define N 10005
vector<ll> e[N];
ll n, u, v, m, c[N], d[N], t;

void dfs(ll pa, ll curr) {
    d[curr] = c[t++];
    m+=c[t];
    for (auto child:e[curr]) {
        if (child == pa) continue;
        dfs(curr, child);
    }
}

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
    cin >> n;
    for (ll i=1; i<n; i++) {
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for (ll i=0; i<n; i++) cin >> c[i];
    sort(c, c+n, greater<ll>());
    m=0; t=0;
    dfs(0,1);
    cout << m << endl;
    for (ll i=1; i<=n; i++) cout << d[i] << ' ';
    cout << endl;
    return 0;
}

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

int main()
{
	long long N;
	cin >> N;
	vector<long long> res;
	for (long long i = N; i >= 0; i--) {
		if ((i - 1) * i / 2 < N) {
			res.push_back(i);
			N -= i;
			if (N == 0) {
				break;
			}
		}
	}
	for (int i = res.size() - 1; i >= 0; i--) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

struct punto{
    int x,y;
    bool operator<(const punto b)const{
        if(y == b.y)
            return x < b.x;
        return y < b.y;
    }
    punto operator-(const punto b)const{
        punto aux;
        aux.x = x-b.x;
        aux.y = y-b.y;
        return aux;
    }
    long long operator^(const punto b)const{
        return x*b.y - y*b.x;
    }
};

int main(){

cin.tie(0);
ios::sync_with_stdio(0);

int N;
cin>>N;
vector<punto> V(N);
for(int i = 0; i < N; i++){
    punto p;
    cin>>p.x>>p.y;
    V[i] = p;
}
sort(V.begin(),V.end());


vector<punto>U;
vector<punto>D;

U.push_back( V[0] );
U.push_back( V[1] );
int c = 2;
for(int i = 2; i < N; i++){
        punto v1 = V[i]-U[c-1];
        punto v2 = U[c-1]-U[c-2];
        int aux = v1^v2;
        if(aux > 0){
            /// joya lo metemos
            U.push_back(V[i]);
            c++;
        }else{
            /// hasta que no de positivo no entra.
            while(aux < 0 && c > 1){
                U.pop_back();
                c--;
                punto v1 = V[i]-U[c-1];
                punto v2 = U[c-1]-U[c-2];
                aux = v1^v2;
            }
            U.push_back(V[i]);
            c++;
        }

}


D.push_back( V[N-1] );
D.push_back( V[N-2] );
c = 2;
for(int i = N-3; i >= 0; i--){
        punto v1 = V[i]-D[c-1];
        punto v2 = D[c-1]-D[c-2];
        int aux = v1^v2;
        if(aux > 0){
            /// joya lo metemos
            D.push_back(V[i]);
            c++;
        }else{
            /// hasta que no de positivo no entra.
            while(aux < 0 && c > 1){
                D.pop_back();
                c--;
                punto v1 = V[i]-D[c-1];
                punto v2 = D[c-1]-D[c-2];
                aux = v1^v2;
            }
            D.push_back(V[i]);
            c++;
        }

}

vector<punto>R;
for(int i = D.size()-1; i >= 0; i--){
        R.push_back(D[i]);
}
for(int i = U.size()-2; i >= 1; i--){
     R.push_back(U[i]);
}
cout<<R.size()<<endl;
for(int i = 0; i < R.size(); i++){
    cout<<R[i].x<<" "<<R[i].y<<endl;
}
/**

for(int i = 0; i < U.size(); i++){
    cout<<U[i].x<<" "<<U[i].y<<endl;
}

for(int i = 0; i < D.size(); i++){
    cout<<D[i].x<<" "<<D[i].y<<endl;
}
*/


return 0;
}




Measured memory_bytes: 5100
#!/usr/bin/env python3

def solve(s):
    return s[0] == "A" and s.count("C",2,-1) == 1 and s[1:].replace("C", "").islower()


def main():
    S = input()
    print("AC" if solve(S) else "WA")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 8948
#python3
def f(ss):
    s = list(ss)
    srv = list(reversed(s))
    if s == srv:
        return True
    else:
        return False
def main():
    s = input()
    n = len(s)
    flag = True
    if not f(s):
        flag = False
    if not f(s[:(n-1)//2]):
        flag = False
    if not f(s[((n+3)//2)-1]):
        flag = False

    if flag:
        print('Yes')
    else:
        print('No')
main()

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

vlli x[200001];

int main() {
    lli n;
    cin1(n);
    lli a[n];
    ncin1(n,a);

    REP(i,0,n) {
        x[a[i]].push_back(i);
    }
    lli ans = 0;
    lli cur = -1;
    bool update = false;
    REPE(i,1,n) {
        //REP(j,0,x[i].size()){
        //    cout3(i,j,x[i][j]);
        //}
        if (x[i].size() == 0) {
            ans = i-1;
            update = true;
            break;
        }
        // i の値がある場所の一覧が、x[i]
        // その中で、最も cur よりも先で小さいものを探す
        auto it = upper_bound(x[i].begin(), x[i].end(), cur);
        if (it == x[i].end()) {
            ans = i-1;
            update = true;
            break;
        }
        cur = *it;
        //cout2(i,cur);
    }
    if (!update) {
        cout << 0 << endl;
        return 0;
    }

    if (ans <= 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << n-ans << endl;
}


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

int main(){
    int N, M, C;
    int B[100];
    int A[100][100];

    cin >> N >> M >> C;
    for (int i = 0; i < M; i++){
        cin >> B[i];
    }
    for (int i = 0; i < N; i++){
        for (int j = 0; j < M; j++){
            cin >> A[i][j];
        }
    }
    int count = 0;

    for (int i = 0; i < N; i++){
        int total = 0;
        for (int j = 0; j < M; j++){
           total += B[j] * A[i][j];
        }
        if (total > -C) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i,j,key;
  int A[1000];

  scanf("%d",&N);

  for(i=0 ; i<N ; i++){
    scanf("%d",&A[i]);
  }

  for(j=0 ; j<N-1; j++) printf("%d ",A[j]);
  printf("%d\n",A[N-1]);

  for(i=1 ; i<N ; i++){
    
    key = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }

    A[j+1] = key;

    for(j=0 ; j<N-1; j++) printf("%d ",A[j]);
    printf("%d\n",A[N-1]);
  }

  return 0;
}

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class141
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            int[] a = new int[M];
            int[] b = new int[M];
            for(int i = 0; i < M; i++)
            {
                var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = r[0];
                b[i] = r[1];
            }
            Array.Sort(a, b);
            int count = 1;
            int start = a[0];
            int last = b[0];
            for(int i = 1; i < M; i++)
            {
                if (a[i] >= last)
                {
                    count++;
                    last = b[i];
                }
                last = Math.Min(last, b[i]);
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 18016
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <deque>
#include <unordered_map>
#include <map>
#include <random>
#include <cstdio>
#include <string>
#include <cctype>
#define int long long
#define pb push_back
#define eb emplace_back
#define rs resize
#define ld long double
#define vi vector<int>


using namespace std;

const double PI = atan2(0, -1);

void solve() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x; sum += x;
    }
    int ans = n - sum;
    if (ans < 0) ans = -1;
    cout << ans;
}


signed main() {
    ///  freopen("salesman.in", "r", stdin);
   //   freopen("salesman.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout.precision(30);
    int t = 1;
    while(t--)
    solve();
    //   system("pause");
}

Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  string s, t; cin >> s >> t;
  string ans = "";
  if (s.length() > t.length()) {
    ans += s.back();
    s.pop_back();
  }
  while (!s.empty()) {
    ans += t.back();
    t.pop_back();
    ans += s.back();
    s.pop_back();
  }
  reverse(ALL(ans));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ans1 = b*d , ans2 = a*c , ans3 = a*d , ans4 = b*c;
    long long ans = max(max(ans1,ans2) , max(ans3 , ans4));
    cout<<ans;
}

Measured memory_bytes: 3632
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, M = MI()
    edge = []
    for _ in range(M):
        a, b, c = MI_()
        c += 1
        edge.append((a, b, -c))

    #edgeは1次元ですべて(始点,終点,重み)を格納
    def bellmanford(edge):
        costs = [inf] * N
        costs[0] = 0
        exist_minus_cycle = False
        for i in range(N):
            update = False
            for from_, to, cost in edge:
                cost_to = costs[from_] + cost
                if cost_to < costs[to]:
                    update = True
                    costs[to] = cost_to
                    
            if not update:
                break
            elif i==N-1:
                exist_minus_cycle = True

        #どこで無限に更新されるか判定
        minus_cycle = set()
        if exist_minus_cycle:
            for i in range(N+1):
                for from_, to, cost in edge:
                    cost_to = costs[from_] + cost
                    if from_ in minus_cycle:
                        minus_cycle.add(to)
                    if cost_to < costs[to]:
                        minus_cycle.add(from_)
                        minus_cycle.add(to)
                        costs[to] = cost_to
        return costs, minus_cycle
    
    costs,minus_cycle = bellmanford(edge)


    if N-1 in minus_cycle :
        print("inf")
    else:
        print(-costs[-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 43356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string c = "CODEFESTIVAL2016";
    
    string s;
    cin >> s;
    int ans = 0;
    
    rep(i, s.length()) {
        if (c[i] != s[i]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_freopen  freopen("in.txt", "r", stdin);
#define out_freopen freopen("out.txt", "w", stdout);

char s[105];

int main(){
    ll n;
    scanf(" %s",s);

    scanf("%lld",&n);

    ll len=strlen(s);
    ll cnt=0,tot=0;
    ll first=0,last=len-1;

    while(s[0]==s[first]&&first<len){
        first++;
        tot++;
    }

    while(s[0]==s[last]&&last>=0){
        last--;
        tot++;
    }

    for(ll i=0;i<len;){
        if(s[i]==s[i+1]){
            cnt++;
            i+=2;
        }
        else{
            i++;
        }
    }

    ll flag=0;

    set<char>st;

    for(ll i=0;i<len;i++){
        st.insert(s[i]);
    }

    if(len==1){
        printf("%lld\n",n/2);
    }
    else if(st.size()==1){
        printf("%lld\n",(len*n)/2);
    }
    else if(first%2==1&&(len-last+1)%2==1){
        printf("%lld\n",cnt*n+n-1);
    }
    else{
        printf("%lld\n",cnt*n);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  string output(10,' ');
  int point;
  cin >> s;
  point = 0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='B'){
      //output.at(point) = '';
      point = max(point-1,0);
    }else{output.at(point) = s.at(i);
          point++;
         }
  }
  cout << output.substr(0,point) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
  int a[26]={};
  char c;
  while((scanf("%c",&c))!=EOF){
    if('A'<=c && c<='Z')a[c-65]++;
    if('a'<=c && c<='z')a[c-97]++;
  }
  for(int i=0,c='a';i<26;i++,c++){
    printf("%c : %d\n",c,a[i]);
  }
  return 0;
}

Measured memory_bytes: 1136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));		
		List<String> list = new ArrayList<>();
		
		try {
			StringBuffer bf = new StringBuffer(br.readLine());
			int q = Integer.parseInt(br.readLine());
			for (int i = 0; i < q; i++) {
				String[] order = br.readLine().split("\\s");
				int a = Integer.parseInt(order[1]);
				int b = Integer.parseInt(order[2]) +1;
				if (order[0] != null) {
					switch (order[0]) {
					case "print" :
						list.add(bf.substring(a, b).toString());
						break;
					case "reverse" :
						bf.replace(a, b, (new StringBuffer(bf.substring(a, b)).reverse()).toString());
						break;
					case "replace" :
						bf.replace(a, b, order[3]);
						break;
					default :
						break;
					}
				}
			}
			for (int i = 0; i < list.size(); i++) {
				System.out.println(list.get(i));
			}
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}

}



Measured memory_bytes: 25488
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    int count[3] = {};
    for(int i = 0;i < n;i++)
    {
        int p;
        cin >> p;
        if(p <= a)
        {
            count[0]++;
        }
        else if(p > b)
        {
            count[1]++;
        }
        else
        {
            count[2]++;
        }
    }
    int ans = 100000;
    for(int i = 0;i < 3;i++)
    {
        ans = min(ans,count[i]);
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int ans =0;

    vector<int> A(N);

    vector<int> B(N-1);
    for (int i = 0; i < N-1; i++) {
        cin >> B.at(i);
    }

    A.at(0) = B.at(0);

    for(int i =0; i<N-2;i++){

        if(B.at(i) <= B.at(i+1)){
            A.at(i+1) = B.at(i);
        }else{
            A.at(i+1) = B.at(i+1);
        }
    }

    A.at(N-1) = B.at(N-2);

    for(int i=0;i<N;i++){
        ans += A.at(i);
    }
    cout << ans << endl;


}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001


int main() {
    int a, b;
    cin >> a >> b;
    int ans = a+b;

    if ( ans % 2 ==0 ) {
        cout << (a+b)/2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

}



Measured memory_bytes: 256
n = gets.to_i

nodes = []

n.times do
  id, k, *vs = gets.chomp.split.map(&:to_i)

  row = Array.new(n + 1, 0)

  nodes[id] = row

  vs.each do |v|
    row[v] = 1
  end
end

puts nodes[1..n].map {|row| row[1..n].join(' ') }.join("\n")

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  map<int, int> mp;
  mp[0]++;
  int res = 0;
  int cur = 0, b = 1;
  reverse(S.begin(), S.end());
  for (int i = 0; i < (int)S.size(); i++) {
    cur += b * (S[i] - '0');
    cur %= 2019;
    b *= 10;
    b %= 2019;
    res += mp[cur]++;
  }
  cout << res << '\n';
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

set<string> st;
string s;
int n;

void dfs(int i,string ns){
  if(i==n){
    st.insert(ns);
    return ;
  }
  int nc=s[i]-'a';
  bool used[30];
  memset(used,0,sizeof(used));
  rep(j,i){
    used[ns[j]-'a']=true;
  }
  if(s[i]!='z'&&!used[nc+1])dfs(i+1,ns+(char)(s[i]+1));
  if(s[i]=='a'||used[nc])dfs(i+1,ns+s[i]);
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>s;
    n=s.length();
    if(s=="#")break;
    st.clear();
    dfs(0,"");
    cout<<st.size()<<endl;
    int cnt=0;
    each(i,st){
      if(cnt<5||st.size()-cnt<=5)cout<<i<<endl;
      cnt++;
    }
  }
	return 0;
}

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

int main() {
  int N;
  vector<int> A;
  bool approved = true;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int buf;
    cin >> buf;
    A.push_back(buf);
  }

  for (int& num : A) {
    if (num % 2 == 0) { // if num is even
      if (num % 3 != 0 && num % 5 != 0) {
        approved = false;
        break;
      }
    }
  }

  if (approved == true) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
x = int(input())

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


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

int main() {
  int a, b, c, cnt = 0;
  cin >> a >> b >> c;
  if(a < b) {
    swap(a, b);
  } if(b < c) {
    swap(b, c);
  } if(a < b) {
    swap(a, b);
  }
  while(1) {
    if(a == b && b == c) {
      cout << cnt;
      return 0;
    } else {
      if(a-b == 1 && a-c == 1) {
        cout << cnt+1;
        return 0;
      }
      c += 2;
      cnt++;
        if(a < b) {
          swap(a, b);
        } if(b < c) {
          swap(b, c);
        } if(a < b) {
          swap(a, b);
        }
      if(a-b == 1 && a-c == 1) {
        cout << cnt+1;
        return 0;
      }
    }
  }
}

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


int main() {
	long long n;
	cin >> n;
	long long r = 0;
	long long t2 = n - 1;
	for(long long k = 2; k <=1000000; k++) {
		long long t = n;
		while(t % k == 0) t /= k;
		if (t % k == 1)  {
			r++;
		}
	}

	for(long long d = 1; d <= 1000000; d++) {
		if (t2 % d == 0) {
			long long k = t2 / d;
			if (k > 1000000) r++;
		}
	}
	if (n > 1000000) {
		r++;
	}
	cout << r << endl;


}


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

using namespace std;

using ll = long long;
#define long long long

double dp[301][301][301];

int main(void) {
    cout << setprecision(16) << fixed;

    ll n;
    cin >> n;
    for(ll k=0; k<=300; k++)
    for(ll j=0; j<=300; j++)
    for(ll i=0; i<=300; i++)
        if(i+j+k)
            dp[i][j][k] = 1.0*n/(i+j+k) * (1
            + (i>0 ? 1.0*  i/n * dp[i-1][j][k] : 0)
            + (j>0&&i<300 ? 1.0 * j/n * dp[i+1][j-1][k] : 0)
            + (k>0&&j<300 ? 1.0 * k/n * dp[i][j+1][k-1] : 0)
            );

    ll v[4] = {};
    while(n--) {
        ll x;
        cin >> x;
        v[x]++;
    }

    
    cout << dp[v[1]][v[2]][v[3]] << endl;
}


Measured memory_bytes: 213248
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int ans = 0, n = sc.nextInt();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    for (int k = 0; k < 10; k++) {
                        for (int l = 0; l < 10; l++) {
                            if (i + j + k + l == n) {
                                ans++;
                            }
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 26832
#include <iostream>
#include <math.h>

using namespace std;
bool checkSosuu(int);
int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)return 0;
    int cnt = 0;
   
    for(int i = n+1;i <= 2*n;i++){
      if(checkSosuu(i)){
	cnt++;
	//cout << i << endl;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
bool checkSosuu(int n){
  //  int k;
  
  if(n < 2){
    return true;
  }
  if(n == 2)return true;
  if(n%2 == 0)return false;
  for(int i = 3;i <= sqrt(n);i = i+2){
    if(n%i == 0){
      return false;
    }
  }
  return true;
}

Measured memory_bytes: 1160
import std.stdio;
import std.string;

enum conv = [
             'I':1,
             'V':5,
             'X':10,
             'L':50,
             'C':100,
             'D':500,
             'M':1000
             ];


void main()
{
    foreach (input; stdin.byLine()){
        int total = 0;
        if (input.length == 1)
            total = conv[input[0]];
        else {
            foreach (i; 1..input.length) {
                if (conv[input[i - 1]] < conv[input[i]]) {
                    total -= conv[input[i - 1]];
                } else {
                    total += conv[input[i - 1]];
                }
            }
            total += conv[input[$ - 1]];
        }
        total.writeln;
    }
}

Measured memory_bytes: 1236