akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D; 
typedef complex<D> P;  
typedef pair<P, P> L;  
typedef vector<P> VP;
typedef vector<VP> Vcon;

const D EPS = 1e-10;

#define X real()
#define Y imag()

D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) { return (conj(a)*b).Y;}

int ccw(P a,P b,P c){
  b-=a;c-=a;
  if(cross(b,c) >  EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) <   -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

bool isecSP(P a1, P a2, P b) {
  return !ccw(a1, a2, b);
  //return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;  //Perfective
}

bool isecSS(P a1,P a2,P b1,P b2){
  return ccw(a1,a2,b1)*ccw(a1,a2,b2) <= 0   && ccw(b1,b2,a1)*ccw(b1,b2,a2) <=0;
}

D distSP(P a1, P a2, P p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}

D distSS(P a1,P a2,P b1,P b2){
  if(isecSS(a1,a2,b1,b2)) return 0;
  return min( min(distSP( a1,a2,b1) , distSP(a1,a2,b2) ), min(distSP( b1,b2,a1),distSP( b1,b2,a2)));
}

int main(){
  int A,B;
  vector<P>v1,v2;
  
  v1.push_back(P(0,0));
  v2.push_back(P(0,1000));

  cin>>A;
  rep(i,A){
    D x,y;
    cin>>x>>y;
    v1.push_back(P(x,y));
  }

  cin>>B;
  rep(i,B){
    D x,y;
    cin>>x>>y;
    v2.push_back(P(x,y));
  }

  v1.push_back(P(1000,0));
  v2.push_back(P(1000,1000));

  A=v1.size();
  B=v2.size();

  double ans=1e10;
  
  for(int i=0;i<A-1;i++){
    for(int j=0;j<B-1;j++){
      // cout<<ans<<endl;
      ans = min( ans , distSS( v1[i],v1[i+1],v2[j],v2[j+1] ) );
    }
  }

  printf("%.9f\n",ans);
  
}



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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w, m;
    cin >> h >> w >> m;
    map<pii, bool> bomb;
    vi hcnt(h), wcnt(w);
    rep(i, m) {
        int hi, wi;
        cin >> hi >> wi;
        --hi; --wi;
        bomb[{hi,wi}] = true;
        hcnt[hi]++;
        wcnt[wi]++;
    }
    int hmx = 0, wmx = 0;
    vi hlis, wlis;
    rep(i, h) hmx = max(hmx, hcnt[i]);
    rep(i, h) if (hcnt[i] == hmx) hlis.pb(i);
    rep(i, w) wmx = max(wmx, wcnt[i]);
    rep(i, w) if (wcnt[i] == wmx) wlis.pb(i);
    bool exist = true;
    int cnt = 0;
    rep(i, sz(hlis)) rep(j, sz(wlis)) {
        if (!bomb[{hlis[i],wlis[j]}]) exist = false;
        if (cnt>3e5) {
            cout << (hmx+wmx) << endl;
            return 0;
        }
        ++cnt;
    }
    if (exist) cout << (hmx+wmx-1) << endl;
    else cout << (hmx+wmx) << endl;
    return 0;
}


Measured memory_bytes: 45444
import sys
from operator import itemgetter
from itertools import permutations
from math import sqrt

def solve(a: list):
    length = len(a)
    if length <= 3:
        return min(sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) for p1, p2 in permutations(a, 2))

    x_set_len = len(set(x for (x, _) in a))
    axis = 0 if x_set_len > length/2 else 1
    a.sort(key=itemgetter(axis))
    mid_index = length//2
    left, right = a[:mid_index], a[mid_index:]
    delta = min(solve(left), solve(right))
    median = a[mid_index][axis]
    m_a = []
        
    for p in left[::-1]:
        if p[axis] < median-delta:
            break
        m_a.append(p)
    for p in right:
        if p[axis] > median+delta:
            break
        m_a.append(p)
    m_a.sort(key=itemgetter(not axis))

    for i, p1 in enumerate(m_a):
        ub = p1[not axis] + delta
        for j, p2 in enumerate(m_a[i+1:]):
            if p2[not axis] > ub:
                break
            delta = min(delta, sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2))

    return delta

if __name__ == "__main__":
    N = int(input())
    a = [tuple(map(float, l.split())) for l in sys.stdin.readlines()]
    print("{:.10f}".format(solve(a)))


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

