akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll money=1000;
    ll maxmoney=1000;
    ll kabu=0;
    rep(i,n-1){
        if(a[i]<a[i+1]){
            kabu+=money/a[i];
            money%=a[i];
        }else if(a[i]>a[i+1]){
            money+=kabu*a[i];
            kabu=0;
            maxmoney=max(maxmoney,money);
        }
    }
    money+=kabu*a[n-1];
    maxmoney=max(maxmoney,money);
    cout<<maxmoney<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{	
	int n;
	cin >> n;
	int a[n + 1];
	rep(i, n){
		cin >> a[i + 1];
	}
	int cnt = 0;
	for(int i = 1; i <= n - 1; ++i){
		if(a[i] == i && a[i + 1] == i + 1){
			swap(a[i], a[i + 1]);
			++cnt;
		}
	}
	for(int i = 1; i <= n; ++i){
		if(a[i] == i && i - 1 && a[i - 1] != i){
			swap(a[i], a[i - 1]), ++cnt;
		}
		else if(a[i] == i && i + 1 <= n && a[i + 1] != i){
			swap(a[i], a[i + 1]), ++cnt;
		}
	}
	cout << cnt;
}


 
 
int main()
{
 //	freopen("sparse.in", "r", stdin);
	//freopen("sparse.out", "w", stdout);
	   Red;
  	//int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    int sum = 0; vector<int> A(N);
    REP(i, 0, N) {
        int a; cin >> a;
        A[i] = a;
        sum += a;
    }

    int cnt = 0, lim = (sum + 4 * M - 1) / (4 * M);
    REP(i, 0, N) if (!(A[i] < lim)) cnt++;

    if (cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    string s;
    cin >> s;

    rep(i,s.size() - 1){
        if(s[i] == s[i + 1]){
            cout << i + 1 << ' ' << i + 2 << endl;
            return 0;
        }
    }

    rep(i,s.size() - 2){
        if(s[i] == s[i + 2]){
            cout << i + 1 << ' ' << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

int main() {
  int N;
  std::cin >> N;
  std::string S;
  std::cin >> S;
  if (S.length() % 2 != 0) {
    std::cout << "No";
    return 0;
  }
  int half = S.length() / 2;
  if (S.substr(0, half) == S.substr(half, half)) {
    std::cout << "Yes";
    return 0;
  }
  std::cout << "No";
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct Point {
  int x, y, z;
  Point(){}
  Point(int x, int y, int z):x(x), y(y), z(z){}
};

struct edge {
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

int n, k, s;
vector<Point> ps;
vector< vector<edge> > graph;

bool isIntersect(int a, int b) {
  if(abs(ps[a].x - ps[b].x) > s) return false;
  if(abs(ps[a].y - ps[b].y) > s) return false;
  if(abs(ps[a].z - ps[b].z) > s) return false;
  return true;
}

int intersectSurface(int a, int b) {
  int vx = s - abs(ps[a].x - ps[b].x);
  int vy = s - abs(ps[a].y - ps[b].y);
  int vz = s - abs(ps[a].z - ps[b].z);
  return (vx*vy + vy*vz + vz*vx) * 2;
}

int ans;

void dfs(int u, int p, int r, int d, int sum) {
  if(d == k) {
    if(k > 2) {
      for(edge& e : graph[u]) {
	if(e.to == r) sum += e.cost;
      }
    }
    chmax(ans, sum);
    return;
  }
  for(edge& e : graph[u]) {
    if(e.to == p || e.to == r) continue;
    dfs(e.to, u, r, d+1, sum+e.cost);
  }
}

int solve() {
  ans = -1;
  rep(u, n) dfs(u, -1, u, 1, 0);
  if(ans == -1) return -1;
  return s*s*6*k - ans;
}

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

  while(cin >> n >> k >> s, n) {
    ps.clear();
    rep(i, n) {
      int x, y, z;
      cin >> x >> y >> z;
      ps.emplace_back(x, y, z);
    }
    graph.clear(); graph.resize(n);
    rep(i, n) rep(j, n) if(i != j) {
      if(isIntersect(i, j)) graph[i].emplace_back(j, intersectSurface(i, j));
    }
    cout << solve() << endl;
  }

  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    rep(i, N) {
        set<char> t;
        t.insert(A[i]);
        t.insert(B[i]);
        t.insert(C[i]);
        ans += t.size() - 1;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2020,OO=1e9;
int dp[N][N];//{b,w}
char c[N+N];int a[N+N];
int wb[N],ww[N];
int bigw[N+N][N],bigb[N+N][N];
int32_t main(){
    int n;
    cin>>n;
    forn(i,n+n){
        cin>>c[i]>>a[i];
        if(i)forn(j,n+1)bigb[i][j]=bigb[i-1][j],bigw[i][j]=bigw[i-1][j];
        if(c[i]=='W'){
            ww[a[i]]=i;
            for(int j=1;j<=a[i];++j)bigw[i][j]++;
        }else{
            wb[a[i]]=i;
            for(int j=1;j<=a[i];++j)bigb[i][j]++;
        }
    }
    forn(i,n+1){
        forn(j,n+1){
            if(i||j)dp[i][j]=OO;
            if(i){
                int p=wb[i];
                int cost=bigb[p][i+1]+bigw[p][j+1];
                upn(dp[i][j],dp[i-1][j]+cost);
            }
            if(j){
                int p=ww[j];
                int cost=bigb[p][i+1]+bigw[p][j+1];
                upn(dp[i][j],dp[i][j-1]+cost);
            }
        }
    }
    cout<<dp[n][n]<<'\n';
    return 0;
}

Measured memory_bytes: 161500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char sp = ' ';

int N;
ll K, A[200000], L, R;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	L = -2e18;
	R = 2e18;
	while (L + 1 < R) {
		ll M = (L + R) / 2;
		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] < 0) {
				int l, r;
				l = i;
				r = N;
				while (l + 1 < r) {
					int m = (l + r) / 2;
					if (A[i] * A[m] <= M) {
						r = m;
					}
					else {
						l = m;
					}
				}
				cnt += N - r;
			}
			else {
				int l, r;
				l = i;
				r = N;
				while (l + 1 < r) {
					int m = (l + r) / 2;
					if (A[i] * A[m] <= M) {
						l = m;
					}
					else {
						r = m;
					}
				}
				cnt += l - i;
			}
		}
		if (cnt < K)L = M;
		else R = M;
	}
	cout << R << endl;
}



Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a;
    int e=0;
    c=0;
    int d[a];
    for(int i=0;i<a;i++){
        cin>>d[i];
        if(e<=d[i]){
            c++;
            e=d[i];
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define INF 1000000007
using namespace std;
int main(){
  long long N;
  long long now=1;
  scanf("%lld",&N);
  for(long long i=1;i<=N;i++){
    now=(now*i)%INF;
  }
  printf("%lld\n",now);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std;
const int M=1000000007;
const int N_MAX=100000;

int n,dp[N_MAX+1][26];
string s,t;
int main(){
	cin>>n;
	cin>>s>>t;
	
	dp[0][s[0]-'a']=1;
	for(int i=1;i<n;i++){
		dp[i][s[i]-'a']=(dp[i][s[i]-'a']+dp[i-1][t[i]-'a'])%M;
		for(int j=0;j<26;j++)dp[i][j]=(dp[i][j]+dp[i-1][j])%M;		
	}
	
	cout<<dp[n-2][t[n-1]-'a']<<endl;
	return 0;
}


Measured memory_bytes: 13476
import java.util.Scanner;

public class Main {
	public static final String[] key = {"apple", "peach"};
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		
		String before = sc.nextLine();
		for (int i = 0; i < before.length(); i++) {
			if (i + 4 > before.length()) {
				sb.append(before.charAt(i));
			} else if ((before.substring(i, i + 5)).equals(key[0])) {
				sb.append(key[1]);
				i += 4;
			} else if ((before.substring(i, i + 5)).equals(key[1])) {
				sb.append(key[0]);
				i += 4;
			} else {
				sb.append(before.charAt(i));
			}
		}
		
		String after = sb.toString();
		System.out.println(after);
	}
}

Measured memory_bytes: 26088
N = int(input())
A = list(map(int, input().split()))
'''
c = 0

for i in range(N):
    if A.count(i) == 2 and i != 0:
        c += 1
    elif A.count(i) == 1 and i == 0:
        continue
    elif A.count(i) == 0:
        continue
    else:
        break
'''
c = N // 2
if N % 2 == 0:
    K = N
else:
    K = N + 1 
if sum(A) == c * K:
    ans = 2 ** c % (10**9 + 7)
else:
    ans = 0

print(ans)

Measured memory_bytes: 13880
n,m = map(int,input().split())
py = [[i+1]+list(map(int,input().split())) for i in range(m)]
pysort = sorted(py,key=lambda x:(x[1],x[2]))

j = 1
cnt = 0
for i in range(m):
    while True:
        if pysort[i][1] == j:
            cnt += 1
            #pysort[i] += [f"{pysort[i][1]}:{cnt}"]
            pysort[i] += [str(pysort[i][1]).zfill(6)+str(cnt).zfill(6)]
            break
        else:
            cnt = 0
            j += 1

pysortsort = sorted(pysort,key=lambda x:x[0])
[print(a[3]) for a in pysortsort]

Measured memory_bytes: 44636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a;
int main() {
	ll n,c,k;
	cin>>n>>c>>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll now=a[0]+k;
	ll ans=0,kari=0;
	for(int i=0;i<n;i++){
		ll nowti=a[i];
		if(kari==0){
			kari++;
			now=nowti+k;
			if(kari==c){
				ans++;
				kari=0;
			}
			continue;
		}
		if(nowti<=now){
			kari++;
			if(kari==c){
				ans++;
				kari=0;
			}
			continue;
		}
		ans++;kari=1;
		now=nowti+k;
	}
	if(kari>=1){
		ans++;
	}
	cout << ans;
	return 0;
}

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

int INF = 1000000001;

typedef struct edge{
  int to;
  int cost;
} edge;

int N,E;
vector< edge > G[100000];
int mincost[100000];

void dijkstra(){
  /*
  priority_queue< pair<int,int>,
                  vector< pair<int,int> > ,
                  greater< pair<int,int> > > Q;
  */
  
  //priority_queue?????£?¨?
  typedef pair<int,int> P;
  priority_queue< P , vector<P> , greater<P> > Q;

  //mincost?????????????????????????????????
  for(int i=0;i<N;i++){
    mincost[i]=INF;
  }
  mincost[0]=0; //??????????????°????????????0

  Q.push( P(0,0) );

  //????????????dijkstra ?????¬???
  while(!Q.empty()){
    int pos=Q.top().second;// position
    int pos_cost=Q.top().first;
    Q.pop();
    
    //aoj0099????????????????????§???2 ??¨??????????????§????°?????????????????????????
    if( mincost[pos] < pos_cost )continue;
    
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(mincost[e.to] > pos_cost+e.cost){
        mincost[e.to]=pos_cost+e.cost;
        Q.push( P( mincost[e.to] , e.to ) );
      }
    }
  }

  for(int i=0;i<N;i++){
    cout<<i<<' '<<mincost[i]<<endl;
  }
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    int id,k;
    cin>>id>>k;
    for(int j=0;j<k;j++){
      edge e;
      cin>>e.to>>e.cost;
      G[id].push_back(e);
    }
  }

  dijkstra();
  
  return 0;
}

Measured memory_bytes: 10184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin>>n>>k;
  long long int p=1;
  for(int i=1;i<=n;i++){
    if(i==1){p*=k;}
    else{p*=(k-1);}
  }
  cout<<p<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = {}
for i in range(n):
    b = input()
    if b in s:
        s[b] += 1
    else:
        s[b] = 1

m = int(input())
t = {}
for i in range(m):
    r = input()
    if r in t:
        t[r] += 1
    else:
        t[r] = 1

temp = 0
for b in s.keys():
    val = 0
    if b in t.keys():
        val = s[b] - t[b]
    else:
        val = s[b]
    if val > temp:
        temp = val

print(temp)

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

int n, ans;
int x[24], y[24], r[24], c[24];
bool exist[24];
// memo[bits] := ツ円ツづ個湘ウツ妥?bits ツづ個づ?つォツづ個づ?づィツ渉慊つッツづゥツ鳴?青板づーツ陛板つキ. 
char memo[1<<24];

void init(){
	for(int i=0 ; i < n ; i++ ) exist[i] = true;
	for(int i=0 ; i < (1<<n) ; i++ ) memo[i] = -1;
}

int dist(int x1, int y1, int x2, int y2){
	return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

// ツ円ツ氾?i ツつェ1ツ氾板湘」 <=> j < i ツづ?づ按づィ, ツ円ツ氾?i ツづ?重ツづ按づゥツ円ツ氾?j ツつェツ堕カツ催敖つオツづ按つ「.
bool is_top(int i){
	for(int j=0 ; j < i ; j++ ){
		if( !exist[j] ) continue;
		
		int r1 = r[i];
		int r2 = r[j];
		int d = dist( x[i] , y[i] , x[j] , y[j] );
		if( d < (r1 + r2) * (r1 + r2) ){
			return false;
		}
	}
	return true;
}

int solve(int bits, int cnt){
	if( memo[bits] >= 0 ) return memo[bits];
	int result = cnt;
	
	ans = max( ans , cnt );
	for(int i=0 ; i < n ; i++ ){
		if( !exist[i] || !is_top(i) ) continue;
		
		for(int j=i+1 ; j < n ; j++ ){
			if( c[i] != c[j] || !exist[j] || !is_top(j) ) continue;
			
			exist[i] = exist[j] = false;
			int next_bits = (bits & (~(1<<i))) & (~(1<<j));
			result = solve( next_bits , cnt+2 );
			exist[i] = exist[j] = true;
		}
	}
	memo[bits] = result;
	ans = max( ans , result );
	return result;
}

int main(){
	while( cin >> n , n ){
		init();
		for(int i=0 ; i < n ; i++ ){
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		ans = 0;
		solve( ((1<<n)-1) , 0 );
		cout << ans << endl;
	}
}

Measured memory_bytes: 16000
def nodef(w,s):
    return (s/(s+w))


a,b,c,d,e,f = map(int,input().split())

best_w = 0
best_s = 0
best_node = 0

for i in range(30//a+1):
    for j in range(30//b+1):
        w = 100*(a*i + b*j)
        if w<=f and w:
            max_s = min(f-w,(a*i + b*j)*e)
            for k in range(max_s//c+1):
                l = (max_s-k*c)//d
                s = k*c + l*d
                node = nodef(w,s)
                if node >= best_node and node<=e and w+s<=f:
                    best_w = w
                    best_s = s
                    best_node = node
                    
print("{} {}".format((best_s+best_w ),best_s))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>

typedef struct node {
    long v;
    node *parent;
    node *left;
    node *right;
} Node;

typedef struct {
    Node *root;
} Tree;

Tree T = {NULL};

void insertTree(Node *node) {
    Node *y = NULL;
    Node *x = T.root;
    while (x != NULL) {
        y = x;
        if (node->v < x->v) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    node->parent = y;
    if (y == NULL) {
        T.root = node;
    } else if (node->v < y->v) {
        y->left = node;
    } else {
        y->right = node;
    }
}

bool find(long v) {
    Node *x = T.root;
    while (x != NULL) {
        if (x->v == v) return true;
        else if (x->v < v) x = x->right;
        else x = x->left;
    }
    return false;
}

void Preorder(Node *n) {
    if (n != NULL) {
        printf(" %ld", n->v);
        Preorder(n->left);
        Preorder(n->right);
    }
}

void Inorder(Node *n) {
    if (n != NULL) {
        Inorder(n->left);
        printf(" %ld", n->v);
        Inorder(n->right);
    }
}

int main () {
    long n;
    scanf("%ld", &n);
    char command[10];
    long value;
    for (long i=0; i<n; i++) {
        scanf(" %s %ld", command, &value);
        if (command[0] == 'i') {
            Node *node = (Node *)malloc(sizeof(Node));
            node->v = value;
            node->parent = NULL;
            node->left = NULL;
            node->right = NULL;
            insertTree(node);
        } else if (command[0] == 'f') {
            bool found = find(value);
            if (found) printf("yes\n");
            else printf("no\n");
        } else {
            Inorder(T.root);
            printf("\n");
            Preorder(T.root);
            printf("\n");
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

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

    int N;
    cin >> N;
    int result = 0;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    int tmp = h[0];
    for (int i= 0; i < N; i++) {
        if (i == 0) {
            result += 1;
            tmp = h[0];
            continue;
        }
        if (tmp <= h[i]) {
            tmp = h[i];
            result++;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int f[100001][4],a[100001][4];
int main()
{
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=3;j++)
        {
            for(k=1;k<=3;k++)
            {
                if(j!=k)
                    f[i][j]=max(f[i][j],f[i-1][k]+a[i][j]);
            }
        }
    }
    printf("%d",max(max(f[n][1],f[n][2]),f[n][3]));
    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt() - 1;
		boolean key = true;
		while (key) {
			X++;
			key = checker(X);
		}
		System.out.println(X);
		
	}
	
	public static boolean checker(int x) {
		for (int i = 2; i <= x/2; i++) {
			if (x%i == 0) {
				return true;
			}
		}
		return false;
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ii> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

int main(){
    int n;cin>>n;
    int c[4];
    for(int i=0;i<4;i++) c[i]=0;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        if(s=="AC") c[0]++;
        else if(s=="WA") c[1]++;
        else if(s=="TLE") c[2]++;
        else c[3]++;
    }
    cout<<"AC x "<<c[0]<<endl;
    cout<<"WA x "<<c[1]<<endl;
    cout<<"TLE x "<<c[2]<<endl;
    cout<<"RE x "<<c[3]<<endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[201][101];

int grundy(int w, int b){
    if(dp[w][b] != -1) return dp[w][b];

    set<int> s;
    if(w) s.insert(grundy(w-1,b));
    if(b) s.insert(grundy(w+1,b-1));
    REP(i,min(w,b)){
        s.insert(grundy(w,b-i-1));
    }

    int ret = 0;
    while(s.count(ret)) ret++;
    return dp[w][b] = ret;
}
void Main(){
    int N; cin >> N;
    REP(i,201)REP(j,101) dp[i][j] = -1;
    dp[0][0] = 0;

    int g = 0;
    REP(i,N){
        int w,b; cin >> w >> b;
        g ^= grundy(w,b);
    }

    cout << (g>0 ? 0 : 1) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
int N,Q;
int s[1000000];
int ss[1000000];
set<int>rd;
void check(int x){
    vector<int>V;
    for(set<int>::iterator it=rd.begin();it!=rd.end();it++){
        V.push_back(s[*it]);
    }
    sort(V.rbegin(),V.rend());

    int ub=1000000001,lb=-1;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        int cnt=0;
        for(int i=0;i<V.size();i++){
            int to;
            if(i+1==V.size()){
                to=max(0,V[i]-mid);
            }
            else{
                to=max(V[i+1]+1,V[i]-mid);
            }
            int l=lower_bound(ss,ss+N,to)-ss;
            int r=upper_bound(ss,ss+N,V[i])-ss;
            cnt+=r-l;
        }
        if(N-cnt<=x)ub=mid;
        else lb=mid;
    }
    if(ub==1000000001)cout<<"NA"<<endl;
    else cout<<ub<<endl;

}

int main(){
    cin>>N>>Q;
    for(int i=0;i<N;i++)cin>>s[i],ss[i]=s[i];
    sort(ss,ss+N);

    while(Q--){
        string str;
        int x;
        cin>>str>>x;
        if(str=="ADD"){
            --x;
            rd.insert(x);
        }
        else if(str=="REMOVE"){
            --x;
            set<int>::iterator it=rd.find(x);
            rd.erase(it);
        }
        else{
            check(x);
        }
    }


    return 0;
}

Measured memory_bytes: 9056
#include<stdio.h>

int main(void)
{
  int a,b,t,i,sum = 0;
  scanf("%d%d%d",&a,&b,&t);

  for(i = 1; a*i < t+0.5; i++) sum += b;
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128
n,y=map(int,input().split())
for i in range(y//10000+1):
    for j in range(y//5000+1):
        if n-i-j>=0 and i*10000+j*5000+(n-i-j)*1000==y:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 9204
class UnionFind:
    def __init__(self,n):
        self.par = [-1] * n     # 負数は友達の数（自分を含む）初期値は自分-1、0と正数は根を示す

    def root(self,x):   # xの根を返す
        if self.par[x] < 0:    # xが根の時は、xを返す
            return x
        self.par[x] = self.root(self.par[x])    # 根でないときは、par[x]に根の根を代入
        return self.par[x]                      # 根の根を返す

    def union(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:     # par[x]が小さく(友達が多く)なるように交換
            x, y = y, x
        self.par[x] += self.par[y]  # 友達が多い方に少ない方を加える
        self.par[y] = x             # yの根をxにする

    def size(self):
        return -1 * min(self.par)


n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1,b-1)               # 1が0番目、２が1番目・・・

print(uf.size())

Measured memory_bytes: 14352
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		ArrayList<Double> al = new ArrayList<Double>();
		while(sc.hasNext()) {
			al.add(sc.nextDouble());
		}
		System.out.println(Collections.max(al) - Collections.min(al));
	}
}

Measured memory_bytes: 0
//tree DP
//ABC036-D
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long dist[4096],par[4096];
void dfs(long long t,long long l,long long bp,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    long long i,j,n,m,k,a,b,c,h,w,r=0,l,t;
    long long arr[4096],mem[4096]={0};
    rs g[4096];
    mkj x[4096];
    sd dat[4096];
    bool dp[8192];
    scanf("%lld",&n);
    for(i=0;i<(n-1);i++){
      scanf("%lld",&a);
      g[2*i].st=a;
      g[2*i].fi=i+2;
      g[2*i].kr=1;
      g[2*i+1].st=i+2;
      g[2*i+1].fi=a;
      g[2*i+1].kr=1;
    }
    for(i=1;i<=n;i++){
      scanf("%lld",&arr[i]);
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    for(i=0;i<=n;i++){
      dist[i]=inf;
    }
    dfs(1,0,-1,g,x);
    for(i=0;i<n;i++){
      dat[i].node=i+1;
      dat[i].val=dist[i+1];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<n;i++){
      w=dat[i].node;
      for(j=1;j<=arr[w];j++){
        dp[j]=0;
      }
      dp[0]=1;
      t=0;
      for(j=x[w].st;j<x[w].st+x[w].kz;j++){
        if(par[w]==g[j].fi){continue;}
        //printf("%lld -> %lld:<%lld %lld>\n",w,g[j].fi,arr[g[j].fi],mem[g[j].fi]);
        t+=(arr[g[j].fi]+mem[g[j].fi]);
        for(k=arr[w];k>=0;k--){
          if(dp[k]==0){continue;}
          dp[k]=0;
          if(k+arr[g[j].fi]<=arr[w]){dp[k+arr[g[j].fi]]=1;}
          if(k+mem[g[j].fi]<=arr[w]){dp[k+mem[g[j].fi]]=1;}
        }
      }
      for(j=arr[w];j>=0;j--){
        if(dp[j]==1){
          mem[w]=t-j;
          //printf("%lld:%lld\n",w,mem[w]);
          break;
        }
        if(j==0){
          printf("IMPOSSIBLE\n");
          return 0;
        }
      }
    }
    printf("POSSIBLE\n");
    return 0;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y;
std::vector<int> v(x);
rep(i,x){
  std::cin >> v[i];
y-=v[i];
}
sort(all(v));
while(true){
  if(v[0]>y)break;
  y-=v[0];
  x++;
}
std::cout << x << '\n';
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<bool> vb;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

const int Mgn = 5;
const int X_MAX = 50;

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

	int N, A;  cin >> N >> A;
	vi X(N + Mgn, 0);
	int xMax = 0;
	FOR(i, 1, N + 1) {
		cin >> X[i];
		xMax = max(xMax, X[i]);
	}

	auto dp = vector<vector<vector<ll>>>(N + Mgn,
		vector<vector<ll>>(N + Mgn, vector<ll>(X_MAX*N + Mgn, 0)));

	dp[0][0][0] = 1;

	FOR(i, 1, N + 1) {
		dp[i][0][0] = 1;

		FOR(j, 1, i + 1) {
			FOR(k, 0, xMax*N + 1) {
				if (k >= X[i]) {
					// dp[i][j][k] : The number of ways to choose
					//   j cards whose sum is k from X[0]..X[i]					
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - X[i]];
				}
				else {
					dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
	}

	ll ans = 0;
	FOR(j, 1, N + 1) ans += dp[N][j][A*j];

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


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll n,a,b;
 cin>>n>>a>>b;
 ll d=a+b;
 cout<<(n/d)*a+min(n%d,a)<<endl;

return 0;
}



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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A * B >= C * D) {
    cout << A * B << endl;
  } else {
    cout << C * D << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char s[10];
int main()
{
	scanf("%s",s+1);int n=strlen(s+1);
	for(int i=1;i<n;i++)
		if(s[i]=='A'&&s[i+1]=='C')
			return !printf("Yes\n");
	return !printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[105][4][2]; // dp[i][j][k]: 0~i-1までのi文字をきめたときの総数

int main () {
  string s;
  int K;
  cin >> s >> K;
  int n = sz(s);

  dp[0][0][0] = 1;
  rep(i,n)rep(j,4)rep(k,2) {
    int nd = s[i]-'0';
    rep(d,10) {
      int ni = i+1, nj = j, nk = k;
      if (d != 0) nj++;
      if (nj > K) continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }

  cout << dp[n][K][0] + dp[n][K][1] << endl;
  return 0;
}

Measured memory_bytes: 256
// 6/26 解き直し
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];

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

    ll ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int maxk = L[i] + L[j] - 1;
            int maxid = upper_bound(L.begin(), L.end(), maxk) - L.begin();
            ans += (maxid-j-1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll n;

int main() {
    cin >> n;
    cout << (n-1)*n/2 << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define in_arr(type, a, n) for(int i = 0; i < n; i++) scanf(type, &((a)[i]));
#define ll long long int

void merge_sort(int *a, int n){
    if(n < 2) return;
    int mid = n / 2;
    int *left = malloc(sizeof(int) * mid);
    int *right = malloc(sizeof(int) * (n - mid));
    for(int i = 0; i < mid; ++i){
        left[i] = a[i];
    }
    
    for(int i = 0; i < n - mid; ++i){
        right[i] = a[i + mid];
    }
    merge_sort(left, mid);
    merge_sort(right, n - mid);
    for(int i = 0; i < n; ++i){
        printf("%d\t", a[i]);
    }
    printf("\n");
    int li = 0, ri = 0;
    for(int i = 0; i < n; ++i){
        if(li >= mid){
            for(; ri < n - mid; ++ri){
                a[i] = right[ri];
                ++i;
            }
            break;
        }
        
        if(ri >= n - mid){
            for(; li < mid; ++li){
                a[i] = left[li];
                ++i;
            }
            break;
        }
        
        if(left[li] < right[ri]){
            a[i] = left[li];
            li++;
        }else{
            a[i] = right[ri];
            ri++;
        }
    }
    free(left);
    free(right);
}

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a % b);
}

int main(){
    int a, b, k;
    scanf("%d%d%d", &a, &b, &k);
    int min = a < b ? a : b;
    for(int i = min; i > 0; --i){
        if(a % i == 0 && b % i == 0){
            --k;
        }
        if(k == 0){
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int a, ap, am;
  int max_n = 200000;
  std::vector<long> p(max_n+1, 0);
  std::vector<long> m(max_n+1, 0);
  for(int i = 0;i<n;++i){
    cin >> a;
    ap = a + i;
    am = i - a;
    if(ap>=0 && ap<= max_n) p[ap]++;
    if(am>=0 && am<= max_n) m[am]++;
  }
  long c = 0;
  for(int i = 0;i<=max_n;++i){
    c += p[i]*m[i];
  }
  cout << c << endl;
}


Measured memory_bytes: 6424
n = int(input())
*a,=map(int, input().split())
from collections import defaultdict
da=defaultdict(int)
for i in a:
    da[i]+=1
q = int(input())
suma=sum(a)
for i in range(q):
    b,c=map(int, input().split())
    numb=da[b]
    suma+=(c-b)*numb
    da[c]+=numb
    da[b]=0
    print(suma)


Measured memory_bytes: 97844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    string s;
    for(int i=0;i<n;i++)
        s+='0';
    bool fg=true;
    bool vis[n];
    for(int i=0;i<n;i++)vis[i]=false;
    for(int i=0;i<m;i++)
    {
        ll ss,c;
        cin>>ss>>c;
        ss--;
        if(vis[ss]==false)
        {
            s[ss]=char('0'+c);
            vis[ss]=true;
        }
        else if(vis[ss]==true)
        {
            if(s[ss]!=char('0'+c)){fg=false;}
        }
    }
    if(!fg){cout<<-1;return 0;}
    if(vis[0]==false){ if(n==1)cout<<0; else{s[0]='1';cout<<s;}return 0;}
    if(vis[0]!=false )
    {
        if(s[0]=='0' && n>1)
            cout<<-1;
        else
            cout<<s;
        return 0;
    }
}


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

int main() {
	int N; cin >> N;
	long sum[2] = {};
	vector<long> B;
	int a;
	for (int i = 0; i < N; i++) {
		cin >> a;
		B.push_back(a - i - 1);
	}

	sort(B.begin(), B.end());
	long med[2] = {};
	med[0] = B[N / 2];
	med[1] = B[N / 2 - 1];

	for (int i = 0; i < N; i++) {
		sum[0] += abs(B[i] - med[0]);
		sum[1] += abs(B[i] - med[1]);
	}

	cout << min(sum[0], sum[1]) << endl;
	return 0;

}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(n == 0)
    {
        if(k != 100)
        printf("%d\n",k);
        else
            printf("101\n");
    }
    else if(n == 1)
    {
        if(k != 100)
            printf("%d00\n",k);
        else
            printf("10100\n");
    }    
    else
    {
        if( k!= 100)
        printf("%d0000\n",k);
        else
            printf("1010000\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int c, p, l, lp;
long long r;
int main() {
  for(; (c = getchar_unlocked()) != EOF && c > ' '; r += ++l) if(c != p) {
    if(c == '<')
      r -= l < lp ? l : lp;
    p = c, lp = l, l = 0;
  }
  if(p == '>')
    r -= l < lp ? l : lp;
  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const long long mod=998244353;

using ll = long long;
using P = pair<int,int>;
 

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 

int main(){
  int N,K;
  cin>>N>>K;
  vector<int>L(K),R(K);
  for(int i=0;i<K;i++){
    cin>>L[i]>>R[i];
  }
  vector<mint>dp(N+1);
  vector<mint>sum(N+1);
  dp[1]=1;
  sum[1]=1;
  for(int i=2;i<=N;i++){
    for(int k=0;k<K;k++){
      int li=i-R[k];
      int ri=i-L[k];
      li=max(li,1);
      if(ri<0){continue;}
      dp[i]+=sum[ri]-sum[li-1];
    }
    sum[i]=(sum[i-1]+dp[i]);
  }
  cout<<dp[N]<<endl;
  return 0;                       
}

Measured memory_bytes: 6432
n = int(input())
 
if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    print(9 + (n-100+1))
elif n < 10000:
    print(9 + 900)
elif n < 100000:
    print(9 + 900 + (n-10000+1))
else:
    print(9 + 900 + 90000)

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

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

    if (n.at(0) == n.at(1) && n.at(1) == n.at(2)){
        cout << "Yes" << endl;
    }
    else if (n.at(1) == n.at(2) && n.at(2) == n.at(3)) {
            cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3548