akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
#define PII pair<int,int>
#define MAXN 100010
map<PII,int>G;
queue<PII>Q;
set<int>A[MAXN];
set<int>::iterator it;
int n,fa[MAXN];
int Find(int x)
{
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}
int main()
{
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<=2*n-2;i++)
	{
		scanf("%d%d",&u,&v);
		A[u].insert(v),A[v].insert(u);
		G[PII(u,v)]++;G[PII(v,u)]++;
		if(G[PII(u,v)]==2)
			Q.push(PII(u,v));
	}
	for(int i=1;i<=n;i++)
		fa[i]=i;
	while(!Q.empty())
	{
		int u=Q.front().first,v=Q.front().second;Q.pop();
		u=Find(u),v=Find(v);
		A[u].erase(v),A[v].erase(u);
		if(A[u].size()>A[v].size()) swap(u,v);
		for(it=A[u].begin();it!=A[u].end();it++)
		{
			int x=(*it);
			G[PII(x,u)]=G[PII(u,x)]=0;
			G[PII(x,v)]++,G[PII(v,x)]++;
			if(G[PII(x,v)]==2)
				Q.push(PII(x,v));
			A[x].erase(u);A[x].insert(v);
			A[v].insert(x);
		}
		fa[u]=v;
		A[u].clear();
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		cnt+=(fa[i]==i);
	if(cnt==1) printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 57984
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

string s;

int main() {
	cin >> s;
	string sl, sr;
	for (int i = 0; i < 4; i++)
		sl += s[i];
	for (int i = 4; i < 12; i++)
		sr += s[i];
	cout << sl << " " << sr << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int W, a, b;
	cin >> W >> a >> b;

	int left = min(a, b);
	int right = max(a, b);

	cout << max(right - (left + W), 0);

	return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**8)

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]", B: "List[int]"):

    def quadrant(a, b):
        if a > 0 and b >= 0:
            return 0
        elif a <= 0 and b > 0:
            return 1
        elif a < 0 and b <= 0:
            return 2
        elif a >= 0 and b < 0:
            return 3
        else:
            return None

    def norm(a, b):
        g = gcd(a, b)
        a //= g
        b //= g
        while quadrant(a, b) != 0:
            a, b = -b, a
        return a, b

    d = defaultdict(lambda: [0, 0, 0, 0])
    kodoku = 0
    for i, (a, b) in enumerate(zip(A, B)):
        if (a, b) == (0, 0):
            kodoku += 1
        else:
            d[norm(a, b)][quadrant(a, b)] += 1

    ans = 1
    for v in d.values():
        buf = pow(2, v[0]+v[2], MOD)
        buf += pow(2, v[1]+v[3], MOD)
        buf = (buf-1) % MOD
        ans *= buf
        ans %= MOD

    print((ans-1+kodoku) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125700
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def min(a,b)
    return a>b ? b : a
end
class SegTree
    attr_accessor:node,:n,:monoid
    def initialize(n,monoid)
        @n=1
        @n*=2 while @n<n
        @monoid=monoid
        @node=array(2*@n,@monoid)
    end

    def update(i,x)
        i+=@n
        @node[i]=x
        while i>0
            i/=2
            @node[i]=min(@node[i*2],@node[i*2+1])
        end
    end

    def get_min(l,r)
      l+=@n
      r+=@n
      res=@monoid
      while l<r
        if l.odd?
            res=min(res,@node[l])
            l+=1
        end 
        if r.odd?
            r-=1
            res=min(res,@node[r])
        end
        l/=2
        r/=2
      end
      return res
    end
end

N,Q=get_i
st=SegTree.new(N,2**31-1)
Q.times do
    c,x,y=get_i
    if c.zero?
      st.update(x,y)
    else
      puts st.get_min(x,y+1) 
    end
end


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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<long>> ma1(n, vector<long>(m, 0));
  vector<vector<long>> ma2(m, vector<long>(l, 0));
  vector<vector<long>> ma3(n, vector<long>(l, 0));
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> ma1.at(i).at(j);
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> ma2.at(i).at(j);
    }
  }
  for(int i = 0; i < n; i++){
	for(int j = 0; j < l; j++){
      for(int k = 0; k < m; k++){
	ma3.at(i).at(j) += ma1.at(i).at(k) * ma2.at(k).at(j);
      }
      cout << ma3.at(i).at(j);
      if(j == l - 1) break; // もしｎ行目の最後にスペースを入れてもよければこれを消す
      cout << " ";
    }
    cout << endl;
  }
  
}



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