void solve(){
    int n; cin >> n;
    vector<int> A(n+1), B(n+1);
    A[0] = -100, B[0] = -100;

    for(int i=1; i<=n; i++){
        cin >> A[i];
        if(i*2>n) B[i] = A[i];
    }

    for(int i=n/2; i>=1; i--){
        int sum = 0;
        for(int j=2; i*j<=n; j++){
            //cout << "j: " << j << endl;
            //cout << "B[i*j]: " << B[i*j] << endl;
            sum += B[i*j];
        }
        //cout << "sum%2" << (sum%2) << endl;
        //cout << "A[i]%2" << (A[i]%2) << endl;
        if((sum%2 == 0 && A[i]%2 == 0) || (sum%2 == 1 && A[i]%2 == 1)) B[i] = 0;
        else B[i] = 1;
    }

    vector<int> res;
    for(int i=1; i<=n; i++){
        if(B[i] == 1){
            res.pb(i);
        }
    }

    if(res.size() == 0) cout << 0 << endl;
    else{
        cout << res.size() << endl;
        REP(i, res.size()){
            cout << res[i];
            if(i!=res.size()-1) cout << " ";
            else cout << "\n";
        }
    }

    
    
}

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

Measured memory_bytes: 3192
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        # if i == j:
        #     continue
        for k in range(j+1, N):
            # if i == k or j == k:
            #     continue
            if L[i] == L[j] or L[i] == L[k] or L[k] == L[j]:
                continue

            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                ans += 1
print(ans)


