akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

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


     // #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
     // #endif
     ll t = 1;
     // cin>>t;
     while(t--){
          ll n;cin>>n;
          pair<ll,ll> e[n-1];
          ll ct[n];
          std::vector<ll> g[n];
          memset(ct,0,sizeof(ct));
          for(int i = 0;i<n-1;i++){
               cin>>e[i].first>>e[i].second;
               e[i].first--;e[i].second--;
               ct[e[i].first]++;ct[e[i].second]++;
               g[e[i].first].push_back(e[i].second);
               g[e[i].second].push_back(e[i].first);
          }
          ll ans = 0;
          for(int i = 0;i<n;i++){
               ans = max(ans,ct[i]);
          }
          map<pair<ll,ll>,ll> cl;
          ll cp[n];
          cp[0] = 0;
          ll visited[n];
          memset(visited,0,sizeof(visited));
          visited[0] = 1;
          queue<ll> q;
          q.push(0);
          while(!q.empty()){
               ll v = q.front();
               q.pop();
               ll col = 1;
               for(int i = 0;i<(int)g[v].size();i++){
                    if(visited[g[v][i]])continue;
                    if(col == cp[v])col++;
                    cp[g[v][i]] = cl[make_pair(g[v][i],v)] = cl[make_pair(v,g[v][i])] = col++;
                    visited[g[v][i]] = 1;
                    q.push(g[v][i]);
               }
          }
          cout<<ans<<'\n';
          for(int i = 0;i<n-1;i++){
               cout<<cl[e[i]]<<'\n';
          }




     }
}            


Measured memory_bytes: 23040
#include<stdio.h>

int main(void){
  int N;
  char S[1000];
  scanf("%d%s",&N,S);
  int x = 0,counter = 0,i;
  for(i=0;i<=N;i++){
    if(S[i] == 'I'){
      x ++;
    }
    if(S[i] == 'D'){
      x --;
    }
    if(x > counter){
      counter ++;
    }
  }
  printf("%d\n",counter);




}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct tapi {
    int k,l,r;
    bool operator<(const tapi& a) const {
        return k < a.k;
    }
};

