akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


class Mod
{
    static const int MOD = 1000000007;
    long long a;
public:
    Mod(){
        a = 0;
    }
    Mod(long long x){
        a = (x % MOD + MOD) % MOD;
    }
    const Mod operator+(const Mod& x) const{
        return Mod(a + x.a);
    }
    const Mod operator-(const Mod& x) const{
        return Mod(a - x.a);
    }
    const Mod operator*(const Mod& x) const{
        return Mod(a * x.a);
    }
    const Mod operator/(const Mod& x) const{ //フェルマーの小定理、aとMODが互いに素の時のみ
        if(x.a == 0)return 0;
		if(a % x.a == 0)return Mod(a/x.a);
		int b = MOD - 2;
        long long c = x.a;
        long long ret = 1;
        while(b > 0){
            if(b & 1){
                ret *= c;
                ret %= MOD;
            }
            c *= c;
            c %= MOD;
            b >>= 1;
        }
        return Mod(a * ret);
    }
    long long getValue(){
        return a;
    }
	void setValue(ll x){a = x;}
};

Mod combA[100010];
Mod combB[100010];

int place[100010];


int main()
{
	REP(i,100010)place[i] = -1;
	
	ll n;cin >> n;
	vector<int> v;
	int r,l;
	REP(i,n+1)
	{
		int tmp;cin >> tmp;
		if(place[tmp] == -1)place[tmp] = i;
		else {r = i;l = place[tmp];}
		v.PB(tmp);
	}
	
	combA[0] = combB[0] = 1;
	
	REP(i,n+1)combA[i+1] = combA[i]*(n+1LL-i);
	//REP(i,n+2)cout << combA[i].getValue() << ' ';cout << endl;
	Mod tmp(1);
	REP(i,n+1){combA[i+1] = combA[i+1] / tmp;tmp = tmp * (i+2LL);}
	REP(i,n-(r-l))combB[i+1] = combB[i] * max(0LL,(n-(r-l)-i));
	tmp.setValue(1);
	REP(i,n-(r-l)){combB[i+1] = combB[i+1] / tmp;tmp = tmp *(i+2LL);}
	
	//REP(i,n+2)cout << combA[i].getValue() << ' ';cout << endl;
	//REP(i,n+2)cout << combB[i].getValue() << ' ';cout << endl;
	
	cout << n << endl;
	for(int i = 2;i <= n+1;i++)
	{
		Mod ans = combA[i];
		ans = ans - combB[i-1];
		cout << ans.getValue() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3704
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
long long int s[1000020];
int main() {
	long long int n;
	cin >> n;
	vector<long long int >s;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		a = a - i - 1;
		s.push_back(a);
	}
	sort(s.begin(), s.end());
	long long int b = s[n / 2];
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = ans + abs(s[i] - b);
	}
	cout << ans;
}

Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int n; cin >> n;
    int t, a; cin >> t >> a;
    int h[n];
    rep(i, n) cin >> h[i];
    int key = -1; double val = inf;
    rep(i, n) {
        if (abs(t - (double)h[i] * 0.006 - a) < abs(a - val)) {
            val = t - (double)h[i] * 0.006;
            key = i;
        }
    }
    cout << key + 1 << endl;
}


Measured memory_bytes: 256
/*************************************************************************
    > File Name: E.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-05-26 20:34:37
 ************************************************************************/

