akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long a[200010], sum[200010];
long long t[10];

long long getsum(int i, int j){
	return sum[j] - sum[i - 1];
}

long long getabs(int x, int y, int z){
	return abs(getsum(x, y) - getsum(y + 1, z));
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	int p1 = 1, p2 = 3;
	long long ans = 1ll * 0x3f3f3f3f * 0x3f3f3f3f;
	for (int i = 2; i <= n - 2; i++){
		while (p1 < i && getabs(1, p1, i) > getabs(1, p1 + 1, i)) p1++;
		while (p2 < n && getabs(i + 1, p2, n) > getabs(i + 1, p2 + 1, n)) p2++;
		t[0] = getsum(1,p1),t[1] = getsum(p1+1,i),t[2] = getsum(i+1,p2),t[3] = getsum(p2+1,n);
		long long maxj = max(max(max(t[0], t[1]), t[2]), t[3]);
		long long minj = min(min(min(t[0], t[1]), t[2]), t[3]);
		ans = min(ans, maxj - minj);
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll mod = 1000000007;
const ll INF = 1ll << 50;


ll n,t;
ll a[3001];
ll b[3001];
ll a_[3001];
ll b_[3001];
ll args[3001];
ll dp[3001][6001];
ll ans;

void chmax_update(ll &a,ll &b,ll v,ll q){
  if(a <= v){
    if(a == v){
      a = v;
      b = max(b,q);
    }else{
      a = v;
      b = q;
    }
  }
}

void update(ll i,ll j){
  if(i-1 >= 0){
    dp[i][j] = max(dp[i][j],dp[i-1][j]);
    if(j-a[i-1] >= 0 && j-a[i-1] < t){
      dp[i][j] = max(dp[i][j],dp[i-1][j-a[i-1]]+b[i-1]);
    }
  }
}

int main(){
  cin >> n >> t;
  for(ll i = 0;i < n;i++){
    cin >> a[i] >> b[i];
  }
  iota(args,args+n,0ll);
  sort(args,args+n,[](ll x,ll y){
    return a[x] < a[y];
  });
  for(ll i = 0;i < n;i++){
    a_[i] = a[args[i]];
    b_[i] = b[args[i]];
  }
  for(ll i = 0;i < n;i++){
    a[i] = a_[i];
    b[i] = b_[i];
  }
  ll max_a = *max_element(a,a+n);

  for(ll i = 0;i <= n;i++){
    for(ll j = 0;j <= t+max_a+1;j++){
      update(i,j);
    }
  }
  for(ll i = 0;i <= n;i++){
    for(ll j = 0;j <= t+max_a+1;j++){
      ans = max(dp[i][j],ans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 141056
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            double u = 0;//under
            for(int i =0; i < n; i++)
            {
                u+=(double)1/int.Parse(In[i]);
            }
            Console.WriteLine(1 / u);           
        }
    }
}


Measured memory_bytes: 27568
#include <iostream>

using namespace std;

int main()
{
  int n, h, w;
  cin >> n >> h >> w;
  if (n < w || n < h)
  {
    cout << 0 << endl;
  }
  else
  {
    int nh = n - h + 1;
    int hw = n - w + 1;
    cout << hw * nh << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define F first
#define S second
#define pb push_back
#define M 1000000007
#define inf 1e18
#define endl "\n"
#define jam(x) cout<<"Case #"<<x<<": "

void display2D( vector<vector<int> > &v ) {
	int n = v.size();
	int m = v[0].size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}
int32_t main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, cap;
	cin >> n >> cap;
	std::vector<int> wei(n);
	std::vector<int> val(n);
	int sm_val = 0;
	for (int i = 0; i < n; i++) {
		cin >> wei[i];
		cin >> val[i];
		sm_val += val[i];
	}
	std::vector<vector<int> > dp(sm_val + 1, vector<int>(n, 0) );
	for (int i = 0; i < n; ++i) {
		dp[0][i] = 0;
	}

	for (int j = 0; j < n; j++) {
		for (int i = 1; i <= sm_val; i++) {
			dp[i][j] = INT_MAX;
		}
	}

	dp[ val[0] ][ 0 ] = wei[0];

	int ans = 0;
	if ( wei[0] <= cap ) ans = val[0];
	for (int j = 1; j < n; j++) {
		for (int i = 1; i <= sm_val; i++) {
			dp[i][j] = dp[i][j - 1];
			if ( val[j] <= i ) {
				dp[i][j] = min( dp[i][j] , wei[j] + dp[i - val[j]] [j - 1]  );
				if ( dp[i][j] <= cap) {
					ans = max( i , ans );
				}
			}
		}
	}
	//display2D(dp);
	cout << ans << endl;

	return 0;
}

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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

int dp[402][402];
int pref[402];
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	memset(dp,63,sizeof dp);
	int n;
	cin >> n;
	vector<int> A(n+1);
	for(int i=1;i<=n;i++){
		cin >> A[i];
		pref[i] = pref[i-1] + A[i];	
	}
	for(int L=n;L>=1;L--)
		for(int R=L;R<=n;R++){
			if(R==L)
				dp[L][R] = 0;
			else{
				for(int i=L;i<=R-1;i++){
					dp[L][R] = min(dp[L][i] + dp[i+1][R]+pref[R]-pref[L-1],dp[L][R]);
				}
			}
		}
	cout << dp[1][n] << '\n';
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















Measured memory_bytes: 1536
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
 
def solve(n):
	#n = readInt()
	i = 1
	maxk = 26
	while 1:
		if n<=maxk:
			ke = i
			break
		else:
			i+=1
			maxk =maxk + 26**i
	#print(ke)
	#ke 桁数
	tar = n
	l= []
	while 1:
		a = tar//26
		b = tar%26
		if b==0:
			a-=1
			b = 26
		l.append(chr(ord("a")-1+b))
		tar = a
		if tar==0:
			break
 
	print("".join(l[::-1]))
 
solve(readInt())
#for i in range(1,1000000,26**2):
#	print(i)
#	solve(i)

Measured memory_bytes: 9224
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;



int main(){
	int n,a=0,b=0;
	cin>>n;
	vector<int>c(10000000);
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	sort(c.begin(),c.end(),greater<>());
	for(int i=0;i<n;i++){
		if(i%2==0){
			a+=c[i];
		}
		else{
			b+=c[i];
		}
	}
	cout<<a-b<<endl;
    return 0;
}

Measured memory_bytes: 39424
#include <iostream>
using namespace std;
int main()
{
  char number[4];
  for (int i=0;i<4;++i) cin>>number[i];
  int count=0;
  for (int i=0;i<4;++i)
  {
    if (number[i]=='2') count+=1;
  }
  cout<<count;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s[n];
	REP(i,n) cin >> s[i];
	ll cnt[5] = {};
	REP(i,n){
		if(s[i][0] == 'M') cnt[0]++;
		else if(s[i][0] == 'A') cnt[1]++;
		else if(s[i][0] == 'R') cnt[2]++;
		else if(s[i][0] == 'C') cnt[3]++;
		else if(s[i][0] == 'H') cnt[4]++;
	}
	ll res = 0;
	for(int i = 0; i < 5; i++){
		for(int j = i + 1; j < 5; j++){
			for(int k = j + 1; k < 5; k++){
				res += cnt[i] * cnt [j] * cnt[k];
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6144
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,m; cin >> n >> m;
    vector<int> cnt(n,0);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        cnt[a]++;
        cnt[b]++;
    }
    rep(i,n) cout << cnt[i]<< endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int in[3], i, rect = 0, rhom = 0;
	while (scanf("%d,%d,%d", &in[0], &in[1], &in[2]) != EOF) {
		if (in[0] == in[1]) {
			rhom++;
		} else if (in[2] * in[2] == in[0] * in[0] + in[1] * in[1]) {
			rect++;
		}
	}
	printf("%d\n%d\n", rect, rhom);
	return 0;
}

Measured memory_bytes: 596
#include<cstdio>

int a, b, c;

bool isAscending(int a, int b, int c){
	if(a < b && b < c) return true;
	else return false;
}

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

	if(isAscending(a, b, c) == true) printf("Yes\n");
	else if(isAscending(a, b, c) == false) printf("No\n");

	return 0;
}

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

#include <atcoder/all>

using namespace std;
using namespace atcoder;
 
//////////////////

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)
    
void solve(){
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(M);
    rep(i,N) cin >> a[i];
    rep(i,M) cin >> b[i];
    vector<int> c = convolution<998244353>(a,b);
    rep(i,N+M-1)
    cout << c[i] << " ";
    cout << endl;
}


signed main(){
    cout << fixed << setprecision(18);
//    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 27272
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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; }
//-------------------
bool rel[30][30];
int p[30];
int onoff[30];
int n,m; 

bool judge(){
	//bool ret = true;
	FOR(i,1,m){
		int now = 0;
		FOR(j,1,n){
			if(rel[i][j] == true){
				now += onoff[j];
			}
		}
		if(now % 2 != p[i]){
			return false;
		}
	}
	return true;
}

int main(){
	cin >> n >> m;
	FOR(i,1,m){
		int k; cin >> k;
		FOR(j,1,k){
			int s; cin >> s;
			rel[i][s] = true;
		}
	}
	FOR(i,1,m){
		cin >> p[i];  
	}

	int ret = 0;
	FOR(i,0,(1<<n)-1){
		int cur = (i<<1);
		FOR(j,1,n){
			if (cur & (1<<j)){
				onoff[j] = 1;
			}else{
				onoff[j] = 0;
			}
		}
		if(judge()==true){
			ret += 1;
		}
	}

	cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

long double dp[5000];
int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	vector<long double> a(n); for (int o = 0; o < n; o++) { cin >> a[o]; }
	dp[0] = 1.0;
	for (int i = 0; i < n; ++i)
		for (int j = 3000; j >= 0; --j)
			dp[j] = (j == 0 ? 0.0l : dp[j - 1] * a[i]) + dp[j] * (1.0l - a[i]);
	long double pp = 0;
	for (int i = (n + 2) / 2; i < 3001; ++i)
		pp += (dp[i]);
	cout << pp;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
using namespace std;

int N, K, H[100100], D[100100];
int main()
{
	scanf("%d %d", &N, &K);

	for (int i=1;i<=N;i++) scanf("%d", &H[i]);
	for (int i=2;i<=N;i++){
		D[i] = D[i-1] + abs(H[i-1]-H[i]);
		for (int k=2;k<=K;k++){
			if (i > k && D[i] > D[i-k] + abs(H[i-k]-H[i]))
				D[i] = D[i-k] + abs(H[i-k]-H[i]);
		}
	}
	printf("%d\n", D[N]);

	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define fr first
#define sc second
#define INF (1<<30)
int main(){
  int N,P;
  while(cin >> N , N){
    int ans = 0;
    vector<pair<int,string> > vc(N);
    for(int i = 0 ; i < N ; i++ ){
      string name;
      int weekday , start;
      cin >> name >> weekday >> start;
      vc[i] = make_pair(weekday * 24 * 60 + (start/100)*60 + start % 100,name);
    }
    sort(vc.begin(),vc.end());
    cin >> P;
    for(int q = 0 ; q < P ; q++ ){
      string fav;
      bool OR = false;
      cin >> fav;
      for(int i = 0 ; i < (int)vc.size() ; i++ ){
        if(vc[i].sc == fav){
          OR = true;
          pair<int,string> r = make_pair(vc[i].fr-29,"0"),l = make_pair(vc[i].fr+30,"0");
          vc.erase(lower_bound(vc.begin(),vc.end(),r),lower_bound(vc.begin(),vc.end(),l));
          break;
        }
      }
      if(!OR) ans = -INF;
    }
    int now = 0;
    for(int i = 0 ; i < (int)vc.size() ; i++ ){
      if(vc[i].fr >= now) now = vc[i].fr + 30 , ans++;
    }
    cout << max(-1,ans+P) << endl;
  }
}

Measured memory_bytes: 1264
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int n;
  cin >> n;
  int sum = 0;
  int tmp = n;
  // cout << int(log10(n)) << endl;
  for (int i = int(log10(n)); i >= 0 ; i--)
  {
    int x = pow(10,i);
    sum += (tmp / x);
    tmp %= x;
  }
  if (n % sum == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int main(void){
    int a[10001], n, min, max;
    long long sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i==1){
            min = a[1];
            max = a[1];
        }
        else{
            if(a[i]<min){
                min = a[i];
            }
            if(a[i]>max){
                max = a[i];
            }
        }
        sum += a[i];
    }

cout << min << " " << max << " " << sum << endl;
}




Measured memory_bytes: 3140
#include<stdio.h>
int main(void)
{
    int n,b=0,i,c;
    scanf("%i",&n);
    int a[n+1],ans;
    a[0]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%i",&a[i]);
        if(a[i]>a[i-1])b=b+a[i]-a[i-1];
        else b=b+a[i-1]-a[i];
        if(i==n-1)c=b;
    }
    i--;
    if(a[i]>0)b=b+a[i];
    else b=b-a[i];
    for(i=1;i<n;i++)
    {
        if(a[i]>a[i-1])ans=b-a[i]+a[i-1];
        else ans=b-a[i-1]+a[i];
        if(a[i+1]>a[i])ans=ans-a[i+1]+a[i];
        else ans=ans-a[i]+a[i+1];
        if(a[i+1]>a[i-1])ans=ans+a[i+1]-a[i-1];
        else ans=ans+a[i-1]-a[i+1];
        printf("%i\n",ans);
    }
    if(a[i-1]>0)ans=c+a[i-1];
    else ans=c-a[i-1];
    printf("%i",ans);
    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

int cnt = 0;

void dfs(vi preorder, vi inorder) {
	if (inorder.size() == 0) {
		return;
	}
	if (inorder.size() == 1) {
		cnt++;
		cout << inorder[0];
		if (cnt == preorder.size()) {
			cout << endl;
		}
		else {
			cout << ' ';
		}
		return;
	}
	int pos = 0;
	bool flag = false;
	rep(i, preorder.size()) {
		rep(j, inorder.size()) {
			if (inorder[j] == preorder[i]) {
				pos = j;
				flag = true;
				break;
			}
		}
		if (flag)break;
	}
	dfs(preorder, vi(inorder.begin(), inorder.begin() + pos));
	dfs(preorder, vi(inorder.begin() + pos + 1, inorder.end()));
	cnt++;
	cout << inorder[pos];
	if (cnt == preorder.size()) {
		cout << endl;
	}
	else {
		cout << ' ';
	}
}

int main() {
	int N;
	cin >> N;
	vi preorder(N), inorder(N);
	rep(i, N) {
		cin >> preorder[i];
	}
	rep(i, N) {
		cin >> inorder[i];
	}

	dfs(preorder, inorder);

	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
    int N;
    double val;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++){
        cin >> v[i];
    }

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

    val = v[0];
    for (int i = 1; i < N; i++){
        val = (val + v[i]) / 2;
    }

    cout << val << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < 3; i++) {
    if(S[i] == 'R') {
    count++;
    }
  }
  if(count == 3) {
    cout << 3 << endl;
  }
  else if(count == 2) {
    if(S[1] == 'R') {
      cout << 2 << endl;
    }
    else {
      cout << 1 << endl;
    }
  }
  else if(count == 0) {
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

bool is_triangle(ll a, ll b, ll c) {
    if (a == b || b == c || c == a) return false;
    // cout << "debug1" << endl;
    if (a + b > c && b + c > a && c + a > b) return true;
    // cout << "debug2" << endl;
    return false;
}

int main() {
    int N; cin >> N;
    vector<ll> v(N); for (int i = 0; i < N; ++i) cin >> v[i];
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            for (int k = j + 1; k < N; ++k) {
                // cout << "===" << endl;
                // cout << i + 1  << " " << j + 1  << " " << k + 1 << endl;
                // cout << "===" << endl;
                if (is_triangle(v[i], v[j], v[k])) ++ ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;*/
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
typedef long long ll;
typedef pair<ll, ll> Pa;

/*
template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}*/

int h[100000];
int dp[100001];
int main() {
	cin >> N >> K;
	rep(i, N) {
		cin >> h[i];
	}
	rep(i, N) {
		dp[i + 1] = 1000000000;
	}
	dp[0] = 0;
	rep(i, K) {
		dp[1+i] = abs(h[1+i] - h[0]);
	}
	rep(i, N - K + 1) {
		rep(j, K) {
			dp[K + i] = min(dp[K + i], dp[K + i - j - 1] + abs(h[K + i] - h[K + i - j - 1]));
		}
	}
	cout << dp[N - 1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k, m, r, b;
vector<V> vvi;
vector<P> vp;
int p, q;
bool used[1000];

int main(){
	cin >> n >> k;
	REP(i, k){
		cin >> m;
		V vi;
		REP(j, m){
			cin >> b;
			vi.push_back(b);
		}
		vvi.push_back(vi);
	}
	cin >> r;
	REP(i, r){
		cin >> p >> q;
		vp.push_back(P(p, q));
		vp.push_back(P(q, p));
	}

	REP(i, vvi.size()){
		REP(j, vvi[i].size()){
			REP(k, vvi[i].size()){
				if (find(ALL(vp), P(vvi[i][j], vvi[i][k])) != vp.end() ||
					find(ALL(vp), P(vvi[i][j], vvi[i][k])) != vp.end()){
					used[vvi[i][j]] = 1;
					used[vvi[i][k]] = 1;
				}
			}
		}
	}

	int ans = 0;
	REP(i, n + 1){
		if (used[i]){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1324
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}

	int flag = 1;
	for (int i = 0; i < n-1; i++) {
		if (s[i][s[i].size() - 1] != s[i + 1][0]) flag = 0;
	}

	int tigau = 1;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			if (s[i] == s[j]) tigau = 0;
		}
	}

	if (flag&&tigau) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
# E - Simple String Queries

class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1)

N = int(input())
S_raw = input()
S = [0]*(N+1)
trees = [FenwickTree(N) for _ in range(26)]
for i in range(1,N+1):
    s = S_raw[i-1]
    S[i] = s
    k = ord(s)-ord('a')
    trees[k].add(i, 1)

Q = int(input())
for _ in range(Q):
    q,x,y = input().split()
    if q=='1':
        i,c = int(x),y
        s = S[i]
        k = ord(s)-ord('a')
        trees[k].add(i, -1)
        S[i] = c
        k = ord(c)-ord('a')
        trees[k].add(i, 1)
    else:
        l,r = int(x),int(y)
        ans = 0
        for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
        print(ans)

Measured memory_bytes: 332276
sx,sy,tx,ty=map(int,input().split())
print("R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy)+"D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"+"U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R")

Measured memory_bytes: 9088
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    if(N<1000){
        p("ABC");
    }else{
        p("ABD");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C[100007];

int main() {
    ll N,X,A[1007],K=0;cin >> N >> X;
    rep(i,N){
        cin >> A[i];
        K+=A[i];
    }
    sort(A,A+N);
    cout << (X-K)/A[0]+N << endl; 
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;
 
ll p[1000000], sz[1000000], sum[1000000], n, X, Y;
ll fact[1000000], ans = 1, min_c[1000000], u[1000000], inv[1000000];

map <ll, ll> mp[1000000];

struct Component
{
	ll mn, c;

} cm[1000000];

ll qpow (ll a, ll b)
{
	ll s = 1;

	while (b)
	{
		if (b & 1) s = (s * a) % MOD;
		a = a * a % MOD;
		b >>= 1;
	}

	return s;
}

vector < pair <ll, ll> > s;

struct ball
{
	ll c, w;

	bool operator < (const ball& b) const
	{
		return w < b.w;
	}

} a[1000000];

ll find (ll x)
{
	if (x == p[x]) return x;
	return p[x] = find (p[x]);
}

void unite (ll a, ll b)
{
	a = find (a);
	b = find (b);

	if (a == b) return;

	if (sz[a] < sz[b]) swap (a, b);

	p[b] = a;

	sz[a] += sz[b];
}
 
int main ()
{
	cin >> n >> X >> Y;

	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
		fact[i] = (i * fact[i-1]) % MOD;

	inv[n] = qpow (fact[n], MOD - 2);

	for (ll i = n - 1; i >= 0; i--)
		inv[i] = (i + 1) * inv[i+1] % MOD;

	for (ll i = 0; i < n; i++)
	{
		p[i] = i;
		sz[i] = 1;
		ll c, w;

		scanf ("%lld%lld", &c, &w);

		a[i] = {c, w};
	}

	sort (a, a + n);

	for (int i = 0; i <= n; i++)
		min_c[i] = -1;

	for (ll i = 0; i < n; i++)
	{
		if (min_c[a[i].c] == -1) min_c[a[i].c] = i;
		else if (a[min_c[a[i].c]].w + a[i].w <= X) unite (min_c[a[i].c], i);
	}

	for (ll i = 1; i <= n; i++)
		if (min_c[i] != -1)
			s.push_back ({a[min_c[i]].w, min_c[i]});

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

	for (ll i = 0; i < n; i++)
	{
		if (a[s[0].second].c == a[i].c)
		{
			if (s.size () > 1 && s[1].first + a[i].w <= Y) unite (s[1].second, i);
		}
		else if (s[0].first + a[i].w <= Y)
		{
			unite (s[0].second, i);
		}
	}

	for (ll i = 1; i < s.size (); i++)
		if (s[i].first + s[0].first <= Y) unite (s[i].second, s[0].second);

	for (ll i = 0; i < n; i++)
		mp[find (i)][a[i].c]++;

	for (ll i = 0; i < n; i++)
		if (p[i] == i)
		{
			ll den = 1;
			for (auto a : mp[i])
				den = (den * inv[a.second]) % MOD;

			ans = (ans * (fact[sz[i]] * den % MOD)) % MOD;
		}

	cout << ans;

}

Measured memory_bytes: 85356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String n = sc.nextLine();
		
		int y = Integer.parseInt(n.substring(0, 4));
		int m = Integer.parseInt(n.substring(5, 7));
		int d = Integer.parseInt(n.substring(8, 10));
		
		if (y <= 2019 && m <= 4 && d <= 30) {
			System.out.println("Heisei");
		}else {
			System.out.println("TBD");
		}
		sc.close();
	}

}


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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e3 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (fat[i-1] * i) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll dp[maxn][10005];

int a[maxn], b[maxn];

int main()
{
  ios::sync_with_stdio(false);
  MSET(dp, INF);
  int h,n;
  cin >> h >> n;
  for(int i = 0; i < n ; i++)
  {
    cin >> a[i] >> b[i];
  }


  dp[0][0] = 0;
  for(int i = 0; i < n ; i++)
  {
    for(int j = 0; j <= h; j++)
    {
      dp[i+1][j] = dp[i][j];
      dp[i][min(h, j + a[i])] = min(dp[i][min(h, j + a[i])], dp[i][j] + b[i]);
      dp[i + 1][min(h, j + a[i])] = min(dp[i + 1][min(h, j + a[i])], dp[i][j] + b[i]);
    }
  }

  cout << dp[n][h] << endl;

  return 0;
}

Measured memory_bytes: 160712
//{
#include<bits/stdc++.h>
using namespace std;
 
#define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif
//}

vl solve(vl &A) {
    vl B(A.size());
    int ax = 0;
    FOR(i, 0, A.size())
        ax = ax ^ A[i];
    FOR(i,0,A.size()) {
        B[i] = ax ^ A[i];
    }
    
    return B;
}

void Input() {
    rd1(ll, n);
    vl A(n);
    
    FOR(i, 0, n)
        cin >> A[i];
    vl B = solve(A);
    FOR(i, 0, n)
        cout << B[i] << " ";
}

int main() {
	
	fastio;

    // rd1(ll, t);
	ll t = 1;

    while(t--) {
        Input();
    }
    
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> s(1 << n);
  std::cin >> s;

  std::multiset<int64_t, std::greater<int64_t>> m(s.begin(), s.end());

  std::multiset<int64_t, std::greater<int64_t>> q;
  q.insert(*m.cbegin());
  m.erase(*m.cbegin());

  for (int64_t i = 0; i < n; i++) {
    std::multiset<int64_t> n;
    for (const auto v : q) {
      auto itr = m.upper_bound(v);
      if (itr == m.cend()) {
        std::cout << "No" << std::endl;
        return 0;
      }
      n.insert(*itr);
      m.erase(itr);
    }
    q.insert(n.cbegin(), n.cend());
  }
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 20736
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int cnt=0;

void dfs(int vis[],vector<int> v[],int curr)
{
	vis[curr]=1;
	cnt++;
	for(int i=0;i<v[curr].size();i++)
	{
		int j=v[curr][i];
		if(vis[j]==0)
		dfs(vis,v,j);
	}
}
int32_t main()
{
	int t=1;
	while(t--)
	{
		int n,m;
		cin >> n >> m;
		vector<int> v[n+1];
		set<pair<int,int> > s;  
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >>  x >> y;
			if(s.find({x,y})==s.end())
			{
				s.insert({x,y});
				s.insert({y,x});
				v[x].push_back(y);
				v[y].push_back(x);
			}
		}
		int vis[n+1]={0};
		int mx=0;
		for(int i=1;i<=n;i++)
		{
			if(vis[i]==0)
			{
				cnt=0;
				dfs(vis,v,i);
				mx=max(mx,cnt);
			}
		}
		cout << mx;
	}
}




Measured memory_bytes: 50460
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
string s;
typedef long long ll;
ll ans = 0;
void dfs(int pt, ll now, ll sum)
{
	if (pt == s.size())
	{
		ans += sum + now;
		return;
	}
	dfs(pt + 1, now * 10 + s[pt] - '0', sum);
	if (pt != 0)dfs(pt + 1, s[pt] - '0', sum + now);
}
int main()
{
	cin >> s;
	dfs(0, 0, 0);
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
def gtr(n):
    tree = [[] for i in range(n)]
    for i in range(n-1):
        u,v =ma()
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)
    return tree
mod=10**9+7
n,k =ma()
tree = gtr(n)
stack = collections.deque()
stack.append(0)
visited=[True]+[False]*(n-1)
col = [k]*n
while stack:
    s = stack.pop()
    if s==0:
        cnt=k-1
    else:
        cnt=k-2
    for node in tree[s]:
        if not visited[node]:
            visited[node]=True
            stack.append(node)
            col[node]= max(0,cnt)
            cnt-=1
ans=1
for c in col:
    ans=ans*c%mod
print(ans)


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

using namespace std;

const int N = 3e5+1;
const int O = 3e4+1;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define ppb pop_back
#define pu push
#define fr front
#define fi first
#define se second
#define setprecision
#define re return 0
#define fast ios_base::sync_with_stdio(false)

ll n, m, a[N], b[N], c[N], d[N], x, y, z, l, r, q, k, cnt, ans;

//vector<int> v;
//set<int> st[N];
//queue<int> q;

int main ()
{
    fast;

    cin >> n >> k;

    for (int i = 1; i <= n; ++i) cin >> a[i];
    d[2] = abs(a[1]-a[2]);
    for (int i = 3; i <= n; ++i)
    {
        d[i]=INF;
        for (int j = max(i-k,1ll); j <= i-1; ++j) {
            d[i] = min (d[j]+abs(a[j]-a[i]), d[i]);
        }
    }
    cout << d[n];
}


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

int main(){
	int M,D;	cin>>M>>D;

	int ans=0;
	for(int m=1;m<=M;m++){
		for(int d=1;d<=D;d++){
			int d10=d/10, d1=d%10;

			if(d1>1 && d10>1 && d1*d10==m){
				ans++;
			}
		}
	}

	cout<<ans<<endl;


	return 0;
}


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

using namespace std;

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    if(n >= s.size() + t.size()){
        cout << n;
    }
    else{
        int i = s.size() - min(s.size(), t.size());
        int j = 0;
        bool can_merge = 0;
        int merge_length = 0;
        while(i < s.size() && j < t.size()){
            if(s[i] == t[j]){
                can_merge = 1;
                merge_length++;
                j++;
            }
            else{
                j = 0;
                if(s[i] == t[j]){
                    can_merge = 1;
                    merge_length = 1;
                    j++;
                }
                else{
                    can_merge = 0;
                    merge_length = 0;
                }
            }
            i++;
        }
        int a = s.size();
        int b = t.size();
        if(can_merge){
            cout << max((a + b - merge_length), n);
        }
        else{
            cout << max(a+b,n);
        }
    }

    return 0;
}


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

int main() {
    string s;
    int n, k;
    cin >> n >> k >> s;
    if(s.at(k-1)=='A'){
        s.at(k-1)='a';
    }
    else if(s.at(k-1)=='B'){
        s.at(k-1)='b';
    }
    else if(s.at(k-1)=='C'){
        s.at(k-1)='c';
    }
    cout << s << endl;
}

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

using namespace std;

const int MAX_N = 300005;

int main()
{
    bool flag[MAX_N];
    for(int i=1;i<=300000;i++){
        flag[i] = true;
    }
    flag[1] = false;
    for(int i=2;i<=300000;i++){
        if(i % 7 != 1 && i % 7 != 6){
            flag[i] = false;
        }else{
            int cnt = 2;
            while(cnt * i <= 300000){
                flag[cnt*i] = false;
                cnt++;
            }
        }
    }
    while(1){
        int n;
        cin >> n;
        if(n == 1){
            break;
        }
        vector<int> vec;
        for(int i = 1;i <= n;i++){
            if(flag[i] == true && n % i == 0){
                vec.push_back(i);
            }
        }
        cout << n << ":";
        for(int i=0;i < vec.size();i++){
            cout << " " << vec[i];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 3352
require "matrix"

#main
arr = Array.new
while line = gets
   arr << line
end

arr.each do |i|
   c = i.split(" ")
   c.map!{|i| i.to_f}
   a = Matrix[[c[0], c[1]],
              [c[3], c[4]]]
   b = Vector[c[2],
              c[5]]
   res = a.inverse * b
   printf("%.3f %.3f\n", res[0], res[1]);
end

Measured memory_bytes: 6428
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[200005],s[200005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&a[i]);
		s[i]=s[i-1]+a[i];
	}
	long long l=1,r=3,p,q,u,t,ans=0x7fffffff;
	for(int i=2;i<n-1;++i){
		while(l<i&&abs(s[l]-s[0]-(s[i]-s[l]))>=abs(s[l+1]-s[0]-(s[i]-s[l+1])))
			++l;
		while(r<n&&abs(s[r]-s[i]-(s[n]-s[r]))>=abs(s[r+1]-s[i]-(s[n]-s[r+1])))
			++r;
		p=s[l]-s[0];
		q=s[i]-s[l];
		u=s[r]-s[i];
		t=s[n]-s[r];
		ans=min(ans,max(p,max(q,max(u,t)))-min(p,min(q,min(u,t))));
	}		
	printf("%lld",ans);
}

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

int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n==0 && m==0) {
      break;
    }
    int a[n];
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    int ans = -INT_MAX;
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	if (i!=j && a[i]+a[j]<=m) {
	  ans = max(ans,a[i]+a[j]);
	}
      }
    }
    if (ans<0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3012
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT2:
    """ 区間加算BIT(区間加算・区間合計取得) """

    def __init__(self, N):
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N

    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k

    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """

        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def query(self, l, r):
        """ 区間[l,r)の和を取得 """

        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

N, Q = MAP()
bit = BIT2(N+1)

for i in range(Q):
    cmd, *arg = MAP()
    if cmd == 0:
        s, t, x = arg
        bit.add(s, t+1, x)
    else:
        s, t = arg
        print(bit.query(s, t+1))



Measured memory_bytes: 12040
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define MAX_N 200000

using namespace std;

int n, q, a, b, parent[MAX_N], p, x, cost[MAX_N];
vector<int> child[MAX_N];
long long ans[MAX_N];

//int dfs(int j) {
//  if (j == 0) {
//    return xx[0];
//  }
//  return dfs(parent[j]) + xx[j];
//}

int main() {
  cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    parent[b - 1] = a - 1;
    child[a - 1].push_back(b - 1);
  }
  for (int i = 0; i < q; ++i) {
    cin >> p >> x;
    cost[p - 1] += x;
  }
  
  ans[0] = cost[0];
  for (int i = 0; i < n; ++i) {
    for (auto j : child[i]) {
      ans[j] += ans[i] + cost[j];
    }
  }
  
  for (int i = 0; i < n; ++i) 
    cout << ans[i] << " ";
  cout << endl;
  return 0;
}



Measured memory_bytes: 16256
#include <stdio.h>

int main (void)
{
	int n, m, i, j, k, l, s, t;
	int puzzle[100][9][9] = {0};
	int error[100][9][9] = {0};

	while (scanf("%d", &n) != EOF)
	{
		for(m = 0; m < n; m++)
		{
			for (i = 0; i < 9; i++)
				for (j = 0; j < 9; j++)
					scanf("%d", &puzzle[m][i][j]);

			for (i = 0; i < 9; i++)
				for (j = 0; j < 9; j++)
					for (k = 0; k < 9; k++)
						if (k != j && puzzle[m][i][j] == puzzle[m][i][k])
							error[m][i][j]++;

			for (j = 0; j < 9; j++)
				for (i = 0; i < 9; i++)
					for (k = 0; k < 9; k++)
						if (k != i && puzzle[m][i][j] == puzzle[m][k][j])
							error[m][i][j]++;

			for (i = 0; i < 9; i += 3)
				for (j = 0; j < 9; j += 3)
					for (k = i; k < i + 3; k++)
						for (l = j; l < j + 3; l++)
							for (s = i; s < i + 3; s++)
								for (t = j; t < j + 3; t++)
									if((s != k || t != l) && puzzle[m][k][l] == puzzle[m][s][t])
										error[m][k][l]++;
		}

		for (n = 0; n < m; n++)
		{
			for (i = 0; i < 9; i++)
			{
				for (j = 0; j < 9; j++)
				{
					if (error[n][i][j] > 0)
						printf("*");
					else
						printf(" ");
					
					printf("%d", puzzle[n][i][j]);
				}
				printf("\n");
			}
			if (n != m - 1)
				printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  ll ans = 1;
  rep(i,n) {
    ans *= (i+1);
    ans %= mod;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3632