akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

//0-index ?????????????????¶?????°?????????(????????????) verified AOJ DSL_2_G, (((CODEFESTIVAL2015-D)))
template<class T>
class lazySegmentTree{
private:
    vector<T> dat;
    vector<T> lazy;
    int _size;  //the number of leaves
    T _init;
    
public:
    //    lazySegmentTree( vector<T> vec, T init = numeric_limits<T>::max() ): _init(init){
    //        int size = vec.size();
    //        if(size==0)return ;
    //
    //        _size = 1;
    //        while(_size<size)_size*=2;
    //        dat.resize(_size*2);
    //        rep(i,vec.size())dat[i+_size] = vec[i];
    //        lazy.resize(_size*2,_init);
    //    }
    
    lazySegmentTree( int size, T init = numeric_limits<T>::max() ): _init(init){
        if(size==0)return ;
        
        _size = 1;
        while(_size<size)_size*=2;
        
        dat.resize(_size*2,_init);
        lazy.resize(_size*2,_init);
    }
    
    
    void eval(int num, int l, int r){
        if(lazy[num]==0) return ;
        dat[num] += lazy[num];
        
        if(r-l>1){  //?????§?????????
            lazy[num*2] += lazy[num]/2;
            lazy[num*2+1] += lazy[num]/2;
        }
        lazy[num] = 0;
    }
    
    
    
    T update(int s, int t, T x, int num=1, int l=0, int r=-1){
        if(r==-1)r =_size;
        
        eval(num,l,r);
        
        if(r<=s || t<=l) return _init ;   //????±??????????
        if(s<=l && r<=t){
            lazy[num] += x * (r-l);
            eval(num,l,r);
        }
        else{
            update(s, t, x, num*2, l, (l+r)/2);
            update(s, t, x, num*2+1, (l+r)/2, r);
            dat[num] = dat[num*2] + dat[num*2+1];
        }
        return dat[num];
    }
    
    
    T find(int s, int t, int num=1, int l=0, int r=-1){
        if(r==-1)r = _size;
        
        eval(num,l,r);
        
        
        if(r<=s || t<=l) return _init;  //????±??????????
        if(s<=l && r<=t) return dat[num];
        else{
            return find(s, t, num*2, l, (l+r)/2) + find(s, t, num*2+1, (l+r)/2, r);
        }
    }
    
    int size(){ return _size; }
};




signed main(){
    int n,q;
    cin>>n>>q;
    
    lazySegmentTree<int> seg(n, 0);
    
    rep(i,q){
        int type,s,t,x;
        cin>>type;
        if(type==0){
            cin>>s>>t>>x;
            s--;
            seg.update(s,t,x);
        }else{
            cin>>s>>t;
            s--;
            cout<<seg.find(s,t)<<endl;
        }
    }
}

Measured memory_bytes: 7024
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    cin >> n >> d >> x;

    vector<int> v(n);

    for(int i=0; i<n; i++) cin >> v[i];

    for(int i=0; i<n; i++){
        int num = 0, m = num * v[i] + 1;
        while(m <= d){
            cnt++;
            num++;
            m = num * v[i] + 1;
        }
    }

    cout << cnt + x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 55
using namespace std;
typedef long long ll;
ll n, k, ans, a[N][N], dp[N][N][100], es[N], yen[N];

