akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

# sys.setrecursionlimit(10 ** 7)

N, MOD = map(int, input().split())


G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
G[0].append(1)
G[1].append(0)

DP1 = [0] * (N + 1)

parent = [-1] * (N + 1)
parent[1] = 0

order = []
order_append = order.append

stack = [1]
stack_pop = stack.pop
stack_append = stack.append

while stack:
    x = stack_pop()
    order_append(x)
    for next_ in G[x]:
        if next_ == parent[x]:
            continue
        parent[next_] = x
        stack_append(next_)

for v in order[::-1]:
    tmp = 1
    for next_ in G[v]:
        tmp *= DP1[next_] + 1
        tmp %= MOD
    DP1[v] = tmp
# print (DP1)

DP2 = [1] * (N + 1)

for x in order:
    # 累積積のパート
    #ここが同じ値を返すかチェックする
    n = len(G[x])
    p = parent[x]
    lst1 = [1] * (n + 1)
    lst2 = [1] * (n + 1)
    for i in range(n):
        #親のときだけは違うルールで対処
        if G[x][i] == p:
            lst1[i + 1] = lst1[i] * DP2[x] % MOD
        else:
            lst1[i + 1] = lst1[i] * (DP1[G[x][i]] + 1) % MOD

        if G[x][n - 1 - i] == p:
            lst2[n - i - 1] = lst2[n - i] * DP2[x] % MOD
        else:
            lst2[n - i - 1] = lst2[n - i] * (DP1[G[x][n - 1 - i]] + 1) % MOD
    
    for i in range(n):
        if G[x][i] == p:
            continue
        tmp = lst1[i] * lst2[i + 1] % MOD
        tmp += 1 #白色の分
        DP2[G[x][i]] = tmp
        # stack.append(G[x][i])

# print (DP2)

for i in range(1, N + 1):
    print ((DP1[i] * DP2[i]) % MOD)

# print (DP1)
# print (DP2)

Measured memory_bytes: 36116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define localin freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\inputf.in","r",stdin);
#define localout freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\outputf.in","w",stdout);
const int MAX=2e5+5;
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define tot(v) v.begin(),v.end()
#define rtcheck cout<<"saurabh\n";exit(0);
#define vcheck(x) cout<<#x<<" "<<x<<endl;                                                                                                                                       
#define pint pair<int,int>
#define forn for(int i=0;i<n;i++)
const int modu=1e9+7;
const int inf=1e17;