#include<bits/stdc++.h>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,q,a[MAXN],ans,c[MAXN],b[MAXN],r,p,w;
int mark[MAXN];
int main()
{
    scanf("%d%d%d",&n,&k,&q); ans=INF;
    for(int i=0;i<n;i++) scanf("%d",&a[i]); 
    for(int o=0;o<n;o++)
    {
        r=a[o];w=0;
        for (int i=0;i<=n;i++){
            if (a[i]<r){
                if (p>=k){
                    sort(b,b+p);
                    for (int j=0;j<=p-k;j++) c[w++]=b[j];
                }
                p=0;
            }
            else b[p++]=a[i];
        }
        sort(c,c+w);
        if (w>=q) ans=min(ans,c[q-1]-r);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int H, W; cin >> H >> W;
	string S[H]; 
	REP(i,H) cin >> S[i];

	vector<bool> vh(H), vw(W);
	REP(i,H){
		REP(j,W){
			if(S[i][j] == '#') vh[i] = true, vw[j] = true;
		}
	}

	REP(i,H){
		if(vh[i]){
			REP(j,W){
				if(vw[j]){
					cout << S[i][j];
				}
			}cout << endl;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
map<int,int>TM;
int s(int n)
{
    int q=(int)sqrt(n);
    for(int i=2; i<=q+1;i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}
int a[110000];
int dabiao()
{
    TM[2]=1;
    TM[3]=1;
    TM[5]=1;
    int t=6;
    for(t; t<=100000; t+=6)
    {
        if(s(t-1)==1)
            TM[t-1]=1;
        if(s(t+1)==1)
            TM[t+1]=1;
    }
}
int dabiao1()
{
    int sum=0;
    for(int i=1;i<=100000;i++)
    {
        if(TM[i]==1&&TM[(i+1)/2]==1)
            sum++;
        a[i]=sum;
    }
}
int main()
{
    int n,m;
    dabiao();
    dabiao1();
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        cout<<a[m]-a[n-1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int n;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			int a, b, c;
			cin >> a >> b >> c;
			if(a == 100 || b == 100 || c == 100){
				cout << "A" << endl;
			}else if(a + b >= 180){
				cout << "A" << endl;
			}else if(a + b + c >= 240){
				cout << "A" << endl;
			}else if(a + b + c >= 210){
				cout << "B" << endl;
			}else if(a + b + c >= 150 && (a >= 80 || b >= 80)){
				cout << "B" << endl;
			}else{
				cout << "C" << endl;
			}
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) {
         Scanner scn=new Scanner(System.in);
         int n=scn.nextInt();
         int max=1;
         for (int i = 1; i < n; i++) {
            for (int j = 2; j <10 ; j++) {
                if(n>=Math.pow(i, j)){
                    max=(int) ((max<Math.pow(i,j)) ? Math.pow(i,j):max);
                }else{break;}
            }
         }
         System.out.println(max);
    }
}


Measured memory_bytes: 22484
n, m = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

table = [[0 for j in range(n+1)] for i in range(m+1)]
table[0][1:] = [float('inf') for j in range(1, n+1)]
for i in range(1, m+1):
    for j in range(1, n+1):
        if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1)

print(table[-1][-1])



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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	ll a, b, k;
	cin >> a >> b >> k;
	if (a <= k) {
		k -= a;
		a = 0;
		b = max(0LL, b - k);
	}
	else
		a -= k;
	cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

pair<int, pair<string, string>> split(string s) {
  string key, val;
  int indent = 0;

  int state = 0;

  for(char c : s) {
    if (state == 0 && c == ' ') {
      indent++; continue;
    }
    if (c == ':') { state = 1; continue; }
    if (c == ' ' && state == 1) { state = 2; continue; }

    if (state == 0) key += c;
    else val += c;
  }

  return {indent, {key, val}};
}

struct Node {
  string val;
  map<string, int> obj;
};

vector<Node> dic;

int main(){
  string query;

  getline(cin, query);

  stack<pair<int, int>> st;
  int prevIndent = 0;

  dic.push_back(Node());
  st.push({0, -1});

  while(1) {
    string str;
    getline(cin, str);
    if (!str.size()) break;

    auto res = split(str);

    int indent = res.first;
    string key = res.second.first;
    string val = res.second.second;

    Node node;
    node.val = val;
    int id = dic.size();
    dic.push_back(node);

    if (st.top().second == indent) {
      st.pop();
      dic[st.top().first].obj[key] = id;
      st.push({id, indent});
    } else if (prevIndent < indent){
      dic[st.top().first].obj[key] = id;
      st.push({id, indent});
    } else {
      while(st.top().second >= indent) st.pop();
      dic[st.top().first].obj[key] = id;
      st.push({id, indent});
    }

    prevIndent = indent;
  }

  int now = 0;
  query += ".";

  string key;
  for(char c : query) {
    if (c == '.') {
      if (key.empty()) continue;
      if (dic[now].obj.find(key) == dic[now].obj.end()) {
        puts("no such property");
        return 0;
      }
      now = dic[now].obj[key];
      key = "";
    } else {
      key += c;
    }
    debug(now);
    debug(key);
  }

  if (dic[now].obj.size()) {
    puts("object");
  } else {
    cout << "string \"" << dic[now].val << "\"" << endl;
  }

  return 0;
}



Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec 29 16:55:54 JST 2019
 **/

vector<string> t3 = {
    "aa.",
    "..b",
    "..b",
};
vector<string> t4 = {
    "efaa",
    "efbb",
    "ccgh",
    "ddgh",
};
vector<string> t5 = {
    "aafbb", "ccf.g", "ddeeg", "..hij", "..hij",
};
vector<string> t7 = {
    "abb..kk", "a.c..ll", "ddc.j..", "....jmn", "..gg.mn", "ef.hh..", "ef.ii..",
};
signed main() {
    Int n = in();
    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }
    vector<string> ans(n, string(n, '.'));
    if (n % 3 == 0) {
        REP(x, n / 3) {
            Int offset = x * 3;
            REP(i, 3) REP(j, 3) ans[offset + i][offset + j] = t3[i][j];
        }
    } else if (n == 7 || n == 11) {
        REP(i, 7) REP(j, 7) ans[i][j] = t7[i][j];
        if (n == 11) {
            Int offset = 7;
            REP(i, 4) REP(j, 4) ans[offset + i][offset + j] = t4[i][j];
        }
    } else {
        Int X = -1, Y = -1;
        REP(x, n + 1) {
            Int rem = n - 4 * x;
            if (rem < 0 || rem % 5) continue;
            X = x, Y = rem / 5;
            break;
        }
        assert(X != -1);
        REP(x, X) {
            Int offset = x * 4;
            REP(i, 4) REP(j, 4) ans[offset + i][offset + j] = t4[i][j];
        }
        REP(y, Y) {
            Int offset = X * 4 + y * 5;
            REP(i, 5) REP(j, 5) ans[offset + i][offset + j] = t5[i][j];
        }
    }
    REP(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 2304
n, m = map(int, input().split())
bri_list=[0]
s = [[]]*m
for i in range(m):
    s[i] = list(map(int, input().split()))
s.sort(key=lambda x :x[1])

for i in range(m):
    if s[i][0]>bri_list[-1]:
        bri_list.append(s[i][1]-0.5)
print(len(bri_list)-1)
        

Measured memory_bytes: 29076
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define INF ( 1 << 30 )
int C[301],V[3][301],N,M;
int solve(){
  int rec = 0,dp[301][301];
  rep(a,3){
    fill_n(dp[0],301*301,0);
    rep(i,N) rep(j,M+1){
      if(j < C[i]) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j],dp[i+1][j-C[i]] + V[a][i]);
    }
    rec = max(rec,dp[N][M]);
  }
  return rec;
}
int main(){
  string nop;
  while(cin >> N >> M){
    rep(i,N){
      rep(j,2)getline(cin,nop);
      cin >> C[i] >> V[0][i] >> V[1][i] >> V[2][i];
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1556
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// // Container コンテナ型, map以外
// template< template<class ...> class Ctn,class T>
// std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
//   // ここでストリームに obj を書き込みます。
//   auto itr=v.begin();
//   while(itr!=v.end()){
//     if(itr!=v.begin())cout << " ";
//     cout << *(itr++);
//   }
//   return os;
// }


int main(){
  int n,a,b; cin >>n >>a >>b;
  string s; cin >>s;
  rep(i,n){
    if(s[i]=='c'){
      print("No");
      continue;
    }
    if(s[i]=='b'){
      if(b){
        print("Yes");
        b--;
        continue;
      }
      print("No");
      continue;
    }
    if(a+b){
      print("Yes");
      if(a)a--;
      else b--;
      continue;
    }
    print("No");
  }
}



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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int N = S.length();
    int K; cin >> K;
    rep(i, N){
        int dist_to_a = 'z'-S[i]+1;
        if(S[i] != 'a' && K >= dist_to_a){
            S[i] = 'a';
            K -= dist_to_a;
        }
    }
    int inc = K % 26;
    S[N-1] += inc;
    if(S[N-1] > 'z') S[N-1] -= 26;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[1]==s[2]){
        cout << "No";
        return 0;
    }
    if(s[0]==s[1]&&s[2]==s[3]){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 384
fun main() = Thread(null, ::abc171d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc171d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    val grouped = aList.groupBy { it }.mapValues { it.value.size }
        .toMutableMap().withDefault { 0 }
    var sum = aList.sum()
    val answer = StringBuilder()

    repeat(readLine()!!.toInt()) {
        val (b, c) = readLine()!!.split(' ').map { it.toLong() }
        val countOfB = grouped.getValue(b)
        sum -= (b - c) * countOfB
        answer.appendln(sum)
        grouped[c] = grouped.getValue(c) + countOfB
        grouped.remove(b)
    }

    print(answer)
}


Measured memory_bytes: 94244
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18
int INF = 100000000;//10^8
ll N;
ll W;
ll w[110];
ll v[110];
ll dp[110][110000];//種類と価値を決めた時の重さの最小値




int main(void){
    cin >> N >> W;
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    
    
   for(int i = 0; i < 110; i++){
       for(int j = 0; j < 100010; j++){
           dp[i][j] = INFL;
           if(j == 0)dp[i][j] = 0;
       }
   }
   //dp[0][0] = 0;
   
   for(int i = 1; i <= N; i++){
       for(int j = 1; j <= 100010; j++){
           dp[i][j] = dp[i-1][j];
           if(0<= j - v[i-1]){
               dp[i][j] = min(dp[i][j], dp[i-1][j - v[i-1]] + w[i-1]);
           }
       }
   }
   
   ll ans = 0;
   
   for(int i = 0; i < 100010; i++){
       if(dp[N][i] <= W){
           if(ans <= i) ans = i;
        }
   }
   cout << ans << endl;
}


Measured memory_bytes: 94592
n = int(input())
s = input()

a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
aa = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

res = ''

for i in range(len(s)):
    b = a.find(s[i])
    res += aa[b + n]

print(res)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, D;
  while (cin >> N >> D) {
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];
    vector<int> A(N + 1);
    A[0] = D;
    for (int i = 0; i < N; i++) {
      if (d[i] < 2 * A[i]) {
        A[i + 1] = abs(A[i] - d[i]);
      } else {
        A[i + 1] = A[i];
      }
    }
    vector<int> B(N + 1);
    B[N] = 1;
    for (int i = N - 1; i >= 0; i--) {
      if (d[i] >= 2 * B[i + 1]) {
        B[i] = B[i + 1];
      } else {
        B[i] = B[i + 1] + d[i];
      }
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
      int q;
      cin >> q;
      --q;
      bool res = A[q] >= B[q + 1];
      cout << (res ? "YES" : "NO") << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
#include <random>

using namespace std;

int main() {
  int x, a;
  cin >> x >> a;

  if (x < a) cout << 0 << endl;
  else cout << 10 << endl;
    
  return 0;
}


Measured memory_bytes: 384
from math import floor, ceil
from statistics import mean, median

N = int(input())
A = list(map(int,input().split()))

for i in range(len(A)):
  A[i] -= i+1

med = median(A)
x = int(floor(med))
y = int(ceil(med))
xans = 0
yans = 0

for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(xans)


Measured memory_bytes: 27256
N = int(input())
b = list(map(int, input().split()))

for i in range(N):
  if i + 1 < b[i]:
    print("-1")
    exit()

b.reverse()
L = []
for i in range(1, N + 1):
  cnt = 0
  for j in range(0, N):
    if i == 1:
      if b[j] == i:
        L.append(i)
    else:
      if b[j] == i:
        L.insert(i + cnt - 1, i)
        cnt += 1
      elif b[j] < i:
        cnt += 1

for i in L:
  print(i)
  

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    VLL h(n);rep(i,n)cin>>h[i];
    bool ok=true;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(h[i+1]-h[i]<-1)ok=false;
            else if(h[i+1]-h[i]==-1||h[i+1]-h[i]==0)h[i]--;
        }
        else{
            if(h[i+1]-h[i]<-1)ok=false;
            else if(((h[i+1]-h[i]==-1)&&(h[i]-1>=h[i-1]))||((h[i+1]-h[i]==0)&&(h[i]-1>=h[i-1])))h[i]--;
            
            if(h[i+1]<h[i-1])ok=false;
        }
        if(!ok){
            //cout<<i<<" "<<h[i-2]<<" "<<h[i]<<" "<<h[i+1]<<endl;
            break;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
}




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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
const double PI=acos(-1.0);
const int INF=1e9;
const double EPS=1e-10;
const ll MOD=1e9+7;


int main(){
string s;
cin>>s;
int cnt1=0,cnt2=0;
REP(i,s.size()){
if(s[i]=='0'&s[i+1]=='0'){
s[i+1]='1';
cnt1++;
}
else if(s[i]=='1'&s[i+1]=='1'){
s[i+1]='0';
cnt1++;
}
}
cout<<cnt1<<endl;

return 0;
}

Measured memory_bytes: 512
@ExperimentalStdlibApi
fun main() {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val guide = IntArray(n){-1}
    val nodes = Array(n){mutableListOf<Int>()}
    repeat(m) {
        val (a, b) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
        nodes[a].add(b)
        nodes[b].add(a)
    }
    val queue = ArrayDeque<Int>().also{it.add(0)}
    while (queue.isNotEmpty()) {
        val top = queue.removeFirst()
        for (next in nodes[top]) if (guide[next] < 0) {
            guide[next] = top
            queue.addLast(next)
        }
    }
    println("Yes")
    println(guide.drop(1).joinToString("\n"){"${it + 1}"})
}

Measured memory_bytes: 84232
n=int(input())

#素因数分解
def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct

import math

l=factorize(math.factorial(n))

a74=0
a24=0
a14=0
a4=0
a2=0

for i,j in l:
    if int(j)>=74:
        a74+=1
        a24+=1
        a14+=1
        a4+=1
        a2+=1
    elif int(j)>=24:
        a2+=1
        a24+=1
        a14+=1
        a4+=1
    elif int(j)>=14:
        a2+=1
        a4+=1
        a14+=1
    elif int(j)>=4:
        a2+=1
        a4+=1
    elif int(j)>=2:
        a2+=1


if a74+a24*(a2-1)+a14*(a4-1)+a4*a4*0.5*(a2-2)>=0:
    print(int(a74+a24*(a2-1)+a14*(a4-1)+a4*(a4-1)*0.5*(a2-2)))
else:
    print(0)
        
        
        
        
        
        
        
        
        

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;






struct  Combination{
  vector<ll> con;
  vector<ll> coni;
  ll n;
  ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
  }

  Combination(ll input){
    n=input;
    con.push_back(1);
    coni.push_back(1);
    rep(i,n){
      con.push_back(con[i]*(i+1)%MOD);
      coni.push_back(coni[i] * mpow(i+1,MOD-2) % MOD);
    }
  }
  
  ll comb(ll N, ll k){
    if(N == 0 && k == 1)return 1;
    if(N < k || k < 0)return 0;
    ll tmp=con[N]*coni[k]%MOD;
    return tmp*coni[N-k]%MOD;
  }
};


ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

////const long long MOD = 1000000007;
//
void solve(long long X, long long Y){
  if(X<Y)swap(X,Y);
  X-=(X-Y)*2;
  
  if(X%3!=0||X<0){
    op(0);
    return;
  }
  struct Combination c(2*X/3-(X-Y));
  

  op(c.comb(2*X/3-(X-Y),Y-X+X/3)%MOD)
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 15576
#include <vector>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

//  E[i]: vertexes which can be reased from i
//  W[i]: their weight
template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        int d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}

#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    int H, W;
    cin>>H>>W;
    vector<string> S(H);
    for (string &s: S)
        cin>>s;

    vector<vector<int>> E(H*W);
    vector<vector<int>> Wt(H*W);
    for (int y=0; y<H; y++)
        for (int x=0; x<W-1; x++)
            if (S[y][x]=='.' && S[y][x+1]=='.')
            {
                E[y*W+x].push_back(y*W+x+1);
                Wt[y*W+x].push_back(1);
                E[y*W+x+1].push_back(y*W+x);
                Wt[y*W+x+1].push_back(1);
            }
    for (int y=0; y<H-1; y++)
        for (int x=0; x<W; x++)
            if (S[y][x]=='.' && S[y+1][x]=='.')
            {
                E[y*W+x].push_back(y*W+W+x);
                Wt[y*W+x].push_back(1);
                E[y*W+W+x].push_back(y*W+x);
                Wt[y*W+W+x].push_back(1);
            }

    int ans = 0;
    for (int y=0; y<H; y++)
        for (int x=0; x<W; x++)
            if (S[y][x]=='.')
            {
                vector<int> D = dijkstra(E, Wt, y*W+x, W*H);
                for (int d: D)
                    if (d<W*H)
                        ans = max(ans, d);
            }
    cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define rev1(i,n) for(int i=n;i>0;i--)
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int> >
#define vb vector<bool>
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

void solve(){
  int n;cin>>n;
  int arr[n];rep(i,n) cin>>arr[i];
  double ans=0.0;
  rep(i,n) ans+=1.0/arr[i];
  cout<<1.0/ans;
}
signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 1020
#include <iostream>

using namespace std;

int main () {
    int m = -1, cur = 0, n;
    char c;
    cin >> n;
    for (register int i = 0; i < n; i++) {
        if(cur>m) {
            m = cur;
        }
        cin >> c;
        if(c=='I') {
            cur++;
        }
        else
            cur--;
    }
    if(cur > m) {
        m = cur;
    }
    cout << m << endl;
    return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*2);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


Measured memory_bytes: 189684
import Foundation

let n = Int(readLine()!)!
let str = readLine()!

let words = str.components(separatedBy: " ")
if let _ = words.filter({ $0 == "0" }).first {
    print("0")
    exit(0)
}

var ans: UInt64 = 1
let max: UInt64 = 1_000_000_000_000_000_000
for i in 0..<n {
    let num = UInt64(words[i])!
    let (partialValue, overflow) = ans.multipliedReportingOverflow(by: num)
    if overflow || partialValue > max {
        print("-1")
        exit(0)
    }
    ans = partialValue
}

print("\(ans)")



Measured memory_bytes: 25232
#include<iostream>
#include <string>
#include <string.h>
using namespace std;

int main(){

	int T = 0;
	int N = 0;
	string str;
	int result = 0;

	bool flag = false;
	int pivot = 0;

	cin >> T;

	for (int i = 0; i<T; i++){
		//?????????
		N = 0, str = "",flag=false,pivot=0,result=0;

		//????????????
		cin >> N;
		cin >> str;

		for (pivot = 0; pivot < (2 * N); pivot++){
			//???????????????
			if (pivot == 0){
				if (str[pivot + 2 * N] == 'Y'){
					result = result + 2;
					flag = true;
				}
				else if (str[pivot] == 'Y'){
					result++;
					flag = true;
				}
			}//?????????????????????
			else if (pivot == (2 * N) - 1){
				if (flag == false){
					if (str[pivot + 2 * N] == 'Y'){
						result = result + 2;
						flag = true;
					}
					else if (str[pivot] == 'Y'){
						result++;
						flag = true;
					}
					else{
						result--;
					}
				}
				else{
					if (str[pivot + 2 * N] == 'Y'){
						result++;
					}
					else if (str[pivot] != 'Y'){
						result--;
					}
				}
			}//?????????
			else{
				if (flag == false){
					if (str[pivot + 2 * N] == 'Y' || str[pivot + 2 * N + 1] == 'Y'){
						result = result + 2;
						flag = true;
					}
					else if (str[pivot] == 'Y' || str[pivot + 1] == 'Y'){
						result++;
						flag = true;
					}
				}
				else{
					if (str[pivot] == 'Y' || str[pivot + 1] == 'Y'){
						result++;
					}
					if (str[pivot + 2 * N] == 'Y' || str[pivot + 2 * N + 1] == 'Y'){
						result++;
					}
				}
			}
			result++;
			if(pivot!=0)pivot++;

		}

		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 1308
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i=0; i<M; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }
        int[] C = new int[K];
        int[] D = new int[K];
        for (int i=0; i<K; i++) {
            C[i] = sc.nextInt();
            D[i] = sc.nextInt();
        }

        int[] ans = solve(N, M, K, A, B, C, D);
        for (int i=0; i<N; i++) {
            if (i != 0) {
                System.out.print(" ");
            }
            System.out.print(ans[i]);
        }
        System.out.println();
    }

    private static int[] solve(int N, int M, int K, int[] A, int[] B, int[] C, int[] D) {
        int[] ans = new int[N];

        UnionFind uf = new UnionFind(N);
        int[] blocked = new int[N+1];
        int[] friend = new int[N+1];

        for (int i=0; i<M; i++) {
            uf.unite(A[i], B[i]);
            friend[A[i]]++;
            friend[B[i]]++;
        }
        for (int i=0; i<K; i++) {
            if (uf.isSame(C[i], D[i])) {
                blocked[C[i]]++;
                blocked[D[i]]++;
            }
        }

        for (int i=0; i<N; i++) {
            ans[i] = uf.size(i+1) - friend[i+1] - blocked[i+1] - 1;
            // System.err.println("i=" + i + ": " + uf.size(i+1) + " - " + friend[i+1] + " - " + blocked[i+1] + " - 1 = " + ans[i]);
        }

        return ans;
    }


    public static class UnionFind {
        /**
         * 各要素のrootを示す．対象要素がrootの場合は木の要素数を負の値で表現する
         */
        int[] parent;

        public UnionFind(int N) {
            parent = new int[N+1];
            Arrays.fill(parent, -1);
        }

        /**
         * xとyの木を併合する
         * @param x
         * @param y
         */
        public void unite(int x, int y) {
            int rootx = find(x);
            int rooty = find(y);

            // XとYが同一木なら何もしない
            if (rootx == rooty) return;

            // 小さい木を大きい木に併合したいので
            // Xの方が小さい場合はXとYを入れ替えてYをXに併合する
            if (size(x) < size(y)) {
                unite(y, x);
                return;
            }

            parent[rootx] += parent[rooty];
            parent[rooty] = x;
        }

        /**
         * UnionFind木のルートを求める
         * @param x
         * @return
         */
        public int find(int x){
            if (parent[x] < 0) {
                return x;
            }

            return parent[x] = find(parent[x]);
        }

        /**
         * 2つの要素が同一グループに属するか
         * @param x
         * @param y
         * @return
         */
        public boolean isSame(int x, int y) {
            return find(x) == find(y);
        }

        public int size(int x) {
            return -parent[find(x)];
        }
    }
}

Measured memory_bytes: 115524
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    long k, n;
    cin >> k >> n;
    vector<long> a(n);
    vector<long> d(n);

    long ans = 0;
    for (long i = 0; i < n; i++) cin >> a[i];
    for (long i = 0; i < n - 1; i++) d[i] = a[i + 1] - a[i];
    d[n - 1] = a[0] + k - a[n - 1];
    sort(d);
    for (long i = 0; i < n - 1; i++) ans += d[i];
    cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.*

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val g = mutableMapOf<Int, MutableList<Pair<Int, Int>>>()
    repeat(m) {
        val (l, r, d) = readLine()!!.split(' ').map { it.toInt() }
        g.getOrPut(l) { mutableListOf() }.add(r to d)
        g.getOrPut(r) { mutableListOf() }.add(l to -d)
    }

    val visited = mutableMapOf<Int, Int>()
    var ans = true

    for (root in g.keys) {
        if (visited.containsKey(root)) continue

        val stack = ArrayDeque<Pair<Int, Int>>()
        stack.addLast(root to 0)
        visited[root] = 0
        
        while (stack.isNotEmpty()) {
            val (u, x) = stack.removeLast()
            for ((v, d) in g[u]!!) {
                if (visited.containsKey(v)) {
                    if (visited[v] != x + d) {
                        ans = false
                        break
                    }
                } else {
                    stack.addLast(v to x + d)
                    visited[v] = x + d
                }
            }
        }

        if (!ans) break
    }

    println(if (ans) "Yes" else "No")
}


Measured memory_bytes: 145348
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int n, m, u, v;
  cin >> n >> m;
  vector<vector<int>> ver(n,vector<int>(0));
  for(int i=0; i<m; ++i){
    cin >> u >> v;
    --u; --v;
    ver[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  --s; --t;
  
  vector<vector<bool>> ng(n,vector<bool>(3,false));
  queue<P> que;
  que.push(make_pair(s,0));
  ng[s][0] = true;
  while(!que.empty()){
    int x = que.front().first;
    int dis = que.front().second;
    if(x == t && (dis%3) == 0){
      cout << dis/3 << endl;
      return 0;
    }
    que.pop();
    int ndis = dis+1;
    for(int a: ver[x]){
      if(ng[a][ndis%3]) continue;
      ng[a][ndis%3] = true;
      que.push(make_pair(a,ndis));
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 15596
#include <cstdio>

int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((a - c) * (a - c) <= d * d){
        printf("Yes");
    }else if((a - b) * (a - b) <= d * d && (b - c) * (b - c) <= d * d){
        printf("Yes");
    }else{
        printf("No");
    }
    printf("\n");

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[252521];

pii S[425252];
int b;
int tail;
int maxtail;

void add(int x, int c){
  while(tail>0){
    int y = S[tail-1].first;
    int d = S[tail-1].second;
    if(x==y){
      tail--;
      c += d;
      int e = 0;
      while(c>b)e++,c-=b;
      if(e>0){
        add(x-1,e);
      }
    }else if(x > y){
      break;
    }else{
      tail--;
      while(y > x+1){
        // printf("%d,%d\n",y,d);
        int tgt = x+1;
        if(tail>0){
          CHMAX(tgt, S[tail-1].first);
        }
        int sa = y-tgt;
        if(sa>2){
          d = 1;
        }else{
          while(sa--)d=(d+b-1)/b;
        }
        y = tgt;
        if(tail>0 && S[tail-1].first == y){
          d += S[--tail].second;
        }
      }
      // printf("%d,%d\n",y,d);
      int e = 0;
      while(d>b)e++,d-=b;
      if(e>0){
        add(x,e);
      }
    }
  }
  S[tail++] = pii(x,c);
  CHMAX(maxtail, tail);
}

bool check(int _b){
  b = _b;
  tail = 0;
  FORR(i,-1,n){
    add(i==-1 ? 0 : a[i], 1);
    // REP(i,tail)printf("(%d,%d),",S[i].first,S[i].second);
    // puts("");
  }
  // printf("end of %d\n",b);
  return tail==1 && S[0]==pii(0,1);
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  // 1 check
  bool ok1 = true;
  REP(i,n-1)if(a[i]>=a[i+1]){
    ok1 = false; break;
  }
  if(ok1){
    puts("1");
    return 0;
  }
  // binary search
  int low = 1, high = n+10;
  // FOR(b,1,10)check(b);
  while(low+1 < high){
    int b = (low+high) / 2;
    if(check(b)){
      high = b;
    }else{
      low = b;
    }
  }
  printf("%d\n",high);
  // printf("mx: %d\n",maxtail);
  return 0;
}


Measured memory_bytes: 3712
x = raw_input()
W, H, x, y, r = x.split()
W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)

if (x - r < 0) or (y - r < 0) or (x + r > W) or (y + r > H):
    print "No"
else:
    print "Yes"

Measured memory_bytes: 6468
//#include <iomanip>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cmath>
#define mod 1000000009
int main() {
	long long n, c;
	std::cin >> n >> c;
	std::vector<long long> v(n, 0);
	std::vector<long long> x(n, 0);
	for (int i = 0; i < n; ++i) {
		std::cin >>x[i] >> v[i];
	}
	std::vector<long long> clockwise(n, 0);
	std::vector<long long> counterclockwise(n, 0);
	std::vector<long long> clockwise1(n, 0);
	std::vector<long long> counterclockwise1(n, 0);
	long long res = 0;
	long long res1 = 0;
	long long res_other = 0;
	long long res1_other = 0;
	for (int i = 0; i < n; ++i) {
		if (i == 0) {
			clockwise[i] = v[i] - x[i];
		} else {
			clockwise[i] = clockwise[i - 1] + v[i] - (x[i] - x[i - 1]);
		}
		res = std::max(res, clockwise[i]);
		//-------------------------
		if (i == 0) {
			clockwise1[i] = std::max(clockwise1[i], clockwise[i] - x[i]);
		} else {
			clockwise1[i] = std::max(clockwise[i] - x[i], clockwise1[i - 1]);
		}
		//---------------------------------
		if (i == 0) {
			counterclockwise[i] = v[n - 1 - i] -  (c - x[n - 1 - i]);
		} else {
			counterclockwise[i] = counterclockwise[i - 1] + v[n - 1 - i] - (x[n - i] - x[n - 1 - i]);
			//std::cout << (x[n - i] - x[n - 1 - i]) <<'\n';
		}
		res_other = std::max(res_other, counterclockwise[i]);
		//------------------
		counterclockwise1[i] = counterclockwise[i] - (c - x[n - 1 - i]);
		if (i == 0) {
			counterclockwise1[i] = std::max(counterclockwise1[i], counterclockwise[i] - (c - x[n - 1 - i]));
		} else {
			counterclockwise1[i] = std::max(counterclockwise[i] - (c - x[n - 1 - i]), counterclockwise1[i - 1]);
		}
	}
	for (int i = 0; i < n - 1; ++i) {
		res1 = std::max(res1, clockwise[i] + counterclockwise1[(n - 1) - i - 1]);
		res1_other = std::max(res1_other, counterclockwise[i] + clockwise1[(n - 1) - i - 1]);
	}
	long long ans = 0;
	//std::cout << res << " " << res_other << " " << res1 << " " << res1_other << '\n';
	ans = std::max(res, res_other);
	ans = std::max(ans, res1);
	ans = std::max(ans, res1_other);
	std::cout << ans << '\n';
}


Measured memory_bytes: 4992