akhauriyash/Code-Regression huggingface dataset:
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("output.out", "r", stdin);
}

void outfile(){
    freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1)
        tmp = (tmp * a) % mod;
    return tmp;
}

//End of template

int main(){
    init();

    ll n;
    ld d;
    cin >> n >> d;
    ld a, b;
    ll cnt = 0;
    FOR(i, 0, n){
        cin >> a >> b;
        ld dist = sqrt(a*a + b*b);
        if(dist <= d){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3868
#include <iostream>
#include <vector>
#include <algorithm>
struct node{
    long long id;
    long long d;
    long long f;
};
long long n;
long long t = 0;
std::vector<struct node> s;
std::vector<std::vector<long long>> G;
std::vector<long long> used;
void dfs(int i){
    t++;
    s[i].d = t;
    used[i] = 0;
    for(int u: G[i]) {
        if(used[u] == 1) dfs(u);
    }
    t++;
    s[i].f = t;
}
int main(){
    std::cin >> n;
    used.resize(n, 1);
    s.resize(n);
    G.resize(n);
    for(int i =0 ; i < n; i++){
        long long u, k;
        std::cin >> u >> k;
        struct node no;
        u--;
        no.id = u;
        s[u] = no;
        for(int j = 0; j < k; j++){
            long long v;
            std::cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    for(int i = 0; i < n; i++) std::sort(G[i].begin(), G[i].end());
    for(int i = 0; i < n; i++){
        if(used[i] == 1) dfs(i);
    }
    for(int i = 0; i < n; i++){
        std::cout << i + 1 << ' ' << s[i].d << ' ' << s[i].f << std::endl;
    }
}


Measured memory_bytes: 3132
import sys

input = sys.stdin.readline


def main():
    x, y = map(int, input().split())
    if x in [1, 3, 5, 7, 8, 10, 12] and y in [1, 3, 5, 7, 8, 10, 12]:
        print("Yes")
    elif x in [4, 6, 9, 11] and y in [4, 6, 9, 11]:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

/*int main(){
  int n, m;
  cin >> n >> m;
  vi vec(n);
  vi num(n);
  rep(i,m){
    int si, ci;
    cin >> si >> ci;
    si -= 1;
    if (vec.at(si) != ci) num.at(si)++;
    vec.at(si) = ci;
  }
  if (num.at(0) != 1 ){
    cout << -1 << endl;
    return 0;
  }
  REP(i,1,n){
    if (num.at(i) > 1){
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i,n){
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}*/

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  rep(i,m) cin >> p.at(i).first >> p.at(i).second;
  rep(i,1000){
    vi d(1, i%10);
    int nx = i / 10;
    while (nx){
      d.push_back(nx%10);
      nx /= 10;
    }
    if ((int)d.size() != n) continue;
    reverse(d.begin(), d.end());
    bool ok = true;
    rep(i,m){
      if (d[p.at(i).first-1] != p.at(i).second) ok = false;
    }
    if (ok){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
#include <iostream>
#include<string>
#include<algorithm>
#include<sstream>
#include<math.h>
#include<queue>
#include<stack>
#include<list>
#include<vector>
#include<map>
#include<set>
#define FOR(i,a) for(int i=0;i<a;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define ll long long
int bmap[]={ 0,1,0,-1 };
int amap[]={ 1,0,-1,0 };
using namespace std;
int a, b, c, d, e;
string s[10];
int ans = 0;
int main() {
	cin >> a >> b >> c;
	a -= b;
	cout << a%c << endl;
	return 0;
}


Measured memory_bytes: 764
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def factorize(num: int) -> dict:
    """ 素因数分解 """
    from math import sqrt
    from collections import Counter

    d = Counter()
    # 終点はルート切り捨て+1
    for i in range(2, int(sqrt(num))+1):
        # 素因数分解：小さい方から割れるだけ割って素数をカウント
        while num % i == 0:
            num //= i
            d[i] += 1
        # 1まで分解したら終了
        if num == 1:
            break
    # 最後に残ったnumは素数(ただし1^1は1^0なので数に入れない)
    if num != 1:
        d[num] += 1
    return d

N = INT()

# N!までを全部素数冪でまとめる
primes = Counter()
for i in range(2, N+1):
    primes.update(factorize(i))

# 約数が75になる素数冪の組み合わせを数える
primes = sorted(primes.values())
M = len(primes)
cnt2 = cnt4 = cnt14 = cnt24 = cnt74 = 0
for a in primes:
    # 組み合わせに使える数を予め数えておく
    if a >= 2: cnt2 += 1
    if a >= 4: cnt4 += 1
    if a >= 14: cnt14 += 1
    if a >= 24: cnt24 += 1
    if a >= 74: cnt74 += 1

ans = 0
# 3種類使う
ans += (cnt2-2) * (cnt4 * (cnt4-1) // 2)
# 2種類使う
ans += (cnt2-1) * cnt24 + (cnt4-1) * cnt14
# 1種類使う
ans += cnt74

print(ans)


Measured memory_bytes: 3316
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  L, R, d = readint()
  c = 0
  for i in L:R
    if i%d==0
      c+=1
    end
  end
  println(c)


end

main()

Measured memory_bytes: 187548
N =int(input())
A = list(map(int,input().split()))
Q =int(input())

ope = []

l = [0] * 100001
for i in A:
    l[i] += 1

for i in range(Q):
    B, C = map(int, input().split())
    ope.append([B,C])

A_sum = sum(A)

for x in ope:
    A_sum = A_sum + (x[1]-x[0])*l[x[0]]
    l[x[1]] += l[x[0]]
    l[x[0]] = 0
    print(A_sum)

Measured memory_bytes: 29748
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    vector<vector<int64_t>> taro(n, vector<int64_t>(n)), jiro(n, vector<int64_t>(n));
    rep(r, n) rirep(l, r)
    {
        if (l == r) {
            taro[l][r] = a[l];
            jiro[l][r] = -a[l];
        } else {
            taro[l][r] = max(jiro[l + 1][r] + a[l], jiro[l][r - 1] + a[r]);
            jiro[l][r] = min(taro[l + 1][r] - a[l], taro[l][r - 1] - a[r]);
        }
    }
    cout << taro[0][n - 1] << endl;

    return 0;
}

Measured memory_bytes: 143232
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
 
#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
///////////////////////
 
int const N = 2e3 + 41;
int const INF = 1e9 + 41;
 
int n;
int a[N], b[N], r[N], l[N];
string s1, s2;
int ans = INF;
 
void answer(int v){
	cout << v << endl;
	exit(0);
}
 
void read(){
	cin >> s1 >> s2;
	if(s1 == s2) answer(0);
	int cnt = 0;
	fr(i, 0, sz(s2)) if(s2[i] == '1') ++cnt;
	if(cnt == 0) answer(-1);
	n = sz(s1);
	fr(i, 0, n) a[i] = s1[i] - '0', b[i] = s2[i] - '0';
}
 
vector<pii> v;
 
int getSufMax(int val){
	int l = -1;
	int r = sz(v);
	while(r-l>1){
		int m = (l+r)/2;
		if(v[m].first > val) r = m;
		else l = m;
	}
	if(r == sz(v)) return 0;
	else return v[r].second;
}
 
int getMinWay(int a, int b){
	if(a > b) swap(a, b);
	int ret = b - a;
	ret = min(ret, a + n - b);
	return ret;
}
 
void solveLR(){
	fr(fs, 0, n){
		v.clear();
		int cntFlip = 0;
		fr(i, 0, n){
			int p = (i - fs + n) % n;
			if(b[p] != a[i]){
				++cntFlip;
				v.pb(mp(l[i], r[i]));
			}
		}
		sort(v.begin(), v.end());
		fdr(i, 0, sz(v)){
			if(i + 1 < sz(v)) v[i].second = max(v[i].second, v[i+1].second);
		}
		fr(ls, 0, n){
			int rs = getSufMax(ls);
			int fp = (rs - ls) % n;
			if(fp < 0) fp += n;
			int cur = cntFlip;
			if(rs > 0){
				cur += ls * 2;
				cur += rs;
				fp = (fp + ls) % n;
			}else{
				cur += ls;
			}
			cur += getMinWay(fp, (0 - fs + n) % n);
			ans = min(ans, cur);
		}
	}
}
 
void solveRL(){
	fr(fs, 0, n){
		v.clear();
		int cntFlip = 0;
		fr(i, 0, n){
			int p = (i + fs + n) % n;
			if(b[p] != a[i]){
				++cntFlip;
				v.pb(mp(r[i], l[i]));
			}
		}
		sort(v.begin(), v.end());
		fdr(i, 0, sz(v)){
			if(i + 1 < sz(v)) v[i].second = max(v[i].second, v[i+1].second);
		}
		fr(rs, 0, n){
			int ls = getSufMax(rs);
			int fp = (rs - ls) % n;
			if(fp < 0) fp += n;
			int cur = cntFlip;
			if(ls > 0){
				cur += rs * 2;
				cur += ls;
				fp = (fp - rs + n) % n;
			}else{
				cur += rs;
			}
			cur += getMinWay(fp, (0 + fs) % n);
			ans = min(ans, cur);
		}
	}
}
 
 
void solve(){
	fr(i, 0, n){
		while(b[(i + r[i]) % n] == 0){
			++r[i];
		}
		while(b[(i - l[i] + n) % n] == 0){
			++l[i];
		}
	}
	solveLR();
	solveRL();
	answer(ans);
}
 
int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
 
	read();
	solve();
 
 
 
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int num=0;
    for(int i=0;i<n;i++){
    	if(a[i]==num)continue;
    	else if(a[i]<num){
    		cout <<"No" <<endl;
    		return 0;
    	}else{
    		num=a[i]-1;
    	}
    }
    cout <<"Yes" <<endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mm 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e,k,count,ru=1000,last;
    cin>>a;
    ll A[a+1]={0};
    for(b=0;b<a;b++)
    {
        cin>>A[b];
    }
    for(b=0;b<a-1;)
    {
        while(A[b+1]<=A[b] && b<a-1) b++;
        //if(b<a && A[b]<A[b-1])
        //{
           last=ru;
           count=ru/A[b];
           ru=ru%A[b];
        //}
        while(A[b+1]>=A[b] && b<a-1) b++;
        //if(b<a && A[b]>A[b-1])
        //{
            ru=ru+count*A[b];
            count=0;
        //}
       // b--;
    }
    if(count==0)
    cout<<ru<<endl;
    else
    cout<<last<<endl;
}

Measured memory_bytes: 3644
#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>
typedef long long ll;
using namespace std;
struct P {
	int i;
	int p;
	int y;
	string num;
	P(int _i, int _p, int _y) {
		i = _i;
		p = _p;
		y = _y;
	}
};
bool indexComp(const P &left, const P &right) {
	return left.i < right.i;
}
bool yearComp(const P &left, const P &right) {
	if (left.p != right.p) {
		return left.p < right.p;
	}
	return left.y < right.y;
}
string padleft(int n) {
	string m = to_string(n);
	while (m.size() != 6)
	{
		m = '0' + m;
	}
	return m;
}
void ID() {
	int N, M;
	cin >> N >> M;
	vector<P> vp;
	for (size_t i = 0; i < M; i++)
	{
		int p, y;
		cin >> p >> y;
		vp.push_back(P(i, p, y));
	}
	sort(vp.begin(), vp.end(), yearComp);
	int c = 1;
	int pi = 0;
	for (size_t i = 0; i < vp.size(); i++)
	{
		if (pi != vp[i].p) {
			c = 1;
			pi = vp[i].p;
		}
		vp[i].num = padleft(vp[i].p) + padleft(c);
		c++;
	}
	sort(vp.begin(), vp.end(), indexComp);
	for (size_t i = 0; i < vp.size(); i++)
	{
		cout << vp[i].num << endl;
	}
}
int main() {
	ID();
	return 0;

}

Measured memory_bytes: 9072
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

typedef long long LL;
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)

int n, m;
vector<int> e[200010];

void dfs(int p, int pre, int d, bool &vis) {

    if (d == 2) {
        if (p == n-1) vis = true;
        return;
    }

    for (int i=0; i<e[p].size(); i++) if (e[p][i] != pre) {
        dfs(e[p][i], p, d+1, vis);
    }

}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin>>n>>m;

    for (int i=0; i<m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        x--; y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    bool res = false;
    dfs(0, -1, 0, res);

    if (res) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;

}


Measured memory_bytes: 12016
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

void lcs(string x, string y, 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 (x[i-1] == y[j-1]) {
                L[i][j] = L[i-1][j-1] + 1;
            } else {
                L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        }
    }
    
    int index = L[m][n];

//    char lcs[index+1];
//    lcs[index] = '\0';
    string lcs = "";

    int i = m, j = n;
    while (i>0 && j>0) {
        if (x[i-1] == y[j-1]) {
            lcs = x[i-1] + lcs;
            i--; j--; index--;
        }
        else if (L[i-1][j] > L[i][j-1]) {
            i--;
        }
        else {
            j--;
        }
    }
    
    
    cout << lcs << "\n";
    
}

int main() {
    string s, t;
    cin >> s >> t;
    auto a = s.length();
    auto b = t.length();
    
    lcs(s, t, a, b);
    
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int printintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}


//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない。デバッグしやすいように細かく！
 3.プログラミングは半分数学だし、もう半分は数学ではない！
 4.できない問題はできない！！！！！
 */

int experiment(){
    int ans;ans=0;
    int N,M;
    cin>>N>>M;
    int a[M+1];
    inarray(a, 0, M);
    a[M]=N+1;
    
    int partlyanswer[N];
    int throughed=0;
    FOR(i, 0, N){
        if(i==0){
            if(a[throughed]-1==0){partlyanswer[0]=0;throughed++;}
            else{partlyanswer[0]=1;}
            
        }
        else if (i==1) {
            if(a[throughed]-1==1){partlyanswer[1]=0;throughed++;}
            else partlyanswer[1]=1+partlyanswer[0];
        }
        else {
            if(a[throughed]-1==i){partlyanswer[i]=0;throughed++;}
            else partlyanswer[i]=(partlyanswer[i-2]+partlyanswer[i-1])%MOD;
        }
        //pf("%d段目 is %d\n",i+1,partlyanswer[i]);
    }
    OutputAndReturn0(partlyanswer[N-1]);
    return 0;
}
signed main(){
    assert(1);
    experiment();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    string S, T;
    cin >> S >> T;
    int a,b;
    cin >> a >> b;
    string U;
    cin >> U;
    if(S == U){
        a--;
    }
    else{
        b--;
    }
    cout << a << " " << b << endl;
}

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

#define NIL -1

typedef struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
}Node;

Node* insert(Node*, Node *);
void find(Node*, int);
//Node* delete(Node *, int);
void print(Node *);
void inorderTreeWalk(Node *);
void preorderTreeWalk(Node *);

main(){
  int m, key, i;
  char string[10];
  Node *T, *node;

  T = NULL;

  scanf("%d", &m);
  for(i=0; i<m; i++){
    scanf("%s", string);
    if(strcmp(string, "insert")==0){
      scanf("%d", &key);
      node = malloc(sizeof(Node));
      node->key = key;
      node->left = NULL;
      node->right = NULL;

      T = insert(T, node);
    }
    else if(strcmp(string, "find")==0){
      scanf("%d", &key);
      find(T, key);
    }
    else print(T);
  }

  return 0;
}

Node* insert(Node *T, Node *z){
  Node *x, *y;
  
  y = NULL;  //xの親
  x = T;
  
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  
  if(y==NULL) T = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  return T;
}

void find(Node *T, int key){
  while(T != NULL && T->key != key){
    if(key < T->key) T = T->left;
    else T = T->right;
  }
  if(T == NULL) printf("no\n");
  else printf("yes\n");
}

void print(Node *T){
  inorderTreeWalk(T);
  printf("\n");

  preorderTreeWalk(T);
  printf("\n");
}

void inorderTreeWalk(Node *T){
  if(T == NULL) return;

  inorderTreeWalk(T->left);
  printf(" %d", T->key);
  inorderTreeWalk(T->right);
}

void preorderTreeWalk(Node *T){
  if(T == NULL) return;
  printf(" %d", T->key);
  preorderTreeWalk(T->left);
  preorderTreeWalk(T->right);
}

Measured memory_bytes: 19364
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi v;
	for (int i = 1; i*i <= m; ++i) {
		if (m%i == 0) {
			v.push_back(i);
			if (i*i != m) {
				v.push_back(m / i);
			}
		}
	}
	int ans = 1;
	REP(i, v.size()) {
		if (m / v[i] >= n)ans = max(ans, v[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAXH 50
#define MAXW 50

int main(void){
    int h, w;
    scanf("%d %d", &h, &w);
    char s[MAXH][MAXW + 1];
    for(int i = 0; i < h; i++){
        scanf("%s", s[i]);
    }

    int mine;
    for(int i = 0; i < h; i++){
        for(int j = 0; s[i][j] !='\0'; j++){
            if(s[i][j] == '.'){
                mine = 0;
                for(int k = i - 1; k < i + 2; k++){
                    if(k < 0 || k >= h ) continue;
                    for(int l = j - 1; l < j + 2; l++){
                        if(l < 0 || l >= w  || (k == i && l == j)) continue;
                        if(s[k][l] == '#') mine++;
                    }
                }
                s[i][j] = '0' + mine;
            }
        }
    }

    for(int i = 0; i < h; i++){
        printf("%s\n", s[i]);
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
Nlist = input().split()

wMax = int(Nlist[0])
wMin = int(Nlist[0])
for value in Nlist:
    if int(value) > wMax:
        wMax = int(value)
    if int(value) < wMin:
        wMin = int(value)

print(abs(wMax - wMin))

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

const int MAX = 100001;
bool isPrime[MAX];

void next(int& k) {
    do {
        k++;
    } while (isPrime[k] == false);
}

int main() {
    fill_n(isPrime, MAX, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = i * 2; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int m, a, b;
        cin >> m >> a >> b;
        if ((m | a | b) == 0) {
            break;
        }
        int max = 0;
        pair<int, int> maxPQ;
        for (int p = 2; p * p <= m; next(p)) {
            for (int q = p; p * q <= m; next(q)) {
                if (a * q <= b * p && max < p * q) {
                    max = p * q;
                    maxPQ = make_pair(p, q);
                }
            }
        }
        cout << maxPQ.first << " " << maxPQ.second << endl;
    }
}

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

const int mod = 1000000007;

int a[300000];
int TOTOT = 32333;
int vis[300000], T[300000];
int n;

void modify(int x, long long mul) {
	x >>= 1, mul = mul * x % mod;
	while (x) {
		if (vis[x] != TOTOT) vis[x] = TOTOT, T[x] = 0;
		T[x] = (T[x] + mul) % mod;
		x >>= 1, mul = mul * x % mod;
	}
}

long long query(int x, long long mul) {
	mul = mul * x % mod, x >>= 1;
	long long lst = 0, ans = 0;
	while (x) {
		lst = lst * x % mod;
		if (vis[x] != TOTOT) vis[x] = TOTOT, T[x] = 0;
		ans += (T[x] - lst + mod) * mul % mod;
		lst = T[x], mul = mul * x % mod, x >>= 1;
	}
	return ans;
}

void modify_son(int x, long long mul) {
	if (x >= (1 << n - 1)) {
		int y = a[x - (1 << n - 1) + 1] + (1 << n - 1) - 1;
		modify(y, mul * y % mod);
		return ;
	}
	modify_son(x << 1, mul * (x << 1) % mod), modify_son(x << 1 | 1, mul * (x << 1 | 1) % mod);
}

long long query_son(int x, long long mul) {
	if (x >= (1 << n - 1)) {
		int y = a[x - (1 << n - 1) + 1] + (1 << n - 1) - 1;
		return query(y, mul * x % mod);
	}
	return (query_son(x << 1, mul * x % mod) + query_son(x << 1 | 1, mul * x % mod)) % mod;
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= (1 << n - 1); i++) {
		scanf("%d", &a[i]);
	}
	int ans = 0;
	for (int i = 1; i < (1 << n - 1); i++) {
		TOTOT++;
		modify_son(i << 1, i << 1);
		ans = (ans + query_son(i << 1 | 1, i)) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

void read() {
    int a;
    cin >> a;
    while (a--) {
        cout << "ACL";
    }
}

void run() {

}

void write() {

}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    read();
    run();
    write();
    return 0;
}

Measured memory_bytes: 3648
using System;
class Program
{
    static void Main(string[] args)
    {

        
        string[] number = Console.ReadLine().Split(' ');
        int A = int.Parse(number[0]);
        int B = int.Parse(number[1]);

        if(A % 3 == 0)
        {
            Console.WriteLine("Possible");
        }
        else if (B % 3 == 0)
        {
            Console.WriteLine("Possible");
        }
        else if((A+B)%3 == 0)
        {
            Console.WriteLine("Possible");
        }
        else
        {
            Console.WriteLine("Impossible");
        }
        



    }
}

Measured memory_bytes: 17652
n, k = map(int, input().split())
p = list(map(int, input().split()))
exp = [(v + 1) / 2 for v in p]

cur = sum(exp[:k])
ans = cur

for i in range(k, n):
    cur = cur - exp[i-k] + exp[i]
    ans = max(ans, cur)

print(ans)

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

static const ll INF = -1;
vector<ll> abc168d(ll n, ll m, vector<vector<ll>> edge) {
  vector<ll> d(n, INF);

  queue<ll> que;
  que.push(0);
  d[0] = 0;

  vector<ll> ans(n-1);
  while(!que.empty()) {
    ll v = que.front();
    que.pop();
    for(auto nv: edge[v]) {
      if(d[nv] == INF) {
	d[nv] = d[v] + 1;
	ans[nv-1] = v + 1;
	que.push(nv);
      }
    }
  }
  return ans;
}

int main() {
  ll n, m;
  cin >> n >> m;
  /*
  ll a[m], b[m];
  for(ll i=0;i<m;i++) {
    cin >> a[i] >> b[i];
  }
  */

  vector<vector<ll>> edge;
  edge.assign(n, vector<ll>());

  for(ll i=0;i<m; i++) {
    ll a, b;
    cin >> a >> b; 
    edge[a-1].push_back(b-1);
    edge[b-1].push_back(a-1);
  }

  vector<ll> ans = abc168d(n, m, edge);
  cout << "Yes" << endl;
  for(ll i=0; i < n-1; i++) {
    cout << ans[i];
    if(i != n-2) {
      cout << endl;
    }
  }
}

Measured memory_bytes: 16280
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

char a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	cout << (((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) ? "H\n" : "D\n");
	return 0;
}

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

int main(){
    int n;
    bool flag=true;
    vector<int> a;
    cin>>n;
    for(int i=0; i<n; i++){
        int in;
        cin>>in;
        a.push_back(in);
    }
    sort(a.begin(),a.end());
    flag&=((n%2==0)?a[0]==1:a[0]==0);
    for(int i=(n%2==1); i<n; i+=2){
        flag&=(a[i]==a[i+1]&&a[i]==(i+1));
    }
    long long int sum=1,N=n/2;
    for(int i=0; i<N; i++){
        sum*=2;
        if(sum>(1e+9)+7){
            sum=sum%(long long int)((1e+9)+7);
        }
    }
    if(flag)cout<<sum<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,W;
    cin >> N >> W;
    vector<ll> val(N);
    vector<ll> wei(N);
    rep(i,N){
        cin >> val[i] >> wei[i];
    }
    vector<vector<ll>> memo(105,vector<ll>(10005));
    rep(i,N){
        rep(j,W + 1){
            if(wei[i] <= j){
                memo[i + 1][j] = max(memo[i][j],memo[i][j - wei[i]] + val[i]);
            }
            else memo[i + 1][j] = memo[i][j];
        }
    }
    cout << memo[N][W] << endl;
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	ll k, n;
	cin >> k >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	vector<ll> b(n);
	rep(i, n - 1) b[i] = a[i+1] - a[i];
	b[n-1] = k - a[n - 1] + a[0];

	sort(b.begin(), b.end(), greater<ll>());
	cout << k - b[0] << endl;

}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  map<int,int> mp;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    mp[vec.at(i)] = i+1;
  }
  vector<int> A(N,1);
  vector<int> B(N,1);
  for(int i=1; i<N; i++){
    A.at(i) = A.at(i-1) + mp[i+1];
  }
  for(int i=N-2; i>=0; i--){
    B.at(i) = B.at(i+1) + mp[i+1];
  }
  for(int i=0; i<N; i++){
    cout <<  A.at(i);
    if(i != N-1){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }
  for(int i=0; i<N; i++){
    cout <<  B.at(i);
    if(i != N-1){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }
}     

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,a[110]={0};
    cin>>n>>k;
    while(k--){
        int j,x;
        cin>>j;
        for(int i=0;i<j;i++){
            cin>>x;
            a[x]+=1;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i]==0) cnt+=1;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
 
  cin >> a >> b;

  cout << (a * b) - (a + b) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

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

int main(){
    int tmp[3]={1,0,0};
    char x,y;
    while (scanf("%c,%c",&x,&y)!=EOF){
        int a=-1,b=-1,c=-1;
        if (x=='A' || y=='A') a=0;
        if (x=='B' || y=='B') b=1;
        if (x=='C' || y=='C') c=2;
        if (a==0 && b==1) swap(tmp[0],tmp[1]);
        if (a==0 && c==2) swap(tmp[0],tmp[2]);
        if (b==1 && c==2) swap(tmp[1],tmp[2]);
    }
    if (tmp[0]==1) printf("A\n");
    if (tmp[1]==1) printf("B\n");
    if (tmp[2]==1) printf("C\n");
    return 0;
}

Measured memory_bytes: 3116
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]
 
city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]
 
under6 = {}
for i,k in city.items():
    city[i] = sorted(k)
    for j in range(len(city[i])):
        under6[city[i][j]] = j + 1

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)
 
def change_birth_code(birth_num):
    return str(birth_num).zfill(6)
 
for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(under6[i[1]]))

Measured memory_bytes: 53408
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isleap (int year )
{
	return ( ( year % 4 == 0 ) && ( ( year % 100 != 0 ) || ( year % 400 == 0 ) ) );
}

int main()
{
	int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

//	cut here before submit 
//	freopen ("testcase.daycount2", "r", stdin );

	string str = "";

	while (getline (cin, str ) ){

		int y1, m1, d1, y2, m2, d2;
		stringstream ss(str);
		ss >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;

		if (y1 == -1 || m1 == -1 || d1 == -1 || y2 == -1 || m2 == -1 || d2 == -1){
			break;
		} // end if
		int res = 0;

		// [úðÇÁ
		for (int year = y1; year <= y2; ++year ){
			if (isleap (year) ){
				++res;
			} // end if
		} // end for
		
		// JnNª[NÅJnª[úðÜÜÈ¢ê
		if (isleap (y1) && m1 >= 3){
			--res;
		} // end if
		// I¹Nª[NÅI¹úª[úðÜÜÈ¢ê
		if (isleap (y2) && m2 <= 2 && d2 <= 29 ){
			--res;
		} // end if
		
		int curr_year = y1;
		int curr_month = m1;
		int curr_day = d1;

		while (curr_year != y2 ){
			while (curr_month != 0 ){
				res += days[curr_month] - curr_day + 1;
				curr_month = (curr_month + 1) % 13;
				curr_day = 1;
			} // end 
			++curr_month;
			++curr_year;
		} // end while

		if (curr_year == y2 ){
			while (curr_month != m2 ){
				res += days[curr_month] - curr_day + 1;
				// _ ++curr_month
				// curr_month = 13 ÆÈÁÄµÜ¤
				// 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1 Æµ½¢
				// (curr_month + 1) % 13
				curr_month = ( (curr_month + 1) % 13 == 0 ? 1 : ++curr_month) ;
				curr_day = 1;
 			}// end while
			res += (d2 - curr_day);
		} // end if
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    t, a = nm()
    H = nl()
    D = list(map(lambda x: abs(a - (t - x * 0.006)), H))
    print(D.index(min(D)) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    a,b = MAP()
    if a<=0 and b>=0:
        print('Zero')
        return
    if a>0: #全部正の場合
        print('Positive')
        return
    
    if b<0: #全部ふの場合
        if (b-a+1)%2 == 0:
            print('Positive')
        else:
            print('Negative')
    

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  vector<double> q(N+1);
  for(int i = 0; i < N; i++){
    cin >> p[i];
    q[i+1]= q[i] + (p[i]+1)/2;
  }
  double ans = 0;
  for(int i = 0; i < N-K+1; i++){
    ans = max(ans, q[i+K]-q[i]);
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    if(t.size()==s.size()+1){
    	if(t.substr(0,s.size())==s){
		    cout<<"Yes"<<endl;
		    return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3632
n = gets.to_i
pos = n.times.map{gets.chomp.split.map(&:to_f)}

sum = 0
cnt = 0
[*0..n-1].permutation(n) do |a|
  cnt += 1
  a.each_cons(2) do |i,j|
    dist = (pos[i][0] - pos[j][0]) ** 2 + (pos[i][1] - pos[j][1]) ** 2
    sum += Math.sqrt(dist)
  end
end

puts sum / cnt


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

int main() {
  int K,N;
  cin >> K >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  sort(V.begin(),V.end());
  
  vector<int> W(N);
  W.at(0) = V.at(0) + K - V.at(N - 1);
  for (int j = 1; j < N; j++)
    W.at(j) = V.at(j) - V.at(j - 1);
  sort(W.begin(),W.end());
  
  cout << K - W.at(N - 1) << endl;
    
  
}


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <map>
using namespace std;

#define MAX_N   (200001)

int N, K, L;
int k[MAX_N];
int rank_k[MAX_N];
int l[MAX_N];
int rank_l[MAX_N];

void init() {
    for (int i = 1; i <= N; i++) {
        k[i] = i;
        rank_k[i] = 0;
        l[i] = i;
        rank_l[i] = 0;
    }
}

int find_k(int x) {
    if (k[x] == x) {
        return x;
    } else {
        return k[x] = find_k(k[x]);
    }
}

int find_l(int x) {
    if (l[x] == x) {
        return x;
    } else {
        return l[x] = find_l(l[x]);
    }
}

void unite_k(int x, int y) {
    x = find_k(x);
    y = find_k(y);
    
    if (x == y) {
        return;
    }
    
    if (rank_k[x] < rank_k[y]) {
        k[x] = y;
    } else {
        k[y] = x;
        if (rank_k[x] == rank_k[y]) {
            rank_k[x]++;
        }
    }
}

void unite_l(int x, int y) {
    x = find_l(x);
    y = find_l(y);
    
    if (x == y) {
        return;
    }
    
    if (rank_l[x] < rank_l[y]) {
        l[x] = y;
    } else {
        l[y] = x;
        if (rank_l[x] == rank_l[y]) {
            rank_l[x]++;
        }
    }
}

/* どちらも連結しているか */
bool isConectivity(int x, int y) {
    if (find_k(x) != find_k(y)) {
        return false;
    }
    if (find_l(x) != find_l(y)) {
        return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /* N, K, Lの取得 */
    cin >> N >> K >> L;
    
    /* 初期化 */
    init();
    
    /* 道路で連結されているものの取得 */
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        unite_k(p, q);
    }
    
    /* 鉄道で連結されているものの取得 */
    for (int i = 0; i < L; i++) {
        int r, s;
        cin >> r >> s;
        unite_l(r, s);
    }
    
    /* 結果の出力 */
    map<pair<int, int>, int> cnt;
    for (int i = 1; i <= N; i++) {
        cnt[make_pair(find_k(i), find_l(i))]++;
    }
    for (int i = 1; i <= N; i++) {
        cout << cnt[make_pair(find_k(i), find_l(i))] << ' ';
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 15104
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n;
map<long long, int> cnt;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    long long x;
    for (int i = 1; i <= n; i++){
        cin>>x;
        cnt[x] ++;
    }
    
    vector<long long> sid;
    vector<long long> sid4;
    for (auto i = cnt.rbegin(); i != cnt.rend(); i++){
        if(i->second >=4)sid4.push_back(i->first);
        if(i->second >=2)sid.push_back(i->first);
    }
    
    long long mx = 0;
    
    if(sid4.size()>0)mx = max(mx, sid4[0]*sid4[0]);
    
    if(sid.size()>=2)mx = max(mx, sid[0]*sid[1]);
    
    if(sid4.size()>0 && sid.size()>0)mx = max(mx, sid4[0]*sid[0]);
    
    cout<<mx<<endl;
    
    
    return 0;
}




Measured memory_bytes: 6528
// D - Islands War
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,M; cin>>N>>M;
	map<int,int> V;
	while(M--){
		int l,r; cin>>l>>r;
		V[r] = max(V[r], l);
	}
	int ans = 0, R = 0;
	for(auto m:V) if(m.second >= R){ R = m.first; ans++; }
	cout<< ans <<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

int main()
{
    std::ios_base::sync_with_stdio(0);

    std::string current_weather;
    std::cin >> current_weather;

    std::string sunny, cloudy, rainy;
    sunny = "Sunny";
    cloudy = "Cloudy";
    rainy = "Rainy";

    if (current_weather == sunny)
        std::cout << cloudy;
    if (current_weather == cloudy)
        std::cout << rainy;
    if (current_weather == rainy)
        std::cout << sunny;

    return 0;
}


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

template<class E, class T> struct Rerooting {
    using F = function<T(T, T)>;
    using H = function<T(T, E)>;
//private : 
    struct Edge {
        int to;
        E data;
        T dp, sum;
        Edge (int to, E data, T dp, T sum) : 
            to(to), data(data), dp(dp), sum(sum) { }
    };
    vector<vector<Edge>> g; // グラフ
    vector<T> subdp, dp;    // 部分木, 全方位
    const T id;             // 単位元
    const F f;              // 累積和生成
    const H h;              // 辺から情報を得る
    int edges;

public : 
    Rerooting (int n, const F &f, const H &h, const T id) : 
        g(n), f(f), h(h), id(id), subdp(n, id), dp(n, id) { edges = 0; }

    void add_edge (int v, int u, const E &val) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val, id, id);
        g[u].emplace_back(v, val, id, id);
    }

    void add_edge2 (int v, int u, const E &val1, const E &val2) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val1, id, id);
        g[u].emplace_back(v, val2, id, id);
    }

    void dfs1 (int v, int p) {
        for (const auto &e : g[v]) {
            if (e.to == p) continue;
            dfs1(e.to, v);
            subdp[v] = f(subdp[v], h(subdp[e.to], e.data));
        }
    }

    void dfs2 (int v, int p, const T &top) {
        T buff = id;
        for (int i = 0; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            e.sum = buff;
            e.dp = h(e.to == p ? top : subdp[e.to], e.data);
            buff = f(buff, e.dp);
        }
        dp[v] = buff;
        buff = id;
        for (int i = (int)g[v].size() - 1; i >= 0; i--) {
            Edge &e = g[v][i];
            if (e.to != p) dfs2(e.to, v, f(buff, e.sum));
            e.sum = f(e.sum, buff);
            buff = f(buff, e.dp);
        }
    }

    vector<T> build(int s = 0) {
        dfs1(s, -1);
        dfs2(s, -1, id);
        return dp;
    }

};


int main() {
    int n;
    long long m;
    cin >> n >> m;
    
    auto f = [&] (long long a, long long b) { return (a * b) % m; };
    auto h = [&] (long long a, long long b) { return (a + b) % m; };
    Rerooting<long long, long long> g(n, f, h, 1);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b, 1LL);
    }
    
    for (const auto &e : g.build()) {
        cout << e << '\n';
    }
    return 0;
}

Measured memory_bytes: 25088
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[][] nums=new int[n][3];
        for(int i=0;i<n;i++){
            nums[i][0]=sc.nextInt();
            nums[i][1]=i;
        }
        Comp comp=new Comp();
        comp.set_index(0);
        Arrays.sort(nums,comp);
        for(int i=0;i<n;i++){
            nums[i][2]=i<n/2?nums[n/2][0]:nums[n/2-1][0];
        }
        comp.set_index(1);
        Arrays.sort(nums,comp);
        for(int i=0;i<n;i++)System.out.println(nums[i][2]);
    }
}
class Comp implements Comparator {

    int index = 0;

    void set_index (int i) {
        index = i;
    }
    
    @Override
    public int compare (Object a, Object b) {
        int[] int_a = (int[]) a;
        int[] int_b = (int[]) b;
        return (int_a[index] - int_b[index]);
    }

}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	char res[111][111];
	int w,h;
	cin>>w>>h;
	for(int i=0;i<111;++i)
		for(int j=0;j<111;++j)
			res[i][j]='#';
	for(int i=1;i<=w;++i)
		for(int j=1;j<=h;++j)
			cin>>res[i][j];
	for(int i=0;i<=w+1;++i){
		for(int j=0;j<=h+1;++j)
			cout<<res[i][j];
		cout<<'\n';
	}
}




Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

        int w = Integer.parseInt(sc.next());
        List<Integer> amida = new ArrayList<>();

        for (int i = 1; i <= w; i++) {
            amida.add(i);
        }


        int n = Integer.parseInt(sc.next());
        for (int i = 0; i < n; i++) {
            String S = sc.next();

            int a = Integer.parseInt(S.split(",")[0]);
            int b = Integer.parseInt(S.split(",")[1]);

            Collections.swap(amida, a - 1, b - 1);
        }
        amida.forEach(System.out::println);
    }
}