string solve(string s1 , string s2 , int n , int m)
{
	int dp[n+1][m+1];

	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
			}
			else if(s1[i-1] == s2[j-1])
			{
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else
			{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	int i = n;
	int j = m;
	string res = "";
	while(i>0 && j>0)
	{
		if(s1[i-1] == s2[j-1])
		{
			res+=s1[i-1];
			i--;
			j--;
			continue;
		}

		if(dp[i-1][j] > dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	reverse(res.begin(),res.end());
	return res;
}


int32_t main()
{
    fast;
    #ifndef ONLINE_JUDGE 
    localin;localout;
    #endif
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
    	string s1,s2;
    	cin >> s1 >> s2;
    	int n = s1.length();
    	int m = s2.length();
    	cout << solve(s1,s2,n,m) << endl;
    }

 }


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

using namespace std;

typedef long long ll;

ll get_num(ll p, ll idx)
{
    vector<int> v;
    while (p > 0) {
        v.push_back(p%10);
        p /= 10;
    }
    reverse(v.begin(), v.end());
    return v[idx];
}

ll get_digit(ll p)
{
    ll res = 0;
    while (p > 0) {
        p /= 10;
        res++;
    }
    return res;
}

int main()
{
    ll dig[11] = {0};
    for (int i = 1; i < 11; i++) {
        dig[i] = (ll)(i)*(9*pow(10, i-1));
        dig[i] += dig[i-1];
    }

    ll N, K;
    while (cin >> N >> K, N) {
        ll j = -1;
        for (int i = 0; i < 11; i++) {
            if (N <= dig[i]) {
                j = i;
                break;
            }
        }
        ll n = (N - (dig[j-1] + 1));
        ll p = pow(10, j-1) + n/j;        
        ll idx = n % j;        
        for (int i = 0; i < K; i++) {
            cout << get_num(p, idx);
            idx++;
            if (idx == get_digit(p)) {
                idx = 0;
                p++;   
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll A;
    int b, c, d;
    cin >> A;
    string X;
    cin >> X;
    b = X[0] - '0';
    c = X[2] - '0';
    d = X[3] - '0';


    ll x = b*100 + c*10 + d;
    ll prod = A * x;
    ll ans = prod / 100;

    //ll test = A*B;
    //cout << test << endl;

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


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<time.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF (1<<30)
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)

//組み合わせ
class Combination
{
	vector<ll> fact, finv;
public:
	Combination(int n) {
		vector<ll> inv(n + 1, 1);
		fact.resize(n + 1, 1);
		finv.resize(n + 1, 1);
		for (int i = 2; i <= n; ++i) {
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			fact[i] = fact[i - 1] * i % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}
	ll cmb(int n, int k) {
		return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
};

//素因数分解
map<int, int> factorize(ll M)
{
	map<int, int> primes;
	for (ll i = 2; i * i <= M; ++i) {
		while (M % i == 0) {
			++primes[i];
			M /= i;
		}
	}
	if (M != 1) {
		++primes[M];
	}
	return primes;
}

int main()
{
	int N, M; cin >> N >> M;
	auto ps = factorize(M);
	auto C = Combination(200000);
	ll ans = 1;
	for (auto p : ps) {
		ans = ans * C.cmb(N - 1 + p.second, p.second) % MOD;
	}
	cout << ans << endl;
	return 0;
}



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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

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

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int H,W;
    cin>>H>>W;
    VS a;
    rep(i,H){
        string v;
        cin>>v;
        a.PB(v);
    }
    int cnt=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a[i][j] == '#')
                cnt++;
        }
    }
    if(cnt == H+W-1)
        cout<<"Possible"<<endl;
    else
        cout<<"Impossible"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var hwm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hwm[0];
        var w = hwm[1];
        var m = hwm[2];
        int[] countY = new int[h + 1];
        int[] countX = new int[w + 1];
        HashSet<(int, int)> set = new HashSet<(int, int)>();
        for (int i = 0; i < m; i++)
        {
            var yx = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var y = yx[0];
            var x = yx[1];
            countY[y]++;
            countX[x]++;
            set.Add((y, x));
        }
        var top2Y = countY.Select((elem, ind) => (elem, ind)).GroupBy(x => x.elem, x => x.ind).OrderByDescending(x => x.Key).ToArray();
        var top2X = countX.Select((elem, ind) => (elem, ind)).GroupBy(x => x.elem, x => x.ind).OrderByDescending(x => x.Key).ToArray();
        var fY = (top2Y[0].Key, top2Y[0].ToArray());
        var fX = (top2X[0].Key, top2X[0].ToArray());
        if (m < fY.Item2.LongLength * fX.Item2.LongLength)
        {
            Console.WriteLine(fY.Key + fX.Key);
            return;
        }
        foreach (var y in fY.Item2)
        {
            foreach (var x in fX.Item2)
            {
                if (!set.Contains((y, x)))
                {
                    Console.WriteLine(fY.Key + fX.Key);
                    return;
                }
            }
        }
        Console.WriteLine(fY.Key + fX.Key - 1);
    }
}


Measured memory_bytes: 59640
while 1:
    H,W=map(int,input().split())
    #0 0 ga input saretara owari
    if H==0 and W==0:
        break
    #board no youso ha '#' to '.'
    board='#.'
    #'#' to '.' wo kougo ni shuturyoku suru koto wo kurikaesu
    for i in range(H):
        for j in range(W):
            print(board[(i+j)%2],end='')
        print()
    print()



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

using namespace std;

int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;  cin >> k;

    cout << a[k - 1] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0)
#define ull unsigned ll
#define uint unsigned
#define pai pair<int,int>
#define pal pair<ll,ll>
#define IT iterator
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);++i)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);--i)
#define endl '\n'
#define ll long long
int main()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3620
import Control.Monad (mapM_)