int main() {
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        vector<tapi> a(n);
        for (int i = 0;i < n;++i) cin >> a[i].k >> a[i].l >> a[i].r;
        sort(a.begin(),a.end());
        int j = 0;
        ll ans = 0;
        priority_queue<P,vector<P>,greater<P>> l,r;
        for (int i = 1;i < n+1;++i) {
            if (!r.empty()) {
                ans += a[r.top().second].r;
                r.pop();
            }
            while (j < n && a[j].k <= i) {
                if (a[j].l <= a[j].r) r.push({a[j].l-a[j].r,j});
                j++;
            }
        }
        while (!r.empty()) {
            ans += a[r.top().second].l;
            r.pop();
        }
        reverse(a.begin(),a.end());
        j = 0;
        for (int i = n;i > 0;--i) {
            while (j < n && a[j].k >= i) {
                if (a[j].l > a[j].r) l.push({a[j].r-a[j].l,j});
                j++;
            }
            if (!l.empty()) {
                ans += a[l.top().second].l;
                l.pop();
            }
        }
        while (!l.empty()) {
            ans += a[l.top().second].r;
            l.pop();
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 6228
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
const int N=50+5;
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
    int n,k;
    cin>>n>>k;
    int l[N];
    for(int i=0;i<n;i++)
    	cin>>l[i];
    sort(l,l+n,cmp);
    int sum=0;
    for(int i=0;i<k;i++)
    	sum+=l[i];
    cout<<sum;
	return  0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
using namespace std;
using namespace __gnu_pbds;

int N;
const int MAX_N = 1100000;
int dp[MAX_N];
int n;
int i;
inline void solve(){
  IN(N);
  UP(i,1,MAX_N)dp[i]=N;
  dp[0]=0;
  REP(n,N){
    for(int pow6=1;pow6+n<=N;pow6*=6)dp[n+pow6]=min(dp[n+pow6],dp[n]+1);
    for(int pow9=1;pow9+n<=N;pow9*=9)dp[n+pow9]=min(dp[n+pow9],dp[n]+1);
  }
  OUT(dp[N]);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define F                 first
#define S                 second
#define C                 continue
#define G                 goto done
#define pb                push_back
#define pf                push_front
#define ppb               pop_back
#define ppf               pop_front
#define sz                size()
#define pi                acos(-1.0)
#define mod               1000000007
#define maxe              *max_element
#define mine              *min_element
#define min3(a,b,c)       min(a,min(b,c))
#define max3(a,b,c)       max(a,max(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define mem(a,b)          memset(a,b,sizeof(a))
#define all(a)            (a).begin(),(a).end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          ((a)*((b)/gcd(a,b)))
#define case(a)           cout<<"Case "<<(a)<<": "
#define point(a)          fixed<<setprecision(a)
#define get(a)            for(auto &x:a) cin>>x;
#define print(a)          for(auto x:a) cout<<x<<" "; cout<<endl;
#define uniq(a)           sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end())
#define big(a)            transform((a).begin(),(a).end(),(a).begin(),::toupper)
#define small(a)          transform((a).begin(),(a).end(),(a).begin(),::tolower)
#define ischar(a)         (('a'<=a&&a<='z')('A'<=a&&a<='Z'))
#define isvowel(a)        (a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
#define fast              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tc                int test; cin>>test; while(test--)
using namespace std;
int main()
{
    ll n; cin>>n; char c;
    stack<char>stk;
    while(n>0)
    {
        if(n%26==0)
        {
            c='`'+26; n--;
        }
        else c='`'+(n%26);
        stk.push(c);
        n=n/26;
    }
    while(stk.sz)
    {
        cout<<stk.top(); stk.pop();
    }
}
















Measured memory_bytes: 3648
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int m,n,o,i,j,k;
    float f,g,h;
    char c;
    //string a;
    //cin>>m;
    cin>>m>>n>>i;
    //cin>>f>>g;
    //cin>>c;
    if(n/m>i) cout<<i;
    else cout<<n/m;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
*A, = map(int,input().split())

C = {}
for a in A:
    C[a] = C.get(a,0) + 1

ans0 = 0
for c in C.values():
    ans0 += c*(c-1)//2

for a in A:
    n = C[a]
    ans = ans0 - n*(n-1)//2 + (n-1)*(n-2)//2
    print(ans)

Measured memory_bytes: 24996
def resolve():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))

    ans = 0
    for i in range(N - 1):
        res = min((X[i + 1] - X[i]) * A, B)
        ans += res
        
    print(ans)


if __name__ == "__main__":
    resolve()

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

using namespace std;

long long mod_pow(long long a,long long b){
	long long res=1,c=a;
	while(b){
		if(b&1) res=res*c;
		c=c*c;
		b/=2;
	}
	return res;
}
int main(){
	//ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<vector<int>> ad(n);
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		ad[a].push_back(b);
		ad[b].push_back(a);
	}
	int m;
	cin >> m;
	vector<pair<int,int>> q(m);
	for(int i=0;i<m;i++){
		cin >> q[i].first >> q[i].second;
		q[i].first--,q[i].second--;
	}
	vector<vector<vector<int>>> path(n,vector<vector<int>>(n));
	function<void(int,int,int)> dfs=[&](int cur,int par,int root){
		for(int ch:ad[cur]){
			if(ch==par) continue;
			path[root][ch]=path[root][cur];
			path[root][ch].push_back(ch);
			dfs(ch,cur,root);
		}
	};
	for(int i=0;i<n;i++){
		path[i][i].push_back(i);
		dfs(i,-1,i);
	}
	
	vector<vector<bool>> ta(n,vector<bool>(n));
	long long res=0;
	for(int i=1;i<(1<<m);i++){
		int kos=0;
		for(int j=0;j<m;j++){
			if((i>>j)&1){
				int from=q[j].first,to=q[j].second;
				
				for(int k=1;k<path[from][to].size();k++){
					int a=path[from][to][k-1],b=path[from][to][k];
					if(!ta[a][b]) kos++;
					ta[a][b]=true;
					ta[b][a]=true;
				}
			}
		}
		//cout << kos << "\n";
		
		long long te=mod_pow(2,n-1-kos);
		if(__builtin_popcount(i)&1) res+=te;
		else res-=te;
		for(int j=0;j<m;j++){
			if((i>>j)&1){
				int from=q[j].first,to=q[j].second;
				
				for(int k=1;k<path[from][to].size();k++){
					int a=path[from][to][k-1],b=path[from][to][k];
					ta[a][b]=false;
					ta[b][a]=false;
				}
			}
		}
	}
	res=mod_pow(2,n-1)-res;
	cout << res << "\n";
	return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

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

  while(i*i<=n){
    i++ ;
  }
  cout << (i-1)*(i-1) << endl ;
	
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000000
#define INF ((ll)1 << 60)

using namespace std;
using ll = long long;

ll A,B,C,D,N,M;
ll K;
ll h[MAX];
ll dp[MAX];


void solve() {
  for(ll i = 1; i < N; i++) {
    for(ll j = 1; j <= K; j++) {
      if(i-j >= 0) {
        dp[i] = min( dp[i], dp[i-j] + abs(h[i] - h[i-j]) );
      }
    }
  }
}




int main() {
  ios::sync_with_stdio(false);
  cin >> N >>K;

  for(ll i = 0; i < N; i++) {
    cin >> h[i];
    dp[i] = INF;
  }

  dp[0] = 0;
  solve();
  cout << dp[N-1];


  return 0;
}


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

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

    sort(a.begin(), a.end());
    cout << a.back() - a.front() << endl;
}