using namespace std;
#define int long long
#define double long double
#define all(a) a.begin(), a.end()

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

int check(int a) {
	int ans = 0;
	while (a) {
		ans++;
		a /= 10;
	}
	return ans % 2;
}

void read() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += check(i);
	}
	cout << ans << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    vector<string> t(h);
    for (int i = 0; i < w + 2; i++)
    {
        s.at(0) = s.at(0) + '-';
        s.at(h + 1) = s.at(h + 1) + '-';
    }
    for (int i = 1; i < h + 1; i++)
    {
        cin >> s.at(i);
        t.at(i-1)=s.at(i);
        s.at(i) = '-' + s.at(i) + '-';
    }
    int count = 0;
    string xxx;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            if (s.at(i)[j] == '.')
            {
                count = 0;
                if (s.at(i - 1)[j - 1] == '#')
                {
                    count++;
                }
                if (s.at(i - 1)[j] == '#')
                {
                    count++;
                }
                if (s.at(i - 1)[j + 1] == '#')
                {
                    count++;
                }
                if (s.at(i)[j + 1] == '#')
                {
                    count++;
                }
                if (s.at(i + 1)[j + 1] == '#')
                {
                    count++;
                }
                if (s.at(i + 1)[j] == '#')
                {
                    count++;
                }
                if (s.at(i + 1)[j - 1] == '#')
                {
                    count++;
                }
                if (s.at(i)[j - 1] == '#')
                {
                    count++;
                }
                xxx = to_string(count);
                t.at(i-1)[j-1] = xxx[0];
            }
            else{
                t.at(i-1)[j-1] = '#';
            }
        }
    }

    //確認
    for (int i = 0; i < h ; i++)
    {
        cout << t.at(i) << endl;
    }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;


int h, w, k;
vector<string> lines;

int main() {
	cin >> h >> w >> k;
	rep(i, h) {
		string s;
		cin >> s;
		lines.push_back(s);
	}
	ll sum = 0;
	for (ll x = 0; x < 1LL << w; x++) {
		for (ll y = 0; y < 1LL << h; y++) {
			ll b = 0;
			rep(i, w) {
				rep(j, h) {
					if (lines[j][i] == '#') {
						if (x & (1LL << i)) continue;
						if (y & (1LL << j)) continue;
						b++;
					}
				}
			}
			if (b == k) {
				sum++;
			}
		}
	}
	cout << sum << endl;
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

const long long P = 1e9 + 7;

map<long long, long long> M;

long long f(long long s) {
  if (M.find(s) != M.end()) {
    return M[s];
  }

  long long res = 0;
  for (int i = 3; i <= s; i++) {
    res += f(s - i);
    res %= P;
  }
  M[s] = res;
  return res;
}

int main() {
  _upgrade;
  int s;
  cin >> s;
  M[0] = 1;
  cout << f(s) << "\n";
  return 0;
}

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

using namespace std;


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

    char S[100] = {};

    int i = 0;
    int x = N;
    while(true){

        if(x == 0){
            S[i] = '0';
            break;
        }
        else if(x == 1){
            S[i] = '1';
            break;
        }
        else if(x % 2 == 0){
            x /= -2;
            S[i] = '0';
            i++;
        }
        else{
            x = x - 1;
            x /= -2;
            S[i] = '1';
            i++;
        }
    }
    for(int j = i; j >= 0; --j) cout << S[j];
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
T Prim(WeightedGraph<T> &g)
{
    T res = 0;
    vector<bool> used(g.size(), false);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
    que.emplace(0, 0);
    while (que.empty() != true)
    {
        auto p = que.top();
        que.pop();
        if (used[p.second] == true)
            continue;
        used[p.second] = true;
        res += p.first;
        for (auto &e : g[p.second])
        {
            que.emplace(e.cost, e.to);
        }
    }
    return res;
}

int N, a, b, c, d, p1, p2;

int main()
{
    cin >> N;
    vector<pair<pair<int, int>, int>> x, y;
    WeightedGraph<int> G(N);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        x.emplace_back(make_pair(a, b), i);
        y.emplace_back(make_pair(b, a), i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    for (int i = 0; i + 1 < N; i++)
    {
        a = x[i].first.first, b = x[i].first.second, c = x[i + 1].first.first, d = x[i + 1].first.second;
        int p1 = x[i].second, p2 = x[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - c), abs(b - d)));
        G[p2].emplace_back(p1, min(abs(a - c), abs(b - d)));
    }

    for (int i = 0; i + 1 < N; i++)
    {
        a = y[i].first.first, b = y[i].first.second, c = y[i + 1].first.first, d = y[i + 1].first.second, p1 = y[i].second, p2 = y[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - c), abs(b - d)));
        G[p2].emplace_back(p1, min(abs(a - c), abs(b - d)));
    }

    cout << Prim(G) << endl;
}