main = do
    [a, b, k] <- map read . words <$> getLine :: IO [Int]
    let l = if b - a + 1 > 2 * k
                then [a..a+k-1] ++ [b-k+1..b]
                else [a..b]
    mapM_ print l


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;


int main() {
    int n;  cin >> n;
    vector<ll> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
        q[i]--;
    }
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
        v[i] = i;
    
    int a, b, cnt = 1;;
    do {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if (p[i] != v[i])
                flag = false;
        }
        if (flag)
                a = cnt;

        flag = true;
        for (int i = 0; i < n; i++) {
            if (q[i] != v[i])
                flag = false;
        }
        if (flag)
            b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!
void solve(){
    int n,l;
    cin>>n>>l;
    
    vector<string> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    
    sort(all(arr),[&](const string &a,const string &b){
        return a+b<b+a;
    });
    
    string ans="";
    for(int i=0;i<n;i++){
        ans+=arr[i];
    }
    cout<<ans<<endl;
}
 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

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

#define ll long long

using namespace std;

ll f(int A[11], int index, int n, int last, int m, int q, int a[50], int b[50], int c[50], int d[50]) {
    if (index > n) { return 0; }
    if (index == n) {
        ll ans = 0;
        for (int i = 0; i < q; i++) {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
                ans += d[i];
            }
        }
        return ans;
    }
    ll ans = 0;
    for (int i = last; i <= m; i++) {
        A[index] = i;
        ans = max(ans, f(A, index + 1, n, i, m, q, a, b, c, d));
    }
    return ans;
}

int main() {
    int A[11], n, q, m, a[50], b[50], c[50], d[50];
    for (int i = 0; i < 11; i++) A[i] = 0;
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ll ans = f(A, 0, n, 1, m, q, a, b, c, d);
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  int vec[n+2];
  vec[0]=0,vec[n+1]=0;
  for(int i=1;i<=n;i++){
    cin>>vec[i];
  }
  int ans=0;
  for(int t=0;t<5000;t++){
    for(int i=0;i<n+2;i++){
      if(vec[i]!=0){
        while(vec[i]!=0){
          vec[i]--;
          i++;
        }
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b=0;
  for(int n=0;n<10;n++){
    cin >>a;
    b+=a;
  }
  cout <<b<<'\n';
  return(0);
}



Measured memory_bytes: 3180
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# １行の入力データを分割
def f(data):
    for i in range(3):
        if 0 > int(data[i]) or int(data[i]) > 10:
            print("NO")
            return 0

    if int(data[0]) == 5:
        if int(data[1]) == 5:
            if int(data[2]) == 7: #[5, 5, 7]
                print("YES")
            else:
                print("NO")
        elif int(data[1]) == 7:
            if int(data[2]) == 5: #[5, 7, 5]
                print("YES")
            else:
                print("NO")
    elif int(data[0]) == 7:
        if int(data[1]) == 5:
            if int(data[2]) == 5: #[7, 5, 5]
                print("YES")
            else:
                print("NO")
        else:
            print("NO")
    else:
        print("NO")

    return 0

data = input().split()
if len(data) == 3:
    f(data)
else:
    print("NO")

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e5; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,p,q,ans=0;
	cin>>n;
	string pq[2];
	forn(i,n){
		cin>>p;
		pq[0]+='0'+p;
	}
	forn(i,n){
		cin>>q;
		pq[1]+='0'+q;
	}
	sort(pq, pq+2);
	while(pq[0]!=pq[1]){
		next_permutation(pq[0].begin(),pq[0].end());
		ans++;
	}
	cout<<ans<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m;
string s;

int main() {
    cin >> s;

    string res = "";
    FOR(i, s) {
        switch (*i) {
            case '0':
                res += "0";
                break;
            case '1':
                res += "1";
                break;
            case 'B':
                if (!res.empty()) res.erase(res.end()-1);
                break;
        }
    }

    std::cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ppi pair< pair<int,int>,int >
#define bs binary_search
#define gcd _gcd
#define fs first
#define sc second
#define MOD 1000000007
int ABS(int a){return max(a,-a);}
ll ABS(ll a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int gif(int x,int a){return (x%a==0)?(x/a):((x/a)+1);}
ll gif(ll x,ll a){return (x%a==0LL)?(x/a):((x/a)+1LL);}
int lif(int x,int a){return (x/a);}
ll lif(ll x,ll a){return (x/a);}

const int N = 100005;
const int  inf = 1e9 +5;
int a[N];

void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> dp(n,inf);
    for(int i=0;i<n;i++)
        cin>>a[i];

    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
                dp[j] = min(dp[j], dp[i]+ABS(a[i]-a[j]));
            }
        }
    }

    cout<<dp[n-1]<<"\n";
}

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

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

    solve();

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
// unbounded knapsack..
using namespace std;
using ll=long long ;
int  main(){
        long long int  n;
        cin>>n;
        vector<long long int >p(n,0);
        for(long long int  i=0;i<n;i++){
            cin>>p[i];
        }
        vector<vector<pair<ll,ll>>>dp(n,vector<pair<ll,ll> >(n,{0,0}));
        for(long long int  l=0;l<=n-1;l++){
            for(long long int  i=0;i<n-l;i++){
                long long int  j=i+l;
                if(i==j) dp[i][j]={p[i],p[i]};
                else {
                    dp[i][j].first=max(p[i]+dp[i+1][j].second-dp[i+1][j].first, p[j]+dp[i][j-1].second-dp[i][j-1].first);
                    dp[i][j].second=dp[i+1][j].second+p[i];
                }
            }
        }
    cout<<2*dp[0][n-1].first-dp[0][n-1].second;
    return 0;
}
// x-y    y=sum-x  x-sum+x 2x-sum

Measured memory_bytes: 143104
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;

  int q;
  cin>>q;
  while(q--){
    int b, e;
    cin>>b>>e;
    reverse(A.begin()+b, A.begin() + e);
  }

  cout<<A<<endl;
  return 0;
}



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