Measured memory_bytes: 32176
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
using ll=long long;
using namespace std;


double ans=0.0;
double cnt=0.0;
void dfs(int now,int N,vector<bool> seen,vector<pair<int,int>> xy,vector<int> select)
{
	if(now==N)
	{
		double val=0.0;
		for(int i=0;i<N-1;i++)
		{
			val+=sqrt(pow(xy[select[i]].first-xy[select[i+1]].first,2.0)+pow(xy[select[i]].second-xy[select[i+1]].second,2.0));	
		}
		//cout<<val<<endl;
		ans+=val;
		cnt++;
	}	
	else
	{
		rep(i,N)
		{
			if(seen[i]) continue;
			seen[i]=true;
			select[now]=i;
			dfs(now+1,N,seen,xy,select);
			seen[i]=false;
			select[now]=-1;
		}
	}
}
int main()
{
	int N;
	cin>>N;
	vector<pair<int,int>> xy(N,make_pair<int,int>(0,0));
	rep(i,N)
	{
		cin>>xy[i].first>>xy[i].second;
	}
	dfs(0,N,vector<bool>(N,false),xy,vector<int>(N,-1));
	//cout<<cnt<<endl;
	cout<<fixed<<setprecision(7)<<ans/cnt<<endl;
	return 0;
}


Measured memory_bytes: 3776