akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	map<string, int> mp;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		mx = max(mx, ++mp[s]);
	}
	set<string> st;
	for (auto i : mp) 
		if (i.second == mx) 
			st.insert(i.first);
	for (auto i : st) cout << i << "\n";
}

Measured memory_bytes: 34560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int h,n,v,sum;
int main()
{
	scanf("%d%d",&h,&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&v);
		sum+=v;
	}
	puts(sum>=h?"Yes":"No");
	return 0;
} 

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

using namespace std;

template <class T> inline bool chmin(T &a, T b) { /* {{{ */
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }
  vector<vector<int>> colors(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> colors[i][j];
      colors[i][j]--;
    }
  }
  vector<vector<int>> costs(3, vector<int>(C));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int c = 0; c < C; c++) {
        costs[(i + j) % 3][c] += D[colors[i][j]][c];
      }
    }
  }
  int ans = 1e9 + 10;
  for (int c1 = 0; c1 < C; c1++) {
    for (int c2 = 0; c2 < C; c2++) {
      for (int c3 = 0; c3 < C; c3++) {
        if (c1 == c2 or c2 == c3 or c1 == c3) continue;
        chmin(ans, costs[0][c1] + costs[1][c2] + costs[2][c3]);
      }
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1280
using System;

namespace AtCoderPractice
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] line = Console.ReadLine().Split(' ');
            int a = int.Parse(line[0]);
            int b = int.Parse(line[1]);
            int c = int.Parse(line[2]);

            int result = c - (a - b);
            result = result < 0 ? 0 : result;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
h = list(map(int, input().split()))
dp = [float('inf')]*n
dp[0] = 0
for i in range(n):
    if i+1 < n:
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i+2 < n:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))
print(dp[n-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int A(int a){
	if(a<0) return -a;
	return a;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int arr[200000],N,K;
	int DP[200000];
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> arr[i];
	}
	DP[0] = 0;
	DP[1] = A(arr[1]-arr[0]);
	for(int i=2;i<N;i++){
		int m = -1;
		for(int j=1;j<=K;j++){
			if(i < j) break;
			if(m == -1) m = DP[i-j] + A(arr[i]-arr[i-j]);
			else m = min( m ,DP[i-j] + A(arr[i]-arr[i-j]) );
		}
		DP[i] = m;
	}
	cout << DP[N-1]<< endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define M 1000000007
#define N 100005
#define int long long
using namespace std;

int A[N], dp[N];
int n, t;

int bynary_search(int idx){

  int l=0, r=idx;

  while(l<r){
    
    int Mid=(l+r)/2;

    if(A[idx]-A[Mid]<=t) r=Mid;
    else l=Mid+1;
      
  }

  return l;
}

main(){


  
  cin>>n>>t;

  for(int i=0;i<n;i++) scanf("%d", &A[i]);

  sort(A, A+n);
  
  dp[0]=1;

  for(int i=1;i<n;i++){
    
    int r=bynary_search(i);
    
    dp[i]=(dp[i-1]+(dp[i-1]*(i-r))%M)%M;
  }
  
  cout<<dp[n-1]<<endl;  
  
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    ll ans = LONG_LONG_MIN;
    rep(lcnt, k + 1) {
        rep(rcnt, k - lcnt + 1) {
            ll l = 0, r = n - 1, sum = 0;
            priority_queue<ll, vector<ll>, greater<ll>> pq;
            rep(i, lcnt) {
                if (l > r) break;
                sum += v[l];
                pq.push(v[l]);
                l++;
            }
            rep(i, rcnt) {
                if (l >= r) break;
                sum += v[r];
                pq.push(v[r]);
                r--;
            }
            rep(i, k - lcnt - rcnt) {
                if (sz(pq) == 0) break;
                ll val = pq.top(); pq.pop();
                if (val > 0) break;
                sum -= val;
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin


d_in = lambda: int(stdin.readline())  # N = d_in()


def get_order(n, m):
    order = 0
    while n > 0:
        n = n // m
        order += 1
    return order


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    if n == 0:
        return []
    order = get_order(n, m)
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = float('inf')
    for i in range(n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)


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

int main() {
    int H, W;
    
    for (;;) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                cout << '#';                
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3088
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int a,b,c,x;
    cin >> a >> b >> c ;
    x = c - (a - b);
    if(x<0) x = 0;

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W;
int c[210][210], a[210][210];


signed main() {
    cin >> H >> W;
    rep(i,0,10) rep(j,0,10) cin >> c[i][j];
    rep(i,0,H) rep(j,0,W) cin >> a[i][j];

    rep(k,0,10) rep(i,0,10) rep(j,0,10) chmin(c[i][j], c[i][k] + c[k][j]);
    
    int ans = 0;
    rep(i,0,H) rep(j,0,W) {
        if(a[i][j] == -1) continue;
        int val = a[i][j];
        ans += c[val][1];
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> v;
    string t = "";
    int tmp = 1;
    s += '2';
    rep(i, n)
    {
        if (s[i] == s[i + 1])
            tmp++;
        else
        {
            v.push_back(tmp);
            tmp = 1;
            t += s[i];
        }
    }
    vector<int> sum(v.size() + 1);
    sum[0] = 0;
    rep(i, v.size()) sum[i + 1] = sum[i] + v[i];
    int ans = 0, l = 0, r = 0, cnt = 0;
    while (l < v.size())
    {
        if (r == v.size())
        {
            if (t[l] == '0')
                cnt--;
            l++;
        }
        else if (t[r] == '1')
            r++;
        else if (cnt < k)
        {
            r++;
            cnt++;
        }
        else
        {
            if (t[l] == '0')
                cnt--;
            l++;
        }
        ans = max(ans, sum[r] - sum[l]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2164
#include<stdio.h>
#include<stdlib.h>

#define N 1000000

void maxHeapify(int);

int x,A[N];

int main() {
  int i;
  scanf("%d",&x);

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

  for(i = x / 2; i >= 1; i--) {
    maxHeapify(i);
  }

  for(i = 1; i <= x; i++) {
    if(i == x) {
      printf(" %d\n",A[i]);
    }else{
      printf(" %d",A[i]);
    }
  }

  return 0;
}

void maxHeapify(int a) {
  int l,r,largest,temp;
  l = 2 * a;
  r = 2 * a + 1;

  if(l <= x && A[l] > A[a]) {
    largest = l;
  }else{ 
    largest = a;
  }
  if(r <= x && A[r] > A[largest]) {
    largest = r;
  }

  if(largest != a) {
    temp = A[a];
    A[a] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

  



Measured memory_bytes: 3660
import sys
p=['41412121','41212141','21414121','21214141','14141212','14121214','12141412','12121414']
g=lambda x:list(map(int,x))
for e in sys.stdin:
 d={}
 for f in p:d[sum(s-t for s,t in zip(g(e.split()),g(f))if s>t)]=f
 print(*list(d[min(d)]))


Measured memory_bytes: 5724
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

LL N;
void dfs(char* s,char max){
  if(strlen(s)==N)printf("%s\n",s);
  else{
    char c,str[100];
    FOR(c,'a',max+1){
      sprintf(str,"%s%c",s,c);
      dfs(str,(c==max)?max+1:max);
    }
  }
}

int main(){
  LL i,ans=0;
  scanf("%lld",&N);
  dfs("a",'b');

	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
    int n, m, x;
    int a;
    int cnt = 0;

    scanf("%d%d%d", &n, &m, &x);

    for (int i=0; m > i; i++) {
        scanf("%d", &a);
        if (a < x) {
            cnt++;
        }
    }
    if (cnt <= m/2 ) {
        printf("%d\n", cnt);
    }
    else {
        printf("%d\n", m-cnt);
    }
}

Measured memory_bytes: 128
#include<stdio.h>
#include<cmath>

int main(){
    int a,b,deg;
    scanf("%d %d %d",&a,&b,&deg);

    double PI = acos(-1);
    double rad = deg * PI / 180;

    double S = a * b * sin(rad) * 0.5;
    double c = sqrt(a*a + b*b - 2*a*b*cos(rad));
    double h = b *sin(rad);
    printf("%lf\n%lf\n%lf\n",S,a+b+c,h);
}


Measured memory_bytes: 2896
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N,M,ans;
  cin>>N>>M;
  if(M%2 == 0){
    long x,y;
    x = N/M;
    y = (N*2/M) - (N/M);
    ans = x*x*x + y*y*y;
  }
  else{
    long z;
    z = N/M;
    ans = z*z*z;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d,area1,area2;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   area1=a*b;
   area2=c*d;
   if(area1>=area2)
    printf("%d",area1);
    else
         printf("%d",area2);

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;

int main(){
    int S[100000],len=0,ans=0,prev=0,cur=1;
    char c;
    while(cin>>c){
        if(c=='0'){
            S[len]=0;
        }else{
            S[len]=1;
        }
        len++;
    }
    while(cur<len){
        if(S[prev]!=S[cur]){
            ans+=2;
            S[prev]=-1;
            S[cur]=-1;
            cur++;
            while(S[prev]==-1){
                prev--;
                if(prev<0){
                    prev=cur;
                    cur++;
                    break;
                }
            }

        }else{
            prev=cur;
            cur++;
        }
    }
    cout<<ans<<endl;
}


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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();

            var result = "Impossible";


            if (((n[0]+n[1]) % 3 == 0) || n[0] % 3 == 0 || n[1] % 3 == 0) {
                result = "Possible";
            }

            Console.WriteLine(result);
            ReadLine();
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    vector<ll> P(N);

    REP(i, N){
        cin >> P[i];
    }

    sort(P.begin(), P.end());

    ll ans = 0;

    REP(i, K){
        ans += P[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
int main(void){
    char order[3];
    int i;
    int x = 0;
    scanf(" %s", order);
    /*printf("%s\n", order);*/
    /*printf("%c\n", order[1]);*/
    for (i = 0; i < 3; i++) {
        /*printf("%c\n", order[i]);*/
        if (order[i] == 'o')
            x = (x + 1);
    }
    printf("%d\n", 700 + (100 * x));
    return 0;

}


Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int a=0, b=0, ab=0, o=0;

	char blood[4];
	while(scanf("%*d,%s", blood) != EOF){
		a += !strcmp(blood, "A");
		b += !strcmp(blood, "B");
		ab += !strcmp(blood, "AB");
		o += !strcmp(blood, "O");
	}
	printf("%d\n%d\n%d\n%d\n", a, b, ab, o);

	return 0;
}

Measured memory_bytes: 0
// C - Unification

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int r = 0;
	int b = 0;

	for (int i=0; i<S.size(); i++) {
		if (S[i] == '0') r++;
		else b++;
	}

	int ans = min(r, b) * 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int a,b;
  cin>>a>>b;
  if((a+b)%2==0)cout<<(a+b)/2<<endl;
  else cout<<(a+b)/2+1<<endl;
  return 0;
}




Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    static int[][] graph;
    static int[] color;
    static long wCnt = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        graph = buildGraph(sc, N, M);
        long ans = 0;
        color = new int[N];
        if (dfs(0, 0, 1)) {
            ans = wCnt * (N - wCnt) - M;
        } else{
           ans = ((long) N * (N - 1)) / 2 - M;
        }
        System.out.println(ans);
        sc.close();

    }

    private static boolean dfs(int pre, int cur, int c) {
        if(color[cur] != 0){
            return color[cur] == c;
        }
        color[cur] = c;
        if(c == 1) wCnt++;
        boolean ret = true;
        for(int i = 0; i < graph[cur].length; i++){
            int x = graph[cur][i];
            if(x == pre) continue;
            ret &= dfs(cur, x, -c);
        }

        return ret;
    }

    public static int[][] buildGraph(Scanner sc, int n, int m){
        int[][] graph = new int[n][];
        int[][] edges = new int[m][2];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() -1;
            int b = sc.nextInt() -1;
            edges[i][0] = a;
            edges[i][1] = b;
            deg[a]++;
            deg[b]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            graph[a][--deg[a]] = b;
            graph[b][--deg[b]] = a;
        }

        return graph;
    }

}


Measured memory_bytes: 96864
#B - Judge Status Summary
N = int(input())
s =list(input() for i in range(N))
DP = [0]*4
for j in range(N):
    if s[j] == "AC":
        DP[0] += 1
    elif s[j] == "WA":
        DP[1] += 1
    elif s[j] == "TLE":
        DP[2] += 1
    else:
        DP[3] += 1

print("AC x",DP[0])
print("WA x",DP[1])
print("TLE x",DP[2])
print("RE x",DP[3])

Measured memory_bytes: 16176
import sys
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
input()
for e in sys.stdin:
 e=e.split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
print('\n'.join(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"for i in map(str,sorted(map(int,t)))))


Measured memory_bytes: 65324
import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
S=list(itertools.permutations(range(1,N+1)))
for i in range(len(S)):
  if S[i]==P:
    break
for j in range(len(S)):
  if S[j]==Q:
    break
print(abs(i-j))

Measured memory_bytes: 8052
#include <iostream>

using namespace std;
int main()
{
    int n, a = 0, b = 0, c = 0, d = 0;
    cin >> n;
    while (n--)
    {
        string s;
        cin >> s;
        if (s[0] == 'A')
            a++;
        else if (s[0] == 'W')
            b++;
        else if (s[0] == 'T')
            c++;
        else
            d++;
    }
    printf("AC x %d\n", a);
    printf("WA x %d\n", b);
    printf("TLE x %d\n", c);
    printf("RE x %d\n", d);
}


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

using namespace std;

const int MaxN = 200005;
const long long Mod = 1000000007;

int n;
vector<int> Adj[MaxN];
long long gt[MaxN], f[MaxN], sz[MaxN];

long long Power(long long a, long long b)
{
    if (b == 0)
    {
        return 1;
    }
    long long t = Power(a, b / 2);
    t = (t * t) % Mod;
    if (b % 2 == 1)
    {
        t = (t * a) % Mod;
    }
    return t;
}

void DFS1(int u, int p)
{
    sz[u] = 1;
    for (auto v : Adj[u])
    {
        if (v != p)
        {
            DFS1(v, u);
            sz[u] += sz[v];
        }
    }
}
void DFS2(int u, int p)
{
    for (auto v : Adj[u])
    {
        if (v != p)
        {
            f[v] = (f[u] * sz[v]) % Mod;
            sz[u] = n - sz[v];
            sz[v] = n;
            f[v] = (f[v] * Power(sz[u], Mod - 2)) % Mod;
            DFS2(v, u);
            sz[v] = n - sz[u];
            sz[u] = n;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int u, v;
    for (int i = 1; i < n; i++)
    {
        cin >> u >> v;
        Adj[u].push_back(v);
        Adj[v].push_back(u);
    }
    gt[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        gt[i] = (gt[i - 1] * i) % Mod;
    }
    DFS1(1, -1);
    f[1] = gt[n];
    for (int i = 1; i <= n; i++)
    {
        f[1] = (f[1] * Power(sz[i], Mod - 2)) % Mod;
    }
    DFS2(1, -1);
    for (int i = 1; i <= n; i++)
    {
        cout << f[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 18676
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int r;
    cin >> r;

    cout << r * r << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
using P=pair<int,int>; //t,x
int main(){
    int W;
    cin>>W;
    vector<int> A(W);
    for(auto &a:A) cin>>a;
    vector<int> M(W);//避難できる上限
    for(int i=0;i<W;i++){
        if(A[i]==0){
            M[i]=1000000;
            for(int j=i+1;j<W;j++){
                if(A[j]<=0) break;
                else M[j]=1000000;
            }
            for(int j=i-1;j>=0;j--){
                if(A[j]<=0||M[j]==1000000) break;
                else M[j]=1000000; 
            }
        }
    }
    vector<P> Event;
    for(int i=0;i<W;i++){
        if(A[i]<0){
            Event.emplace_back(A[i],i);
        }
    }
    sort(Event.begin(), Event.end());
    for(auto e:Event){
        int t,x;
        tie(t,x)=e;
        if(0<=x-1) M[x]=max(M[x],min(-t,M[x-1]-1));
        if(x+1<W) M[x]=max(M[x],min(-t,M[x+1]-1));
        for(int i=x-1;i>=0;i--){
            if(A[i]<0&&A[i]>A[x]) break;            
            if(M[i]<M[i+1]-1){
                M[i]=M[i+1]-1;
            }else{
                break;
            }
        }
        for(int i=x+1;i<W;i++){
            if(A[i]<0&&A[i]>A[x]) break;
            if(M[i]<M[i-1]-1){
                M[i]=M[i-1]-1;
            }else{
                break;
            }
        }
    }
    /**
    for(int i=0;i<W;i++){
        cout<<M[i]<<' ';
    }cout<<endl;**/
    int64_t ans=0;
    for(int i=0;i<W;i++){
        if(A[i]>0) ans+=min(A[i],M[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4264
A,B=map(int,input().split())
import math

uA=A/0.08
tA=(A+1)/0.08
uB=B/0.1
tB=(B+1)/0.1

if uA>=tB or uB>=tA:
    print(-1)
else:
    print(math.ceil(max(uA,uB)))   

Measured memory_bytes: 3060
#include <iostream>
#include <map>

using namespace std;

map<long long, int> prime_factorize(long long n)
{
	map<long long, int> f;

	for (long long i = 2; i * i <= n; ++i) {
		for (; n % i == 0; n /= i) {
			++f[i];
		}
	}

	if (n != 1) {
		++f[n];
	}

	return f;
}


int main()
{
	long long N, P;
	cin >> N >> P;

	auto f = prime_factorize(P);

	long long ans = 1;

	for (const auto &e : f) {
		for (long long i = N; i <= e.second; i += N) {
			ans *= e.first;
		}
	}

	cout << ans << endl;
}


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

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

    long long cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] < B[i]) {
            cnt += (B[i] - A[i]) / 2;
        } else if (A[i] > B[i]) {
            cnt -= A[i] - B[i];
        }
    }

    if (cnt >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  string b;
  cin >> b;
  
  if(b.compare("A") == 0){ cout << "T"; }
  if(b.compare("T") == 0){ cout << "A"; }
  if(b.compare("C") == 0){ cout << "G"; }
  if(b.compare("G") == 0){ cout << "C"; }
  
  return 0;
}

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

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

int main() {

    string s; cin >> s;
    // 最初に1文字必ず消す必要がある
    string tmp = s.substr(0, s.size()-1);
    while(tmp.size() >= 2) {
        if(tmp.size() % 2 == 0) {
            string prev = tmp.substr(0, tmp.size()/2);
            string post = tmp.substr(tmp.size()/2, tmp.size()/2);
            if(prev == post) {
                // 長い順に見てるので、できた時点でそれが最長
                cout << tmp.size() << endl;
                return 0;
            }
        }
        tmp = tmp.substr(0, tmp.size()-1);
    }

    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
int main() {
	int squ[32768] = {};
	for (int i = 1; i < 200; i++) {
		if (i*i >= 32768)break;
		else squ[i*i] = 1;
	}
	int n;
	while (cin >> n, n) {
		int cnt = 0;
		for (int i = 0; i < 200; i++) {
			for (int j = i; j < 200; j++) {
				for (int k = j; k < 200; k++) {
					int sum = i * i + j * j + k * k;
					if (sum > n)break;
					int res = n - sum;
					if (res >= k * k&&squ[res])cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <cstdio>

int get() {
    int x = 0; char s = getchar();
    while (s < '0' || s > '9') s = getchar();
    while (s >= '0' && s <= '9') x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
    return x;
}

const int M = 1e5 + 5;
int n, m, h[M], ans;
bool vis[M];

int main() {
    n = get(), m = get();
    for (int i = 1; i <= n; ++i) h[i] = get();
    for (int a, b; m--;) {
        a = get(), b = get();
        if(h[a] > h[b]) vis[b] = 1;
        else if(h[a] < h[b]) vis[a] = 1;
        else vis[a] = vis[b] = 1;
    }
    for (int i = 1; i <= n; ++i) if(!vis[i]) ++ans;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 2056
n,m = map(int ,input().split())
a = set([int(input()) for _ in range(m)])

mod = 10**9+7
ans = [0]*(n+1)
ans [0] = 1
if 1 not in a: ans[1] = 1

for i in range(2,n+1):
  if i in a: continue
  ans[i] = ans[i-1] + ans[i-2]
print(ans[-1]%mod)

Measured memory_bytes: 465768
import math
from itertools import permutations
n = int(input())
total = 0
a = [list(map(int, input().split())) for _ in range(n)]

per = list(permutations([i for i in range(n)]))
for p in per:
    for i in range(1, n):
        p1, p2 = p[i], p[i-1]
        total += ((a[p1][0]-a[p2][0])**2 + (a[p1][1]-a[p2][1])**2)**0.5
print(total/math.factorial(n))

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;

  int aa,bb,cc;
  aa= A * 10 + B + C;
  bb= A + B * 10 + C;
  cc= A  + B + C * 10;

  cout << max({aa,bb,cc}) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String x = sc.next();
            if (x.equals("0")) {
                break;
            }
            int answer = 0;
            int len = x.length();
            String[] array = new String[len];
            for (int i = 0; i < len; i++) {
                array[i] = x.substring(i, i+1);
                answer += Integer.parseInt(array[i]);
            }
            System.out.println(answer);
        }
        sc.close();
    }
}


Measured memory_bytes: 26512
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  char S[10];
  int i;
  int a=0,b=0,c=0,d=0;
  for(i=0; i<n; ++i){
    scanf("%s",S);
    if(S[0]=='A')a++;
    if(S[0]=='W')b++;
    if(S[0]=='T')c++;
    if(S[0]=='R')d++;
  }
  
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
  return 0;
  
}


Measured memory_bytes: 1704
///
// File:  0001.cpp
// Author: ymiyamoto
//
// Created on Sat Nov  4 15:34:23 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  vector<uint32_t> heights(10);

  for (uint32_t i = 0; i < 10; i++) {
    cin >> heights[i];
  }

  sort(heights.begin(), heights.end());

  cout << heights[heights.size() - 1] << endl;
  cout << heights[heights.size() - 2] << endl;
  cout << heights[heights.size() - 3] << endl;

  return 0;
}

Measured memory_bytes: 3112
'use strict';(function(input){
  function count(pi,A,B){
    var C=A&B;
    var counter=pi;
    while(C>0){
      counter+=(C%2);
      C=(C>>1);
    }
    return ((counter%2)===0);
  }
  
  input=input.trim().split(/\n+/);
  input=input.map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0];
  const M=input[0][1];
  const p=input.pop();
  for(let i=1;i<=M;i++)
    input[i].shift();
  const arr=new Array(1<<N).fill('filler').map((x,i)=>i);
  const mask=[];
  for(let i=1;i<=M;i++)
    mask.push(input[i].reduce((acc,cur)=>acc+(1<<(cur-1)),0));
  mask.forEach(function(A,i){
    let j=0;
    while(j<arr.length){
      if(!count(p[i],A,arr[j])){
        arr.splice(j,1);
      }else{
        j++;
      }
    }
  });
  console.log(arr.length);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 7500
import java.util.*;
public class Main {
   static int check(char ob[][]) {
        int  m = ob.length;
        int n = ob[0].length;
        int arr[][]=new int [ob.length][ob[0].length];
        int count=1;
        for (int i =0;i<m;i++) {
            if(ob[i][0]=='#') {
                arr[i][0]=0;
                count=0;
            }
            else {
                arr[i][0]=count;
            }
            
        }
        count =1;
        for (int j =0;j<n;j++) {
            if(ob[0][j]=='#') {
                arr[0][j]=0;
                count=0;
            }
            else {
                arr[0][j]=count;
            }
            
        }
        for (int  i =1 ; i< m ; i++) {
            for (int  j =1 ; j<n ; j++) {
           
               
                    if(ob[i][j]=='#') {
                        arr[i][j]=0;
                    
                    }
                else {
                       arr[i][j]=(arr[i-1][j]%1000000007+arr[i][j-1]%1000000007)%1000000007;
                }
                      
                    
                   
                }
            }
return arr[m-1][n-1] ;   
    }
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int h = s.nextInt();
        int w = s.nextInt();
        char ob[][] = new char[h][w];
        for(int i =0; i<h ;i++) {
          
                ob[i] = s.next().toCharArray();
            
        }
        System.out.println(check(ob));
        
    }
}

Measured memory_bytes: 37468
#include<bits/stdc++.h>
#define int long long
#define scf(n) scanf("%lld",&n)
#define rep1(n) for(int i=1;i<=n;i++)
#define prf(n) printf("%lld",n)
#define sci(n) scanf("%lld",&n)
#define pri(n) printf("%lld",n)

#define nl printf("\n")
#define spc printf(" ")
#define file freopen("in.txt","rt",stdin)
#define pii pair<int,int>
#define piii pair<pii,int>
#define MOD 10000007
using namespace std;

/*bool sortBySec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/
void faster(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/******************************************/

/***********************************/
int n,mn;
int dp[100009];
int arr[100009];
int temp[100009];
int k;
int DP(int pos)
{
    if(pos>=n)
    {
        return 0;
    }
    if(dp[pos]!=-1)
        return dp[pos];
    int a=9999999999,mn = 9999999999;
    for(int i=1; i<=k; i++)
    {
        if(pos+i<=n)
            a = abs(arr[pos]-arr[pos+i]) + DP(pos+i);
        mn = min(mn,a);
        dp[pos] = mn;
    }
        return dp[pos];
}
int32_t main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    cin>>k;
    mn = 9999999999;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
    }
    cout<<DP(1)<<endl;

    return 0;
}


Measured memory_bytes: 6528
from sys import setrecursionlimit
setrecursionlimit(10**8)


def dfs(i, d):
    # print(i, d)
    for j, w in node_array[i]:
        if color_array[j] == -1:
            color_array[j] = (d + w) % 2
            dfs(j, d + w)


N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N

for _ in range(N - 1):
    i, j, w = map(int, input().split())
    node_array[i - 1].append((j - 1, w))
    node_array[j - 1].append((i - 1, w))

color_array[0] = 0
dfs(0, 0)

for i in range(N):
    print(color_array[i])


Measured memory_bytes: 81300
def main():
    def gcd(a,b):
        while b!=0:
            a, b = b, a%b
        return a

    def lcm(a,b):
        return a*b // gcd(a,b)

    N = int(input())
    T = [int(input()) for _ in range(N)]
    ans = 1
    for t in T:
        ans = lcm(ans, t)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
const int N=3e5+5;
const int P=1e9+7;
char s[N];
int n,Ans,f[N][3][3];
int Mod(int x){return x>=P?x-P:x;}
void Mod(int &x,int y){(x+=y)>=P?x-=P:0;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1);
	f[0][0][0]=1;
	for(int i=1,tp=0;i<=n;i++){
		for(int x=0;x<=2;x++)
		for(int y=0;y<=2;y++)
		if((tp=f[i-1][x][y])){
			if(s[i]!='0'){//1
				if(y==0)Mod(f[i][min(2,x+1)][0],tp);
				else Mod(f[i][x][y-1],tp);
			}
			if(s[i]!='1'){//0
				if(y==2)Mod(f[i][x][1],tp);
				else Mod(f[i][x][y+1],tp);
			}
		}
	}
	for(int x=0;x<=2;x++)
	for(int y=0;y<=2;y++)if(x>=y)Mod(Ans,f[n][x][y]);
	printf("%d",Ans);
	return 0;
}


Measured memory_bytes: 14664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if((i+1)%2!=0 && a[i]%2!=0){
            c++;
        }
    }
    cout<<c<<endl;






}



Measured memory_bytes: 3632
from sys import stdin, setrecursionlimit
from collections import defaultdict

setrecursionlimit(10 ** 9)


def input():
    return stdin.readline().strip()


X = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for i, a in enumerate(A, 1):
    d[i + a] += 1

ans = 0
for i, a in enumerate(A, 1):
    ans += d[i - a]

print(ans)


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

using namespace std;

int main(){
  int N;
  cin >> N;
  int d[N];
  
  for(int i=0;i<N;i++)
    cin >> d[i];
  
  sort(d, d + sizeof(d)/sizeof(d[0]));
  
  //for(int i=0;i<N;i++)
  //  cout << d[i] << " ";
  //cout <<endl;
  
  cout << d[N/2] - d[N/2-1] << endl;
  
  return 0;
}

Measured memory_bytes: 640
import sys
n = int(input())
a = list(map(int, input().split()))

max_edge_num = pow(2,n)

if a[0] > 0 and n>0:
    print(-1)
    sys.exit()
if a[0] == 1 and n==0:
    print(1)
    sys.exit()
elif a[0] > 1 and n == 0:
    print(-1)
    sys.exit()

total_lost = 0
remained_alls = [1]

for depth in range(1,n+1):
    total_lost *= 2
    full_nodes = pow(2,depth)
    remained_nodes = full_nodes - total_lost
    remained_alls.append(remained_nodes)
    if a[depth] > remained_nodes:
        print(-1)
        sys.exit()
    else:
        total_lost += a[depth]

max_nodes_all = [a[n]]

for depth in range(n-1,0,-1):
    possible = max_nodes_all[-1]
    now = min(possible+a[depth],remained_alls[depth])
    max_nodes_all.append(now)

max_nodes_all.append(1)

answer = 0
for nodes in max_nodes_all:
    answer+=nodes

print(answer)

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a + b, min(b + c, c + a)) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3584
#include<stdio.h>
#include <math.h>

int main(void)
{
  int N,K; scanf("%d %d",&N,&K);
  int i;
  double j;
  double kaku = 0;
  for(int i = 1; i < N+1; i++){
    int temp = i;
    int count = 0;
    while(temp < K){
		temp *= 2;
		count++;      	
    }
    double jo = pow(0.5,(double)count);
    double n = (double)N;
    kaku += 1/n * jo;
    
    
  }
  printf("%.20lf",kaku);
  return 0;
}

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

int64_t gcd(int64_t a, int64_t b) {
  if(a < b) return gcd(b, a);
  int64_t r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int64_t A, B; cin >> A >> B;
  int64_t k=gcd(A,B);
  if(k==1){
    cout << 1 << endl;
    return 0;
  }
  int ans=0;
  int i=1;
  if(k%2==0){
    ans++;
    while(k%2==0){
      k/=2;
    }
  }
  while(k!=1){
    i+=2;
    if(sqrt(k)<i){
      ans++;
      break;
    }
    if(k%i==0){
      ans++;
    }
    while(k%i==0){
      k/=i;
    }
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printA(arr) for(int i = 0; i < SZ(arr); i++){cout << arr[i];if (i==SZ(arr)-1){cout<<endl;}else{cout << " ";}}
typedef long long ll;

struct UnionFind {
  vector<int> data;
  void init(int n) { data.assign(n, -1); }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main()
{
  int N;
  int M;

  cin >> N >> M;
  vector<int> p;
  int invp[N];
  REP(i,N){
    int a;
    cin >> a;
    p.push_back(a-1);
    invp[a-1] = i;
  }


  vector<int> x;
  vector<int> y;
  REP(i,M){
    int a,b;
    cin >> a >> b;
    x.push_back(a-1);
    y.push_back(b-1);
  }
  UnionFind uf;
  uf.init(N);
  REP(i,M){
    uf.unionSet(x[i],y[i]);
  }

  int cnt=0;
  REP(i,N){
    if (uf.findSet(invp[i],i)){
      cnt ++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	string t;
	cin >> t;
	int n = t.size();
	// vvi dp(n, vi(2, -1));
	// for(int i = 0; i < n; i++){
	// 	if(i == 0){
	// 		if(s[i] == '?'){
	// 			dp[i][0] = 1;
	// 			dp[i][1] = 0;
	// 		}
	// 		else if(s[i] == 'P')
	// 			dp[i][1] = 0;
	// 		else dp[i][0] = 1;
	// 		continue;
	// 	}
	// 	if(s[i] == 'P'){
	// 		dp[i][1] = max(dp[i - 1][1], dp[i - 1][0]);
	// 		continue;
	// 	}
	// 	else if(s[i] == 'D'){
	// 		if(dp[i - 1][1] >= 0)
	// 			dp[i][0] = max(dp]i][0], 1 + dp[i - 1][1]);
	// 		if(dp[i - 1][0] >= 0)
	// 			dp[i][0] = max(dp[i][0], 1 + dp[i - 1][0]);
	// 		continue;
	// 	}
	// 	if(dp[i - 1][1] >= 0)
	// 		dp[i][0] = max(dp]i][0], 1 + dp[i - 1][1]);
	// 	if(dp[i - 1][0] >= 0)
	// 		dp[i][0] = max(dp[i][0], 1 + dp[i - 1][0]);
	// 	dp[i][1] = max(dp[i - 1][1], dp[i - 1][0]);
	// }
	// cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
	for(auto & i : t)
		if(i == '?')
			i = 'D';
	cout << t << endl;
}

Measured memory_bytes: 3772