ll f(ll x, ll y, ll d){
	ll &r = dp[x][y][d];
	if(r != -1)
		return r;
	if(d == 0)
		return r = a[x][y];
	r = 0;
	for(ll i = 1; i <= n; i++)
		r = (r + f(x, i, d - 1)*f(i, y, d - 1)%mod )%mod;
	return r;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	memset(dp, -1, sizeof dp);
	scanf("%lld %lld",&n ,&k);
	for(ll i = 1; i <= n; i++)
		for(ll j = 1; j <= n; j++)
			scanf("%lld",&a[i][j]);
	for(ll i = 1; i <= n; i++)
		es[i] = 1;
	for(ll i = 60; i >= 0; i--)
		if((1ll<<i) <= k){
			k -= (1ll<<i);
			for(ll x = 1; x <= n; x++)
				for(ll y = 1; y <= n; y++)
					yen[y] = (yen[y] + es[x]*f(x, y, i)%mod )%mod;
			for(ll i = 1; i <= n; i++){
				es[i] = yen[i];
				yen[i] = 0;
			}
		}
	for(ll i = 1; i <= n; i++)
		ans = (ans + es[i])%mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2688
a,b,c,d=map(int,input().split())
s='';t='';p=''
if c-a>=0:
    s+='R'*(c-a);t+='L'*(c-a)
if c-a<0:
    s+='L'*(a-c);t+='R'*(a-c)
if d-b>=0:
    s+='U'*(d-b);t+='D'*(d-b+1)+s[:(c-a)]+s[0]+s[c-a:]+s[-1]
    p+=t[0]+t[-1]+t[0]*(c-a+1)+'D'*(d-b+1)+s[0]
if d-b<0:
    s+='D'*(b-d);t+='U'*(b-d+1)+s[:(c-a)]+s[0]+s[c-a:]+s[-1]
    p+=t[0]+t[-1]+t[0]*(c-a+1)+'U'*(d-b+1)+s[0]
print(s+t+p)



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

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0; i<N; i++) cin >> S.at(i);
  sort(S.begin(),S.end());
  for(int i=1; i<N; i++) S.at(0)+=S.at(i);
  cout << S.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;ll sum[N],X[N];