Measured memory_bytes: 888
N, M = map(int,input().split()) 

sunuke = [int(i+1) for i in range(N)]

sulist = []

for j in range(M):
    K = int(input())
    P = [list(map(int,input().split()))]
    for i in sunuke:
      if i in P[0]:
        sulist.append(i)
print(N-len(set(sulist)))

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define N 4005
#define int long long
#define P 1000000007
using namespace std;
int n,m,K,C[N][N];
signed main(){
	scanf("%lld%lld",&n,&K);
	C[0][0]=1;
	C[1][0]=C[1][1]=1;
	for(int i=2;i<N;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=((C[i-1][j-1]+C[i-1][j])%P+P)%P;
	}
	for(int i=1;i<=K;i++){
		int k=K;
		int ans=(C[k-1][i-1]*C[n-k+1][i]%P+P)%P;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 123776
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

map<ll,int> PrimeFact(ll N){
  map<ll,int> mp;

  while(1){
    bool isPrime = true;
    for(ll i = 2LL ; i*i <= N ; i++){
      if(N % i == 0LL){
        mp[i]++;
        N /= i;
        isPrime = false;
        break;
      }
    }
    if(isPrime){
      mp[N]++;
      break;
    }
  }

  return mp;
}

//================================================
ll pw(ll n, int cnt){
  ll ans = 1LL;
  for(int i=0;i<cnt;i++){
    ans *= n;
  }
  return ans;
}

int main(){
  ll N;
  cin >> N;
  map<ll,int> mp = PrimeFact(N);

  queue<ll> que;
  que.push(1LL);
  for(auto it = mp.begin(); it != mp.end(); it++){
    ll num = it->first;
    ll cnt = it->second;
    //cout << num << " " << cnt << endl;

    int sz = que.size();
    for(int i=0;i<sz;i++){
      ll t = que.front();
      que.pop();
      for(int j=0;j<=cnt;j++){
        que.push(t * pw(num, j));
      }
    }
  }

  /*while(que.size()){
    cout << que.front() << endl;
    que.pop();
  }*/

  ll ans = 0LL;
  while(que.size()){
    ll m, p;
    p = que.front();
    que.pop();
    m = N / p - 1;
    if(p < m){
      ans += m;
    }
  }

  //cout << pow(2LL, 12) << endl;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<string> vec(h);
  rep(i, h){
  	cin >> vec[i];
  }
  
  rep(i, w+2){
  	cout << "#";
  }
  cout << endl;
  
  rep(i, h){
  	cout << "#" << vec[i] << "#" << endl;
  }
  
  rep(i, w+2){
  	cout << "#";
  }
  cout << endl;
}

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

typedef long long ll;

int f(char c) {
	return (c == '(')?1:-1;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n; cin>>n;
	string s; cin>>s;
	
	int b = 0;
	int mi = 0;
	
	for (int i = 0; i < n; i++) {
		b += f(s[i]);
		mi = min(mi,b);
	}	
	
	if (mi < 0) {
		for (int i = 0; i < -mi; i++) {
			s = "("+s; b++;
		}
	}
	
	for (int i = 0; i < b; i++) {
		s += ")";
	}
	
	cout<<s<<endl;	
		
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int n = s.length();
  
  vector<int>check(26,0);
  
  for(int i=0;i<n;i++){
    check[s[i] - 'a']++;
  }
  
  bool ans = true;
  for(int i=0;i<26;i++){
    if(check[i] % 2 != 0)
      ans = false;
  }
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

  
  
  
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
 

int main(){
	
	int a,b,c,d;cin>>a>>b>>c>>d;
	cout <<max(0,min(b,d)-max(a,c))<<endl;	
}

//cout << ans << endl;

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();

        if (a == 0) {
            System.out.println(b / x + 1);
        } else {
            System.out.println(b / x - (a - 1) / x);
        }
    }
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		int ans = a + b;
		if (ans < (a - b))
			ans = a - b;
		if (ans < (a * b))
			ans = a * b;
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21204
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  int n;
  cin >> n;
  double ans = 2 * n * 3.1415926535;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
fun main(args:Array<String>) {
	val (n,m,x) = readLine()!!.split(" ").map{ it.toInt() }
	val a = readLine()!!.split(" ").map{ it.toInt() }
	println( Math.min(
			a.count{ it<x },
			a.count{ it>x }
	))
}

Measured memory_bytes: 35992
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n % 2 == 0:
        cnt = 0
        for i in range(1, 10 ** 20):
            md = pow(5, i) * 2
            if md <= n:
                cnt += n // md
            else:
                break
        print(cnt)
    else:
        print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
import sys

s = sys.stdin.readlines()
for i in s:
    a, op, b = i.split()
    a, b = int(a), int(b)
    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)

Measured memory_bytes: 7644
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
using namespace std;
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, temp;
  cin >> m >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++){
	cin >> d.at(i);
  }
  
  temp = d.at(n-1);
  for(int i=n-1; i>0; i--){
	d.at(i) -= d.at(i-1);
  }
  d.at(0) += (m - temp);
  
  int sum = accumulate(d.begin(), d.end(), 0);
  int ans = sum;
  
  for(int i=0; i<n; i++){
	ans = min(sum - d.at(i), ans);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  int x;
  cin >> x;
  vector<int> vec;
  vec.push_back(1);
  for (int i = 2;i <= 31;i++) {
    for (int j = 2; j <= 9;j++) {
      if (pow(i,j) <= x) vec.push_back(pow(i,j));
    }
  }
  sort(vec.begin(),vec.end());
  cout << vec.at(vec.size()-1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll s;
    cin >> s;
    ll l = 1000000000;
    if(s % l == 0){
        ll a = s / l;
        cout << "0 0 0 " << l << ' ' << a << " 0" << endl;
    }else{
        ll x = (s + l - 1) / l;
        cout << "0 0 1 1000000000 " << x << ' ' << l - s % l << endl;
    }
    
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
priority_queue<ll, vc<ll>, greater<ll>> fq;
priority_queue<ll> bq;
ll C[100000], fans[100005], bans[100005];

int main() {
    init();
    ll N;
    cin >> N;
    rep(i,N){
        ll a;
        cin >> a;
        fq.emplace(a);
        fans[0] += a;
    }
    rep(i, N) cin >> C[i];
    rep(i,N){
        ll a;
        cin >> a;
        bq.emplace(a);
        bans[0] += a;
    }

    rep(i,N){
        if(fq.top()<C[i]){
            fans[i + 1] += C[i] - fq.top();
            fq.pop();
            fq.emplace(C[i]);
        }
        fans[i + 1] += fans[i];
        if(bq.top()>C[N-i-1]){
            bans[i + 1] += C[N - i - 1] - bq.top();
            bq.pop();
            bq.emplace(C[N - i - 1]);
        }
        bans[i + 1] += bans[i];
    }

    ll ans = -INF;
    rep(i,N+1){
        chmax(ans, fans[i] - bans[N - i]);
    }
    cout << ans << endl;

}

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

struct block{

    ll start;
    ll end;
    ll cross;

};

int main() {
    string s;
    cin>>s;
    vector<block> b;
    ll lpos=0;
    ll cpos;
    bool m=true;
    for(ll i=1;i<s.size();i++){
        if(m){
            if(s[i]=='L'){
                cpos=i-1;
                m=false;
                if(i==s.size()-1){
                    block bbb;
                    bbb.start=lpos;
                    bbb.cross=cpos;
                    bbb.end=i;
                    b.push_back(bbb);
                }
            }
        }else{
            if(s[i]=='R'){
                block bbb;
                bbb.start=lpos;
                bbb.cross=cpos;
                bbb.end=i-1;
                b.push_back(bbb);
                m=true;
                lpos=i;
            }else{
                if(i==s.size()-1){
                    block bbb;
                    bbb.start=lpos;
                    bbb.cross=cpos;
                    bbb.end=i;
                    b.push_back(bbb);
                }
            }
        }
    }
    for(block a:b){
        //cout<<a.start<<":"<<a.cross<<":"<<a.end<<endl;
        for(ll i=0;i<a.cross-a.start;i++){
            cout<<"0 ";
        }
        ll sum=1;
        if((a.cross-a.start)%2==0){
            sum+=(a.cross-a.start)/2;
        }else{
            sum+=(a.cross-a.start-1)/2;
        }
        if((a.end-a.cross)%2==0){
            sum+=(a.end-a.cross)/2;
        }else{
            sum+=(a.end-a.cross-1)/2;
        }
        cout<<sum<<" "<<a.end-a.start+1-sum<<" ";
        for(ll i=0;i<a.end-a.cross-1;i++){
            cout<<"0 ";
        }
    }
    cout<<endl;
}


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

int main(void)
{
    int D;
    cin >> D;

    vector<int> c(27,0);

    for(int i = 1; i <= 26; ++i)
    {
        int tmp;
        cin >> tmp;

        c[i] = tmp;
    }

    int s[D+1][27] = {};

    for(int i = 1; i <= D; ++i)
    {
        for(int j = 1; j <= 26; ++j)
        {
            int tmp;
            cin >> tmp;
            s[i][j] = tmp;
        }
    }
    
    vector<int> t(D+1,0);

    for(int i = 1; i <= D; ++i)
    {
        int tmp;
        cin >> tmp;
        t[i] = tmp;
    }

    vector<int> lastd(27,0);
    int ans=0;

    for(int i = 1; i <= D; ++i)
    {
        ans += s[i][t[i]];
        lastd[t[i]] = i;
        for(int j = 1; j <= 26; ++j)
        {
            ans -= c[j]*(i - lastd[j]);
        }
        cout << ans << endl;
    }

    

    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int rode[210000];
int metro[210000];

int find(int child,bool which){
	
	if(which){
		if(rode[child]==child){
			return child;
		}else{
			int grand=find(rode[child],which);
			rode[child]=grand;
			return grand;
		}
		
	}else{
		if(metro[child]==child){
			return child;
		}else{
			int grand=find(metro[child],which);
			metro[child]=grand;
			return grand;
		}
		
	}
	
}

void unit(int x,int y,bool which){
	
	int xpar=find(x,which);
	int ypar=find(y,which);
	
	if(xpar==ypar){return;}
	if(which){
		rode[xpar]=ypar;
	}else{
		metro[xpar]=ypar;
	}
	
}

int main() {
	
	int N,K,L;
	cin>>N>>K>>L;
	fx(N){
		rode[x+1]=x+1;
		metro[x+1]=x+1;
	}
	fx(K){
		int a,b;
		cin>>a>>b;
		unit(a,b,true);
	}
	fx(L){
		int a,b;
		cin>>a>>b;
		unit(a,b,false);
	}
	map<pair<int,int>,int> Z;
	fx(N){
		Z[make_pair(find(x+1,true),find(x+1,false))]++;
	}
	fx(N){
		cout<<Z[make_pair(find(x+1,true),find(x+1,false))];
		if(x!=N-1){
			cout<<' ';
		}else{
			cout<<endl;
		}
	}
	
}

Measured memory_bytes: 13568
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int x,y,z,tmp;

  cin >> x >> y >> z;

  tmp = x;
  x = y;
  y = tmp;
  tmp = x;
  x = z;
  z = tmp;

  cout << x << " " << y << " "  << z << endl;
  

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MAX 100

using namespace std;

int N, ans;
int A[MAX], B[MAX], C[MAX];

int main() {
	cin >> N;
	for(int i = 1; i <= N; ++i) cin >> A[i];
	for(int i = 1; i <= N; ++i) cin >> B[i];
	for(int i = 1; i < N; ++i) cin >> C[i];
	for(int i = 1; i <= N; ++i)	ans += B[A[i]];
	for(int i = 1; i < N; ++i) if(A[i + 1] == A[i] + 1) ans += C[A[i]];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int x[105];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x[i]);
    }
    long long minn=999999999;
    for(int i=1;i<=100;i++){
        long long sum=0;
        for(int j=1;j<=n;j++){
            sum+=(x[j]-i)*(x[j]-i);
        }
        minn=min(minn,sum);
    }
    printf("%d",minn);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int v[10000009];
int main()
{
    int n;
    cin>>n;

    ll ans=0;
    map<ll,ll>bas;
    for (int i=1; i<=n; ++i)
    {
        cin>>v[i];
        if (bas[i-v[i]]>0)
            ans+=bas[i-v[i]];

        bas[i+v[i]]++;
    }
    cout<<ans;









}


Measured memory_bytes: 27128
A, B, C = map(int, input().split())
num = []
num.append(A)
num.append(B)
num.append(C)
answer = 0
# print(num)
if (num[0] % 2 == 0 and num[1] % 2 == 0 and num[2] % 2 == 0) or (num[0] % 2 != 0 and num[1] % 2 != 0 and num[2] % 2 != 0):
    pass
elif (num[0] % 2 == 0 and num[1] % 2 == 0) or (num[0] % 2 != 0 and num[1] % 2 != 0):
    num[0] += 1
    num[1] += 1
    answer += 1
elif (num[2] % 2 == 0 and num[1] % 2 == 0) or (num[2] % 2 != 0 and num[1] % 2 != 0):
    num[2] += 1
    num[1] += 1
    answer += 1
elif (num[0] % 2 == 0 and num[2] % 2 == 0) or (num[0] % 2 != 0 and num[2] % 2 != 0):
    num[0] += 1
    num[2] += 1
    answer += 1
# print(answer)
num.sort()
# print(num)
answer += (num[2] - num[0]) // 2
answer += (num[2] - num[1]) // 2
# print(A, num[1], C)
print(answer)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<math.h>
#include<iomanip>
using namespace std;

int cnt = 0;

void merge(int *A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;

  int *L = new int[n1 + 1];
  int *R = new int[n2 + 1];

  for(int i = 0; i < n1; i++){
    L[i] = A[left + i];
  }

  for(int i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }

  L[n1] = 1000000000;
  R[n2] = 1000000000;

  int i = 0, j = 0;

  for(int k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
    cnt++;
  }

  delete[] L;
  delete[] R;
}


void mergesort(int *A, int left, int right){
  if(left + 1 < right){
    int mid = (left + right) / 2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(){

  int n;

  cin >> n;
  int *A = new int[n];

  for(int i = 0; i < n; i++){
    cin >> A[i];
  }


  mergesort(A, 0, n);

  for(int i = 0; i < n - 1; i++){
    cout << A[i] << ' ';
  }

  cout << A[n - 1] << endl << cnt << endl;


  delete[] A;
  return 0;
}



Measured memory_bytes: 6796
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

void solve(long long N){
    vll R(N+1, 0);
    REP(i, N) R[i+1] = R[i] + i+1;
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        ll t = N/i;
        ans += i * R[t];
    }
    cout<<ans<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

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

	ll n, k = 2;
	cin >> n;
	std::vector<int> h(n);
	std::vector<int> dp(n, INT_MAX);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	for (int i = 0; i <= k; ++i) {
		dp[i] = abs(h[0] - h[i]);
	}

	for (int i = k + 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {

			dp[i] = min( dp[i] , dp[i - j] + abs( h[i] - h[i - j] ) );
		}
	}
	cout << dp[n - 1];

	return 0;
}

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

class Cube {
public:
  int f[6];
  Cube(void){}
  void roll_z(void) { 
    roll(1,2,4,3);
  }
  void roll_y(void) { 
    roll(0,2,5,3);
  }
  void roll_x(void) {
    roll(0,1,5,4);
  }
  void roll(int i,int j,int k,int l) {
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
};

int getRight(Cube c1,int f1,int f2) {
  for (int i=0;i<6;i++) {
    for (int j=0;j<4;j++) {
      if (c1.f[0]==f1 && c1.f[1]==f2) {
        return c1.f[2];
      }
      c1.roll_z();
    }
    if (i%2==0) {
      c1.roll_y();
    }  else {
      c1.roll_x();
    }
  }
  return -1;
}

int main(void) {
  Cube c;
  int f1,f2;
  for (int i=0; i<6; i++) {
    cin >> c.f[i];
  }
  int q;
  cin >> q;
  for (int i=0; i<q; i++) {
    cin >> f1 >> f2;
    cout << getRight(c,f1,f2) << endl;
  }
  return 0;
}

Measured memory_bytes: 3056
#include<stdio.h>
int main(void) {
	int x[2999], y[2999], i, tmp;
	i = 0;
	while (1) {
		i = i + 1;
		scanf("%d %d", &x[i], &y[i]);
		if (x[i] == 0) {
			if (y[i] == 0) {
				break;
			}
		}
	}
	i = 0;
	while (1) {
		i = i + 1;
		if (x[i] == 0) {
			if (y[i] == 0) {
				break;
			}
		}
		if (x[i] > y[i]) {
			tmp = x[i];
			x[i] = y[i];
			y[i] = tmp;
		}
		printf("%d %d\n", x[i], y[i]);
	}
	return 0;
}

Measured memory_bytes: 620
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

long long int h[100100],dp[100100],n;

long long int f(int i);

int main()
{
    cin>>n;
    for(int i = 0; i<n; i++)
    {
        cin>>h[i];
        dp[i] = -1;
    }

    cout<<f(0)<<endl;

}

long long int f(int i)
{
    if(dp[i] != -1)
    {
        return dp[i];
    }

    if(i == n-2)
    {
        dp[i] = abs(h[i+1] - h[i]);
    }
    else if(i == n-1)
    {
        dp[i] = 0;
    }
    else
    {
        dp[i] = min(abs(h[i+1] - h[i]) + f(i+1), abs(h[i+2] - h[i]) + f(i+2));
    }
    
    return dp[i];
}   


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

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

    ll geta = 1e9;
    atcoder::mcf_graph<ll, ll> graph(N*N*2+N*2+2);
    vector<int> edgenum(N*N);
    int start = N*N*2+N*2, goal = start+1;
    for (int i = 0; i < N; i++) {
        graph.add_edge(start, N*N*2+i, K, 0);
        graph.add_edge(N*N*2+i, goal, K, geta);
        graph.add_edge(N*N*2+N+i, goal, K, 0);
    }
    for (int i = 0; i < N*N; i++) {
        int x = i/N, y = i%N;
        edgenum[i] = graph.add_edge(i, i+N*N, 1, geta-A[i]);
        graph.add_edge(N*N*2+x, i, 1, 0);
        graph.add_edge(i+N*N, N*N*2+N+y, 1, 0);
    }
    auto flow = graph.flow(start, goal);

    vector<char> ansgrid(N*N, '.');
    ll ans = 0;
    for (int i = 0; i < N*N; i++) {
        auto e = graph.get_edge(edgenum[i]);
        if (e.flow == 1) {
            ansgrid[i] = 'X';
            ans += A[i];
        }
    } 
    cout << ans << endl;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << ansgrid[i*N+j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 4544
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int N;cin>>N;
  if(N<=999){
    cout<<"ABC"<<endl;
  }else{
    cout<<"ABD"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
//  Copyright 2019 Nikita Golikov

#include <iostream>
#include <vector>
#include <set>

int main() {
  std::size_t n, d;
  std::cin >> n >> d;
  std::vector<std::vector<int>> p(n, std::vector<int>(d));
  for (auto& v : p) {
    for (auto& x : v) {
      std::cin >> x;
    }
  }
  std::set<int> squares;
  auto sq = [](int x) {
    return x * x;
  };
  for (int i = 0; i != 200; ++i) {
    squares.insert(sq(i));
  }
  unsigned ans = 0;
  for (size_t i = 0; i != n; ++i) {
    for (size_t j = i + 1; j != n; ++j) {
      int dist = 0;
      for (size_t k = 0; k != d; ++k) {
        dist += sq(p[j][k] - p[i][k]);
      }
      ans += squares.count(dist);
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


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

string n;int k;
vector<int> vec;
int dp[200][2][10];
signed main(){
  cin>>n>>k;
  rep(i,n.length()){
    vec.push_back((int)(n[i]-'0'));
  }
  dp[0][1][0] = 1LL;
  rep(i,n.length()){
    rep(j,k+1){
      (vec[i] == 0 ? dp[i+1][1][j] : dp[i+1][1][j+1]) += dp[i][1][j];
      dp[i+1][0][j+1] += dp[i][0][j]*9 + dp[i][1][j]*max(0LL,vec[i]-1);
      dp[i+1][0][j] += dp[i][1][j]*(vec[i] > 0) + dp[i][0][j];
    }
  }
  cout << dp[n.length()][1][k] + dp[n.length()][0][k] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ 
	long long h,n;
	cin>>h>>n;
	long long a[h+1],b[n+1],c[n+1];
	a[0]=0;
	for(int i=1;i<=n;i++)
	{ 
		cin>>b[i]>>c[i];
	} 
	for(int i=1;i<=h;i++)
	{ 
		a[i]=210000000;
		for(int j=1;j<=n;j++)
		{ 
			if(b[j]>=i)
			{ 
				a[i]=min(a[i],c[j]);
			} 
			else if(a[i-b[j]]+c[j]<=a[i])
			{ 
				a[i]=a[i-b[j]]+c[j];
			} 
		} 
	} 
	cout<<a[h];
	return 0;
} 

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	int a,b,c;

	cin >> a >> b >> c;

	if ((a == 1 && b == 1) || c == 1) {
		cout << "Open" << endl;
	} else {
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Red_or_Not(void) {

	int a; string s; cin >> a >> s;

	cout << (a >= 3200 ? s : "red") << flush;
	return;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int32_t main(void){
	IOS;
	in2(n, k);
	int arr[n+1];
	rep(i, 1, n+1) cin>>arr[i];
	bool vis[n+1];
	mem(vis);
	int i = 1;
	vi v;
	while(true)
	{
		if(vis[i] == true) break;
		else
		{
			vis[i] = true;
			v.pb(arr[i]);
			i = arr[i];	
		}
	}
	
	vi cycle;
	bool vis1[n+1];
	mem(vis1);
	while(true)
	{
		if(vis1[i] == true) break;
		else
		{
			vis1[i] = true;
			cycle.pb(i);
			i = arr[i];
		}
	}
	int total = v.size();
	int final = cycle.size();
	int akele = total-final;
	if(k <= total) cout<<v[k-1]<<endl;
	else
	{
		k -= akele;
		k = k%final;
		cout<<cycle[k]<<endl;
	}	
}

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

int main(){
	string s; cin>>s;
	int k=s.size();
	int cnt=0;
	rep(i,k){
		if(s[i]=='x') cnt++;
	}
	if(k>=8&&cnt>7) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

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

int main(){
  int k, s, n;
  cin >> k >> s;

  if(s < k){
    cout << (s+2)*(s+1)/2 << endl;
  }else if(s > 2*k){
    cout << (3*k-s+1)*(3*k-s+2)/2 << endl;
  }else{
    cout << (k+1)*(k+1) - ((2*k-s)*(2*k-s+1) + (s-k)*(s-k+1))/2 << endl;
  }
}


Measured memory_bytes: 256
H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(list(input()))

row = [False for i in range(H)]
col = [False for i in range(W)]

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i] == True:
        for j in range(W):
            if col[j] == True:
                print(a[i][j],end="")
        print()


Measured memory_bytes: 4596
N, A, B, C = map(int,input().split())
l = [int(input()) for _ in range(N)]

def dfs(x, a, b, c):
  if x == N:
    if min(a, b, c) > 0:
      return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
      return float("inf")
  
  ret0 = dfs(x+1, a, b, c)
  ret1 = dfs(x+1, a+l[x], b, c)+10
  ret2 = dfs(x+1, a, b+l[x], c)+10
  ret3 = dfs(x+1, a, b, c+l[x])+10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import java.util.*
import kotlin.Comparator

fun main(args: Array<String>) {
    val (n, m) = readIntList()
    val job = Array(100001) { mutableListOf<Int>() }

    repeat(n) {
        val (a, b) = readIntList()
        job[a].add(b)
    }

    val queue = PriorityQueue<Int> { a, b -> b.compareTo(a) }
    var ans = 0
    for (i in 1..m) {
        queue.addAll(job[i])
        if (queue.isNotEmpty()) {
            ans += queue.remove()
        }
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 70368
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

const int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int solve(){
    int n,x;
    cin >> n >> x;
    int ans = 0;
    if(n==0 && x==0) return 1;
    for(int i = 1; i<n-1; i++){
        for(int j = i+1; j<n; j++){
            if(j<x-i-j && x-i-j<=n){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

int main(){
    while(true){
        int flag = solve();
        if(flag) break;
    }
}


Measured memory_bytes: 3116