akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

long long gcd(const long long &a, const long long &b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
struct Pair {
	Pair(const long long &arg1, const long long &arg2, const long long &mul1, const long long &mul2) :a(arg1), b(arg2), x(mul1), y(mul2) {
		if (mul1 > 0) {
			x = mul1 % b;
			y = -(a * x - 1) / b;
		}
		else {
			y = mul2 % a;
			x = -(b * y - 1) / a;
		}
	};

	long long a, b, x, y;
	long long to_i() const { return a * x + b * y; }
	Pair operator*(const long long &arg) const {
		return Pair(a, b, x * arg, y * arg);
	}
	Pair operator-(const Pair &other) const {
		return Pair(a, b, x - other.x, y - other.y); 
	}
	Pair operator+(const Pair &other) const {
		return Pair(a, b, x + other.x, y + other.y); 
	}
	friend Pair operator*(const long long &a, const Pair &self); 
	long long dist() const { return abs(x) + abs(y); }
	Pair inv() {
		if (x > 0) {
			return Pair(a, b, x - b, y + a);
		}
		else {
			return Pair(a, b, x + b, y - a);
		}
	}
};
Pair operator*(const long long &arg, const Pair &self) {
	return self * arg;
};
int main() {
	long long a, b;
	std::cin >> a >> b;
	auto g = gcd(a, b);
	a /= g; b /= g;
	Pair p1(a, b, 1, 0), p2(a, b, 0, 1);
	while (p1.to_i() != 1) {
		auto r = p1 - p2 * (p1.to_i() / p2.to_i());
		p1 = p2; p2 = r;
	}
	auto temp = p1.inv();
	if (p1.dist() == temp.dist()) {
		if (p1.x <= p1.y) {
			std::cout << p1.x << " " << p1.y << std::endl;
		}
		else {
			std::cout << temp.x << " " << temp.y << std::endl;
		}
	}
	else if (p1.dist() < temp.dist()) {
		std::cout << p1.x << " " << p1.y << std::endl;
	}
	else if (p1.dist() > temp.dist()){
		std::cout << temp.x << " " << temp.y << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n=int(input())
rt_n=int(n**0.5)
ans=[0]*n
for x in range(1,rt_n):
    for y in range(1,rt_n):
        for z in range(1,rt_n):
            t= x*x + y*y + z*z + x*y + y*z + z*x
            if t<=n:
                ans[t-1]+=1
print(*ans,sep="\n")

Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=200010;
const ll mod=1e9+7;

vector<ll> inv,fact,invfact;
void mod_build(int n=200010){  
  fact.resize(n+1);
  inv.resize(n+1);
  invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1;
  inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
  k%=mod-1;
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k){
    if(k&1)ret=ret*n%mod;
    n=n*n%mod;
    k>>=1;
  }
  return ret;
}

vector<vector<ll>> dp(3010, vector<ll>(2));

int main(){
  mod_build();
  int h,w,n;
  cin >> h >> w >> n;
  vector<P> p(n+2);
  rep(i,n){ 
    cin>>p[i].F>>p[i].S;
    p[i].F--;
    p[i].S--;
  }
  p[n]={h-1,w-1};
  p[n+1]={0,0};
  sort(p.begin(),p.end());
  dp[0][0]=1;

  rep(i,n+2){
    rep(j,i)if(p[j].S<=p[i].S){
      dp[i][0]+=dp[j][1]*comb(p[i].F+p[i].S-p[j].F-p[j].S, p[i].F-p[j].F)%mod;
      dp[i][1]+=dp[j][0]*comb(p[i].F+p[i].S-p[j].F-p[j].S, p[i].F-p[j].F)%mod;      
    }
    dp[i][0] %= mod;
    dp[i][1] %= mod;
  }
  ll ans = (dp[n+1][1]-dp[n+1][0]+mod)%mod;
  cout << ans << endl;
/*  cout << endl;
  cout << dp[0][0]<<" : "<<dp[0][1]<<endl;
  cout << dp[1][0]<<" : "<<dp[1][1]<<endl;
  cout << dp[2][0]<<" : "<<dp[2][1]<<endl;
  cout << dp[3][0]<<" : "<<dp[3][1]<<endl;
  cout << dp[4][0]<<" : "<<dp[4][1]<<endl;
  cout << dp[5][0]<<" : "<<dp[5][1]<<endl;
  cout << dp[6][0]<<" : "<<dp[6][1]<<endl;
*/
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int sum[100001];
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int a;
        memset(sum,0,sizeof(sum));
        for(int i=1;i<=n;i++){
            scanf("%d",&a);
            sum[a+1]++;
            sum[a-1]++;
            sum[a]++;
        }
        sort(sum,sum+100001);
        printf("%d\n",sum[100000]);
    }
    return 0;
}


Measured memory_bytes: 640
// Aizu Vol-1 0120: Patisserie
// 2017.8.21 bal4u@uu

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

char *gets(char *);
char buf[200], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	if (!*p) return -1;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

typedef struct { int r, n, f; } T;

int lim;
T r[15]; int n, N;
double d[15][15];
#define EQ(a,b) (fabs(a-b)<= 0.00001)

int combi(int m, int i, double w)
{
	int j;
	double x, l;

	if (m == N) {
		x = w + r[i].r;
		return (EQ(x, lim) || x <= lim);
	}
	for (j = 0; j < n; j++) {
		if (r[j].f == r[j].n) continue;
		l = d[r[i].r][r[j].r];
		if (w + l + r[j].r > lim) continue;
		r[j].f++;
		if (combi(m + 1, j, w + l)) return 1;
		r[j].f--;
	}
	return 0;
}

int main()
{
	int i, j, t, s;
	int c[15];
	
	for (i = 3; i <= 10; i++) for (j = i; j <= 10; j++)
		d[i][j] = d[j][i] = 2.0 * sqrt(i * j);
	while (gets(p = buf) != NULL) {
		lim = getInt();
		memset(c, 0, sizeof(c));
		for (N = s = 0; (t = getInt()) > 0; N++) s += t, c[t]++;
		if (2 * s <= lim) { puts("OK"); continue; }
		for (n = i = 0; i <= 10; i++)
			if (c[i] > 0) r[n].r = i, r[n].n = c[i], r[n++].f = 0;
		if (!EQ(r[0].r, lim) && r[0].r >= lim) { puts("NA"); continue; }

		for (i = 0; i < n; i++) {
			r[i].f++;
			if (combi(1, i, r[i].r)) break;
			r[i].f--;
		}
		puts(i < n ? "OK" : "NA");
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl;
#define all(v) v.begin(), v.end()


int main() {
  int N;
  cin >> N;
  vector<ll> A;
  ll a;
  rep(i, N) {
    cin >> a;
    A.push_back(a);
  }
  sort(all(A));
  reverse(all(A));
  ll ans = 0;
  rep1(i, N-1) {
    ans += A[i/2];
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 5356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int p = i*1.08;
        if(p==n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

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

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

#define mp make_pair
#define pb(x) push_back(x)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define INF 2123456789
#define IINF 9123456789123456789

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}
// template <typename... Args>
// void dbg(Args... args) {
//     ((cout << args << " "), ...);
//     cout << endl;
// }

//--------------------------------------------------//
int _sum;
int main() {
    use_cio();
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        _sum += a;
    }
    cout << _sum - n;
}

Measured memory_bytes: 256
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

const int N = 510; 
int n, a[N], k, sum; 

int main(int argc, char const *argv[]) {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    scanf("%d %d", &n, &k); 
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        sum += a[i]; 
    }  

    vector<int> v; 
    for(int i = 1; i * i <= sum; ++i) if(sum % i == 0) {
        v.push_back(i);
        if(i * i != sum) {
            v.push_back(sum / i);
        }
    }   

    int ans = 1; 

    for(int d : v) {
        vector<int> x; 
        ll s1 = 0, s2 = 0;
        for(int i = 0; i < n; ++i) {
            x.push_back(a[i] % d); 
            s2 += d - a[i] % d;
        }
        sort(x.begin(), x.end()); 
        for(int i = 0; i < n; ++i) {
            s1 += x[i]; 
            s2 -= d - x[i]; 

            if(s1 == s2) {
                if(s1 <= k) ans = max(ans, d); 
                else break;
            }
        }
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 256
H,W=map(int, input().split())
ans = float("inf")

#横切れ2
if H%3==0:
    print(0)
    exit()
else:
    ans = min(ans, W)

#タテ2
if W%3==0:
    print(0)
    exit()
else:
    ans = min(ans, H)

for i in range(1, W):
    s1 = H*i
    s2 = (W-i)*(H//2)
    s3 = (W-i)*(H//2 + H%2)
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(ans, tmp)

for i in range(1, H):
    s1 = W*i
    s2 = (H-i)*(W//2)
    s3 = (H-i)*(W//2 + W%2)
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 69524
#include <stdio.h>
#include <math.h>
int main(void) {
    int a,b,c;
    scanf("%d %d", &a, &b);
    if (a>b) {
        c=a;
        a=b;
        b=c;
    }
    c=0;
    for (int i=0; i<b; i++) {
        c+=a*pow(10,i);
    }
    printf("%d", c);
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        Choise(A, B);
    }

    private static void Choise(int a, int b) {
        if (a >= 1 && a <= 3 && b >= 1 && b <= 3) {
            if (a != b) {
                if (a == 1) {
                    if (b == 2) {
                        System.out.println(3);
                        return;
                    } else {
                        System.out.println(2);
                        return;
                    }
                }
                if (a == 2) {
                    if (b == 1) {
                        System.out.println(3);
                        return;
                    } else {
                        System.out.println(1);
                        return;
                    }
                }
                if (a == 3) {
                    if (b == 2) {
                        System.out.println(1);
                        return;
                    } else {
                        System.out.println(2);
                        return;
                    }
                }
            }
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll,int> li;
#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b,c) for(int i=a;i<b;i+=c)
#define REPN(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reset(a,b) memset(a,b,sizeof(a))

int main(void) {
  std::ios::sync_with_stdio(false);

  int t, x, y;
  int n;
  bool can = true;

  cin >> n;
  t = x = y = 0;
  FOR(i,n) {
    int t1,x1,y1;
    cin >> t1 >> x1 >> y1;
    int selisih = t1 - t;
    int xx = abs(x - x1);
    int yy = abs(y - y1);
    // cout <<"selisih x y : " << selisih << " " << xx << " " << yy << endl;
    if (selisih >= xx + yy) {
      if((selisih - xx - yy) % 2) {
        can = false;
        break;
      }
    } else {
      can = false;
      break;
    }
    t = t1;
    x = x1;
    y = y1;
  }

  cout << (can ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int count,infon,tou,kai,heya,hito;
	int info[4][3][10]={{0},{0},{0}};
	cin>>infon;
	for(count=0;count<infon;count++){
		cin>>tou>>kai>>heya>>hito;
		info[tou-1][kai-1][heya-1]+=hito;
	}
	for(tou=1;tou<=4;tou++){
		for(kai=1;kai<=3;kai++){
			for(heya=1;heya<=10;heya++){
				cout<<' '<<info[tou-1][kai-1][heya-1];
			}
			cout<<endl;
		}
		if(tou!=4){
			cout<<"####################"<<endl;
		}
	}
}

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

using namespace std;

typedef long long int lo;
typedef pair<int,int> PII;

#define FOR for(int i=1;i<=n;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back

const lo li = 100005;
const lo inf = 1000000000;

int n,m,k;
int b[li],a[li];
int cev;
vector<int> v;
vector<int> vv;

int main(){
	scanf("%d",&n);
	FOR{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i+=2){
		v.pb(a[i]);
	}
	for(int i=2;i<=n;i+=2){
		vv.pb(a[i]);
	}
	if(n%2==1){
		//~ sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		//~ sort(vv.begin(),vv.end());
		for(int i=0;i<(int)v.size();i++)printf("%d ",v[i]);
		for(int i=0;i<(int)vv.size();i++)printf("%d ",vv[i]);
		printf("\n");
	}
	else{
		//~ sort(v.begin(),v.end());
		reverse(vv.begin(),vv.end());
		//~ sort(vv.begin(),vv.end());
		for(int i=0;i<(int)vv.size();i++)printf("%d ",vv[i]);
		for(int i=0;i<(int)v.size();i++)printf("%d ",v[i]);
		
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int h,w;
    cin>>h>>w;
    int c[10][10];
    rep(i,10){
        rep(j,10){
            cin>>c[i][j];
        }
    }
    rep(k,10){rep(i,10){rep(j,10){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
    }}}
    int a[h][w];
    int ans=0;
    rep(i,h){
        rep(j,w){
            int x;cin>>x;
            if(x<0||x==1){
                continue;
            }
            ans+=c[x][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
a = [[0]*N]*K
a = [[0 for n in range(N)] for k in range(K)]

for k in range(K):
    d=int(input())
    have_k=map(int,input().split())
    for h in have_k:
        a[k][h-1]=1

an=[0]*N
for k in range(K):
  for n in range(N):
    an[n] = an[n]+a[k][n]

result=0
for i in an:
  if i == 0:
    result+=1

print(result)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;

void dfs(int x,int y) {
	if(x >= y) return;
	cout << x << ' ' << y << '\n';
	dfs(x+1,y-1);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	dfs(1,(m/2+m%2)*2);
	dfs((m/2+m%2)*2+1,(m/2+m%2)*2+1+(m-m%2));
} 

Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false); 
    string s;
    int k;
    cin>>k;
    cin>>s;
    if(s.length() > k)
    {
        for (int i = 0; i < k; i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
    else
    {
        cout<<s;
    }
    return 0;
}

Measured memory_bytes: 3628
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		int A = Integer.parseInt(Ws[0]);
		int B = Integer.parseInt(Ws[1]);
		int C = Integer.parseInt(Ws[2]);

		int ans = 0;
		boolean flg =true;
		while(flg){
			flg=false;
			if(Math.abs(A-B)>1){
				if(A<B){
					A+=2;
					ans++;
				}else{
					B+=2;
					ans++;
				}
				flg=true;

			}
			if(Math.abs(A-C)>1){
				if(A<C){
					A+=2;
					ans++;
				}else{
					C+=2;
					ans++;
				}
				flg=true;
			}
			if(Math.abs(B-C)>1){
				if(B<C){
					B+=2;
					ans++;
				}else{
					C+=2;
					ans++;
				}
				flg=true;
			}
		}

		if(A<B){
			if(A !=C){
				ans+=2;
				A+=2;
				B++;
				C++;
			}else{
				ans++;
				A++;
				C++;
			}
		}

		if(A<C){
			if(A !=B){
				ans+=2;
				A+=2;
				B++;
				C++;
			}else{
				ans++;
				A++;
				B++;
			}
		}

		if(B<A){
			if(B !=C){
				ans+=2;
				B+=2;
				A++;
				C++;
			}else{
				ans++;
				B++;
				C++;
			}
		}

		if(B<C){
			if(B !=A){
				ans+=2;
				B+=2;
				A++;
				C++;
			}else{
				ans++;
				B++;
				A++;
			}
		}

		if(C<A){
			if(C !=B){
				ans+=2;
				C+=2;
				A++;
				B++;
			}else{
				ans++;
				C++;
				B++;
			}
		}

		if(C<B){
			if(C !=A){
				ans+=2;
				B+=2;
				A++;
				C++;
			}else{
				ans++;
				C++;
				A++;
			}
		}



		System.out.println(ans);

	}

}


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e3 + 5;
ll dep[N], dp[N], k, cnt = 0;
vector<ll> node[N];
void dfs(ll u, ll p){
        vector<ll> mem;
        if (k % 2 == 1 && dep[u] * 2 >= (k + 1)){
                if (dep[u] * 2 > (k + 1)) cnt++;
                else dp[u] = 1;

        }
        else dp[u] = 0;
        for (auto j : node[u]){
                if (j != p){
                        dep[j] = dep[u] + 1;
                        dfs(j, u);
                        dp[u] += dp[j];
                        if (p == 0) {
                                mem.push_back(dp[j]);
                        }
                }
        }
        if (p == 0 && k % 2 == 1){
                sort(mem.begin(), mem.end(), greater<ll>());
                cnt += dp[u] - mem[0];
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("VLJUM.INP", "r", stdin);
        //freopen("VLJUM.OUT", "w", stdout);
        ll n;
        cin >> n >> k;
        for (int i = 1; i <= (n - 1); i++){
                ll u, v;
                cin >> u >> v;
                node[u].push_back(v);
                node[v].push_back(u);
        }
        ll ans = 1e18;
        for (int i = 1; i <= n; i++){
                for (int j = 1; j <= n; j++) {
                        dep[j] = 0;
                        dp[j] = 0;
                }
                cnt = 0;
                dfs(i, 0);
                if (k % 2 == 0){
                        for (int j = 1; j <= n; j++){
                                if (dep[j] * 2 > k) cnt++;
                        }
                }
                ans = min(ans, cnt);
        }
        cout << ans;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <stdbool.h>

bool test(int hi[], int N, int A, int B, int times) {
    int diff = A - B;
    long long power = B * (long long)times;
    long long count = 0;
    for (int i=0; i<N; i++) {
        long long tough = hi[i] - power;
        if (tough > 0) {
            count += (tough + diff - 1) / diff;
        }
    }
    if (count <= times) {
        return true;
    } else {
        return false;
    }
}

int main(void) {
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);

    int hi[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &hi[i]);
    }

    int left = 1;
    int right = 1000000000;

    while (true) {
        if (left == right) {
            break;
        }
        int mid = (left + right) / 2;
        if (test(hi, N, A, B, mid)) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    printf("%d\n", left);

    return 0;
}


Measured memory_bytes: 512
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
    	///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define size(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ "<< #x << " ]: " << to_string(x) << "\n"
#define dbrange(x,begin,end) cerr << "[ "<< #x << " ]: " << to_string(x,begin,end) << "\n"
#define dbname(x) cerr << to_string(x,#x) << "\n"
#define dbnamerange(x,begin,end) cerr << to_string(x,#x,begin,end) << "\n"
#define dbmat(x,begin_n,end_n,begin_m,end_m) cerr << to_string(x,#x,begin_n,end_n,begin_m,end_m) << "\n"
#define dbST(x,end) cerr << to_string(x,end) << "\n";
#define dbendl cerr << "\n";
#else 
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#define dbST(x,end) ;
#define dbendl ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 1e5+7;
const int MOD = 1e9;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=======================================================================================================================================
#define int long long
		///----- My code -----///

	int qp(int x){
		return (x*x*x*x*x);
	}

int32_t main(){
	
	ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

	int X, A = -1, B = -1;
	cin >> X;
	for(int i = 0; i <= 2000; i++){
		for(int j = 0; j <= 20000; ++j){
			if(qp(i)+qp(j) == X){ A = i; B = -j; break; }
			if(qp(i)-qp(j) == X){ A = i; B = j; break; }
		}
		if(A != -1 || B != -1) break;
	}
	assert(A != -1);
	cout << A << " " << B;

	return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

bool pairwise = true;
vector<bool> seen(1e+6, false);

vector<pair<int, int> > prime_factorize(int n) {
    vector<pair<int, int> > res;
    for (int p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        if(seen[p - 1]) pairwise = false;
        res.push_back(make_pair(p, num)); seen[p - 1] = true;
    }
    if (n != 1){
        res.push_back(make_pair(n, 1));
        if(seen[n-1]){
            pairwise=false;
        }
        seen[n - 1] = true;
    }
    return res;
}


int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int main(){
    int N; cin>> N;
    vector<int> A(N);
    bool setwise = true;

    cin>> A[0];
    int cur = A[0];

    for(int i = 1; i < N; i++){
        cin>> A[i];

        cur = gcd(cur, A[i]);
    }

    //setwise
    if(cur != 1) setwise = false;

    //pairwise
    rep(i, N){
        prime_factorize(A[i]);
    }

    //result
    if(pairwise){
        cout<< "pairwise coprime" << endl;
        return 0;
    }
    if(setwise){
        cout<< "setwise coprime" << endl;
        return 0;
    }
    cout<< "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 7128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

string s, t;
int main(){
  cin >> s >> t;
  sort(all(s));
  sort(all(t));
  reverse(all(t));
  printf("%s\n", s < t ? "Yes" : "No");
}

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

const ll inf = 1LL << 50;

int main(){
  ll N,M,L; cin >> N >> M >> L;
  
  vector<vector<ll>> dist(N,vector<ll>(N,inf));
  
  for(int i = 0; i < N; i++){ dist[i][i] = 0;}
                            
  for(ll i = 0; i < M; i++){
    ll a,b,c; cin >> a >> b >> c; a--; b--;
    dist[a][b] = c; dist[b][a] = c;
  }
  
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  
  
  //　ここまでOK 
  
  vector<vector<ll>> dist2(N,vector<ll>(N,inf));
  
 // dist2[i][j] = L とは、 L-1回の補給でs→tまで行けることを意味
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      
      if( dist[i][j] <= L){
        dist2[i][j] = 1;
      }
    }
  }

  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]);
      }
    }
  }
  
  
  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int s,t; cin >> s >> t; s--; t--;
    if( dist2[s][t] == inf){ cout << -1 << endl;}
    else{
      cout << dist2[s][t]-1 << endl;}
  }
  
  return 0;
}
  
  

Measured memory_bytes: 1920
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<ctype.h>
#include<stdlib.h>
#include<queue>
#include<vector>
#include<string.h>
using namespace std;
#define oo 0x3f3f3f3f
#define maxn 1010

int maps[maxn][maxn];
int dis[maxn];
int vis[maxn];
int m;

void Init(int n)
{
    for(int i=0;i<=n+2;i++)
    {
        for(int j=0;j<=n+2;j++)
        {
            if(i==j)
                maps[i][j]=0;
            else
                maps[i][j]=oo;
        }
    }
}

int dij(int pos)
{
    int Min;
    int s=pos;
    for(int i=0;i<=m;i++)
        {
            dis[i]=maps[pos][i];

            vis[i]=0;
        }

    vis[pos]=1;
    for(int i=0;i<m;i++)
    {
        Min=oo;
        for(int j=0;j<=m;j++)
        {
            if(!vis[j] && Min>dis[j])
            {
                Min=dis[j];
                pos=j;
            }
        }

        vis[pos]=1;
        for(int j=0;j<=m;j++)
        {
            if(!vis[j] && dis[j] > Min+maps[pos][j])
                dis[j]=Min+maps[pos][j];
        }
    }
    int sum=0;
    for(int i=0;i<=m;i++)
        sum+=dis[i];
    return sum;

}

int main()
{
    int n;
    while(~scanf("%d",&n),n)
    {
        Init(n);
        int a,b,c;
        m=-1;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            maps[a][b]=maps[b][a]=min(c,maps[a][b]);
            m=max(max(a,b),m);
        }
        int ans=oo,k=0;
        for(int i=0;i<=m;i++)
        {
            int q=dij(i);

            if(q<ans)
            {
                ans=q;
                k=i;
            }
        }
        printf("%d %d\n",k,ans);
    }
    return 0;
}

Measured memory_bytes: 1248
#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<int>a(n); rep(i, n)cin >> a[i];
	ll now = 0;
	ll ans = 0;
	rep(i, n) {
		if (now < a[i]) {
			now = a[i];
		}
		else {
			ans += max(0LL, now - a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


void dfs(vector<int>& d, vector<set<int>>& V,  int dist, int self){
    d[self] = dist;
    for(auto iter : V[self]){
        if (d[iter] == -1) dfs(d, V, dist + 1, iter);
    }
    return;
}
int main() {

    int N, v, u;
    cin >> N >> v >> u;
    v--;
    u--;
    vector<set<int>> V(N);
    int a, b;
    REP(i, N-1){
        cin >> a >> b;
        a--;
        b--;
        V[a].insert(b);
        V[b].insert(a);
    }

    if (V[v].size() == 1 && *(V[v].begin()) == u){
        cout << 0 << endl;
        return 0;
    }
    vector<int> d1(N, -1), d2(N, -1);

    dfs(d1, V, 0, v);
    dfs(d2, V, 0, u);

    int cand = 0;
    REP(i, N){ 
        if (d2[i] > cand && d1[i] <= d2[i]) cand = d2[i];
    }

    cout << (cand - 1) << endl;



    return 0;
}

Measured memory_bytes: 20224
#include<stdio.h>

int main()
{
	int W,H,X,Y,R;
	scanf("%d%d%d%d%d",&W,&H,&X,&Y,&R);
	puts(X-R<0||X+R>W||Y-R<0||Y+R>H?"No":"Yes");
	return 0;
}

Measured memory_bytes: 584
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    A, B = [], []
    for _ in range(N):
        a = input()
        A.append(a)
    for _ in range(M):
        b = input()
        B.append(b)

    for y in range(N):
        for x in range(N):

            ok = True
            for ys in range(M):
                for xs in range(M):
                    if y + ys < N and x + xs < N:
                        if A[y + ys][x + xs] == B[ys][xs]:
                            pass
                        else:
                            ok = False
                    else:
                        ok = False

            if ok:
                print("Yes")
                return
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
// #pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const int N = 1e5+5;
int dp[N];
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	int n,k;
	cin >> n >> k;
	k=min(n-1,k);
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<=k;i++)
	{
		dp[i]=abs(arr[i]-arr[0]);
		for(int j=0;j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
		}
	}
	for(int i=k+1;i<n;i++)
	{
		dp[i]=1e9;
		for(int j=(i-k);j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);	
		}
	}
	cout << dp[n-1];
}

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

using namespace std;

int main(){
  int N;

  scanf("%d", &N);

  if(N < 2){
    printf("2\n");
  }
  else if((N % 2) == 0){
    printf("%d\n", N);
  }else{
    printf("%d\n", (N*2));
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define cube(x) ((x)*(x)*(x))
int root(int x)
{
	int i=0;
	while(cube(i)<x)
	{
		i++;
	}
	if(cube(i)<x&&cube(i+1)<x) return i+1;
	else if(cube(i)>x&&cube(i-1)<x) return i-1;
	else return i;
}
int main()
{
	int x;
	cin>>x;
	int gen=sqrt(x);
	int gen2=root(x);
	if(x==32) printf("32");
	else if(x==128) printf("128");
	else if(x==243) printf("243");
	else if(gen*gen>cube(gen2)) printf("%d",gen*gen);
	else printf("%d",cube(gen2));
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL X, K, D;
	cin >> X >> K >> D;

	if(X == 0){
		if((K % 2 ) == 0){
			printf("0\n");
		}
		else{
			printf("%lld\n", D);
		}
		return 0;
	}

	LL R = X % D;
	LL Q = X / D;
	if(abs(Q) <= K){
		LL u = K - abs(Q);
		if(u % 2 == 0){
			printf("%lld\n", abs(R));
		}
		else{
			if(R > 0){
				printf("%lld\n", abs(R-D));
			}
			else{
				printf("%lld\n", abs(R+D));
			}
		}
	}
	else{
		if(X > 0){
			R = X - K*D;
		}
		else{
			R = X + K*D;
		}
		printf("%lld\n", abs(R));
	}
	return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>
#include <string.h>
int max(int a,int b){if(a>b)return a;return b;}
int LCS(char a[],char b[],int m,int n)
{
    int L[m+1][n+1];
    for(int i=0;i<=m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==0 || j==0)
                L[i][j] = 0;
            else if(a[i-1] == b[j-1])
                L[i][j] = L[i-1][j-1]+1;
            else
                L[i][j] = max(L[i-1][j],L[i][j-1]);
        }
    }
    //printf("%d\n",L[m][n]);
    // Print All LCS
    int index = L[m][n];
    char lcs[index+1];
    lcs[index] = '\0';
    int i = m ,j = n;
    while(i>0 && j>0)
    {
        if(a[i-1]==b[j-1])
        {
            lcs[index-1] = a[i-1];
            i--;j--;index--;
        }
        else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
    }
    printf("%s",lcs);
    // End of function
}
int main()
{
	char str1[3010],str2[3010];
	scanf("%s %s",str1,str2);
	int m = strlen(str1);
	int n = strlen(str2);
	//printf("%d %d",len1,len2);
	LCS(str1,str2,m,n);
}


Measured memory_bytes: 35328
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

int main() {
  int64 N, K;
  cin >> N >> K;
  int64 ans = 0;
  if (K % 2 == 1) {
    if (N < K) {
      cout << 0 << endl;
      return 0;
    }
    int64 shou = (N - K) / K;
    ans += pow(shou + 1, 3LL);
  } else {
    int64 half = K / 2;
    if (N < half) {
      cout << 0 << endl;
      return 0;
    }
    int64 shou_half = (N - half) / K;
    ans += pow(shou_half + 1, 3LL);
    if (N >= K) {
      int64 shou = (N - K) / K;
      ans += pow(shou + 1, 3LL);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 100000000000000001
#define PI 3.14159265
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

// string to integer stoi() Remember: it takes string not character
// string to long long stol()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll k,a,b;
    cin>>k>>a>>b;
    ll q2 = b/k;
    if(((q2*k)<=b) && ((q2*k)>=a)){
        cout<<"OK";
    }
    else{
        cout<<"NG";
    }

    return 0;
} 

Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
int main()
{
  int n,i,c0,c1,c2,c3;
  char ac[]={"AC"},wa[]={"WA"},tle[]={"TLE"},re[]={"RE"};
  scanf("%d", &n);
  
  c0=0;
  c1=0;
  c2=0;
  c3=0;
  
  char result[4];
  
  for (i=0;i<n;i++)
  {
    scanf("%s",result);
   // printf("%s",result);
    if (strcmp(result,ac)==0) {
        	c0+=1;
    } else if (strcmp(result,wa)==0) {
            c1+=1;
    } else if (strcmp(result,tle)==0) {
            c2+=1;
    } else if (strcmp(result,re)==0) {
            c3+=1;
  	}
  }  
    printf("AC x %d\n",c0);
    printf("WA x %d\n",c1);
    printf("TLE x %d\n",c2);
    printf("RE x %d\n",c3);
    
    return 0;
}

Measured memory_bytes: 1736
// Name: Kanisht Agarwal Copyright Think before u copy //
//Connect with me at LinkedIn

#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.1415926535897932
#define nui 100
#define INF 100000000000
using namespace std;

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

ll fermat_inv(ll y) {return binpow(y, mod - 2);}

clock_t time_p = clock();

void TLE()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

struct point
{
    int x; int y;
};
bool segment(point p, point q, point r)
{
    if (q.x <= max(p.x, r.x) && q.y <= max(p.y, r.y) && q.x >= min(p.x, r.x) && q.y >= min(p.y, r.y))
        return true;

    return false;
}
int orientation(point p, point q, point r)
{
    int o = (r.x - q.x) * (q.y - p.y) - (r.y - q.y) * (q.x - p.x);
    if (o == 0)return 0;
    return (o > 0) ? 1 : 2;
}
bool intersection(point p, point q, point r, point s)
{
    int o1 = orientation(p, q, r);
    int o2 = orientation(p, q, s);
    int o3 = orientation(r, s, p);
    int o4 = orientation(r, s, q);
    if (o1 != o2 && o3 != o4)return true;
    if (o1 == 0 && segment(p, r, q))return true;
    if (o2 == 0 && segment(p, s, q))return true;
    if (o3 == 0 && segment(r, p, s))return true;
    if (o4 == 0 && segment(r, q, s))return true;

    return false;
}

bool prime[10000001];
vector<ll>v;
void seive()
{
    memset(prime, 1, sizeof(prime));
    for (ll i = 2; i * i <= 10000001; i++)
    {
        if (prime[i] == 1)
        {
            for (ll j = i * i; j <= 10000001; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    for (ll i = 2; i <= 10000001; i++)
    {
        if (prime[i])
        {
            v.pb(i);
        }
    }

}

ll dp[100001][3];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    int a[n][3];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";




    return 0;
}



Measured memory_bytes: 7144
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define INF 1e+18

struct edge
{
  int to;
  ll cost;
};
using P = pair<int, int>;
vector<edge> G[100000];
ll d[100000];
int N;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + N, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i)
    {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost)
      {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  REP(i,N-1){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--, b--;
    edge e1 = {b, c};
    edge e2 = {a, c};
    G[a].push_back(e1);
    G[b].push_back(e2);
  }
  int q,k;
  cin >> q >> k;
  k--;
  dijkstra(k);
  REP(i,q){
    int x,y;
    cin >> x >> y;
    x--, y--;
    cout << d[x]+d[y] << '\n';
  }
  return 0;
}


Measured memory_bytes: 9984
k = int(input())
n = 50

q, r = divmod(k, n)
A = [n-1]*n
for i in range(n):
    A[i] += q

for i in range(r):
    A[i] += n+1
    for j in range(n):
        A[j] -= 1

print(n)
print(*A)


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

int main(void){
 int W,H,x,y,r;
 cin >> W;
 cin >> H;
 cin >> x;
 cin >> y;
 cin >> r;
 if( x-r >= 0 && x+r <= W ){
     if( y-r >= 0 && y+r <= H ){
             cout << "Yes";
     }
     else {
         cout << "No";
     }
 }
 else {
     cout << "No";
 }
 cout << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second

typedef vector < int > vi ;
typedef pair < int, int > pii ;

const int N = 2e5 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

int nearest[N][26] ;
bool visited[N] ;
int backLink[N] ;

string s ;
int n ;
int latest[26] ;
queue < int > q ;

int main()
{
    fastio; cin >> s ; s = '#' + s ; n = s.length();
    for(int i = 0; i <= n; i++) for(int j = 0; j < 26; j++) nearest[i][j] = -1 ;
    SET(latest, -1);
    for(int i = n; i >= 0; i--)
    {
        for(int j = 0; j < 26; j++) nearest[i][j] = latest[j] ;
        if(i) latest[s[i] - 'a'] = i ;
    }
    SET(visited, 0); SET(backLink, 0);
    q.push(0); string ans = "" ; bool found = 0 ;
    while(!q.empty())
    {
        int cur = q.front(); q.pop(); visited[cur] = 1 ;
        for(int j = 0; j < 26; j++)
        {
            int nxt = nearest[cur][j];
            if(nxt == -1)
            {
                ans = ('a' + j);
                // cout << ans << endl ;
                if(cur) ans = s[cur] + ans ;
                while(backLink[cur]) {
                    cur = backLink[cur] ;
                    ans = s[cur] + ans ;
                }
                found = 1 ;
                break ;
            }
            else if(!visited[nxt]) {
                q.push(nxt);
                backLink[nxt] = cur ;
                visited[nxt] = 1 ;
            }
        }
        if(found) break ;
    }
    cout << ans ;
}



Measured memory_bytes: 21968
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll n,m;
vi a[100005];
ll dp[100005];

ll find(ll node){
	if (sz(a[node])==0)return 0;
	if (dp[node]!=-1)return dp[node];
	ll temp=0;
	for (auto i:a[node]){
		temp=max(temp,find(i));
	}
	dp[node]=1+temp;
	return dp[node];
}

void solve() {
    cin>>n>>m;
    rep(i,0,m){
    	ll x,y;
    	cin>>x>>y;
    	a[x].pb(y);
    }
    ll ans=0;
    memset(dp,-1,sizeof dp);
    rep(i,1,n+1){
    	ans=max(find(i),ans);
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 8576
h,w = map(int,input().split())
field = [list(input())for i in range(h)]


vec = [(-1,0),(1,0),(0,1),(0,-1)]
ans = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":continue
        stack = [(i,j)]
        visited = [[0]*w for i in range(h)]
        a= [[0]*w for i in range(h)]
        
        while stack:
            next = []
            for x,y in stack:
                
                if visited[x][y]:continue

                visited[x][y] = 1
                

                for tx,ty in vec:
                    nx = x+tx
                    ny = y+ty
                    if nx < 0 or ny <0 or nx >=h or ny >=w:continue
                    if field[nx][ny] == "#" :continue
                    if visited[nx][ny]:continue
                    next.append((nx,ny))
                    a[nx][ny] = a[x][y]+1
                    
                    
            stack = next
        ans = max(ans,max(max(row)for row in a))
print(ans)
            
            
            
            

Measured memory_bytes: 47580