Measured memory_bytes: 14636
s = int(input())
mod = 10**9 + 7

# dp[i]: 最後に切った場所がi
dp = [0]*(s + 1)
dp[0] = 1
total = 0
for i in range(3, s+1):
    total += dp[i-3]
    total %= mod
    dp[i] = total

print(dp[s])

Measured memory_bytes: 63572
#include <stdio.h>
#include <string.h>
int main(){
	char in[1000];
	scanf("%s",in);
	int mojisu=strlen(in);
	int i;
	for(i=0;i<mojisu;i++){
		if('A'<=in[i]&&in[i]<='C'){
			printf("%c",in[i]-'A'+'X');
		}
		else{
			printf("%c",in[i]-'D'+'A');
		}
	}
	printf("\n");
	return 0;
}

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

typedef long long ll;

const int N = 200000 + 5;
const ll MOD = 1e9 + 7;

ll n, m, k;
ll fact[N], invFact[N], ans;

void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}

inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return res % MOD;
}

inline void init() {
    fact[0] = 1;
    for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % MOD;
    invFact[N - 1] = inv(fact[N - 1]);
    for (int i = N - 2; i >= 0; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}

inline ll C(int n, int m) {
    // if (m == 0) return 1;
    if (m > n) return 0;
    return fact[n] * (invFact[m] * invFact[n - m] % MOD) % MOD;
}

int main() {
    init();
    scanf("%lld %lld %lld", &n, &m, &k);
    for (ll i = 1; i <= n; i++) {
        ll tmp1 = (n - i) * m % MOD * m % MOD * C(n * m - 2, k - 2) % MOD * i % MOD;
        ll tmp2 = (i - 1) * m % MOD * m % MOD * C(n * m - 2, k - 2) % MOD * i % MOD;
        ans = ans + (((tmp2 - tmp1) % MOD + MOD) % MOD);
        ans %= MOD;
    }
    for (ll i = 1; i <= m; i++) {
        ll tmp1 = (m - i) * n % MOD * n % MOD * C(n * m - 2, k - 2) % MOD * i % MOD;
        ll tmp2 = (i - 1) * n % MOD * n % MOD * C(n * m - 2, k - 2) % MOD * i % MOD;
        ans = ans + (((tmp2 - tmp1) % MOD + MOD) % MOD);
        ans %= MOD;
    }
    printf("%lld\n", ans % MOD);
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

// index が条件を満たすかどうか vector<>maeに検索したいvectorを入れる keyを超える最小の要素番号を返す
bool isOK(int index, long long key, vector<long long>&mae) {
	if (mae[index] >= key) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(long long key, vector<long long>&mae) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)mae.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key, mae)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

long long mod(const long long &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}
int mod(const int &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}

int main() {
	ll n, k;cin >> n >> k;
	VLL pmt(n);
	rep(i, n)cin >> pmt[i];
	VLL so = pmt;
	sort(so.begin(), so.end());
	//nの各文字に対して大きい要素をカウント
	VI ba(n);
	for (int i = 0; i < n; i++)
	{
		ba[i]=n-binary_search(pmt[i] + 1, so);
	}
	VI bb(n,0);
	//自分より前にある自分より大きい要素
	for (int i = 0; i < n; i++)
	{
		int it = i - 1;
		while (it >= 0)
		{
			if(pmt[it]>pmt[i])bb[i]++;
			it--;
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans +=ba[i];
	}
	ans = mod(ans);
	ans = mod(ans*mod((k - 1)*k/2));
	for (int i = 0; i < n; i++)
	{
		ans += bb[i]*k;
	}
	cout << mod(ans) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+500;
typedef long long ll;

int gti(void)
{
    char c=getchar();
    int ret=0,st=1;
    for (;!isdigit(c);c=getchar()) if (c=='-') st=-1;
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
    return ret*st;
}

struct edge{edge *nxt;int to;}pool[N<<1],*pt[N],*ep=pool;
void add(int a,int b)
{
    *(++ep)=(edge){pt[a],b},pt[a]=ep;
    *(++ep)=(edge){pt[b],a},pt[b]=ep;
}

struct P
{
    int a,b,id;
    bool operator<(const P &y)const
    {
        return a<y.a||(a==y.a&&id<y.id);
    }
}p[N],q[N];

int fa[N],vis[N];
int getfa(int v)
{
    if (fa[v]==v) return v;
    return fa[v]=getfa(fa[v]);
}

ll f[N],g[N];
int main(void)
{
    int n=gti(),m=gti();
    for (int i=1;i<=n;i++)
    {
        p[i].a=gti(),p[i].b=gti(),p[i].id=i;
        p[i].a=max(0,p[i].a-p[i].b),q[i]=p[i];
    }
    for (int i=1;i<=m;i++)
    {
        int u=gti(),v=gti();
        add(u,v);
    }
    sort(p+1,p+1+n);
    for (int i=1;i<=n;i++)
    {
        int v=p[i].id;
        g[v]=q[v].b,f[v]=1e18,fa[v]=v;
        for (edge *e=pt[v];e;e=e->nxt)
            if (q[e->to]<q[v]&&vis[getfa(e->to)]<i)
                g[v]+=g[fa[e->to]],vis[fa[e->to]]=i;
        for (edge *e=pt[v];e;e=e->nxt)
            if (q[e->to]<q[v])
            {
                f[v]=min(f[v],g[v]-g[fa[e->to]]+max(f[fa[e->to]],1ll*q[v].a));
                fa[fa[e->to]]=v;
            }
        if (f[v]==1e18) f[v]=q[v].a+q[v].b;
    }
    printf("%lld\n",f[p[n].id]);
    return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}
typedef pair<ll, ll> pll;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), b(n), c(n);
	rep(i, n) cin >>a[i];
	rep(i, n) cin >>b[i];
	rep(i, n) cin >>c[i];
	
	sort(all(a)); 
	sort(all(b)); 
	sort(all(c)); 
	ll ans = 0;
	
	rep(i, sz(b)){
		ll zx = 1;
		int cr = lower_bound(all(a), b[i]) - a.begin();
		zx *= cr;
		int zr = lower_bound(all(c), b[i]+1) - c.begin();
		ans += zx * (n - zr);
		//dbg(zx,n-zr,cr,b[i]);
	}
	
	cout << ans <<"\n";
	
	return 0;
}


Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import sys
from heapq import heappush,heappop,heapify

N=int(sys.stdin.readline().strip())
V=[]    #頂点の集合 (x座標、y座標、頂点番号)
for v in range(N):   #v:頂点番号
    x,y=tuple(map(int, sys.stdin.readline().split()))
    V.append((x,y,v+1))

#頂点をy軸でソート
V.sort(key=lambda x:(x[0]) )
E=[]    #辺の集合 (辺の長さ、頂点番号、頂点番号)
for i in range(N-1):
    fro_x,fro=V[i][0],V[i][2]
    to_x,to=V[i+1][0],V[i+1][2]
    E.append( (abs(fro_x-to_x),fro,to))

#頂点をx軸でソート
V.sort(key=lambda x:(x[1]) )
for i in range(N-1):
    fro_y,fro=V[i][1],V[i][2]
    to_y,to=V[i+1][1],V[i+1][2]
    E.append( (abs(fro_y-to_y),fro,to))

#辺の集合を辺の長さで昇順ソート
E.sort(key=lambda x:(x[0]) )

al=[[] for _ in range(N+1)]

for cost,fro,to in E:
    al[fro].append((cost,to))
    al[to].append((cost,fro))


#確定した頂点のリスト
fixed_v=[ 0 for _ in range(N+1) ]
hq=[]   #最短の辺を取得するためのヒープキュー
V=[1]   #次に処理する頂点が常に1つだけ入る、頂点1が常にスタート地点

ans=0
while V:
    cur=V.pop()
    #確定した頂点の更新
    fixed_v[cur]=1
    #頂点curから出て行く辺を全てhqに入れる
    for cost,to in al[cur]:
        heappush(hq,(cost,to))
    while hq:
        #hqから辺を取り出す
        cost,to=heappop(hq)
        #未確定の頂点が見つかれば、次に見る頂点としてVにappendし、whileループはbreak
        if fixed_v[to]==0:
            ans+=cost
            V.append(to)
            break
        #確定済みの頂点の場合は、#未確定の頂点が見つかるまでheapqからpopする

print ans

Measured memory_bytes: 185552
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        string s = ReadLine();

        int[,] dp = new int[n+1, n+1];
        int ans = 0;
        for (int i = 1; i < n; i++){
            for (int j = i + 1; j <= n; j++)
            {
                if (s[i-1] == s[j-1])
                    dp[i,j] = Math.Max(dp[i,j], dp[i-1,j-1] + 1);
                ans = Math.Max(ans, Math.Min(dp[i, j], j-i));
            }
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 108640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1 << 21;
const ll MOD = 1e9 + 7;

const int N = 500;

double p[5000], q[5000], sump[5000], sumq[5000];
double memo[5000][5000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, n) { cin >> p[i + 1]; }
    rep(i, n + 1) { cin >> q[i]; }
    sumq[0] = q[0];

    rep(i, n)
    {
        sump[i + 1] = sump[i] + p[i + 1];
        sumq[i + 1] = sumq[i] + q[i + 1];
    }

    for (int i = 1; i < n + 1; ++i) {
        for (int j = 1; j < n + 1; ++j) {
            if (j >= i) {
                memo[i][j] = INF;
            } else {
                memo[i][j] = 0;
            }
        }
    }

    for (int l = 1; l < n + 1; ++l) {
        for (int i = 1; i < n + 2 - l; ++i) {
            int j = i + l - 1;
            for (int k = i; k < j + 1; ++k) {
                double sum = sump[j] - sump[i - 1];
                if (i == 1) {
                    sum += sumq[j];
                } else {
                    sum += sumq[j] - sumq[i - 2];
                }
                memo[i][j] = min(memo[i][j], sum - p[k] + memo[i][k - 1] + memo[k + 1][j]);
            }
        }
    }
    cout << memo[1][n] + sump[n] + sumq[n] << endl;
    return 0;
}


Measured memory_bytes: 7284
#include<iostream>
#include<vector>
#include <cassert>
#include<algorithm>
#include <tuple>
#include <utility>
#include<string>
#include <cmath>
#include <queue>
#include <functional>
#define ll long long
using namespace std;

int main() {
    ll N,ans=0,a;
    cin >> N;
    vector<ll> A;
    queue<ll> q1;
    for(ll i =0; i < N; i++){
        cin >> a;
        A.push_back(-a);
    }
    sort(A.begin(),A.end());
    q1.push(-A[1]);
    q1.push(-A[1]);
    ans = -A[0];

    for(ll i = 2; i < N; i++){
        ans+= q1.front();
        q1.pop();
        q1.push(-A[i]);
        q1.push(-A[i]);
    }
    cout << ans << endl;

}

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

#define ll long long

using namespace std;

const int mod = 998244353;

ll n, m, k, f[2000005], ans;

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

ll c (ll n1, ll k1) {
    return ((f[n1] * binpow (f[k1], mod - 2) % mod) % mod * binpow (f[n1 - k1], mod - 2) % mod) % mod;
}

int main () {
    cin >> n >> m >> k;
    f[0] = 1;
    for (ll i = 1;i <= max (n, m);i ++) {
        f[i] = (f[i - 1] * 1ll * i) % mod;
    }
    for (ll i = 0;i <= k;i ++) {
        ans = (ans + ((c (n - 1, i) * m) % mod * binpow (m - 1, n - 1 - i)) % mod) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 5192
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define lowbit(x) ((x)&(-(x)))
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    return x*f;
}

const int MAXN=300005;
char s[MAXN];
int n,m,a[MAXN];
int main(){
	scanf("%s",s+1);
	if (s[1]=='Y'&&s[2]=='A'&&s[3]=='K'&&s[4]=='I') printf("Yes\n");
	else printf("No\n");
    return 0;
}

/*
*/


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

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c)
  {
    cout << "No"<<endl;
  }
  else if(a==b||a==c||b==c)
  {
    cout << "Yes"<<endl;
  }else 
  {
    cout << "No"<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int x,y;

    while(1) {
      scanf("%d %d", &x, &y);
      if(x==0 && y==0)  break;
      if(x>y) printf("%d %d\n", y, x);
      else    printf("%d %d\n", x, y);
    }

    return 0;
}



Measured memory_bytes: 1976
#include<cstdio>
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cctype>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a) for(int i=0;i<a-1;i++)
using namespace std;
int main(void)
{
	int n,w,h,cnt=0,xx,yy;
	int x[1000],y[1000];
	cin>>w>>h>>n;
	rep(i,n) cin>>x[i]>>y[i];
	rep2(i,n) {
		xx=(x[i+1]-x[i]);yy=(y[i+1]-y[i]);
		if(xx*yy>0) cnt+=max(abs(xx),abs(yy));
		else cnt+=abs(xx)+abs(yy);
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3092
n = int(input())
a = list(map(int, input().split()))

ball = [0]*n

for i in reversed(range(1, n+1)):

    ball_in_or_not = a[i-1] ^ sum(ball[i-1:n:i]) % 2
    
    if ball_in_or_not == 1:
        ball[i-1] =1

if sum(ball) > 0:
    print(sum(ball))
    print(*[i+1 for i in range(n) if ball[i] > 0]) 

else:
    print(0)

Measured memory_bytes: 13112
/*input
9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e4+1;
int a[N];
int b[N];
int dp[N];
int h,n;

void solve(){
    cin >> h >> n;
    RE(i,n)cin >> a[i] >> b[i];
    RE(i,h){
      dp[i] = INF;
      RE(j,n){
        if(a[j] > i)dp[i] = min(dp[i],b[j]);
        else dp[i] = min(dp[i],dp[i-a[j]]+b[j]);
      }
    }
    cout << dp[h];
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    int A, B, C, D, a, c; cin>>A>>B>>C>>D;
    a=A/D;
    c=C/B;    
    if(A%D !=0){
        a++;
    }
    if(C%B !=0){
        c++;
    }
    if(a>=c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3624
heap_size = STDIN.gets().to_i
heap_keys = STDIN.gets().split(' ').map{ |i| i.to_i }

1.upto(heap_size) do |i|
  print "node #{i}: key = #{heap_keys[i-1]}, "
  print "parent key = #{heap_keys[i/2-1]}, " unless i==1
  print "left key = #{heap_keys[i*2-1]}, " unless i*2-1>=heap_size
  print "right key = #{heap_keys[i*2]}, " unless i*2>=heap_size
  print "\n"
end

Measured memory_bytes: 8688
#include<bits/stdc++.h>
using namespace std; 
const int N=100005;
int n,m,q,d,c,u,v; 
pair<int,int>dp[N][15]; 
vector<int>a[N]; 
int main()
{ 
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{ 
		scanf("%d%d",&u,&v); 
		a[u].push_back(v); 
		a[v].push_back(u);
	} 
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{	
		scanf("%d%d%d",&v,&d,&c);
		dp[v][d]=make_pair(i,c); 
	} 
	for(int k=9;k>=0;k--) 
		for(int i=1;i<=n;i++)
		{ 
			dp[i][k]=max(dp[i][k],dp[i][k+1]); 
			for(int j=0;j<a[i].size();j++)
			{ 
				v=a[i][j]; 
				dp[i][k]=max(dp[i][k],dp[v][k+1]); 
			} 
		} 
	for(int i=1;i<=n;i++) 
		printf("%d\n",dp[i][0].second); 
	return 0;
} 


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

int main(){
  int n,k,i;
  cin >> n >> k;
  vector<int> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(i=k;i<n;i++){
    if(a.at(i-k)<a.at(i)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4048
n,x = map(int,input().split())
arr = list(map(int,input().split()))
total = 0
for ix,a in enumerate(arr):
    if a > x:
        total+=a-x
        arr[ix]=x
for i in range(len(arr)-1):
    if arr[i]+arr[i+1]>x:
        total+=arr[i]+arr[i+1]-x
        arr[i+1]-=arr[i]+arr[i+1]-x
print(total)


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=998244353;

int main(){
    int n,x,t;cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<endl;
}

Measured memory_bytes: 3584
if __name__ == "__main__":
    n, k = map(int, input().split())
    n += 1
    sum_ = 0
    sums = [0]

    for i in range(1, n):
        sums.append(sums[-1] + i)

    for i in range(k, n + 1):
        if i == n:
            sum_ += 1
            continue
        up = (sums[-1] - sums[-i - 1])
        low = sums[i - 1]
        tmp = up - low + 1
        sum_ += tmp

    print(sum_ % (10 ** 9 + 7))


Measured memory_bytes: 79476
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[100005],pa[100005],pb[100005];
void solve() {
	int n,k;
	cin>>n>>k;
	fr(i,1,n) {
		cin>>a[i];
		pa[i]=pa[i-1];
		if(a[i]>0)
			pa[i]+=a[i];
		pb[i]=pb[i-1]+a[i];
	}
	int ans=0;
	fr(i,k,n) {
		ans=max(ans,pa[n]-pa[i]+pb[i]-pb[i-k]+pa[i-k]);
		ans=max(ans,pa[n]-pa[i]+pa[i-k]);
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(20);
//	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if((a+b)%2==0){
		cout<<(a+b)/2;
	}else{
		cout<<"IMPOSSIBLE";
	}
	return 0;
}

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int full, n; cin >> full >> n;
        while (n--) {
                int x; cin >> x;
                full -= x;
        }
        cout << max(-1, full);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

const int MAX = 1000000;
const int MOD = 1000000007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll my_combination(ll n, ll k) {
    if(k < 0 || n < k) return 0;
    ll ret = 1;
    for(ll i = 1; i <= k; ++i) {
        ret = (ret * n) % MOD;        
        n--;
        ret = ret * modinv(i, MOD) % MOD;
    }
    return ret;
}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


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

    ll ans = 0;

    ll n, a, b;
    cin >> n >> a >> b;

    ll p = modpow(2, n);
    ll ca = my_combination(n, a);
    ll cb = my_combination(n, b);

    ans = p - ca - cb - 1;
    while(ans < 0) ans += MOD;

    cout << ans << endl;
}

Measured memory_bytes: 256
import math

N = int(input())

flag = True
s = math.floor(math.sqrt(N))
for i in range(s, 1, -1):
    if N % i == 0:
        ii = N // i
        print(i - 1 + ii - 1)
        flag = False
        break
if flag:
    print(N - 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
ll k;
cin >> k;
REP(i, k) cout << "ACL";
cout << '\n';
return 0;
}


Measured memory_bytes: 3648
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	long double a,b,c;
	cin>>a>>b>>c;
	a=sqrt(a),b=sqrt(b),c=sqrt(c);
	if(a+b+1e-14<c)cout<<"Yes";
	else cout<<"No";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>

using namespace std;
using LL = long long;

const int MAX = 2e5 + 9;
const LL INFL = 1e17;

struct SegmentTree
{
    LL a[MAX << 2], lz[MAX << 2];
    #define MID ((lo + hi) >> 1)
    #define ROOT0 (root<<1)
    #define ROOT1 (root<<1|1)

    SegmentTree() {}

	void upd (int root, int lo, int hi, int l, int r, LL x)
	{
        if (l > hi || lo > r) return;
        if (l <= lo && hi <= r) { a[root] += x, lz[root] += x; return; }
        lz[ROOT0] += a[root], lz[ROOT1] += a[root], a[ROOT0] += a[root], a[ROOT1] += a[root], a[root] = 0;
        upd (ROOT0, lo, MID, l, r, x);
        upd (ROOT1, MID + 1, hi, l, r, x);
		lz[root] = max(lz[ROOT0], lz[ROOT1]);
	}
	void upd (int l, int r, LL x) { upd (1, 0, MAX - 1, l, r, x); }

    LL get (int root, int lo, int hi, int l, int r)
    {
        if (l > hi || lo > r) return 0;
        if (l <= lo && hi <= r) return lz[root];
        return a[root] + max (get(ROOT0, lo, MID, l, r), get(ROOT1, MID + 1, hi, l, r));
    }
    LL get (int l, int r) { return get (1, 0, MAX - 1, l, r); }
} st;

struct Score
{
    int l, r; LL x;
    Score () {}
    Score (int l, int r, LL x): l(l), r(r), x(x) {}
    bool operator< (const Score &s) const
    {
        return r < s.r;
    }
} scores[MAX];

int N, M;

signed main()
{
//	st.upd (2, 4, 4);
//	st.upd (3, 4, 9);
//	cerr << st.get(2, 2) << endl;
//	return 0;

	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	for (int i = 0; i < M; ++i) cin >> scores[i].l >> scores[i].r >> scores[i].x;
    sort (scores, scores + M);
    int last = 0;
    for (int i = 0; i < M; ++i) {
        Score sc = scores[i];
        if (last + 1 <= sc.r) st.upd (last + 1, sc.r, st.get(0, last));
//        cerr << "S" << last + 1 << ' ' << sc.r << ' ' << st.get(0, last) << endl;
//        for (int j = 1; j <= 6; ++j) cerr << st.get(j, j) << ' '; cerr << endl << endl;
        st.upd (sc.l, sc.r, sc.x);
//        cerr << "S" << sc.l << ' ' << sc.r << ' ' << sc.x << endl;
//        for (int j = 1; j <= 6; ++j) cerr << st.get(j, j) << ' '; cerr << endl << endl;
        last = sc.r;

//        cerr << sc.l << ' ' << sc.r << ' ' << sc.x << endl;
//        for (int j = 1; j <= 6; ++j) cerr << st.get(j, j) << ' '; cerr << endl << endl;
    }
    cout << st.get(0, MAX - 1) << endl;
}


Measured memory_bytes: 14592
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


bool ok(map<char, int> M){
    if(M.size()!=2) return false;
    for(auto m:M){
        if(m.second!=2) return false;
    }
    return true;
}


int main() {
    string S; cin >> S;
    map<char, int> M;
    for(int i=0; i<(int)S.size(); i++){
        M[S[i]]++;
    }
    
    if(ok(M)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define inf 1e10
ll a[200001][2];
int n;
ll GetManhattan(int n, int dem)
{
    ll ans = 0, Min, Max;
    int i, j, k;
    for (i = 0; i < (1 << (dem)); i++) {    //用二进制形式遍历所有可能的运算情况
        Min = inf, Max = -inf;
        for (j = 0; j < n; j++) {    //遍历每一个点
            double sum = 0;
            for (k = 0; k <2; k++) {    //因为是五维的，所以有4个运算符
                //提取当前运算符
                int t = i & 1 << k;    //1为+，0为-
                if (t) sum +=a[j][k];
                else sum -= a[j][k];
            }
            if (sum > Max) Max = sum;
            if (sum < Min) Min = sum;
        }
        if (Max - Min > ans)
            ans = Max - Min;
    }
    return ans;
}
int main() {
    scanf("%d", &n);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 2; j++) scanf("%lld", &a[i][j]);
        ll ans = GetManhattan( n, 2);
        printf("%lld\n", ans);
    return 0;
}

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

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
typedef vector<int> vi;
inline int in() { int x; cin >> x; return x; }
int MOD = 1000000007;
struct mint {
  int x;
  mint (int x = 0) : x(x % MOD){}
  mint& operator+=(const mint a) { (x+=a.x) %= MOD; return *this; }
  mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
};

void solve() {
  int n = in();
  mint m = 0;
  vi v(n); for (auto &i : v) i = in();
  FOR(i,0,60) {
    int odd = 0, even = 0;
    for (auto j : v) (((j>>i)&1) ? odd : even)++;
    mint k = (int)1 << i;
    k *= odd * even;
    m += k;
  }
  cout << m.x << endl;
}

#undef int
int main() {
  solve();
  return 0;
}


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

#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++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL dp[3001];

void solve(long long N, long long T, std::vector<long long> A, std::vector<long long> B){
    vector<pair<LL, LL> > sortAB;
    REP(i, N) sortAB.PB(MP(A[i], B[i]));
    sort(ALL(sortAB));
    
    REP(i, T+1) dp[i] = -1;
    dp[0] = 0;

    REP(i, N) {
        RREP(j, T-1) {
            if(dp[j] == -1) continue;
            int idx = min(j+sortAB[i].first, T);
            dp[idx] = max(dp[idx], dp[j] + sortAB[i].second);
        }
    }

    LL ans = 0;
    REP(i, T+1) ans = max(ans, dp[i]);
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, T, std::move(A), std::move(B));
    return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

int n;
const int nax = 22;
int a[nax][nax];
int dp[nax][1 << (nax)];
void add(int& a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}

int solve(int i, int bm) {
    if(dp[i][bm] >= 0) return dp[i][bm];
    if(i == n && bm == 0) {
        return dp[i][bm] = 1;
    } else {
        int cnt = 0;
        for(int j = 0; j < n; j++) {
            if((bm & (1 << j)) && a[i][j]) {
                add(cnt, solve(i + 1, bm ^ (1 << j)));
            }
        }
        return dp[i][bm] = cnt;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    rep(i,0,n) rep(j,0,n) cin >> a[i][j];
    memset(dp,-1,sizeof(dp));
    cout << solve(0,(1 << (n)) - 1) << endl;
    return 0;
}


Measured memory_bytes: 360832
#include<stdio.h>

int main(){
  int n; scanf("%d",&n);
  int fst[2]={0,0},scd[2]={0,0};
  for(int i=0; i<n; i++){
    int t; scanf("%d",&t);
    if(t>fst[1]){
      scd[1]=fst[1];
      scd[0]=fst[0];
      fst[1]=t;
      fst[0]=i;
    }
    else if(t>scd[1]){
      scd[1]=t;
      scd[0]=i;
    }
  }
  for(int i=0; i<n; i++){
    if(fst[0]==i) printf("%d\n",scd[1]);
    else printf("%d\n",fst[1]);
  }
  return 0;
}

Measured memory_bytes: 1536