akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
#define u_s  unordered_set
#define endl "\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
#define ll long long int
#define ipair pair<int,int>
#define all(x) (x).begin(), (x).end()

const int mod=pow(10,9)+7;

bool compare(pair<int,int>p1,pair<int,int>p2){
    return p1.second<p2.first;
}
/*
  ll C(ll n,ll k){
  
  if(k>n)return 0;
  
  ll ans=1;

  if(k>n-k)
    k=n-k;
  for(ll i=1;i<=k;i++)
    ans*=(n-i+1),ans/=i;

  return ans;
  }
  unsigned long long fact(long long a)
  {
  unsigned long long res=1;
  for(long long i=a;i>0;i--)
    res*=i;
  return res;
  }
  unsigned long long comb(long long a,long long b)
  {
  if((a-b)<b) b=a-b;
  if(a<=19) return fact(a)/(fact(a-b)*fact(b));
  if(a==b||b==0) return 1;
  if(b==1) return a;
  return comb(a-1,b-1)+comb(a-1,b);
  }
*/


void solve(){
   
   int row,col; cin>>row>>col;
    
   ll dp[row+1][col+1];
   memset(dp,0,sizeof dp);

   for(int i=0;i<row;i++){

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

          char c; cin>>c;
          if(c=='#')dp[i][j]=-1;
      }
   }

   for(int i=1;i<col;i++){
      
      if(dp[0][i]==-1)break;
      dp[0][i]=1;
   }
   for(int i=1;i<row;i++){

       if(dp[i][0]==-1)break;
       dp[i][0]=1;
   }

   for(int i=1;i<row;i++){

      for(int j=1;j<col;j++){

          if(dp[i][j]==-1)continue;

          ll way1=( dp[i-1][j]==-1 ? 0 :dp[i-1][j]);
          ll way2=( dp[i][j-1]==-1 ? 0 :dp[i][j-1]);
          dp[i][j]=(ll)(way1+way2)%mod;
      }
   }
   

    cout<<dp[row-1][col-1];
 }
int main(){


    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
        
    solve();

    return 0;  
    
}


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

int getDigit(int in)
{
  if (in == 0) return 0;
  int ret = 1;

  while (in /= 10) ret++;

  return ret;
}