int main() {
	string S;
	cin >> S;
	string ymd;
	for (char X : S) {
		if (X != '/') {
			ymd += X;
		}
	}
	if (stoi(ymd) <= 20190430) {
		cout << "Heisei" << endl;
	} else {
		cout << "TBD" << endl;
	}
}


Measured memory_bytes: 256
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let S = cin.getStr();
    let N = S.length;
    const ABC = "ABC";
    const MOD = 1000000007;
    let dp = new Array(N + 1).fill(0).map(() => new Array(3 + 1).fill(0));
    for (let i = N; i >= 0; --i) {
        for (let j = 3; j >= 0; --j) {
            if (i == N) {
                dp[i][j] = (j == 3 ? 1 : 0);
            } else {
                dp[i][j] = dp[i + 1][j] * (S[i] == '?' ? 3 : 1);
                if (j < 3 && (S[i] == '?' || S[i] == ABC[j])) {
                    dp[i][j] += dp[i + 1][j + 1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    console.log(dp[0][0]);
}
class Inputer{constructor(t){this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29776
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N, x = MI()
    if x in [1, 2 * N - 1]:
        print("No")
        return
    print("Yes")
    if N == 2:
        print("1\n2\n3")
        return
    s = set([i for i in range(1, 2 * N)])
    a = [None] * (2 * N - 1)
    MED = N - 1
    if x == 2 * N - 2:
        l = (x - 1, x, x + 1, x - 2)
        a[MED - 1:MED + 3] = l
        for i in l:
            s.remove(i)
    else:
        l = x + 1, x, x - 1, x + 2
        a[MED - 1:MED + 3] = l
        for i in l:
            s.remove(i)
    for i in range(2 * N - 1):
        if a[i] is None:
            a[i] = s.pop()
    for i in range(2 * N - 1):
        print(a[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 25456
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n+1);
  vll B(n);
  FOR(i,0,n+1){
    ci(A[i])
      //co(A[i])
  }
  FOR(i,0,n){
    ci(B[i])
      //co(B[i])
  }
  
  ll ans=0;
  ll z=0;
  FOR(i,0,n){
    if(A[i]+A[i+1]>=B[i]){
      ans+=B[i];
      if(A[i]>B[i]){
        A[i]-=B[i];
        B[i]=0;
      }
      else{
        B[i]-=A[i];
        A[i]=0;
        A[i+1]-=B[i];
      }
    }
    else{
      ans+=A[i]+A[i+1];
      A[i]=0;
      A[i+1]=0;
    }
    //co(A[i]<<" "<<A[i+1])
  }
  co(ans)
}

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


int main(){
  int n;
  int x,y, dx,dy, d ;
  int xm,ym, max;

  cin >> n;
  for( int loop=0;loop<n;loop++ ){

    max=-1; x=0; y=0;
    while( cin>>dx>>dy && (dx || dy) ){

      x+=dx; y+=dy;
      d = x*x + y*y;
      if( d>max || ( d==max && x>xm  )  ){
	max = d; xm=x; ym=y;
      }
    }
    cout << xm <<" "<< ym << endl;

  }

  return 0;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        s: chars,
    }

    let mut ans = vec![0_usize; s.len() + 1];

    for i in 0..s.len() + 1 {
        if i == 0 && s[i] == '<'
            || i > 0 && i < s.len() && s[i - 1] == '>' && s[i] == '<'
            || i == s.len() && s[i - 1] == '>'
        {
            ans[i] = 0;

            let mut l = i;
            while l >= 1 && s[l - 1] == '>' {
                ans[l - 1] = max(ans[l - 1], i - l + 1);
                l -= 1;
            }

            let mut r = i;
            while r < s.len() && s[r] == '<' {
                ans[r + 1] = max(ans[r + 1], r - i + 1);
                r += 1;
            }
        }
    }

    // dbg!(&ans);

    println!("{}", ans.into_iter().sum::<usize>());
}


Measured memory_bytes: 11512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int[] cnt = new int[100002];

            for (int i = 0; i < N; i++) {
                int a = sc.nextInt();
                cnt[a]++;
                cnt[a + 1]++;
                if ( a - 1 >= 0 ) {
                    cnt[a - 1]++;
                }
            }

            int maxCnt = -1;

            for (int i = 0; i <= 100000; i++) {
                maxCnt = Math.max(maxCnt, cnt[i]);
            }
            System.out.println(maxCnt);
        }
    }
}


Measured memory_bytes: 49152
from collections import deque
class Dinic:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
    
    def add_edge(self,v,w,cap):
        edge = [w,cap,None]
        edge[2] = rev_edge = [v,0,edge]
        self.graph[v].append(edge)
        self.graph[w].append(rev_edge)
    
    def bfs(self,s,t):
        self.level = [None]*self.N
        d = deque([s])
        self.level[s] = 0
        while d:
            v = d.popleft()
            nlevel = self.level[v]+1
            for w,cap,_ in self.graph[v]:
                if cap and self.level[w] is None:
                    self.level[w] = nlevel
                    d.append(w)
        return self.level[t] is not None
    
    def dfs(self,s,v,f):
        if v == s:
            return f
        for rev in self.it[v]:
            w,_,e = rev
            cap = e[1]
            if cap and self.level[w] is not None:
                if self.level[v] > self.level[w]:
                    d = self.dfs(s,w,min(f,cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
        return 0
    
    def max_flow(self,s,t):
        flow = 0
        INF = 10**9
        while self.bfs(s,t):
            *self.it, = map(iter,self.graph)
            f = INF
            while f:
                f = self.dfs(s,t,INF)
                flow += f
        return flow


N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = Dinic(N*M+2)

s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i + j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)

for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u, v, 1)
        if i+1 < N and S[i][j] == "." and S[i + 1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u, v, 1)

print(dc.max_flow(s, t))
for u in range(N*M+2):
    for v, cap, _ in dc.graph[u]:
        ui, uj = divmod(u, M)
        vi, vj = divmod(v, M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"

for res in S:
    print("".join(res))

Measured memory_bytes: 86228
#include <stdio.h>

int main() {
	int n = 0;
	scanf("%d", &n);

	int data[100];
	for (int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}

	for (int i = n - 1; -1 < i; i--) {
		printf("%d", data[i]);
		if (i == 0) {
			printf("\n");
		}else{
			printf(" ");
		}
	}

	return 0;
}

Measured memory_bytes: 1744
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    que = queue.PriorityQueue()
    for a in A:
        que.put(-a)

    while M > 0:
        M -= 1
        a = que.get()
        que.put(-(-a // 2))

    ans = 0
    while not que.empty():
        ans += -que.get()

    print(ans)


Measured memory_bytes: 77032
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int n,l;cin>>n>>l;
  vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];

  int buf=(1<<30);
  for(int i=0;i<n-1;i++)if(a[i]+a[i+1]>=l)buf=i+1;
  if(buf==(1<<30)){cout<<"Impossible"<<endl;return 0;}
  vector<int> order;
  for(int i=1;i<buf;i++)order.push_back(i);
  for(int i=n-1;i>buf;i--)order.push_back(i);
  order.push_back(buf);
  cout<<"Possible"<<endl;
  for(int i=0;i<n-1;i++)cout<<order[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 1784
#include <algorithm>
#include <iostream>
#include <vector>

struct Student
{
    int number = 0;
    int order = 0;    
};

int main()
{
    int n = 0;
    std::cin >> n;
    std::vector<Student> student_v {static_cast<std::size_t>(n)};
    
    int classnum = 0;
    for(int index = 0; index < n; ++index)
    {
        std::cin >> classnum;
        student_v.at(index).number = index + 1;
        student_v.at(index).order = classnum;
    }
    
    std::sort(student_v.begin(), student_v.end(),
              [](const Student& s1, const Student& s2)
              { return s1.order < s2.order;
              });
    
    for(const Student& s : student_v)
    {
        std::cout << s.number << std::endl;
    }
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;
int ans = 0;
int n, k, s;

void DFS(int num, int use, int sum)
{
	if (use > k || num > n + 1)
	{
		return;
	}
	if (use == k)
	{
		if (sum == s)
		{
			++ans;
		}
		return;
	}
	DFS(num + 1, use + 1, sum + num);
	DFS(num + 1, use, sum);
}

void solve()
{
	while (cin >> n >> k >> s, n || k || s)
	{
		ans = 0;
		DFS(1, 0, 0);
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1164
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;

int main(){
  int i;
  string s,t;
  cin >> s;

  cout << s[0];
  for( i=1; i < s.length()-1; i++)
    t += s[i];

  cout << t.length();
  cout << s[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  a, b, c, d; 
  string ans = "Yes";
  cin >> a >> b >> c >> d;  
  while(a > 0 && c > 0){
    c = c - b;
    a = a - d;
  }
  
  if(a <= 0){
    if(c > 0){
      ans = "No";
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	int n,m,i,j,ans;
	cin>>n>>m;
	int a[n],b[m],f[n]={0};
	for(i=0;i<n;i++)cin>>a[i];
	for(i=0;i<m;i++)cin>>b[i];
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(b[i]>=a[j]){
				f[j]++;
				break;
			}
		}
	}
	ans=0;
	for(i=1;i<n;i++){
		if(f[ans]<f[i])ans=i;
	}
	//for(i=0;i<n;i++)cout<<f[i]<<endl;
	cout<<ans+1<<endl;
}
/*
4 7 5
.#.....
.....##
.......
#......
  */


Measured memory_bytes: 3084
#include<stdio.h>
#include<iostream> 
#include<utility>
#include<map> 
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
 int N; cin >> N;
 long int sum = 0;
 map<int,int> d;
 for(int i=0;i<N;i++){
     int a_i; cin >> a_i;
     sum += a_i;
     decltype(d)::iterator iter = d.find(a_i);
     if(iter != d.end()){
         int tmp = d.at(a_i);
         d.erase(a_i);
         d.insert(make_pair(a_i,tmp+1));
     }
     else{
         d.insert(make_pair(a_i,1));
     }
 }
 int Q; cin >> Q;
 for(int i=0;i<Q;i++){
     int B_i,C_i; cin >> B_i >> C_i;
     decltype(d)::iterator iter = d.find(B_i);
     if(iter == d.end()){
         cout << sum << endl;
     }
     else{
         sum+=((C_i-B_i)*d.at(B_i));
         int tmp = d.at(B_i);
         d.erase(B_i);
         decltype(d)::iterator iter2 = d.find(C_i);
         if(iter2 == d.end()){
             d.insert(make_pair(C_i,tmp));
         }
         else{
             int tmp2 = d.at(C_i);
             d.erase(C_i);
             d.insert(make_pair(C_i,tmp+tmp2));
         }
         cout << sum << endl;
     }
 }
 return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,total,a[51];
bool pd(const int &a,const int &b)
{
	return a>b;
}
int main()
{
	cin>>n>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	sort(a+1,a+n+1,pd);
	for(int i=1; i<=k; i++) total+=a[i];
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
import Text.Printf

main = interact $ show' . solve . read'
  where
    show' = unlines . map (printf "%.9f")
    solve [] = []
    solve (x:y:xs) = (solveRow (x ++ y)):(solve xs)
    solveRow (n:xs) = sqrt $ sigma / n
      where
        sigma = sum [(x - avg)**2 | x <- xs]
        avg = (sum xs) / n
    read' = map (map read . words) . init . lines :: String -> [[Double]]



Measured memory_bytes: 5228
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e

n = int(input())
A = list(map(int, input().split()))
MOD = 1000000007

counts = [0, 0, 0]
result = 1
for i in range(n):
    a = A[i]
    # print(a, counts, result)
    cnt = counts.count(a)
    result *= cnt
    result %= MOD
    for j in range(len(counts)):
        if counts[j] == a:
            counts[j] += 1
            break

print(result)


Measured memory_bytes: 84176
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>b)cout<<a-1<<endl;
  else cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
c = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        p = [l[j:j+m] for l in a[i:i+m]]
        if b == p and c==0:
            print('Yes')
            c=1
            break
if c==0:
    print('No')

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

int N;
int par[100010];
vector<int> G[100010];

int DFS(int v)
{
    if(G[v].size() == 0)return 1;
    vector<int> D;
    for(int i = 0; i < G[v].size(); i++)D.push_back(DFS(G[v][i]));
    sort(D.begin(),D.end());
    reverse(D.begin(),D.end());
    int res = 0;
    for(int i = 0; i < D.size(); i++)res = max(res,D[i] + i + 1);
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 2; i <= N; i++)
    {
        int a;
        scanf("%d",&a);
        par[i] = a;
        G[a].push_back(i);
    }

    printf("%d\n",DFS(1) - 1);
    return 0;
}


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

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

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int t[110]={0};
	for(int i=0;i<n;i++) cin>>t[i];
	int m; cin>>m;
	int p[110]={0}, x[110]={0};
	for(int i=0;i<m;i++) cin>>p[i]>>x[i];

	for(int i=0;i<m;i++){
		ll sum = 0;
		for(int j=0;j<n;j++){
			sum += t[j];
		}
		sum = sum - t[p[i]-1];
		sum += x[i];

		printf("%lld\n", sum);
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
//qsort�֐��Ɏg��compare�֐�,(long long int, int, double�^)
int compare_lli(const void *a, const void *b)
{
    return *(lli*)a - *(lli*)b;
}
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int compare_double(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}
/*qsort(data, 10, sizeof(int_lli_double), compare_int);*/
/*qsort(�z��, �v�f��, sizeof(�z��̌^), compare_�z��̌^);*/
int main(void)
{
	lli n, i, k, sum1=0, sum2=0, ans;
	scanf("%lld", &n);
	lli a[n+1], b[n];
	rep(i,n+1){
		scanf("%lld", &a[i]);
		sum1+=a[i];
	}
	rep(i,n) scanf("%lld", &b[i]);
	rep(i,n){
		k = b[i]-a[i];
		a[i] -= b[i];
		if(a[i]<0){
			a[i]=0;
			a[i+1] -= k;
			if(a[i+1]<0) a[i+1]=0;
		}
	}
	rep(i,n+1){
		sum2 += a[i];
	}
	ans = sum1 - sum2;
	printf("%lld", ans);
	return 0;
}

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

public class Main {
 

 public static void main(String[] args) throws NumberFormatException, IOException {
  // TODO 自動生成されたメソッド・スタブ
   InputStreamReader is = new InputStreamReader(System.in);
   BufferedReader br = new BufferedReader(is);
   int count = 1;
   int input = Integer.parseInt(br.readLine());
   while (input != 0) {
    System.out.println("Case"+" "+count+": "+input);
    input = Integer.parseInt(br.readLine());
    count++;
   }
  
 
 }
}


Measured memory_bytes: 31888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    if (K <= A) ans = K;
    else if (K > A) {
        ans = A;
        if (K > B) {
            ans -= (K-A-B);
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3656
import itertools

n,m = map(int, input().split())
AB = []
ans = 0
for n in range(n):
    a,b = map(int,input().split())
    AB.append([a,b])
AB.sort()
A,B = zip(*AB)
A,B = list(A), list(B)

i = list(_ for _ in itertools.accumulate(B) if _ <= m)
if i == []:
    ans = A[0]*m
else:
    B = B[:len(i)] + [m-i[-1]]
    A = A[:len(B)]

    ans = sum([a*b for a,b in zip(A,B)])
print(ans)

Measured memory_bytes: 28348
#include<iostream>
    #include<vector>
    #include<string>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<queue>
    #include<list>
    #include<stack>
    #include<cstdio>
    #include<fstream>
    #include<numeric>
    #include<functional>
    #include<utility>
    #include<memory>
    #include<cstring>
    #include<bits/stdc++.h>
    using namespace std; 
      
    #define CLEAN(a,b) memset(a,b,sizeof(a))
    #define mp make_pair
    #define pb push_back
    typedef long long ll;
    typedef pair<int, int> pii;
     
    ll a[105];
    int n;
     
    int main()
    {
    	cin>>n;
    	for (int i=0;i<n;i++)
    	{
    		cin>>a[i];
    	}
    	sort(a,a+n);
    	cout<<a[n-1]-a[0]<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=(int)1e9+7;
void factorize(int x);
int freq[1005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=2;i<=n;i++)
        factorize(i);
    long long ans=1;
    for(int i=2;i<=n;i++)
        ans*=freq[i]+1,
        ans%=MOD;
    cout<<ans;
    return 0;
}

void factorize(int x)
{
    int ret=0,cpyX=x;
    for(int i=2;i<=sqrt(x);i++)
        while(cpyX%i==0)
            cpyX/=i,
            freq[i]++;
    if(cpyX!=1)
        freq[cpyX]++;
}


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

typedef long long int int64;

const int mod=1000000007;
int *fact=NULL;
int *invFact=NULL;
void init(int n){
  fact=(int *)malloc(sizeof(int)*(n+1));
  invFact=(int *)malloc(sizeof(int)*(n+1));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)fact[i-1]*i%mod;
  int t=1;
  int s=fact[n];
  int m=mod-2;
  while(m>0){
    if(m&0x01) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    m>>=1;
  }
  invFact[n]=t;
  for(i=n-1;i>=0;i--) invFact[i]=(int64)(i+1)*invFact[i+1]%mod;
  return;
}

int comb(int n,int k){
  if(!(0<=n && 0<=k && k<=n)) return 0;
  return (int64)fact[n]*invFact[n-k]%mod*invFact[k]%mod;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *index=(int *)calloc(n+1,sizeof(int));
  int l,r;
  int i;
  for(i=1;i<=n+1;i++){
    int a;
    scanf("%d",&a);
    if(index[a]>0){
      l=index[a];
      r=i;
    } else {
      index[a]=i;
    }
  }
  init(n+1);
  for(i=1;i<=n+1;i++){
    int ans=(comb(n+1,i)-comb(l-1+(n+1-r),i-1)+mod)%mod;
    printf("%d\n",ans);
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2304