ll a[N];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    sum[1]=X[1]=a[1];
    for(int i=2;i<=n;i++) sum[i]=sum[i-1]+a[i],X[i]=X[i-1]^a[i];
    ll ans=0;int l=1;
    for(int r=1;r<=n;r++){
        for(;sum[r]-sum[l-1]!=(X[r]^X[l-1]);l++);
        ans+=(r-l+1);
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;           \
    cin >> name;
#define VL(name, num) \
    vl name(num);           \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

int main() { cin.sync_with_stdio(0);
    LL(N) LL(M);

    vvl adj(N);

    FOR(i, 0, M) {
        LL(A) LL(B);
        A--, B--;

        adj[A].pb(B);
        adj[B].pb(A);
    }

    vl pred(N, -1);
    pred[0] = 0;

    queue<ll> todo;
    todo.push(0);

    while (sz(todo)) {
        ll cur = todo.front();
        todo.pop();

        for (ll nei : adj[cur]) {
            if (pred[nei] != -1) {
                continue;
            }

            pred[nei] = cur;
            todo.push(nei);
        }
    }

    for (ll p : pred) {
        if (p == -1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    FOR(i, 1, N) {
        cout << (pred[i] + 1) << endl;
    }
}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 12804
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
using namespace std;
typedef long long int ll;


int main() {

	int n;
	int T = 0;
	int ans = -1;

	cin >> n >> T;

	for (int i = 0; i < n; i++) {
		int cost, time;
		cin >> cost >> time;

		if (T >= time) {
			if (ans==-1) { ans = cost; }
			ans = min(ans, cost);
		}
	}

	if (ans == -1) {
		cout << "TLE" << endl;
	}else{
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    int a[6];
    int i,q,j,tmp,top,fro;
    for(i = 0;i<6;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        j=0;
        scanf("%d%d",&top,&fro);
        while(top!=a[0]&&j<4){
            tmp = a[0];
            a[0] = a[4];
            a[4] = a[5];
            a[5] = a[1];
            a[1] = tmp;
            j++;
        }
        if(top!=a[0]){
            while(top!=a[0]){
                tmp = a[0];
                a[0] = a[2];
                a[2] = a[5];
                a[5] = a[3];
                a[3] = tmp;
            }
        }
        while(fro!=a[1]){
            tmp = a[1];
            a[1] = a[2];
            a[2] = a[4];
            a[4] = a[3];
            a[3] = tmp;
        }
        printf("%d\n",a[2]);
    }
    return 0;
}

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

int main(){
    

        int n;
        cin>>n;
        vector<int> dp(3);
        
        for(int d=0;d<n;d++){
           vector<int> newdp(3,0);//assuming new cost INT_MAX
           vector<int> arr(3,0);
           for(int i=0;i<3;i++){
              cin>>arr[i];
           }   
           for(int i=0;i<3;i++){
               for(int j=0;j<3;j++){
                   if(i!=j){
                      newdp[j]=max(newdp[j],dp[i]+arr[j]);
                   }
               }
               
           }
           
           
           dp=newdp;
          
        }
        cout<<max(dp[0],max(dp[1],dp[2]))<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
 
#define N 120
int g[N][N];
 
int main(){
	int h, w, n;
	cin>>h>>w>>n;
	int p = 0;
	rep(i, n){
		int a;
		cin>>a;
		while(a--){
			g[p/w][p%w] = i+1;
			p++;
		}
	}
	rep(i, (h+1)/2) reverse(g[i*2], g[i*2]+w);
	rep(i, h){
		rep(j, w) cout<<g[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; cin >> n;
  double p[n];
  for(int i=0;i<n;i++)
    cin >> p[i];
  double m[n][n+1] = {0};
  for(int i=0;i<n;i++) {
    for(int j=0;j<=n;j++)
      m[i][j] = 0;
  }
  m[n-1][0] = 1-p[n-1];
  m[n-1][1] = p[n-1];
  for(int coin=n-2;coin>=0;coin--) {
    for(int heads=0;heads<=n;heads++) {
      if (heads == 0)
        m[coin][heads] = (1-p[coin]) * m[coin+1][0];
      else {
        m[coin][heads] = p[coin]*m[coin+1][heads-1] + (1-p[coin])*m[coin+1][heads];
      }
    }
  }
  // for(int i=0;i<n;i++) {
  //   for(int j=0;j<=n;j++) {
  //     cerr << m[i][j] << ' ';
  //   }
  //   cerr << '\n';
  // }
  double res = 0;
  for(int heads=n/2+1;heads<=n;heads++) {
    res += m[0][heads];
  }
  cout << setprecision(10) << res;
  return 0;
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
const int MX=(1<<20);
int a  = 0 , b = 0;
int main(){
    int x;
    cin>>x;
    if(x == 0){
        puts("0");
        return 0;
    }
    x = abs(x);
    for(int j = 1 ; ; j++){
        if(j * (j+1)/2 >= x){
            cout<<j<<endl;
            return 0;
        }
    }
}


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

int main(){
   while(true){
       int m,f,r;
       cin >> m >> f >> r;
       string ans;
       int total = m+f;
       if(m == -1 && f == -1 && r == -1)break;
       if(m == -1 || f == -1) ans = "F";
       else if (total >= 80) ans ="A";
       else if( 80 > total && total >= 65) ans ="B";
       else if( 65 > total && total >= 50) ans = "C";
       else if( 50 > total && total >= 30){
           ans = "D";
           if(r>=50) ans = "C";
       }else if(30>total) ans ="F";
       cout << ans << endl;
   } 
   
return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int dist[1000][1000];
int hp[] = {-1,1,0,0};
int wp[] = {0,0,-1,1};
void Calc(){
	queue<pair<int,int>> que;
	int H = rei();
	int W = rei();
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			dist[i][j] = 100000;
		}
	}
	for(int i=0;i<H;i++){
		string S = res();
		for(int j=0;j<W;j++){
			if(S[j] == '#'){
				dist[i][j] = 0;
				que.push({i,j});
			}
		}
	}
	int ans = 0;
	while(!que.empty()){
		int vh = que.front().first;
		int vw = que.front().second;
		que.pop();
		for(int i=0;i<4;i++){
			int th = vh+hp[i];
			int tw = vw+wp[i];
			if(th >= 0 && th < H && tw >= 0 && tw < W){
				if(dist[th][tw] == 100000){
					dist[th][tw] = dist[vh][vw] + 1;
					ans = max(ans,dist[th][tw]);
					que.push({th,tw});
				}
			}
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 12432
#include<bits/stdc++.h>
#define AwD 1000000007
#define int long long
using namespace std;
int n, a[100005];
int p[100005], f[100005], ans = 0, tmp = 0;
int Mi(int x, int n) {
	int base = x, tmp = 1;
	while (n) {
		if (n & 1) tmp = base * tmp % AwD;
		base = base * base % AwD; n >>= 1;
	}
	return tmp;
}
int calc(int n, int k) {
	if (k > n || k < 0) return 0;
	return (p[n] * Mi(p[k], AwD - 2) % AwD) * Mi(p[n - k], AwD - 2) % AwD;
}
main() {
	cin >> n; p[0] = 1;
	for (int i = 0; i <= n; i ++) cin >> a[i];
	for (int i = 1; i <= n + 1; i ++) p[i] = p[i - 1] * i % AwD;
	int d = -1;
	for (int i = 0; i <= n; i ++) f[i] = -1;
	for (int i = 0; i <= n; i ++) {
		if (f[a[i]] != -1) d = i - f[a[i]] + 1;
		f[a[i]] = i;
	}
	for (int i = 1; i <= n + 1; i ++) {
		cout << (calc(n + 1, i) - calc(n + 1 - d, i - 1) + AwD) % AwD << endl;
	}
	return 0; 
}


Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
	bool operator<(const B& b) const { return cost < b.cost; }
	bool operator>(const B& b) const { return cost > b.cost; }
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s;
signed main() {
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad\n";
	}
	else {
		cout << "Good\n";
	}
}

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

#define f0(i,a,b) for(int i= a; i<= b; ++i)
#define f1(i,a,b) for(int i= a; i>= b; --i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define X first
#define Y second
using namespace std;
const long long base=1e9+7;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
const long long MAX_N = 100011;
ll dp[MAX_N];
int Solves() {
    ll n, k;
    cin >> n >> k;
    ll h[n + 1];
    for(int i = 1; i <= n;i++) {
        cin >> h[i];
        dp[i] = base*1000;
    }
    dp[1] = 0;
    for(int i = 2; i <= k;i++){
        for(int j = 1; j < i; j++) {
            dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i]);
        }
    }
   // DEBUG(dp[k]);
    for(int i = k + 1; i <= n;i++) {
        for(int j = 1; j <= k; j++) {
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
        }
      //  DEBUG(dp[i]);
    }
    cout << dp[n];
}

int main() {
    Solves();
}


Measured memory_bytes: 1792
DIV = 100000
while 1:
    n, m, s = map(int, raw_input().split())
    if n == 0: break
    dp = [[0]*(s+1) for i in range(n*n+1)]
    dp[0][0] = 1
    for i in range(1, n*n+1):
        for j in range(s+1):
            if j - i >= 0: dp[i][j] = (dp[i][j] + dp[i-1][j-i] + dp[i][j-i]) % DIV
            if j - m - 1 >= 0: dp[i][j] = (dp[i][j] - dp[i-1][j-m-1] + DIV) % DIV
    print dp[n*n][s]

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (a + b <= k) {
        cout << "0 0" << endl;
    } else if (a > k) {
        cout << a - k << " " << b << endl;
    } else {
        cout << 0 << ' ' << a + b - k << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int ans = 0;
    for(int i = 0; i<n; ++i)
    {
     int t;
     cin>>t;
     ans+= (t-1);
    }
    cout<<ans<<endl;
}


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

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

main(){
  int n,i,a[N];
  scanf("%d",&n);
  for( i = 1 ; i < n+1 ; i++ ){
    scanf("%d",&a[i]);
  }
  for(i=1; i<=n; i++){
    printf("node %d: key = %d, ",i,a[i]);

    if(i > 1){
      printf("parent key = %d, ",a[parent(i)]);
    }

    if(left(i) <= n){
      printf("left key = %d, ",a[left(i)]);
    }

    if(right(i) <= n){
      printf("right key = %d, ",a[right(i)]);
    }

    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,0,s.size()){
        if(s[i] == '1') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
void swap(int*, int*);

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) swap(&a, &b);
	if (b > c) swap(&b, &c);
	if (a > b) swap(&a, &b);
	cout << a << " " << b << " " << c << endl;
}

void swap(int* high, int* low){
	int tmp = *low;
	*low = *high;
	*high = tmp;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int f(int a){
    int cnt = 0;
    for(int i = 1;; i++){
        if(i * (i + 1) / 2 > a) break;
        cnt ++;
    }
    return cnt;
}
int main(){
    ll n;
    cin >> n;
    map<int, int> mp;
    for(int i = 2; i <= sqrt(n); i++){
        int cnt = 0;
        while(n % i == 0){
            cnt++;
            n = n / i;
        }
        if(cnt != 0) mp.insert(make_pair(i, cnt));
    }
    if(n != 1)mp[(int)n] = 1;
    int ans = 0;
    for(auto itr : mp){
        //cout << itr.first << " " << itr.second << "\n";
        ans += f(itr.second);
    }
    cout << ans;
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T> &A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

i64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

class UnionFind {
 public:
  vector<u64> Par;
  vector<u64> sz;

  UnionFind(u64 n);
  u64 root(u64 x);
  bool same(u64 x, u64 y);
  void unite(u64 x, u64 y);
  u64 size(u64 x);
};

UnionFind::UnionFind(u64 n) {
  Par.resize(n);
  sz.assign(n, 1);
  for (u64 i = 0; i < n; ++i) Par[i] = i;
}

u64 UnionFind::root(u64 x) {
  if (Par[x] == x) {
    return x;
  } else {
    return Par[x] = root(Par[x]);
  }
}

bool UnionFind::same(u64 x, u64 y) { return root(x) == root(y); }

u64 UnionFind::size(u64 x) { return sz[root(x)]; }

void UnionFind::unite(u64 x, u64 y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  Par[y] = x;
}

bool isPrime(u32 n) {
  if (n == 2) return true;
  if (n % 2) return false;
  for (u32 i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  cout << setprecision(18);

  string s;
  cin >> s;

  if (*(s.end() - 1) == 's') {
    cout << s + "es" << endl;
  } else {
    cout << s + 's' << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


vll v;
ll lim=3234566667;

void make(ll i){
    queue<ll> que;
    que.push(i);
    while(!que.empty()){
        ll A=que.front();
        v.pb(A);
        ll a=A%10;
        que.pop();
        if(a==0){
            ll b=A*10+0;
            ll c=A*10+1;
            if(b<=lim) que.push(b);
            if(c<=lim) que.push(c);
        }
        else if(a==9){
            ll b=A*10+8;
            ll c=A*10+9;
            if(b<=lim) que.push(b);
            if(c<=lim) que.push(c);
        }
        else{
            ll b=A*10+a-1;
            ll c=A*10+a;
            ll d=A*10+a+1;
            if(b<=lim) que.push(b);
            if(c<=lim) que.push(c);
            if(d<=lim) que.push(d);
        }
    }

}




void solve() {
    
    ll k;
    cin>>k;
    rep2(i,1,10){
        make(i);
    }
    sort(v.begin(),v.end());
    cout<<v[k-1]<<endl;
    



}





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


    solve(); 


    return 0;
}


Measured memory_bytes: 4316
#include<bits/stdc++.h>
#include<string>
#include<map>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define vii         vector<pair<ll,ll> >
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define rep1(i,a,b) for(ll i=a;i<= b;i++)
#define PI          3.14159
#define MAX         100000001
#define fast_io      ios_base::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
#define scan(var)    scanf("%lld",&var)
#define print(var)   printf("%lld\n", var);
#define BLOCK 317
#define double       long double
#define mod          998244353
using namespace std;
vector<ll> adj[100005];
ll dp[100005];
ll indegree[100005];
void dfs(ll u)
{
  rep(i,0,adj[u].size())
  {
    ll v = adj[u][i];
    dp[v] = max(dp[v],dp[u] + 1);
    indegree[v]--;
    if(indegree[v] == 0)
    {
      dfs(v);
    }
  }
  return;
}
int main()
{
  fast_io
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  rep(i,0,m)
  {
    ll u,v;
    cin >> u >> v;
    adj[u].pb(v);
    indegree[v]++;
  }
  memset(dp,0,sizeof(dp));
  rep(i,1,n + 1)
  {
    adj[n + 1].pb(i);
    indegree[i]++;
  }
  dfs(n + 1);
  ll ans = 0;
  rep(i,1,n + 1)
  {
    ans = max(ans,dp[i]);
  }
  cout << ans - 1;
  return 0;
}



Measured memory_bytes: 9588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define int long long 
using namespace std;

signed main(){
	int n,a[100000],b[100000];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i] >> b[i];
	int cnt = 0;
	for(int i = n - 1;i >= 0;i--){
		a[i] += cnt;
		if(a[i] % b[i]) cnt += (a[i] / b[i] + 1) * b[i] - a[i];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1920
X = int(input())
if X>= 400: ans = 8
if X>= 600: ans = 7
if X>= 800: ans = 6
if X>=1000: ans = 5
if X>=1200: ans = 4
if X>=1400: ans = 3
if X>=1600: ans = 2
if X>=1800: ans = 1
print(ans)

Measured memory_bytes: 9204
#B
import sys
from collections import Counter
n=int(input())
d=list(map(int,input().split()))
e=Counter(d)
mod=998244353
if d[0]!=0 or e[0]!=1:
    print(0)
    sys.exit()
ans=1
for i in range(2,n):
    ans*=pow(e[i-1],e[i],mod)
    ans%=mod
print(ans%mod)

Measured memory_bytes: 24356
/*
 * AOJ 2224: Save Your Cats
 * ?¢?????????????????????????????????????????????±?´????????????????????±???¨????°??????±?´?????????¨???????????????????????????
 * ?±???????????°??????????
 * ?????????????±?????????????????????????????????????????£????????????????????????§????????§???????£????????¢?????°?Kruskal???????????¢???????¬?????????§???????????¨??¶??\??????????????????
 */

#include <cstdio>
#include <queue>
#include <iostream>
#include <cmath>

using namespace std;

struct E{
  E() {}
  E(int uu, int vv, double cc): u(uu), v(vv), c(cc) {}
  bool operator > (const E& e) const {
    return c < e.c;
  }
  int u, v;
  double c;
};

int fa[10010];
priority_queue<E, vector<E>, greater<E> > pq;

int find(int x) {
  if(x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}

double Kruskal(int n) {
  for(int i = 1; i <= n; ++i) {
    fa[i] = i;
  }
  int cnt = 1;
  double ans = 0;

  while(cnt < n && !pq.empty()) {
    const E& e = pq.top();
    int u, v;
    double c;
    u = e.u;
    v = e.v;
    c = e.c;
    pq.pop();

    u = find(u);
    v = find(v);
    if(u == v) continue;
    fa[u] = v;
    ans += c;
    ++cnt;
  }
  return ans;
}

double x[10010], y[10010];

int main() {
  int n, m;
  double ans = 0;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; ++i) {
    scanf("%lf%lf", &x[i], &y[i]);
  }
  while(m--) {
    int u, v;
    double c;
    scanf("%d%d", &u, &v);
    c = sqrt((x[u]-x[v])*(x[u]-x[v]) + (y[u]-y[v])*(y[u]-y[v]));
    ans += c;
    pq.push(E(u, v ,c));
  }
  ans -= Kruskal(n);
  printf("%.3f\n", ans);
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void)
{
    int i,n,j,k;
    int data[4][3][10]={{{0}}};
    scanf("%d",&n);
    for(i=0; i<n; i++){
        int b,f,r,v;
        scanf("%d %d %d %d",&b,&f,&r,&v);
        data[b-1][f-1][r-1]+=v;
    }
    for(i=0; i<4; i++){
        for(j=0; j<3; j++){
            for(k=0; k<10; k++){
                printf(" %d",data[i][j][k]);
                
            }
            printf("\n");
        }
        
        if(i != 3){
            printf("####################\n");
        }
        
    }
    return 0;
    
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;


lli calc_formula(string s, queue<int> index){
  lli sum = 0, current_num = 0;
  for(lli i = 0; i < s.size() -1; i++){
    current_num += s[i] - '0';
    if(index.front() == i && index.size() != 0){
      sum += current_num;
      current_num = 0;
      index.pop();
      }
    else
      current_num *= 10;
  }
  current_num += s[s.size()-1] - '0';
  sum += current_num;
  return sum;
}

int main(){
  string s;
  cin >> s;
  lli sum = 0;
  lli n = s.size()-1;
  for(lli bit = 0; bit < (1<<n); bit++){
    queue<int> index;
    for(lli i=0; i < n; i++){
      if(bit & (1<<i))
        index.push(i);
    }
    sum += calc_formula(s, index);
  }

  cout << sum << endl;

}

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

using namespace std;

int main(void) {
    int a,b,c;
    int n;
    int sum = 0;
    int count = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> n;

    for(int i=0; i<=a; i++) {
        for(int j=0; j<=b; j++) {
            for(int k=0; k<=c; k++) {
                sum = 500 * i + 100 * j + 50 * k;
                if (sum == n) count++;
            }
        }

        sum = 0;
    }

    cout << count << endl;
}



Measured memory_bytes: 256
k = gets.to_i
queue = [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
lunlun_count = 0
until queue.empty?
  digits = queue.shift
  lunlun_count += 1
  if lunlun_count == k
    puts digits.join
    exit
  end
  last = digits.last
  from = last - 1
  from = 0 if from < 0
  to = last + 1
  to = 9 if to > 9
  (from..to).each do |addition|
    queue << digits + [addition]
  end
end


Measured memory_bytes: 38524
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int K;
    string S;
    
    cin >> K >> S;

    int n;
    n=S.size();

    if(n<=K)
    {
        cout << S << endl;
    }
    else
    {
        cout << S.substr(0,K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <stdio.h>
#include <map>
#include <queue>
using namespace std;
#define ll long long
int n;
ll arr[100005];
map<ll, int> m;
priority_queue<ll> pq;
int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &arr[i]);
		if (m.find(arr[i]) == m.end()){
			m[arr[i]] = 1;
		} else {
			m[arr[i]] = m[arr[i]] + 1;
		}
	}
	
	for (map<ll,int>::iterator it = m.begin(); it != m.end(); it++){
		if (it -> second == 1) continue;
		pq.push(it -> first);
	}
	if (pq.size() < 1){
		printf("0\n");
	} else if (pq.size() == 1){
		ll a = pq.top();
		if (m[a] < 4){
			printf("0\n");
		} else {
			printf("%lld\n", a*a);
		}
	} else {

		ll a = pq.top();
		if (m[a] >= 4){
			printf("%lld\n", a*a);
			return 0;
		}
		pq.pop();
		ll b = pq.top();
		printf("%lld\n", a*b);
	}
	
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<math.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define set setprecision
#define pi 3.141592653589793238
using namespace std;
int main() {
	while (true) {
		int n, x;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		int count = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)count++;
				}
			}
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)
			return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m=mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)
		return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod ;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int> engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


signed main() {
	int a,b,k;cin>>a>>b>>k;
	if(a>=k)cout<<a-k<<" "<<b<<endl;
	else if(a+b>=k)cout<<0<<" "<<b-(k-a)<<endl;
	else cout<<0<<" "<<0<<endl;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n;
    cin>>n;
    cout<<3*n*n el;

}

main()
{
//      fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3584
#include <stdio.h>
#include <stdint.h>
#define DIGIT 32

class TransferValue
{
    public:
    void DecToBin(uint32_t decimal);
    void Invarted(uint32_t decimal);
    void LeftShift(uint32_t decimal);
    void RightShift(uint32_t decimal);
};

void TransferValue::DecToBin(uint32_t decimal)
{
    int i = 0;
    int binary[DIGIT] = {};
    for(i = 0; i < DIGIT; i++)
    {
        binary[i] = decimal % 2;
        decimal = decimal / 2;
    }
    for(i = DIGIT - 1; i >= 0; i--)
    {
        printf("%d", binary[i]);
    }
    printf("\n");
}

void TransferValue::Invarted(uint32_t decimal)
{
    int i = 0;
    int binary[DIGIT] = {};
    for(i = 0; i < DIGIT; i++)
    {
        binary[i] = decimal % 2;
        if(binary[i] == 0)
        {
            binary[i] = 1;
        }
        else if(binary[i] == 1)
        {
            binary[i] = 0;
        }   
        decimal = decimal / 2;
    }
    for(i = DIGIT - 1; i >= 0; i--)
    {
        printf("%d", binary[i]);
    }
    printf("\n");
}

void TransferValue::LeftShift(uint32_t decimal)
{
    int i = 0;
    int binary[DIGIT] = {};
    binary[0] = 0;
    for(i = 0; i < DIGIT; i++)
    {
        binary[i + 1] = decimal % 2;
        decimal = decimal / 2;
    }
    for(i = DIGIT - 1; i >= 0; i--)
    {
        printf("%d", binary[i]);
    }
    printf("\n");
}

void TransferValue::RightShift(uint32_t decimal)
{
    int i = 0;
    int binary[DIGIT] = {};
    binary[0] = 0;
    for(i = 0; i < DIGIT; i++)
    {
        binary[i - 1] = decimal % 2;
        decimal = decimal / 2;
    }
    for(i = DIGIT - 1; i >= 0; i--)
    {
        printf("%d", binary[i]);
    }
    printf("\n");
}

int main(void)
{
    uint32_t n;
    TransferValue tv;
    
    scanf("%d", &n);
    
    tv.DecToBin(n);
    tv.Invarted(n);
    tv.LeftShift(n);
    tv.RightShift(n);
    
    return 0;
}



Measured memory_bytes: 2756
#!/usr/bin/env python3

N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
    
    return divisors

f = lambda a, b: max(len(str(a)), len(str(b)))
divisors = make_divisors(N)
ans = float("inf")
for d in divisors:
    ans = min(ans, f(d, N // d))
print(ans)

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N; cin >> N;
    ll acc = 0;
    int A[N]; rep(i, N) cin >> A[i];
    rep(i, N-1){
        if(A[i] % 2 == 1 && A[i+1] > 0){
            acc++;
            A[i]--;
            A[i+1]--;
        }
    }
    rep(i, N) acc += A[i]/2;
    cout << acc << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 640
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 100005
int n,cnt,head[N],bit[N][25],ans;
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void dfs(int u,int pr){
	for (int i=head[u];i;i=e[i].nxt) if (e[i].to!=pr){
		int v=e[i].to;
		dfs(v,u);
		rep (j,0,20) bit[u][j]+=bit[v][j];
	}
	int Min=0;
	per (i,20,0) if (bit[u][i]>=2){Min=i+1;break;}
	while (bit[u][Min]) Min++;
	ans=max(ans,Min);
	bit[u][Min]=1;
	rep (i,0,Min-1) bit[u][i]=0;
}
int main(){
	n=read();
	rep (i,1,n-1){
		int x=read(),y=read();
		adde(x,y);adde(y,x);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 17664
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 100007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 1000000007
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}

int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	/*int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;*/
	int n, m;
	int a[107];
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int need = ceil(sum * 1.0 / (4 * m));
	int total = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= need)total++;
	}
	if (total >= m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int K = sc.nextInt();

		int len = n.length();

		char[] s = n.toCharArray();

		int[][][] dp = new int[105][4][2]; //dp[i][j][k]は、i桁目までの数字で、j個の非ゼロがある場合の数。k=0のとき、dpはi桁目までnと同じ数字である。
		dp[0][0][0] = 1;
		for (int i = 0; i < len; i++) {
			int maxD = s[i] - '0';
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 2; k++) {
					for (int d = 0; d < 10; d++) {
						int nextI = i + 1;
						int nextJ = j;
						int nextK = k;

						if (d != 0) {
							nextJ++;
						}
						if (nextJ > K) {
							continue;
						}
						if (k == 0) {
							if (d > maxD) {
								continue;
							}
							if (d < maxD) {
								nextK = 1;
							}
						}
						dp[nextI][nextJ][nextK] += dp[i][j][k];
					}
				}
			}
		}
		int ans = dp[len][K][0] + dp[len][K][1];
		System.out.println(ans);
	}

}

Measured memory_bytes: 35716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  vector<pll>v;
  ll ans=0;
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    ans+=a[i];
    if(a[i]>b[i]){
      v.push_back(make_pair(b[i],i));
    }
  }
  if(v.size()==0){
    cout<<0<<endl;
    return 0;
  }
  sort(v.begin(),v.end());
  ans-=b[v[0].second];
  cout<<ans<<endl;
}

Measured memory_bytes: 896