Measured memory_bytes: 68512
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,k;
int a[100005];
int ans;
int mx;
int di;
int main(){
	cin>>n>>k;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=n-1;i>=0;i--){
	    mx=max(mx,a[i]);
	    a[i]=mx-a[i];
	    di=max(di,a[i]);
	}
	for (int i=0;i<n;i++){
		if (a[i]==di){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
n, m, l = gets.split( " " ).map { | val | val.to_i }

matrixA = []
matrixB = []
matrixC = Array.new( n ) {
	Array.new( l, 0 )
}

n.times {
	matrixA.push( gets.split( " " ).map { | val | val.to_i } )
}
m.times {
	matrixB.push( gets.split( " " ).map { | val | val.to_i } )
}

output = []
for i in ( 0 ... n )
	for j in ( 0 ... l )
		for k in ( 0 ... m )
			matrixC[i][j] += ( matrixA[i][k] * matrixB[k][j] )
		end
		output.push( matrixC[i][j] )
		output.push( " " )
	end
	output.pop
	output.push( "\n" )	
end

print( output.join  )

Measured memory_bytes: 7192
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 998244353;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

const int MAXN = 2000 + 5;
ll N, K;
vi G[MAXN];
int vis[MAXN];

void dfs(int from, int par, int deep, int& cnt)
{
	if (deep > (K / 2)) return;
	cnt++;
	for (int to : G[from]) {
		if (to != par) {
			dfs(to, from, deep + 1, cnt);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//	freopen("a.in","r",stdin);
	//	freopen("a.out","w",stdout);
	cin >> N >> K;
	int u, v;
	rep(i, 0, N - 1)
	{
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	if (K % 2 == 0) {
		int ans = 0;
		rep(i, 0, N)
		{
			int cnt = 0;
			dfs(i, -1, 0, cnt);
			ans = max(ans, cnt);
		}
		cout << N - ans << endl;
	}
	else {
		if (K == 1) cout << N - 2 << endl;
		else {
			int ans = 0;
			memset(vis, 0, sizeof(vis));
			rep(i, 0, N)
			{
				vis[i] = 1;
				rep(j, 0, sz(G[i]))
				{
					if (vis[G[i][j]]) continue;
					int cnt = 0;
					dfs(i, G[i][j], 0, cnt);
					dfs(G[i][j], i, 0, cnt);
					ans = max(ans, cnt);
				}
			}
			cout << N - ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int D;
vector<int> c(26);
vector<int> last(26, 0);
vector<vector<int>> s(365, vector<int>(26));
void input();
int score;
int next_num;
const int Way = 26;
const int Nest = 0;
/*void dfs(int nest, int d) {
	int M = 0, temp = score;
	int prev, n;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp;
		score += s[d - 1][j];
		prev = last[j];
		last[j] = d;
		rep(k, 0, 26)score -= c[k] * (d - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
		last[j] = prev;
	}
	//sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way) {
		//prev = last[kouho[j].second];
		//last[kouho[j].second] = d;
		score = kouho[j].first;
		if (nest && d < D)dfs(nest - 1, d + 1);
		if (M < score)M = score, n = kouho[j].second;
		printf("j:%2d score:%d\n", j, score);
		//last[kouho[j].second] = prev;
	}
	score = M;
	next_num = n;
}*/
int dfs(int nest, int i) {
	ll M = 0, temp = score;
	int prev, p;
	rep(j, 0, 26) {
		score = temp + s[i - 1][j];
		prev = last[j];
		last[j] = i;
		rep(k, 0, 26)score -= c[k] * (i - last[k]);
		if (nest && i < D)dfs(nest - 1, i + 1);
		last[j] = prev;
		if (M < score)M = score, p = j;
	}
	score = M;
	return p;
}
int main()
{
	input();
	/*rep(i, 1, D + 1) {
		//score = 0;
		dfs(Nest, i);
		printf("%d\n", next_num + 1);
		last[next_num] = i;
		printf("%d\n", score);
	}*/
	rep(i, 1, D + 1) {
      score = 0;
		int p = dfs(1, i);
		last[p] = i;
		printf("%d\n", p + 1);
		//printf("%d\n", score);
	}
	return 0;
}
void input() {
	cin >> D;
	rep(i, 0, 26)cin >> c[i];
	rep(i, 0, D) {
		rep(i2, 0, 26)cin >> s[i][i2];
	}
}

Measured memory_bytes: 3780
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

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

const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
	ll N;
	cin >> N;
	vector<string> S;
	ll i, j, k;
	for (i = 0; i < N; i++){
		string s;
		cin >> s;
		S.push_back(s);
	}
	ll ans = 0;
	for (k = 0; k < N; k++){
		bool flg = true;
		for (i = 0; i < N; i++){
			for (j = 0; j < N; j++){
				if (S[i][(j + k) % N] != S[j][(i + k) % N]){
					flg = false;
					break;
				}
			}
			if (!flg){
				break;
			}
		}
		if (flg){
			ans += N;
		}

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


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int M=gi();
         int[] x=new int[M];
         int[] y=new int[M];
         boolean[] f=new boolean[N];

         for(int i=0; i<M;i++) {
        	 x[i]=gi()-1;
        	 y[i]=gi()-1;
         }
         int[] c=new int[N];

         for(int i=0; i<N;i++) {
              c[i]=1;
         }
         f[0]=true;

         int ans=0;
         for (int i=0; i<M;i++) {
        	 c[x[i]]--;
        	 c[y[i]]++;
        	 if(f[x[i]])f[y[i]]=true;
        	 if(c[x[i]]==0)f[x[i]]=false;
         }

         for(int i=0; i<N;i++) {
             if(f[i])ans++;
        }
         System.out.println(ans);
         //System.out.println(ans);
     }

     public static class Edge {
    	    private int from;
    	    private int to;
    	    private long cost;

    	    public Edge(int f, int t, long c) {
    	    	this.from=f;
    	    	this.to=t;
    	    	this.cost=c;
    	    }
    	}
     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 60008
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int X, Y;
	cin >> X >> Y;
	int ans = 1 << 30;
	for (int i = 0; i <= max(X, Y); i++) {
		int x = max(X - i, 0);
		int y = max(Y - i, 0);
		ans = min(ans, A*x + B*y + C*2*i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[100002];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  A[0] = 0;
  rep(i, N) cin >> A[i+1];
  A[N+1] = 0;
  long long sum = 0;
  rep(i, N+1) sum += abs(A[i+1]-A[i]);
  for (int i=1; i<=N; i++) {
    long long d = sum;
    d -= abs(A[i]-A[i-1]);
    d -= abs(A[i+1]-A[i]);
    d += abs(A[i+1]-A[i-1]);
    cout << d << "\n";
  }
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int a,b,c,x,y,sum=0,sum1=0;
    scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
    if(a+b<=2*c)
    {
        sum=sum+x*a+y*b;
        printf("%d\n",sum);
    }
    else
    {
        if(x>=y)
        {
            sum=sum+c*2*y;
            sum=sum+(x-y)*a;
            sum1=sum1+c*2*x;
        }
        else
        {
            sum=sum+c*2*x;
            sum=sum+(y-x)*b;
            sum1=sum1+c*2*y;
        }
        if(sum1>=sum)
            printf("%d\n",sum);
        else
            printf("%d\n",sum1);
    }
    return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, c, k; cin >> n >> c >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i];
	sort(A.begin(), A.end());
	ll x = 0, b = -2e9, s = 0;
	for (int i = 0; i < n; i++)
	{
		if (b + k < A[i] || x == c) s++, b = A[i], x = 1;
		else x++;
	}
	cout << s << '\n';
}


Measured memory_bytes: 640
n = int(input())
a=list(map(int, input().split()))
count = 0
success = True
while True:
    for i, ele in enumerate(a):
        if ele % 2 == 0:
            a[i] = ele / 2
        else:
            success = False
    if not success:
        break
    count += 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int width,high,i,j;

  while(1){
    scanf("%d %d",&high,&width);
    if(width == 0 && high == 0) break;
    for(i=0;i<high;i++){
      for(j=0;j<width;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2076
#include <iostream>
using namespace std;
long long n, m, g, ans;
string s, t;

int gcd(int p, int q) {return q ? gcd(q, p%q) : p;}
int main() {
	cin>>n>>m>>s>>t;
	g = gcd(n, m);
	ans = n / g * m;
	n /= g, m /= g;
	for(int i=0; i<g; i++) {
		if(s[i*n] != t[i*m]) {ans = -1; break;}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
N = int(input())

money = 0
c = int((N + (4 - 1)) / 4)
d = int((N + (7 - 1)) / 7)

for i in range(c+1):
    for j in range(d+1):
        if (i * 4) + (j * 7) == N:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;cin>>n;
    int cnt = 0;
    rep(i, n)
    {
        int a,b;cin>>a>>b;
        if (a == b)
        {
            ++cnt;
        }
        else
        {
            cnt = 0;
        }
        if (cnt == 3)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>

int N, t[100005], x[100005], y[100005];
int main()
{
    std::cin >> N;
    for (int i = 0; i < N; ++i)
        std::cin >> t[i] >> x[i] >> y[i];

    int nowT = 0, nowX = 0, nowY = 0;
    for (int i = 0; i < N; ++i)
    {
        int temp = std::abs(x[i] + y[i] - nowX - nowY);
        if (t[i] < nowT || temp > t[i] - nowT || (temp - t[i] - nowT) % 2 != 0)
        {
            std::cout << "No" << std::endl;
            return 0;
        }
        nowX = x[i], nowY = y[i], nowT = t[i];
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template<typename T>
T pow(T x, int n, T p) {
        if (n == 0) {
                return T(1);
        } else {
                T rest = n % 2 ? x : T(1);
                return pow(x * x % p, n / 2, p) * rest % p;
        }
}

int main() {
        ll n, p;
        cin >> n >> p;

        string s;
        cin >> s;
        
        vector<ll> a(n), c(n + 1, 0);
        REP(i, n) {
                a[i] = s[i] - '0';
                c[i + 1] = c[i] + pow(10LL, n - 1 - i, p) * a[i] % p;
                c[i + 1] %= p;
        }

        if (p == 2 || p == 5) {
                ll x = 0, y = 0;
                REP(i, n) {
                        if (a[i] % 2 == 0) {
                                x += i + 1;
                        }
                        if (a[i] % 5 == 0) {
                                y += i + 1;
                        }
                }

                if (p == 2) {
                        cout << x << endl;
                } else {
                        cout << y << endl;
                }
                
                return 0;
        }

        ll ans = 0;
        map<ll, ll> mp;
        
        REP(i, n + 1) {
                ans += mp[c[i]];
                mp[c[i]]++;
        }

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


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

using namespace std;

typedef long long int ll;

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

  string s;
  cin >> s;
  int n = s.length();

  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int val = s[i] - '0';
    if (val < 10 - val) {
      ans += val;
    } else if (val == 5 && (i == 0 || s[i - 1] < '5')) {
      ans += val;
    } else {
      ans += 10 - val;
      int j = i - 1;
      while (j >= 0 && s[j] == '9') {
        s[j] = '0';
        j--;
      }
      if (j == -1){
        ans++;
        break;
      }
      else s[j]++;
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 1948
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace AtCoder {
    public class Program {
        static int[] getKeys() {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(delimiter);
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }

        public static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        public static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }

        static void Main() {
            bool[] one = new bool[4];
            for (int i = 0; i < 3; i++) {
                var Ke = getKeys();
                one[Ke[0] - 1] = !one[Ke[0] - 1];
                one[Ke[1] - 1] = !one[Ke[1] - 1];
            }
            if (one.Where(t => t).Count() == 2) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define endl '\n'
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double d, t, s;
	cin >> d >> t >> s;
	double time = d / s;
	if (time > t)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 3732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		int N = sc.nextInt();
		int count=0;
		long[] array = new long[N];
		long max = 0;

		for(int i=0;i<N;i++) {
			array[i] = sc.nextLong();
		}
		for(int i=0;i<N;i++) {
			if(max <= array[i]) {
				max = array[i];
			}
			if(max - array[i] >= 2) {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");
	}


	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 61196
def main():
    stk = []
    line = list(input().split())
    for i in line:
        if i == "+":
            temp = stk.pop(-1)
            temp += stk.pop(-1)
            stk = stk + [temp]
        elif i == "-":
            temp = stk.pop(-1)
            temp -= stk.pop(-1)
            stk = stk + [-1*temp]
        elif i == "*":
            temp = stk.pop(-1)
            temp *= stk.pop(-1)
            stk = stk + [temp]
        else:
            stk = stk + [int(i)]
    print(stk[0])

main()
            


Measured memory_bytes: 5600
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(max(a,d),max(b,c))
#define MAX   1e9
#define MIN  -1e9
#define PI 3.14159265358979
#define eps 1e-9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(long long int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define inp(a,start,len) for(long long int i = start;i < len;i++) cin>>a[i]
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

ll dp[100005];
int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll T = 1;
	// cin>>T;
	while(T--){
		ll n;
		cin>>n;
		ll ans = 0;
		repA(i,1,n-1){
			ll a = i;
			repA(j,1,n/a){
				ll b = j;
				ll c = n-a*b;
				if(c>0)
					ans++;
			}
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>

using namespace std;

int main() {
    long long a, b, c, d, N;
    cin >> a >> b >> c >> d >> N;
    
    long long res = 0;
    
    if (4 * a <= 2 * b && 4 * a <= c) {
        if (8 * a <= d) res  = 4 * N * a;
        else if (N % 2 == 0) res = N/ 2 * d;
        else res = (N - 1)/2 * d + 4 * a;
    }
    
    else if (2 * b <= 4 * a && 2*b <= c) {
        if (4 * b <= d) res  = 2 * N * b;
        else if (N % 2 == 0) res = N/ 2 * d;
        else res = (N - 1)/2 * d + 2 * b;
    }
    else {
        if (2 * c <= d) res  =  N * c;
        else if (N % 2 == 0) res = N/ 2 * d;
        else res = (N - 1)/2 * d + c;
    }
    
    cout << res <<endl;
    
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};



int main() {
    int N;
    cin >> N;
    std::vector<vector<int> > G(N, vector<int>(N, 100000000));
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            G[u][v] = c;
        }
    }

    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        cout << i << " " << G[0][i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll c(n+1); rep(i, 1, n+1) cin >> c.at(i);
  vll dp(200005, 0);  // (個数, prev idx)
  vll ans(n+1, 0);
  ans.at(0) = 1;
  rep(i, 1, n+1) {
    ans.at(i) = ans.at(i-1);
    if (dp.at(c.at(i)) > 0 && dp.at(c.at(i)) < i-1)
      ans.at(i) = (ans.at(i) + ans.at(dp.at(c.at(i)))) % MOD;
    dp.at(c.at(i)) = i;
  }
  cout << ans.at(n) << endl;
  return 0;
}


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

int main()
{
    int D, N;
    cin >> D >> N;
    int ans = 1;
    for (int i = 0; i < D; i++)
    {
        ans *= 100;
    }
    if (N == 100)
    {
        N++;
    }
    cout << N * ans << endl;
}


Measured memory_bytes: 256
# 2019/09/16

import sys
input=sys.stdin.readline

n,h=map(int,input().split())

que=[]

for i in range(n):
    a,b=map(int,input().split())
    que.append((a,b))

que.sort(key=lambda x: (x[0],x[1]))
a,b=que.pop()
que.sort(key=lambda x: x[1])

cnt=0
def solve(cnt,h):
    while h>0 and que:
        _,bb=que.pop()
        if h<=b:
            break
        if bb>=a:
            h-=bb
            cnt+=1
        else:
            break
    return cnt,h

if que:
    cnt,h=solve(cnt,h)



if h>0:
    h-=b
    cnt+=1
if h>0:
    cnt+=-(-h//a)
print(cnt)

Measured memory_bytes: 24496
#include<stdio.h>
int main(){
  long a,v,b,w,t;
  scanf("%ld %ld",&a,&v);
  scanf("%ld %ld",&b,&w);
  scanf("%ld",&t);
  if (b>a) {
    if(b+w*t>a+v*t)printf("NO");
    else printf("YES");
  }else{
    if(b-w*t<a-v*t)printf("NO");
    else printf("YES");
  }
  return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
typedef long long LL;


int main()
{		
	LL a, b, n, t;
		
	scanf("%lld%lld%lld", &a, &b, &n);
	if(n < b) t = n;
	else t = b - 1;
	printf("%lld\n", a * t / b);
			
	return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpl vector<pair<ll,ll> >
#define mll map<ll,ll>
#define mcl map<char,ll>
#define pqll priority_queue<ll>
#define mpl map<pair<ll,ll>,ll >
#define msl map<string,ll>
#define mset(a,k) memset(a,k,sizeof(a));
#define len length()
#define fr(a,b,c) for(ll a=b;a<c;a++)
void in(ll *a,ll n){fr(i,0,n){cin>>a[i];}}
void out(ll *a,ll n){fr(i,0,n){cout<<a[i]<<" ";}}
void out(vl v){fr(i,0,(ll)v.size())cout<<v[i]<<" ";}
void out(ll a){cout<<a;}
void out(string s){cout<<s;}
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}


int main(){
	fast();
	ll n;
	cin>>n;
	ll p[n],q[n];
	in(p,n);
	in(q,n);
	ll a[n];
	fr(i,0,n){
		a[i]=i+1;
	}
	ll flag=1;
	ll k=0;
	ll pk,jk;
	//out(a,n);
	while(flag){
		ll nk=0;
		//out(a,n);
		fr(i,0,n){
			if(a[i]!=p[i]){
				nk=1;
			}
		}
		if(!nk){
			pk=k;
			break;
		}
		next_permutation(a,a+n);
		k++;
	}
	k=0;
	fr(i,0,n){
		a[i]=i+1;
	}
	while(flag){
		ll nk=0;
		fr(i,0,n){
			if(a[i]!=q[i]){
				nk=1;
			}
		}
		if(!nk){
			jk=k;
			break;
		}
		next_permutation(a,a+n);
		k++;
	}
	cout<<abs(jk-pk);
	
	
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s, t string
	fmt.Scan(&n, &s, &t)
	var ans []string
	for i := 0; i < n; i++ {
		ans = append(ans, string(s[i]))
		ans = append(ans, string(t[i]))
	}
	fmt.Println(strings.Join(ans, ""))
}


Measured memory_bytes: 640
#if 0
2019.12.10

（不是给人做的）

首先由于列车都是每隔 k 个单位发一次，那么列车的行迹每连续 k 个单位是完全一致的，
因此只考虑连续 k 个单位时间的情况即可，此时时间成环，即第 k + 1 个单位等价于第 1 个单位，等等。

然后转化问题，设 p[i], q[i] 分别表示正向和反向列车离开第 i 站的时间，
那么在第 i 站到第 i + 1 站之间，正向列车在 [p[i], p[i] + a[i]] 时间段存在，
而反向列车在 [q[i + 1], q[i + 1] + a[i]] 时间段存在，
如果 b[i] = 1 ，需要满足两个区间无交，
也就是 p[i] - q[i + 1] <= - a[i] 或 >= a[i] 。

设 x[i] = p[i] - q[i + 1] ，那么 x[i] % k 需要在 [a[i], k - a[i]] 之内，
设这个区间为 [l[i], r[i]] 。
而由 p[i + 1] >= p[i] + a[i], q[i] >= q[i + 1] + a[i] 可知：
x[i + 1] >= x[i] + a[i] + a[i + 1] 。

不妨将 x[i + 1] 即以后整体减去 a[i] + a[i + 1] ，
那么对于所有满足 j > i 的 j ，需要把 l[j], r[j] 都减去 a[i] + a[i + 1] ，
每个 i （包括 i = 0 ）都进行这样的操作后，就把 x[i + 1] 的限制改成了 x[i + 1] >= x[i] ，
此时 l[i] = -2A[i - 1], r[i] = -2A[i] (mod k) ，其中 A 是 a 的前缀和。

至此，问题转换为，在长为 k 的环上有 n 个区间，
环上有位置 x ，初值任意，需要每次让 x 右移若干位来依次落入各个区间，
最小化 x 总共的移动次数（答案是这个移动次数加上 2A[n] ）。
其中 b = 2 的区间是整个环 (l = 0, r = k - 1) 。

先考虑贪心，如果 x 落在第 i 个区间的左端点 l[i]，那么对于第 i + 1 个区间，
如果 l[i] 落在第 i + 1 个区间内，x 不需要移动，否则 x 移动到 l[i + 1] 。

然后根据这个贪心设计 dp ，设 f[i] 表示考虑当前 x 落在 l[i] ，
走完剩下的区间需要的最小移动次数。
那么只需要找到一个 j > i 满足 (i, j) 之内的区间都包含 l[i] 且第 j 个区间不包含 l[i] ，
那么 x 在 (i, j) 之间的区间内都无需移动，直接从 f[j] 转移即可，
如果不存在这样的 j ，说明 x 之后永远无需移动，有 f[i] = 0 。

最后优化找 j 的过程，倒着 dp 时考虑 j 对 i 的影响时实际上是个区间覆盖，
用 odt 维护即可，由于只有单点查询，均摊复杂度最坏一个 log 。
#endif
#include <cstdio>
#include <set>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
ll a[maxn], b[maxn];
ll f[maxn];

struct Node {
	int r;
	mutable int v;
	Node(int r, int v = 0): r(r), v(v) { }
};
inline bool operator < (Node x, Node y) { return x.r < y.r; }

typedef std::set<Node>::iterator iter;
std::set<Node> odt;

inline iter split(int k) {
	iter it = odt.lower_bound(k);
	if(it -> r == k) return it;
	return odt.insert(Node(k, it -> v)).first;
}

inline void set(int l, int r, int v) {
	if(l > r) return;
	iter li = split(l - 1), ri = split(r);
	ri -> v = v;
	odt.erase(++ li, ri);
}

inline int query(int k) {
	iter it = odt.lower_bound(k);
	return it -> v;
}

int l[maxn], r[maxn];
int main() {
	int n = read, k = read;

	for(int i = 1; i <= n; i ++) {
		a[i] = a[i - 1] + read;
		b[i] = read;
		if(b[i] == 1) {
			l[i] = (k - a[i - 1] * 2 % k) % k;
			r[i] = (k - a[i] * 2 % k) % k;
			if((a[i] - a[i - 1]) * 2 > k) return puts("-1"), 0;
		} else {
			l[i] = 0;
			r[i] = k - 1;
		}
	}

	odt.insert(Node(k, n + 1));

	for(int i = n; i; i --) {
		int j = query(l[i]);
		if(j <= n)
			f[i] = f[j] + (l[j] - l[i] + k) % k;
		if(l[i] <= r[i]) {
			set(0, l[i] - 1, i);
			set(r[i] + 1, k - 1, i);
		} else
			set(r[i] + 1, l[i] - 1, i);
		/* debug("%d : %d-%d f=%lld j=%d\n", i, l[i], r[i], f[i], j); */
	}

	ll ans = 1000000000000000000ll;
	for(Node x : odt)
		if(x.r >= 0 and x.r < k) {
			/* debug("%d %d\n", x.r, x.v); */
			if(x.v <= n)
				ans = std::min(ans, f[x.v] + (l[x.v] - x.r + k) % k);
			else
				ans = 0;
		}
	ans += a[n] * 2;

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


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

const long long INF = 1LL << 61;
using ll = long long;

typedef pair<ll, ll> ii;

vector<ii> AdjList[140005];

long long W;

vector<ii> S[140005];

void dfs(int u){
    if(AdjList[u].empty()){
        S[u].emplace_back(0, 0);
        return;
    }

    int l = AdjList[u][0].first;
    long long w_l = AdjList[u][0].second;
    int r = AdjList[u][1].first;
    long long w_r = AdjList[u][1].second;
    dfs(l);
    dfs(r);

    int indxD = 0;
    int indxC = 0;
    for(ii temp1: S[l]){
        long long a, b;
        tie(a, b) = temp1;
        long long tempC = INF;
        long long tempD = INF;

        while(indxD < (int)S[r].size()){
            ii temp2 = S[r][indxD];
            long long c, d;
            tie(c, d) = temp2;
            if(c > W-b-w_l-w_r){
                //indxD --;
                break;
            }else{
                indxD ++;
                tempD = min(tempD, d+w_r);
            }
        }

        while(indxC < (int)S[r].size()){
            ii temp2 = S[r][indxC];
            long long c, d;
            tie(c, d) = temp2;
            if(d <= W-a-w_l-w_r){
                tempC = min(tempC, c+w_r);
                break;
            }else{
                indxC ++;
            }
        }

        if(tempD < INF){
            S[u].emplace_back(a+w_l, tempD);
        }
        if(tempC < INF){
            S[u].emplace_back(tempC, b+w_l);
        }
    }
    sort(S[u].begin(), S[u].end());
}

int N;

bool boleh(long long W2){
    W = W2;
    for(int i = 1; i <= N; i ++){
        S[i].clear();
    }
    dfs(1);
    return !S[1].empty();
}

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

    for(int i = 2; i <= N; i ++){
        int a, v;
        scanf("%d%d", &a, &v);
        AdjList[a].push_back(ii(i, v));
    }

    long long lo = 0;
    long long hi = 1LL << 23;
    while(lo < hi){
        long long mid = (lo+hi)>>1;
        if(boleh(mid)){
            hi = mid;
        }else{
            lo = mid+1;
        }
    }

    printf("%lld", lo);
    return 0;
}


Measured memory_bytes: 36024
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] p = new int[N];
    for (int i = 0; i < N; i++) p[i] = scanner.nextInt() - 1;
    UnionFind uf = new UnionFind(N);
    for (int i = 0; i < M; i++) {
      int x = scanner.nextInt() - 1;
      int y = scanner.nextInt() - 1;
      uf.union(x, y);
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
      if (uf.find(i) == uf.find(p[i])) res++;
    }
    System.out.println(res);
  }

  private static class UnionFind {
    private final int[] table;
    private final int[] ranks;
    private final int[] sizes;

    public UnionFind(int size) {
      this.table = new int[size];
      this.ranks = new int[size];
      this.sizes = new int[size];
      for (int i = 0; i < size; i++) {
        table[i] = i;
        sizes[i] = 1;
      }
    }

    public int find(int x) {
      if (table[x] != x) {
        table[x] = find(table[x]);
      }
      return table[x];
    }

    public void union(int x, int y) {
      int xRoot = find(x);
      int yRoot = find(y);
      if (xRoot == yRoot) return;

      if (ranks[xRoot] < ranks[yRoot]) {
        int tmp = xRoot;
        xRoot = yRoot;
        yRoot = tmp;
      }

      table[yRoot] = xRoot;
      sizes[xRoot] += sizes[yRoot];
      if (ranks[xRoot] == ranks[yRoot]) ranks[xRoot]++;
    }
  }
}


Measured memory_bytes: 89936
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> m(n+1, pair<ll, ll>(INT64_MAX
    , 0));
    rep(i, 0, n) {
        ll h;
        cin >> m[i].first >> h;
        m[i].second = h;
    }

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

    ll ans = 0;
    ll rIdx = 0;
    vector<ll> num(n+1, 0L);
    rep(i, 0, n)
    {
        // 一番右にいる敵
        ll left = m[i].first;
        ll right = m[rIdx].first;
        while (right - left <= 2 * d && rIdx < n)
        {
            right = m[++rIdx].first;
        }
        
        if (num[i] < m[i].second)
        {
            ll need = (m[i].second - num[i] + a - 1) / a;
            // 攻撃
            ans += need;
            num[i] += need * a;
            num[rIdx] -= need * a;

        }
        num[i+1] += num[i];
    }

    cout << ans << endl;
}
			

Measured memory_bytes: 4992
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		char s[] = sc.nextLine().toCharArray();
		s[0] = '2'; 
		s[1] = '0'; 
		s[2] = '1'; 
		s[3] = '8';
	   System.out.println(s);	
	}
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara,x) memset((ara),x,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	ll int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

    cin>>n;

    (n & 1)?cout<<n*2<<endl:cout<<n<<endl;

}


Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=b[n//2-1]
d=b[n//2]
if c==d:
  for i in range(n):print(c)
else:
  for i in range(n):
    if a[i]<=c:print(d)
    else:print(c)


Measured memory_bytes: 93780
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
dic = defaultdict(int)
x = 1
for n in range(1, N+1):
	for i in factorization(n):
		if i[0] == 1:
			continue
		dic[i[0]] += i[1]
for val in dic:
	x = (x * (dic[val]+1))%MOD

print(x)


Measured memory_bytes: 4148