int main(void)
{
  int a, b;

  while (cin >> a) {
    cin >> b;

    cout << getDigit(a + b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=200010;
char col[maxn];
vector<int> g[maxn];
int acnt[maxn],bcnt[maxn];
bool vis[maxn];
int main(){
	int n,m,u,v;
	scanf("%d%d%s",&n,&m,col+1);
	for(int i=0;i<m;i++){
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<int> q;
	for(int u=1;u<=n;u++){
		for(int i=0;i<(int)g[u].size();i++){
			int v=g[u][i];
			if(col[v]=='A') acnt[u]++;
			else bcnt[u]++;
		}
		if(acnt[u]==0 || bcnt[u]==0){
			q.push(u);
			vis[u]=true;
		}
	}
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0;i<(int)g[u].size();i++){
			int v=g[u][i];
			if(!vis[v]){
				if(col[u]=='A') acnt[v]--;
				else bcnt[v]--;
				if(acnt[v]==0 || bcnt[v]==0){
					q.push(v);
					vis[v]=true;
				}
			}
		}
	}
	bool found=false;
	for(int v=1;v<=n;v++)
		if(!vis[v]) found=true;
	puts(found?"Yes":"No");
	return 0;
}

Measured memory_bytes: 12544
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
for i in range(h):
    a[i] = [aij % 2 for aij in a[i]]

cnt, ans = 0, []
for i, ai in enumerate(a):
    for j in range(w):
        if i % 2 == 1:
            j = w - 1 - j
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            cnt = 0
            ai[j] = (ai[j] + 1) % 2
        if ai[j] == 1:
            cnt = 1
        bi, bj = i, j

print(len(ans))
for q in ans:
    print(*q)


Measured memory_bytes: 99264
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
typedef struct node * Node;
Node NIL;
Node Search(int key){
  Node  x;
  for(x=NIL;x->next!=NIL;x=x->next){
  if(x->next->key==key)return x->next;
  }
  return NULL;
}
void in(){
  NIL= malloc(sizeof(struct node));
  NIL->next=NIL;
  NIL->prev=NIL;
}
void print(){
  Node s=NIL->next;
  int flag=1;
  while(1){
    if (s==NIL)break;
    if (flag==0)printf(" ");
    printf("%d",s->key);
    s=s->next;
    flag=0;
  }
  printf("\n");
}
 void NODEdelete(Node x){
   x->next->prev=x->prev;
   x->prev->next=x->next;
   free(x);
 }
void delete1(){
  Node t=NIL->next;
  if (t==NIL)return;
  NODEdelete(t);
}
void delete2(){
 Node x;
  x=NIL->prev;
  NODEdelete(x);
}
void delete(int t){
  Node x;  
  x=Search(t);
  if(x!=NULL)NODEdelete(x);
}
void insert(int t){
  Node x;
  x=malloc(sizeof(struct node));
  x->key=t;
  x->next=NIL->next;
  NIL->next->prev = x;
  NIL->next=x;
  x->prev=NIL;
}

int main(){
  int n,key,i,l=0;
  char s[20];
  int p=0,d=0;
  scanf("%d", &n);
  in();
  for (i=0;i<n;i++){
    scanf("%s%d",s,&key);
    if (s[0]=='i'){
      insert(key);
      p++;
      l++;
    }
    if(s[0]=='d') {
      if(strlen(s) > 6){
	      if (s[6]=='F')delete1();
	      else if(s[6]=='L')delete2();
      }else{
	      delete(key);
        d++; 
      }
      l--;
    }
  }
  print();
  return 0;
}


Measured memory_bytes: 32996
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> s(m);
    vector<ll> c(m);
    rep(i, m){
        cin >> s.at(i) >> c.at(i);
    } 
    
    vector<ll> vec(3);
    rep(i,3){
        vec.at(i) = -1;
    }

    ll ans = -1;

    rep(i,m){
        if(vec.at(s.at(i) - 1) == -1){
            vec.at(s.at(i) - 1) = c.at(i);
        }else{
            if(c.at(i) == vec.at(s.at(i) - 1)){
                continue;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }

    if(vec.at(0) == 0 && n != 1){
        cout << -1 << endl;
        return 0;
    }



    rep(i,n){
        if(vec.at(i) == -1 && n == 1){
            vec.at(i) = 0;
        }
        if(vec.at(i) == -1 && n != 1 && i == 0){
            vec.at(i) = 1;
        }
        if(vec.at(i) == -1 && n != 1 && i != 0){
            vec.at(i) = 0;
        }
        cout << vec.at(i);
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>



using ll = long long;


using namespace std;
int gcd(int a, int b) {
	if (a < b) {
		int t = a;
		a = b;
		b = t;
	}
	
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

int factorial(ll n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else
		return 1;
}
int main()
{/*13日目*/
	vector<int> a(5);
	for (int i = 0;i < 5;i++) {
		cin >> a[i];
		switch (a[i])
		{
		case 0: cout << 1 + i;		
			
		}
	}

}
	
	


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

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

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int n = 1e7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    priority_queue<ll> pq;
    rep (i, n) {
        ll a;
        cin >> a;
        pq.push(a);
    }
    rep (i, m) {
        ll x = pq.top();
        pq.pop();
        x /= 2;
        pq.push(x);
    }
    ll res = 0;
    while (!pq.empty()) {
        res += pq.top();
        pq.pop();
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 1400
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];
		for( int i=0; i<N; i++ ){
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		long ans = 0;      
		if( N%2==1 ){
			if( N==1 && a[0]==0 ){
				ans = 1;              
            }           
			for( int i=1; i<N; i+=2 ){
				if( a[i]!=a[i+1] && a[i]!=i+1 ){
					ans = 0;		
					break;
				}      
				if( i==N-2 && a[0]==0 ){
					ans = 2;
					for( int j=0; j<N/2-1; j++ ){
						ans = 2*ans;
						if(ans>1000000007L){
							ans = ans%1000000007L; 
						}
					}             
				}
			}  
		}
		if( N%2==0 ){
			for( int i=0; i<N; i+=2 ){
				if( !( a[i]==a[i+1] && a[i]==i+1 ) ){
					ans = 0;
					break;
				}
				if( i==N-2 ){
					ans = 2;
					for( int j=0; j<N/2-1; j++ ){
						ans = 2*ans;
						if(ans>1000000007L){
							ans = ans%1000000007L;
						}
					}                 
				}
			}
		}  
		System.out.println(ans);
	}
}


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

int main()
{
    string C1, C2;
    cin >> C1 >> C2;
    reverse(C2.begin(), C2.end());
    if (C1 == C2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>    
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 1000005, mo = 1000000007;
using namespace std;
int n, f[N], g[N];
void upd(int &x, int y) {
    x = (x + y) % mo;
}
int main() {
    scanf("%d", &n);
    f[1] = n, g[1] = n;
    rep(i, 2, n) {
        f[i] = f[i - 1];
        upd(f[i], (ll) (n - 1) * (n - 1) % mo);
        int x = max(i - 3, 0), y = n - 1 - x;
        upd(f[i], g[x]), upd(f[i], y);
        g[i] = (g[i - 1] + f[i]) % mo;
    }
    printf("%d\n", (f[n] + mo) % mo);
    return 0;   
}

Measured memory_bytes: 8064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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


	cin >> N >> M >> K;
	if (N + M >= K) {
		cout << M + K << endl;
		return 0;
	}
	cout << N + M + M + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

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

int main() {
  int n; cin >> n;
  int maxval = -1, minval = INF;
  int tmp;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    minval = min(minval, tmp);
    maxval = max(maxval, tmp);
  }
  cout << maxval - minval << endl;
  return 0;
}


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

using namespace std;

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

const int MAXN = 2e5 + 7;
const ll INF = 1e18;

double x[10], y[10], dist[10][10];

double calc_dist(int i, int j) {
	return sqrt(abs(x[i] - x[j]) * abs(x[i] - x[j]) + abs(y[i] - y[j]) * abs(y[i] - y[j]));
}

double fat(int n) {
	double ans = 1;
	for (int i = 1; i <= n; i++) {
		ans *= i;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			dist[i][j] = calc_dist(i, j);
			dist[j][i] = dist[i][j];
		}
	}
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		v[i] = i;
	}
	double total = 0.0;
	do {
		double curr = 0.0;
		for (int i = 1; i < n; i++) {
			curr += dist[v[i - 1]][v[i]];
		}
		total += curr;
	} while(next_permutation(v.begin(), v.end()));
	cout << fixed << setprecision(10) << total / fat(n) << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		String ans = "";

		if (n < 1200) {
			ans = "ABC";
		} else if (n < 2800) {
			ans = "ARC";
		} else {
			ans = "AGC";
		}

		System.out.println(ans);

		sc.close();
	}
}


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

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int64_t x, k, d; cin >> x >> k >> d;
    x = abs(x);
    int64_t t = x / d;
    if (t >= k) {
        cout << x - d * k;
    } else {
        int64_t mn[2];
        x -= t * d;
        k -= t;
        mn[0] = x;
        mn[1] = abs(x - d);
        cout << mn[k%2];
    }
    return 0;
}

Measured memory_bytes: 3620
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}
void YesNo(bool flag){ cout<<(flag? "Yes":"No");}

ll a,b,c,d,n,x;
vector<ll>v[3];
map<ll,ll>m;
string s,s2;
void input(){
    cin>>a>>b>>c;
    m[a]++;
    m[b]++;
    m[c]++;
}
void src(){
    cout<< find_if(m.begin(),m.end(),[](auto x){return x.second==1;})->first;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	private static final int m = 0;
	public static void main(String[] args) {
 Scanner sc=new Scanner(System.in);
 int 	n=sc.nextInt();
 long ans=1;
 for(int i=2;i<=n;i++) {
 	ans=(ans*i)%1000000007;
 }
System.out.println(ans);
 
		
		
	}
}

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

int main()
{
  int N;
  cin>>N;
  vector<double> A(N);
  double rsum=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    rsum += 1/A.at(i);
  }
  cout<<1/rsum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

int check1(int a[], int N){
  bool judge;
  for (int p = 0; p < 10; p++) {
    for (int i = 0; i < N; i++) {
      judge = false;
      if(p == a[i]){
        judge = true;
        break;
      }
    }
    if(!judge) return p;
  }
  return -1;
}

int check10(int a[], int N){
  bool judge;
  for (int p = 1; p < 10; p++) {
    for (int q = 0; q < 10; q++) {
      for (int i = 0; i < N-1; i++) {
        judge = false;
        if(p == a[i] && q == a[i+1]){
          judge = true;
          break;
        }
      }
      if(!judge) return p*10+q;
    }
  }
  return -1;
}

int check100(int a[], int N){
  bool judge;
  for (int p = 1; p < 10; p++) {
    for (int q = 0; q < 10; q++) {
      for (int r = 0; r < 10; r++) {
        for (int i = 0; i < N-2; i++) {
          judge = false;
          if(p == a[i] && q == a[i+1] && r == a[i+2]){
            judge = true;
            break;
          }
        }
        if(!judge)return p*100+q*10+r;
      }
    }
  }
  return -1;
}

int main(){
  int N,ans;

  cin>>N;

  int a[N];
  REP(i,N) cin>>a[i];

  if((ans = check1(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }

  if((ans = check10(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }

  if((ans = check100(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }


  return 0;
}

Measured memory_bytes: 3128
import math

def digit(n):
  return math.floor(math.log10(n)) + 1

N = int(input())
sqN = math.sqrt(N)

minD = 0

for i in range(int(sqN) + 2):
  if i == 0:
    minD = digit(N)
  elif N % (i + 1) == 0:
    D = max([digit(i + 1), digit(N // (i + 1))])
    if minD > D:
      minD = D

print(minD)

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

int N;
vector<int> C, S, F;

int des_time(int st, int time){
  if(st == N-1) return time;
  
  int nst = st + 1;
  if(time <= S[st]) time = S[st];
  else if(time % F[st] != 0){
    time += (F[st] - time % F[st]);
  }
  
  return des_time(st+1, time + C[st]);
}

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    int c, s, f; cin >> c >> s >> f;
    C.push_back(c);
    S.push_back(s);
    F.push_back(f);
  }
  
  for(int i = 0; i < N-1; i++){
    cout << des_time(i, S[i]) << endl;
  }
  cout << 0 << endl;
  
}

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

using namespace std;

int st[101];
int cnt=0;

int top() { return st[--cnt]; }
void push(int a) { st[cnt++]=a; }
int dif(int a,int b) { return a-b; }
int frac(int a,int b) { return a/b; }

int main() {
  char s[10];
  while(cin>>s) {
    switch(s[0]) {
    case '+': push(top()+top()); break;
    case '-': push(dif(top(),top())); break;
    case '*': push(top()*top()); break;
    case '/': push(frac(top(),top())); break;
    default: push(atoi(s)); break;
    }
  }
  cout << top() << endl;
  
  return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <tuple>

#define MOD (1000000007)
using namespace std;

typedef long long ll;

vector<ll> fac(2000100, 0); //n!(mod M)
vector<ll> ifac(2000100, 0); //k!^{M-2} (mod M)

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll combination(ll a, ll b) {
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}


int main() {
    ll X, Y;
    cin >> X >> Y;

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<2000099; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    ll a_3 = 2 * Y - X;
    ll b_3 = 2 * X - Y;

    // cout << a_3 << "," << b_3 << endl;

    if(a_3 % 3 != 0 || b_3 % 3 != 0 || a_3 < 0 || b_3 < 0) {
        cout << 0 << endl;
    } else {
        ll a = a_3 / 3;
        ll b = b_3 / 3;
        cout << combination(a+b, a) << endl;
    }

    return 0;
}

Measured memory_bytes: 31488
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if (x[i+1] - x[i])*a > b:
        ans += b
    else:
        ans += (x[i+1] - x[i])*a
print(ans)

Measured memory_bytes: 86316
A, B = map(int, input().split())

ans = 0

for i in range(1, 9 + 1):
    for j in range(10):
        for k in range(10):
            i, j, k = str(i), str(j), str(k)
            kaibun = int(i+j+k+j+i)
            if A <= kaibun and kaibun <= B:
                ans += 1

print(ans)

Measured memory_bytes: 9192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int total;
		int count = 0;

		for (int a = 0; a <= A; a++) {
			for (int b = 0; b <= B; b++) {
				for (int c = 0; c <= C; c++) {
					total = 500*a + 100*b + 50*c;
					if (total ==X) count++;
				}
			}
		}

		System.out.println(count);
	}

	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}


}


Measured memory_bytes: 22996
#include<stdio.h>

int main()
{
	long long first = 2, second = 1, temp = 1, count = 0, num;
	scanf("%d",&num);
	for(count = 2; count <= num; ++count){
		second = first + temp;
		first = temp;
		temp = second;
	}
	printf("%lld",second);
	return 0;
}

Measured memory_bytes: 128
// インクルード(GCC only)
#include <bits/stdc++.h>

// 長い型名
using namespace std;
typedef long long LL;

// 省略記法
#define INF 1e9
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n), i=(i##_len-1); i>=0; ++i)
#define FOR(i,m,n) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define all(x) (x).cbegin(),(x).cend()
#define sizei(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define printvector(x) rep(i,sizei(x)){cout << x[i] << endl;}
#define summation(x) (accumulate(all(x), 0LL))
#define product(x) (accumulate(all(x), 1LL, [](int acc, int i) { return acc * i;}))

// mod付き四則演算(mod関数のオーバーヘッドが重いかも)
// TODO: 二項係数、離散対数、平方剰余の実装
//#define MOD 1000000007LL
#define MOD 998244353LL
inline LL mod(LL const &a) { return (a % MOD + MOD) % MOD; }
inline LL madd(LL const &a, LL const &b) { return mod(mod(a) + mod(b)); }
inline LL msub(LL const &a, LL const &b) { return mod(mod(a) - mod(b)); }
inline LL mmul(LL const &a, LL const &b) { return mod(mod(a) * mod(b)); }
inline LL mpow(LL a, LL b) {
  LL r = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) (r *= a) %= MOD;
    (a *= a) %= MOD;
  }
  return r;
}
inline LL minv(LL const &a) { return mpow(a, MOD-2); }
inline LL mdiv(LL const &a, LL const &b) { return mod(mod(a) * minv(b)); }


// デバッグ用
#ifdef LOCAL
    #define TO_STRING(VariableName) # VariableName
    #define eprint(...) {fprintf(stderr, "DEBUG: "); fprintf(stderr, __VA_ARGS__);}
    #define eprintvector(x) rep(i,sizei(x)){fprintf(stderr, "DEBUG: %s[%d] = %lld\n", TO_STRING(x), i, x[i]);}
#else
    #define eprint(...) 42
    #define eprintvector(x) 42
#endif

/**************** 便利な関数 ****************/
vector<string> split_impl(string &&s, regex &&r) { return { sregex_token_iterator{s.begin(), s.end(), r, -1}, sregex_token_iterator{} }; }
auto split(string s, string pattern) { return split_impl(move(s), regex{pattern}); }
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; }


/**************** ラムダ再帰用 ****************/
template<typename F>
class FixPoint : F
{
public:
  explicit constexpr FixPoint(F&& f) noexcept
    : F(std::forward<F>(f))
  {}
 
  template<typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
 
template<typename F>
static inline constexpr decltype(auto)
makeFixPoint(F&& f) noexcept
{
  return FixPoint<F>{std::forward<F>(f)};
}

/**************** main ****************/
int main()
{
  LL N;
  cin >> N;

  vector<LL> a(N+1), b(N+1), c(N+1);
  FOR(i, 1, N+1) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<vector<LL>> dp(N+1, vector<LL>(3, 0));

  dp[1][0] = a[1];
  dp[1][1] = b[1];
  dp[1][2] = c[1];

  FOR(i, 2, N+1) {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
  }

  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

  return 0;
}


Measured memory_bytes: 8064
#include<iostream>

using namespace std;

int main() {

   int n, x;
   cin >> n >> x;
   while (n != 0 || x != 0) {
      if (x < 6 || x > 3 * n - 3) {
         cout << 0 << endl;
         cin >> n >> x;
         continue;
      }
      int a, b, c;
      a = x / 3;
      b = (x - a) / 2;
      c = x - (a + b);
      while (c < n) {
         if (a == 1) {
                    if (b == 2) {
                           break;
                        }
            b--;
         } else {
            a--;
         }
         c++;
      }
      while (a > 1 && b < n - 1) {
         a--;
         b++;
      }

      int cnt = 0;
      while (a <= n - 2) {
         cnt += (c + 1 - b) / 2;
         a++;
         b--;
         while (b <= a) {
            b++;
            c--;
         }
         if (b >= c) {
            break;
         }
      }
      cout << cnt << endl;
      cin >> n >> x;
   }

   return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;

    string T[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    // 0, 1, 2, ...
    // 7, 6, 5, ...
    for(int i=0;i<7;i++){
        if(S == T[i]){
            cout << 7 - i << endl;
            return 0;
        }
    }

}

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

int main() {
	int N; cin >> N;
	vector<pair<int,int>>P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i].first;
		P[i].second = i;
	}
	sort(P.begin(), P.end());

	int max_length = 0;
	int length = 1;
	for (int i = 1; i < N; i++) {
		if (P[i].second > P[i - 1].second)length++;
		else {
			max_length = max(length, max_length);
			length = 1;
		}
	}
	max_length = max(length, max_length);

	cout << N - max_length << endl;

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i >= 1 and A[i]- A[i-1] == 1:
        ans += C[A[i-1]-1]
print(ans)

Measured memory_bytes: 61724
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    
    int sum = 0;
    for(int i=1; i<=n; i++){
        std::string str = std::to_string(i);
        int tmp = 0;
        for(int j=0; j<str.length(); j++){
            tmp += int(char(str[j]) - '0');
        }
        if(tmp >= a && tmp <= b){
            sum += i;
        }
    }
    cout << sum << endl;

    return 0;
}

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

int a[3][3];
int x,y,z;

main()
{
        rep(i,3)rep(j,3)cin>>a[i][j];
        x=a[0][0]+a[1][1]+a[2][2];
        y=a[0][1]+a[1][2]+a[2][0];
        z=a[0][2]+a[1][0]+a[2][1];
        if(x==y&&y==z)
        {
                cout<<"Yes"<<endl;
                return 0;
        }
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
def submit():
    n = int(input())
    s = ""
    c = 0
    base = 1

    def check_mod(n, base, c):
        divider = -2 * base
        tmp = n % divider
        if tmp == c:
            return True
        else:
            # 剰余の符号違いも許容する
            return tmp - divider == c

    while c != n:
        if check_mod(n, base, c):
            s = "0" + s
        else:
            s = "1" + s
            c += base
        base *= -2

    if s:
        print(s)
    else:
        print("0")


if __name__ == "__main__":
    submit()


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

using namespace std;

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

  string n;
  cin >> n;

  int ans = 0;
  bool ok = false;
  for (unsigned int i = n.size() - 1; i > 0; --i) {
    ans += 9;
    if (n[i] != '9') {
      ok = true;
    }
  }
  if (ok) {
    ans += ((n[0] - '0') - 1);
  } else {
    ans += (n[0] - '0');
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdio>
using namespace std;
int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if(n*a<=b)
        printf("%d\n",n*a);
    else
        printf("%d\n",b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main(){
  ll A = 0,B = 0,M = 0,ans = 1000000000;
  cin >> A >> B >> M;
  vector<ll>a(A);
  rep(i,A){
    cin >> a[i];
  }
  vector<ll>b(B);
  rep(i,B){
    cin >> b[i];
  }
  ll x = 0,y = 0,c = 0;
  rep(i,M){
    cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ans = min(a[0] + b[0],ans);
  cout << ans;
}

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

int main()
{
    int n, m, x, y; cin >> n >> m >> x >> y;
    string ans = "No War";

    int z = x + 1, xi, yi;
    for(int i = 0; i < n; i++){
        cin >> xi;
        if(xi >= z) z = xi + 1;
    }
    
    for(int i = 0; i < m; i++){
        cin >> yi;
        if(yi < z) ans = "War";
    }
    if(z > y) ans = "War";
    cout << ans << endl;
    return 0;
}


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

int P,Q,R;

int main(){
  cin >> P >> Q >> R;
  int A,B,C;
  A = P + Q;
  B = Q + R;
  C = R + P;
  int minimum = min(A,min(B,C));
  cout << minimum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MAXN 205
//#define N 262144
#define ULL unsigned long long
#define ll long long
int val[2005];
int lowbit(int x){
    return val[x&-x];
}
vector<pii> tot[300005];
int main(){
    for(int i = 0;i<=10;i++)val[1<<i]=i;
    int n=(1<<18)-1;
    scanf("%d",&n);
    int v[300005],w[300005];
    tot[0].pb(mp(0,0));
    for(int i = 1;i<=n;i++){
       // v[i]=rand()%100000+1;
       // w[i]=rand()%100000+1;
        scanf("%d %d",&v[i],&w[i]);
        if(i==1){
            tot[1].pb(mp(0,0));
            tot[1].pb(mp(w[i],v[i]));
            continue;
        }
        vector<pii> v1=tot[i/4];
        vector<pii> v2=tot[i/4];
        for(auto &it:v2)it.x+=w[i],it.y+=v[i];
        int l=0,r=0;
        while(l!=v1.size()||r!=v2.size()){
            if(l==v1.size()){
                tot[i].pb(v2[r]);
                r++;
            }
            else if(r==v2.size()){
                tot[i].pb(v1[l]);
                l++;
            }
            else if(v1[l]<v2[r]){
                tot[i].pb(v1[l]);
                l++;
            }
            else{
                tot[i].pb(v2[r]);
                r++;
            }
        }
       // for(auto it:tot[i])printf("%d %d\n",it.x,it.y);
      //  printf("\n");
    }

    int q;
    scanf("%d",&q);
    while(q--){
        int a=(1<<17)+18,b=rand();
        scanf("%d %d",&a,&b);
        int now=a;
        vector<pii> v1=tot[now],v2=tot[now/2];
        now=0;
        for(auto &it:v2){
            now=it.y=max(it.y,now);
        }
        reverse(v2.begin(),v2.end());
        now=0;
        int ans=0;
        for(auto it:v1){
            while(now!=v2.size()&&v2[now].x+it.x>b)now++;
            if(now==v2.size())break;
            ans=max(ans,v2[now].y+it.y);
        }
        printf("%d\n",ans);
    }
}
/*
1000000000000000000
1000000000000000000 1 1 1 1000000000
*/


Measured memory_bytes: 915768
<?php
$fl=[];
for($i=0;$i<4;$i++){
  $fl[$i]=[];
  for($j=0;$j<3;$j++){
    $fl[$i][$j]=[];
    for($k=0;$k<10;$k++)$fl[$i][$j][$k]=0;
  }
}

$n=trim(fgets(STDIN));

for($i=0;$i<$n;$i++){
  list($b,$f,$r,$v)=explode(' ',trim(fgets(STDIN)));
  $fl[$b-1][$f-1][$r-1]+=$v;
}

$o=[];
for($i=0;$i<4;$i++){
  $oo='';
  for($j=0;$j<3;$j++){
    $oo.=' '.implode(' ',$fl[$i][$j]).PHP_EOL;
  }
  $o[]=$oo;
}
$sp='';for($i=0;$i<20;$i++){$sp.='#';}$sp.=PHP_EOL;
print implode($sp,$o);

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

typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll A;
    ll m = 1000000000;
    ll S = 0;
    ll cnt = 0;

    for (ll i = 0; i < N; i++) {
        cin >> A;
        if (A < 0) {
            cnt++;
            A = -1 * A;
        }
        if (m > A) {
            m = A;
        }
        S += A;
    }
    if (cnt % 2 == 0) {
        cout << S << endl;
    } else {
        cout << S - 2 * m << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>


using namespace std;


int main()
{
	int n,ans=0;
	int v[21];
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	
	for(int i=1;i<n-1;i++){
		if(v[i-1] > v[i] && v[i+1] < v[i]) ans++;
		else if(v[i+1] > v[i] && v[i-1] < v[i]) ans++;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))


int main() {
	string a, b, c;
	cin >> a >> b >> c;

	if (a.back() == b.front() && b.back() == c.front()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}





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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

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


int main() {
    ll n;
    cin>>n;

    ll ans=inf;

    for (ll i=1;i*i<=n;i++) {
        if(n%i==0){
            ans=min(ans,n/i+i-2);
        }
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

class vertex{
public:
    int id;
    int parent = -1;
    int left = -1;
    int right = -1;
};
bool operator<(const vertex &a, const vertex &b){
    return a.id<b.id;
}

void preorder(vertex *v, int i){
    cout << " " << v[i].id;
    if(v[i].left>=0) preorder(v, v[i].left);
    if(v[i].right>=0) preorder(v, v[i].right);
}
void inorder(vertex *v, int i){
    if(v[i].left>=0) inorder(v, v[i].left);
    cout << " " << v[i].id;
    if(v[i].right>=0) inorder(v, v[i].right);
}
void postorder(vertex *v, int i){
    if(v[i].left>=0) postorder(v, v[i].left);
    if(v[i].right>=0) postorder(v, v[i].right);
    cout << " " << v[i].id;
}

int main(){
    int n;
    vertex v[25];
    cin >> n;
    for(int i=0;i<n;i++){
        int id, l, r;
        cin >> id >> l >> r;
        v[i].id=id;
        v[i].left=l;
        v[i].right=r;
    }
    sort(v, v+n);
    for(int i=0;i<n;i++){
        int l = v[i].left;
        int r = v[i].right;
        if(l>=0){
            v[l].parent=i;
        }
        if(r>=0){
            v[r].parent=i;
        }
    }

    int p;
    for(int i=0;i<n;i++){
        if(v[i].parent<0){
            p=i;
            break;
        }
    }

    cout << "Preorder" << endl;
    preorder(v, p);
    cout << endl;

    cout << "Inorder" << endl;
    inorder(v, p);
    cout << endl;

    cout << "Postorder" << endl;
    postorder(v, p);
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    int n;cin>>n;
    int cnt;
    cin>>cnt;
    int b=cnt;
    rep(i,n-2){
        int nb;cin>>nb;
        cnt+=min(b,nb);
        b=nb;
    }
    cnt+=b;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a >9 || b > 9) {
            System.out.println("-1");
            return;
        }
        System.out.println(a * b);

    }

}


Measured memory_bytes: 23124
N,A,B = [int(i) for i in input().split()]
S = input()
ans = []*N
b = 0
a = 0
for i in S:
    if i == "a" and a+b < A+B:
        a += 1
        ans.append("Yes")
        continue
    elif i == "b" and a+b < A+B and b < B:
        b += 1
        ans.append("Yes")
        continue
    ans.append("No")
print("\n".join(ans))

Measured memory_bytes: 10620
N,Q = map(int,input().split())

adj = [list() for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)

memo = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    memo[p-1] += x

result = [None]*N
stack = [(0,0)]
while stack:
    v,a = stack.pop()
    a += memo[v]
    result[v] = a
    for u in adj[v]:
        stack.append((u,a))

print(*result)

Measured memory_bytes: 95744
N = int(input())
dp = [10 ** 6] * (N + 1)
dp[0] = 0

for i in range(N+1):
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i-p] + 1)
        p *= 6
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i-p] + 1)
        p *= 9

print(dp[N])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=(1<<18)+10;
int n,m,s[MAXN];
multiset<int> Q,P;
int stk[MAXN],tp=0;
int main()
{
	n=read();
	m=(1<<n);
	for(int i=1;i<=m;++i)
		s[i]=read();
	sort(s+1,s+1+m);
	reverse(s+1,s+1+m);
	Q.insert(s[1]);
	for(int i=2;i<=m;++i)
		P.insert(s[i]);
	for(int i=0;i<n;++i)
	{
		tp=0;
		auto it=Q.end();
		--it;
		for(int j=1;j<=(1<<i);++j)
		{
			int x=*it;
			auto k=P.lower_bound(x);
			if(k==P.begin())
				return puts("No")&0;
			--k;
			stk[++tp]=*k;
			P.erase(k);
			--it;
		}
		for(int j=1;j<=tp;++j)
			Q.insert(stk[j]);
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 14080
#include <stdio.h>

int main(void)
{
  long x;
  scanf("%ld", &x);
  long thus, five, ans;
  thus = x / 500;
  five = (x % 500) / 5;
  ans = thus * 1000 + five * 5;
  printf("%ld", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

ll dp[51][51][2501];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A;
    cin >> N >> A;
    int x[N+1]; rep(i, N) cin >> x[i+1];
    dp[0][0][0] = 1;
    for(int j = 0; j <= N; j++) {
        for(int k = 0; k <= N; k++) {
            for(int s = 0; s <= 2500; s++) {
                if (j >= 1 && s < x[j]) {
                    dp[j][k][s] = dp[j-1][k][s];
                }
                else if(j >= 1 && k >= 1 && s >= x[j]) {
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
                }
                //if (dp[j][k][s] != 0) cout << j << " " << k << " " << s << " = " <<  dp[j][k][s] << endl;  
            }
        }
    }
    ll ans = 0;
    rep(k, N) {
        ans += dp[N][k+1][(k+1)*A];
        //cout << N << " " << k+1 << " " << (k+1)*A << " = " <<  dp[N][k+1][(k+1)*A] << endl;  
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 50048
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let s: Vec<char> = util::line().chars().collect();

    for i in 0..s.len() {
        if i + 1 < s.len() && s[i] == s[i + 1] {
            println!("{} {}", i + 1, i + 2);
            return;
        }

        if i + 2 < s.len() && s[i] == s[i + 2] {
            println!("{} {}", i + 1, i + 3);
            return;
        }
    }

    println!("-1 -1");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
  using namespace std;
  typedef long long ll;
 string s1,s2,s3;
  int main()
  {
      int num1=0;
      int num2=0;
      cin>>s1;
     cin>>s2;
     for(int i=0;i<s1.size()+s2.size();i++)
     {
         if(i%2)
         {
             cout<<s2[num1++];
         }
         else
         {
           cout<<s1[num2++];
       }
}
}

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

using namespace std;

main(){
  long long data[4];
  for(int i=0;i<4;i++) data[i]=0;
  while(1){
    int tmp;
    char c;
    string type;
    if(scanf("%d%c", &tmp, &c)==EOF) break;
    cin >> type;
    if(type=="A"){
      data[0]++;
    }
    else if(type=="B"){
      data[1]++;
    }
    else if(type=="AB"){
      data[2]++;
    }
    else if(type=="O"){
      data[3]++;
    }
  }
  printf("%lld\n%lld\n%lld\n%lld\n", data[0], data[1], data[2], data[3]);
  return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
    int N=0;
    cin >> N;
    int L[N], count=0;
    for(int i=0; i<N; i++) cin >> L[i];
    sort(L, L+N);
    for(int i=0; i<N-1; i++) count += L[i];
    cout << (L[N-1]<count?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    string s;
    cin >> s;
    ll n = (ll)s.size();
    ll ans = INF, tmp = 0;
    rep(i, 0, n) {
        if (i % 2 == 0 && s[i] == '0') tmp++;
        if (i % 2 == 1 && s[i] == '1') tmp++;
    }
    chmin(ans, tmp);

    tmp = 0;
    rep(i, 0, n) {
        if (i % 2 == 0 && s[i] == '1') tmp++;
        if (i % 2 == 1 && s[i] == '0') tmp++;
    }
    chmin(ans, tmp);
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
} //三項演算子を使ったgcd(最大公約数)

int main()
{
    int K;
    cin >> K;
    ll ans = 0;
    for (int i = 1; i < K + 1; i++)
    {
        for (int j = 1; j < K + 1; j++)
        {
            for (int k = 1; k < K + 1; k++)
            {
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }

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


Measured memory_bytes: 3640
import heapq
n, m = map(int,input().split())
List = list(map(int,input().split()))

List = list(map(lambda x: x*(-1), List))  # 各要素を-1倍

heapq.heapify(List)
for i in range(m):
  max = heapq.heappop(List)
  heapq.heappush(List, int(max/2))  # 要素の挿入
print(sum(List)*(-1))

Measured memory_bytes: 14180