akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t>
vi toposort(vvc<t> g){
	int n=g.size();
	vi a(n);
	rep(i,n)for(auto e:g[i])
		a[e]++;
	queue<int> q;
	rep(i,n)if(a[i]==0)
		q.push(i);
	vi res;
	rep(i,n){
		if(q.empty())return {};
		int v=q.front();q.pop();
		res.pb(v);
		for(auto e:g[v])
			if(--a[e]==0)
				q.push(e);
	}
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	
	int n,m;cin>>n>>m;
	vvc<int> g(n);
	rep(i,m){
		int s,t;cin>>s>>t;
		g[s].pb(t);
	}
	
	vi idx=toposort(g);
	for(auto i:idx)
		cout<<i<<"\n";
}



Measured memory_bytes: 4612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n;
    cin >> n;
    SegmentTree<int> seg(n, [](int a, int b){return __gcd(a, b);}, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        seg.update(i, a);
    }
    int res = 0;
    for(int i = 0; i < n; ++i){
        chmax(res, __gcd(seg.query(0, i), seg.query(i+1, n)));
    }
    cout << res << endl;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {

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

        int N = new Integer(scanner.nextLine());
        String[] temp = scanner.nextLine().split(" ");
        int A = new Integer(temp[0]);
        int B = new Integer(temp[1]);
        List<Integer> P = new ArrayList<>();
        temp = scanner.nextLine().split(" ");
        for (int i = 0; i < N; i++) {
            P.add(new Integer(temp[i]));
        }

        Collections.sort(P);

        int count = 0;
        while (true) {
            if (P.size() < 3 || P.get(0) > A || P.get(P.size()-1) < B+1) {
                break;
            }

            P.remove(0);
            int index = -1;
            for (int i = 0; i < P.size(); i++) {
                int p = P.get(i);
                if (A+1 <= p && p <= B) {
                    index = i;
                    break;
                }
            }
            if (index == -1) {
                break;
            }
            P.remove(index);
            index = -1;
            for (int i = 0; i < P.size(); i++) {
                int p = P.get(i);
                if (B+1 <= p) {
                    index = i;
                    break;
                }
            }
            if (index == -1) {
                break;
            }
            P.remove(index);
            count++;
        }

        System.out.println(count);
    }

}


Measured memory_bytes: 21972
N = int(input())
S = input()

result = 0
for i in range(0, 1000):
    number = ''.join(['00', str(i)])[-3:]
    number_i = 0
    for s in S:
        if number[number_i] == s:
            number_i += 1
            if number_i == 3:
                result += 1
                break

print(result)


Measured memory_bytes: 73464
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

vector<int> tovec(ll x, int N){
    vector<int> vec;
    rep(i, N){
        if(x % 2 == 0) vec.push_back(0);
        else vec.push_back(1);
        x /= 2;
    }
    return vec;
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    string L, R;
    rep(i, N){
        L += S[i];
        R += S[2*N-1-i];
    }
    ll e[N+1];
    e[0] = 1;
    rep(i, N) e[i+1] = e[i]*2;
    map<pair<string, string>, ll> lmp, rmp;
    rep(i, e[N]){
        vector<int> vec = tovec(i, N);
        string l1, l2, r1, r2;
        rep(i, N){
            if(vec[i] == 0){
                l1 += L[i];
                r1 += R[i];
            }
            else{
                l2 += L[i];
                r2 += R[i];
            }
        }
        pair<string, string> p1 = make_pair(l1, l2), p2 = make_pair(r1, r2);
        if(lmp.count(p1)) lmp[p1]++;
        else lmp[p1] = 1;
        if(rmp.count(p2)) rmp[p2]++;
        else rmp[p2] = 1;
    }
    ll ans = 0;
    map<pair<string, string>, ll>::iterator ite;;
    ite = lmp.begin();
    while(ite != lmp.end()){
        if(rmp.count(ite->first)){
            ans += ite->second * rmp[ite->first];
        }
        ite++;
    }
    cout << ans << endl;
}

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

n = input()
p = []
for i in range(n):
    p.append(input())

# 最高値を調べる
maxVal = 0
maxID = 0
for i in range(n):
    if p[i] >= maxVal:
        maxID = i
        maxVal = p[i]

# 合計金額の計算
sum = 0
for i in range(n):
    if i == maxID:
        p[i] /= 2

    sum += p[i]

print sum


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    int n, m;
    cin >> n >> m;
    vector<vector<int>> conect;
    REP(i, m) {
        int k;
        cin >> k;
        vector<int> s(k);
        REP(i, k) {
            int a;
            cin >> a;
            s[i] = a - 1;
        }
        conect.push_back(s);
    }
    vector<int> p(m);
    REP(i, m) { cin >> p[i]; }
    int res = 0;
    for (int bit = 0; bit < (1 << n); ++bit) {
        bool ok = true;
        REP(i, m) {
            int con = 0;
            for (const auto& v : conect[i]) {
                if (bit & (1 << v)) ++con;
            }
            if (con % 2 != p[i]) ok = false;
        }
        if (ok) ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

string solve(string& s1, string& s2, string& s3){
    string s{s1[0], s2[0], s3[0]};
    transform(begin(s), end(s), begin(s), ::toupper);
    return s;
}


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

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << solve(s1, s2, s3) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll fact[100005];
void factorial()
{
    fact[0]=1;
    REP(i,1,100002)
    {
        fact[i]=mymod(i*fact[i-1], num);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t,u;
	ll a,b; 
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s.compare(u)==0)
	{
		a--;
	}
	else
	{
		b--;
	}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(" ");
            var a = long.Parse(x[0]);
            var b = long.Parse(x[1]);
            var c = long.Parse(x[2]);
            var d = long.Parse(x[3]);
            while(true)
            {
                c = c - b;
                if (c <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                a = a - d;
                if (a <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 27480
import java.math.*;
import java.util.*;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			Set<Integer> Aset = new HashSet<Integer>();
			
			for(int i=0;i<N;i++) {
				Aset.add(sc.nextInt());
			}
			
			int L = Aset.size();
			
			if(L==N) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}

	}

Measured memory_bytes: 100812
#include<stdio.h>
#include<string.h>

int main(){
    char s[4];
    scanf("%s", s);
    if(strcmp(s,"SUN") == 0){
        printf("7");
    }
    if(strcmp(s,"MON") == 0){
        printf("6");
    }
    if(strcmp(s,"TUE") == 0){
        printf("5");
    }
    if(strcmp(s,"WED") == 0){
        printf("4");
    }
    if(strcmp(s,"THU") == 0){
        printf("3");
    }
    if(strcmp(s,"FRI") == 0){
        printf("2");
    }
    if(strcmp(s,"SAT") == 0){
        printf("1");
    }

    return 0;
}

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

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	int a = 0;
	for (int i = l; i <= r; ++i) {
		if (i % d == 0) {
			++a;
		}
	}
	cout << a << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
using namespace std;

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

typedef pair<int, int> pint;
struct Prog {
  int s, t, c;
};
bool operator < (const Prog &a, const Prog &b) {
  if(a.s < b.s) return true;
  if(a.s > b.s) return false;
  if(a.t < b.t) return true;
  if(a.t > b.t) return false;
  return a.c < b.c;
}

bool sim(const vector<Prog> &data, int N) {
  vector<int> canuse(N); REP(i,N) canuse[i] = i;
  priority_queue<pint, vector<pint>, greater<pint> > q;
  REP(i, data.size()) {
    q.push(make_pair(data[i].s, data[i].t));
  }
  while(! q.empty()) {
    pint d = q.top(); q.pop();
    if(d.second > 0) { // start                                                     
      if(canuse.empty()) return false; // FAIL....                                  
      int c = canuse.back(); canuse.pop_back();
      q.push(make_pair(d.second, -c));
    } else {
      canuse.push_back(-(d.second));
    }
  }
  return true;
}

int main() {
  int N, C; cin>>N>>C;
  vector<Prog> data(N);
  REP(i,N) {
    cin>>data[i].s>>data[i].t>>data[i].c;
    data[i].s *= 2;     data[i].s -= 1;
    data[i].t *= 2;
  }
  sort(data.begin(), data.end());
  int low = 0, high = C;
  while(low + 1 < high) {
    int mid = (low + high) / 2;
    bool ans = sim(data, mid);
    if(ans) high = mid;
    else low = mid;
  }
  cout << high << endl;
  return 0;
}



Measured memory_bytes: 3280
n, w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]

def knapsack(n,w,wv):
    inf = float('inf')
    dp = [[-inf for _ in range(w+1)] for _ in range(n+1)]
    for i in range(w+1): dp[0][i] = 0

    for i in range(n):
        for w in range(w+1):
            if wv[i][0]<=w:
                dp[i+1][w] = max(dp[i][w-wv[i][0]]+wv[i][1],dp[i][w])
            else:
                dp[i+1][w] = dp[i][w]
    return dp[n][w]

print(knapsack(n,w,wv))

Measured memory_bytes: 310068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const double inf = 1e9;
const int MAX_N = 500;

int main() {
    int n; cin >> n;
    if (n&1) cout << n*2 << endl;
    else cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
int a[100009];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>1&&i==1)a[i]--;
        else{
            if(a[i]<a[i-1]){
                flag=true;break;
            }
            else if(a[i]>a[i-1])a[i]--;
        }
    }
    if(flag)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

void shortestPath(const vector<vector<Edge> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int m = 0;
        map<int, int> index;
        vector<int> num;

        vector<vector<Edge> > edges;
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if(index.find(a) != index.end())
                a = index[a];
            else{
                index.insert(make_pair(a, m));
                num.push_back(a);
                a = m;
                ++ m;
                edges.resize(m);
            }
            if(index.find(b) != index.end())
                b = index[b];
            else{
                index.insert(make_pair(b, m));
                num.push_back(b);
                b = m;
                ++ m;
                edges.resize(m);
            }

            edges[a].push_back(Edge(b, c));
            edges[b].push_back(Edge(a, c));
        }

        vector<vector<int> > dist;
        shortestPath(edges, dist);

        int k;
        int sum = INT_MAX;
        for(int i=0; i<m; ++i){
            int tmp = accumulate(dist[i].begin(), dist[i].end(), 0);
            if(tmp < sum){
                sum = tmp;
                k = i;
            }
        }
        cout << num[k] << ' ' << sum << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
using Graph = vector<vector<int>>;

int main() {
	double n, a[100], sum = 0;
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) sum += 1 / a[i];
	cout << 1 / sum << endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        Map<Integer, List<Integer>> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            if (map.containsKey(b[i])) {
                List<Integer> list = map.get(b[i]);
                list.add(a[i]);
                map.put(b[i], list);
            } else {
                List<Integer> list = new ArrayList<>();
                list.add(a[i]);
                map.put(b[i], list);
            }
        }

        long sum = 0;
        for (Map.Entry<Integer, List<Integer>> e : map.entrySet()) {
            List<Integer> list = e.getValue();
            for (int i = 0; i < list.size(); i++) {
                sum += list.get(i);
            }
            if (sum > e.getKey()) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");


    }

}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

class DisjointSet{
public:
	vector<int> rank, par;

	DisjointSet(){}
	DisjointSet(int size){
		rank.resize(size, 0);
		par.resize(size, 0);
		for(int i=0; i<size; i++){
			par[i]=i;
			rank[i]=0;
		}
	}

	int find(int x){
		if(par[x]==x){
			return x;
		}else{
			par[x]=find(par[x]);
			return par[x];
		}
	}

	void unite(int x, int y){
		x=find(x), y=find(y);
		if(x==y) return;

		if(rank[x]<rank[y]){
			par[x]=y;
		}else{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x)==find(y);
	}
};

class edge{
public:
	int source, target;
	ll cost;

	edge(int source=0, int target=0, ll cost=0):
	source(source), target(target), cost(cost){}

	bool operator<(const edge &e)const{
		return cost<e.cost;
	}
};

int n;
vector<edge> e;

ll kruskal(){
	sort(e.begin(), e.end());
	DisjointSet ds(n);

	ll sum=0;
	for(int i=0; i<e.size(); i++){
		if(!ds.same(e[i].source, e[i].target)){
			ds.unite(e[i].source, e[i].target);
			sum+=e[i].cost;
		}
	}
	return sum;
}

int main(){
	cin >> n;

	vector<pair<ll, int>> vx, vy;
	for(int i=0; i<n; i++){
		ll a, b;
		cin >> a >> b;
		vx.push_back(make_pair(a, i));
		vy.push_back(make_pair(b, i));
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	for(int i=1; i<vx.size(); i++){
		pair<ll, int> sv=vx[i-1], tv=vx[i];
		e.push_back(edge(sv.second, tv.second, tv.first-sv.first));
	}
	for(int i=1; i<vy.size(); i++){
		pair<ll, int> sv=vy[i-1], tv=vy[i];
		e.push_back(edge(sv.second, tv.second, tv.first-sv.first));
	}

	cout << kruskal() << endl;
	return 0;
}

Measured memory_bytes: 9572
#include<iostream>
using namespace std;
int main()
{
    int i, n, j, A[100] = {0};
    cin >> n;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        A[i*j]=1;
    }
    if(A[n] == 1)
    cout << "Yes";
    else
    {
        cout << "No";
    }
    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static int parents[200001];
    static vector<int> edges[200001];
    cin >> n >> m;
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }

    queue<pair<int,int>> q;
    parents[1] = 1;
    q.emplace(1, 1);
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        for(int to: edges[p.first]){
            if(to == p.second) continue;
            if(parents[to] == 0){
                parents[to] = p.first;
                q.emplace(to, p.first);
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=2;i<=n;++i) cout << parents[i] << endl;
    
    return 0;
}

Measured memory_bytes: 13032
#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
typedef long long d;
int main(){
	string s;
	d k;
	cin>>s>>k;
	for(d i=0;i<k;i++){
		if(s[i]!='1'){
			cout<<s[i];
			return 0;
		}
	}
	cout<<1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string SA, SB, SC;
    cin >> SA >> SB >> SC;

    char p = SA[0];
    int x_A = 0, x_B = -1, x_C = -1;
    while (x_A < (int)SA.length() && x_B < (int)SB.length() && x_C < (int)SC.length())
    {
        if (p == 'a')
        {
            if (x_A == (int)SA.length() - 1)
            {
                cout << "A" << endl;
                break;
            }
            x_A++;
            p = SA[x_A];
        }
        else if (p == 'b')
        {
            if (x_B == (int)SB.length() - 1)
            {
                cout << "B" << endl;
                break;
            }
            x_B++;
            p = SB[x_B];
        }
        else
        {
            if (x_C == (int)SC.length() - 1)
            {
                cout << "C" << endl;
                break;
            }
            x_C++;
            p = SC[x_C];
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<PAIR> a;
	REP(i, m) {
		int x, y;
		cin >> x >> y;
		a.push_back({ x,y });
	}

	sort(ALL(a), [](const PAIR& a, const PAIR& b) {
		return a.second < b.second;
	});

	int count = 0;
	int e = 0;
	REPC(v, a) {
		if (v.first >= e) {
			++count;
			e = v.second;
		}
	}
	cout << count << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		//int k = sc.nextInt();

		int[] array = new int[3];
		array[0]=n;
		array[1]=m;
		//array[2]=k;

		long count=0;
		Arrays.sort(array);

		if(n<m) {
			System.out.println(0);
		}else {
			System.out.println(10);
		}

		//System.out.println(array[0]+array[1]);
	}
}




Measured memory_bytes: 23892
n = int(input())
p = list(map(int, input().split(" ")))

c = 0
for i in range(1, len(p)-1):
  #print(p[i-1], p[i] ,p[i+1])
  if (p[i] > p[i-1] and p[i] < p[i+1]) or (p[i] < p[i-1] and p[i] > p[i+1]):
    c += 1
print(c)

Measured memory_bytes: 3060
import numpy as np

def solve_a():
    #
    N = int(input())

    # 
    list_S = []
    list_T = []

    for i in range(N):
        s, t = input().split()
        list_S.append(s)
        list_T.append(int(t))
    
    sentense = input()

    idx = list_S.index(sentense)

    sum_time = 0
    for i in range(idx + 1, N):
        sum_time = sum_time + list_T[i]

    print(sum_time)

def main():
    solve_a()

if __name__ == "__main__":
    main()

Measured memory_bytes: 12492
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a;
bool b;
signed main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2)b=true;
	}
	if(b)cout<<"first"<<endl;
	else cout<<"second"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (b - a == c - b){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23252
/*
    author: blue_matrix
*/
#include <bits/stdc++.h>
using namespace std;

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#define ll long long
void dfs(vector<string> &v,vector<vector<bool>> &vis,ll i,ll j,ll n,ll m)
{
    vis[i][j]=true;
    if(i>n || i<1 || j>m || j<1)
        return ;
    
    // cout<<" ("<<i<<" "<<j<<") ";
    for(ll k=-1;k<=1;k++)
    {
        for(ll p=-1;p<=1;p++)
        {
            if(p==0 || k==0)
            {
                if(vis[i+k][j+p]==false and v[i+k][j+p]=='.' )
                    dfs(v,vis,i+k,j+p,n,m);
            }
        }
    }
    return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<string> v={"pon","pon","hon","bon","hon","hon","pon" ,"hon","pon" ,"hon"};
    string s;
    cin>>s;
    cout<<v[s[s.size()-1]-'0'];
    return 0;
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int cookie = scan.nextInt();
		int number = scan.nextInt();
		int rest = 0;

		if (number == 1) {
			rest = 0;
		} else if (cookie % number == 0) {
			rest = 0;
		} else {
			rest = 1;
		}
		System.out.println(rest);
	}
}

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


int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	std::map<int, int> map;
	std::vector<int> vec;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		map[a]++;
	}
	for (auto p : map) {
		vec.push_back(p.second);
	}
	std::sort(vec.begin(), vec.end());
	int ans = 0;
	n = map.size();
	for (int i = 0; i < n - k; i++) {
		ans += vec[i];
	}
	printf("%d", ans);
}

Measured memory_bytes: 10748
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   

    ll n,k;
    cin >> n >> k;
    cout << min(n%k, k-(n%k)) << endl;

}

Measured memory_bytes: 256
///*
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {

	string input;
	string difference[8] = { "0" };
	int dif[8] = { 0 };
	int sitigosan = 753;
	
	cin >> input;
	for (unsigned int i = 0; i < input.length() - 2; i++) {
		difference[i] = input.substr(i, 3);

		dif[i] = (difference[i][0] - '0') * 100 
			+ (difference[i][1] - '0') * 10
			+ (difference[i][2] - '0');
		
		dif[i] -= 753;
		if (dif[i] < 0)dif[i] *= -1;
	}

	///*debug
	//for (int i = 0; i < input.length() - 2; i++) {
		//cout << difference[i];
		//cout << " " << dif[i] << endl;
	//}
	//*/

	sort(dif, dif + input.length() - 2);

	cout << dif[0];

	return 0;
}
//*/

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

typedef long long ll;

int main(){

    int n;
    cin>>n;
    set<string>S;
    string s = "MARCH";
    vector<ll>vec(5, 0);
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        for(int j=0;j<5;j++){
            if(str[0]==s[j]){
                vec[j]++;
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans += vec[i]*vec[j]*vec[k];
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

int comp(const void* a, const void* b);

int main() {
	int t,n, k,i, j;
	int *x,*ans,*bou;
	scanf("%d", &t);
	ans = (int*)malloc(t * sizeof(int));
	for (i = 0; i < t; i++) {
		ans[i] = 0;
		scanf("%d%d", &n, &k);
		x = (int*)malloc(n * sizeof(int));
		bou = (int*)malloc((n - 1) * sizeof(int));
		for(j=0;j<n;j++)scanf("%d", &x[j]);
		if (k >= n)ans[i] = 0;
		else {
			for (j = 0; j < n - 1; j++) {
				bou[j] = x[j + 1] - x[j];
			}
			qsort(bou, n - 1, sizeof(int), comp);
			for (j = k-1 ; j < n - 1; j++)ans[i] += bou[j];
		}
	}
	for (i = 0; i < t; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

int comp(const void* a, const void* b) {
	return *((int*)b) - *((int*)a);
}

Measured memory_bytes: 5936
one, two, three, four, five, six = (int(x) for x in input().split())
move = input()
top = one
bottom = six
north = five
east = three
west = four
south = two

for i in range(len(move)):
    if move[i] == "N":
        top, north, bottom, south = south, top, north, bottom
    elif move[i] == "E":
        top, east, bottom, west = west, top, east, bottom
    elif move[i] == "W":
        top, east, bottom, west = east, bottom, west, top
    elif move[i] == "S":
        top, north, bottom, south = north, bottom, south, top

print(top)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;


int n;
int a[200011];


int dp[200011 * 5][2];

int f;
int l,r;

int query(int idx,int b,int e){
    if(b > r || l > e)return -1;
    if(b>=l && r>=e)return dp[idx][f];
    
    int mid = (b+e)/2;
    
    int r1 = query(idx*2 , b,mid);
    int r2 = query(idx*2+1,mid+1,e);
    
    if(r1 == -1)return r2;
    else if(r2 == -1)return r1;
    else if(a[r1] > a[r2])return r2;
    else return r1;
}

void build(int idx,int b,int e){
    if(b == e){
        if(f % 2 == b % 2){
            dp[idx][f] = b;
        }else
            dp[idx][f] = -1;
        return ;
    }
    int mid = (b+e)/2;
    
    build(idx*2,b,mid);
    build(idx*2+1,mid+1,e);
    
    int r1 = dp[idx*2][f];
    int r2 = dp[idx*2+1][f];
    
    int res ;
    if(r1 == -1)res = r2;
    else if(r2 == -1)res = r1;
    else if(a[r1] > a[r2])res = r2;
    else res = r1;
    dp[idx][f] = res;
}

struct seg{
    int l,r;
    int v;
    int sec;
};

struct comp{
    bool operator()(seg x,seg y){
        return a[x.v] > a[y.v];
    }
};

seg newSeg(int ll,int rr){
    f = ll%2;
    l = ll;
    r = rr;
    int v = query(1,0,n-1);
    f = rr%2;
    l = v;
    int sec = query(1,0,n-1);
    
    seg res ;
    res.l = ll;
    res.r = rr;
    res.v = v;
    res.sec =  sec;
    return res;
}

int main(){
   //ios::sync_with_stdio(0);
    //freopen("in.in","r",stdin);
    //freopen("out_1.out","w",stdout);
    
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    f = 0;
    build(1,0,n-1);
    f = 1;
    build(1,0,n-1);
    
    priority_queue<seg , vector<seg>,comp > q;
    
    seg s = newSeg(0,n-1);
    q.push(s);
    
    while(q.size()){
        s = q.top();
        q.pop();
        
        printf("%d %d ",a[s.v] , a[s.sec]);
        
        if(s.v != s.l){
            q.push( newSeg(s.l,s.v - 1) );
        }
        if(s.r != s.sec){
            q.push( newSeg(s.sec + 1,s.r) );
        }
        if(s.v != s.sec - 1){
            q.push( newSeg(s.v + 1 , s.sec - 1) );
        }
    }
    
}

Measured memory_bytes: 10868
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

dp = [[0 for _ in range(W)] for _ in range(H)]

SIZE = 20000

D = abs(A[0][0] - B[0][0])
dp[0][0] = 1 << SIZE - D | 1 << SIZE + D
#print("dp:", dp)

for i in range(H):
  for j in range(W):
    D = abs(A[i][j] - B[i][j])
    dp[i][j] |= dp[i - 1][j] << D | dp[i - 1][j] >> D
    dp[i][j] |= dp[i][j - 1] << D | dp[i][j - 1] >> D

#for i in range(H):
#  a = list(map(lambda x: bin(x)[2::], dp[i]))
#  print(a)

for i in range(SIZE):
  if (dp[-1][-1] >> (SIZE + i)) & 1:
    print(i)
    exit()

Measured memory_bytes: 63708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct line {
    ll a, b, f;
};
using pllll = pair<ll, ll>;
using pl6 = pair<ll, pair<ll, ll>>;
struct edge {
    ll dstb, dstc, cost;
};
int main() {
    
    ll c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {

        s--; d--;

        vector<line> l(m, line{0, 0, 0});
        for (ll i = 0; i < m; i++) {
            cin >> l[i].a >> l[i].b >> l[i].f;
            l[i].a--; l[i].b--;
            if (l[i].a > l[i].b) swap(l[i].a, l[i].b);
        }

        sort(l.begin(), l.end(), [](line &i, line &j) -> bool {
                 if (i.a != j.a) return i.a < j.a;
            else if (i.b != j.b) return i.b < j.b;
            else return i.f < j.f;
        });

        // 被った路線はなかったことに
        for (ll i = m; --i; ) {
            if (l[i].a == l[i-1].a && l[i].b == l[i-1].b) {
                l.erase(l.begin() + i);
            }
        }
        m = l.size();

        
        // 無向グラフを構築
        vector<vector<vector<edge>>> g(n, vector<vector<edge>>(c+1));
        for (ll i = m; i--; ) {
            ll a = l[i].a;
            ll b = l[i].b;
            ll f = l[i].f;
            for (ll c0 = c; c0 >= 0; c0--) {
                g[a][c0].push_back(edge{b, c0, f});
                g[b][c0].push_back(edge{a, c0, f});
                if (c0 > 0) {
                    g[a][c0].push_back(edge{b, c0-1, f/2});
                    g[b][c0].push_back(edge{a, c0-1, f/2});
                }
            }
        }

        // 拡張Dijkstra
        vector<vector<ll>> dp(n, vector<ll>(c+1, 0x7FFFFFFFLL));
        vector<vector<bool>> determined(n, vector<bool>(c+1, false));
        priority_queue<pl6, vector<pl6>, greater<pl6>> q;
        q.push(pl6(0, pllll(s, c)));
        dp[s][c] = 0;
        while (!q.empty()) {
            pl6 cv = q.top(); q.pop();
            pllll v = cv.second;
            ll vf = dp[v.first][v.second];
            if (determined[v.first][v.second]) continue;
            determined[v.first][v.second] = true;
            for (edge &ed : g[v.first][v.second]) {
                if (determined[ed.dstb][ed.dstc]) continue;
                if (vf + ed.cost < dp[ed.dstb][ed.dstc]) {
                    q.push(pl6(vf + ed.cost, pllll(ed.dstb, ed.dstc)));
                    dp[ed.dstb][ed.dstc] = vf + ed.cost;
                }
            }
        }

        ll ans = 0x7FFFFFFFLL;
        for (ll i = 0; i <= c; i++) {
            ans = min(ans, dp[d][i]);
        }
        cout << ans << endl;

    }

}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		double in[110][110]={0},dp[110][110]={0};
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,n)dp[0][i]=1;
		rep(i,m-1)rep(j,n)rep(k,n)
			dp[i+1][k]=max(dp[i+1][k],dp[i][j]*in[j][k]);
		double out=0;
		rep(i,n)out=max(out,dp[m-1][i]);
		cout<<shosu(2)<<out<<endl;
	}
}

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

int main()
{
  long long n, result = 0;
  cin >> n;

  vector<long long> v(n, 0);

  for (int i = 0; i < v.size(); i++)
  {
    cin >> v[i];

    while (true)
    {
      if (v[i] % 2 != 0)
        break;

      v[i] /= 2; 
      result++;
    }
  }

  cout << result << endl;

}


Measured memory_bytes: 384
from collections import Counter
n, *A = map(int, open(0).read().split())
A.sort()
c, s = Counter(A), set()
M = max(A) + 1
ans = 0
for a in A:
    if a in s:
        continue
    ans += c[a] == 1
    for i in range(a, M, a):
        s.add(i)
print(ans)

Measured memory_bytes: 104604
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int diffab = (a >= b) ? a - b : b - a;
	int diffbc = (b >= c) ? b - c : c - b;
	int diffac = (a >= c) ? a - c : c - a;
	if(diffac <= d || (diffab <= d && diffbc <= d)) cout << "Yes";
	else cout << "No";
	cout << endl;
	return EXIT_SUCCESS;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n,m)= readLine()!!.split(" ").map{it.toLong()}
    (1L..Math.sqrt(m.toDouble()).toLong())
            .filter { m%it==0L }
            .map { listOf(it, m/it) }.flatten()
            .sorted()
            .last{ it*n<=m }
            .let { println(it) }

}

Measured memory_bytes: 38580
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(double)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){    
    int N;cin>>N;
    set<int>st;
    int cnt=0;
    REP(i,N){
        int a;
        cin>>a;
        if(a<3200){
            st.insert(a/400);
        }else{
            cnt++;
        }
    }
    cout<<max(SZ(st),1)<<" "<<SZ(st)+cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;

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

//--------------------



int main() {

  int n, d;
  cin >> n >> d;
  int x[n][d];
  rep(i, n) {
    rep(j, d) cin >> x[i][j];
  }

  int cnt = 0;
  for(int i=0; i<n; ++i) {
    for(int j=i+1; j<n; ++j) {
      int s = 0;
      for(int k=0; k<d; ++k) {
        int t = abs(x[i][k]-x[j][k]);
        s += t*t;
      }
      //整数か判定
      bool flag = false;
      for(int k=0; k<=s; ++k) {
        if(k*k==s) flag = true;
      }

      if(flag) ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    int curH = -1;
    int curMax = 0;
    while (N-- > 0) {
      int nextH = sc.nextInt();
      if (curH >= nextH) {
        ans++;
      } else {
        curMax = Math.max(curMax, ans);
        ans = 0;
      }
      curH = nextH;
    }
    curMax = Math.max(curMax, ans);
    System.out.println(curMax);
  }
}


Measured memory_bytes: 47448
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, M, X = map(int, input().split())
    C = [0] * N
    A = []
    for n in range(N):
        s = list(map(int, input().split()))
        C[n] = s[0]
        A.append(s[1:])
    
    res = INF
    for bit in range(2**N):
        tmp = 0
        P = [0] * M
        for n in range(N):
            if (bit >> n) & 1:
                tmp += C[n]
                for m in range(M):
                    P[m] += A[n][m]
        flg = True
        for m in range(M):
            if P[m] < X:
                flg = False
        if flg:
            res = min(res, tmp)

    if res == INF:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 73384
package main

import "fmt"

var N, A, B, C int
var ls []int

func main() {
	fmt.Scan(&N, &A, &B, &C)
	ls = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&ls[i])
	}
	fmt.Println(dfs(0, make([]int, N)))
}

func dfs(i int, prefix []int) int {
	if i == N {
		var ans, a, b, c int
		for j, v := range prefix {
			switch v {
			case 0:
				a += ls[j]
				ans += 10
			case 1:
				b += ls[j]
				ans += 10
			case 2:
				c += ls[j]
				ans += 10
			}
		}
		if a*b*c == 0 {
			return 3000
		}
		return ans + Abs(A-a) + Abs(B-b) + Abs(C-c) - 30
	}
	ans := 3000
	for j := 0; j < 4; j++ {
		prefix[i] = j
		ans = Min(ans, dfs(i+1, prefix))
	}
	return ans
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}


Measured memory_bytes: 1844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32e4,M=1e9+7;

vector<int>t[N];
bool u[N];
int s[N],n;
ll d[N],a[N],f[N];
ll qpow(ll a,ll x){
	ll ans=1;
	for(;x;x>>=1){
		if(x&1)ans=ans*a%M;
		a=a*a%M;
	}
	return ans;
}
ll C(int n,int m){
	return f[n]*qpow(f[m]*f[n-m]%M,M-2)%M;
}
int get_ss(int x){
	u[x]=s[x]=1;
	for(int y:t[x])if(!u[y])
		s[x]+=get_ss(y);
	u[x]=0;
	return s[x];
}
ll dfs(int x){
	u[x]=d[x]=1;
	int sx=s[x]-1;
	for(int y:t[x])if(!u[y]){
		d[x]=d[x]*C(sx,s[y])%M*dfs(y)%M;
		sx-=s[y];
	}
	u[x]=0;
	return d[x];
}
void get_ans(int x,ll z){
	u[x]=1;
	z=a[x]=d[x]*C(n-1,n-s[x])%M*z%M;
	for(int y:t[x])if(!u[y]){
		ll w=z*qpow(d[y]*C(n-1,s[y])%M,M-2)%M;
		get_ans(y,w);
	}
	u[x]=0;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	f[0]=1;
	for(int i=1,u,v;i<n;i++){
		f[i]=f[i-1]*i%M;
		cin>>u>>v;
		t[u].push_back(v);
		t[v].push_back(u);
	}
	get_ss(1);
	dfs(1);
	get_ans(1,1);
	for(int i=1;i<=n;i++)cout<<a[i]<<'\n';
	return 0;
}

Measured memory_bytes: 25332
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin >> N;
    vector<vector<int>> G(N + 1);
    vector<int> A(N + 1), H(N + 1), D(N + 1);
    for(int i = 2; i <= N; i += 1){
        cin >> A[i];
        D[A[i]] += 1;
    }
    queue<int> q;
    for(int i = 1; i <= N; i += 1) if(not D[i]) q.push(i);
    while(not q.empty()){
        int u = q.front();
        q.pop();
        sort(G[u].begin(), G[u].end(), greater<int>());
        for(int i = 0; i < (int)G[u].size(); i += 1)
            H[u] = max(G[u][i] + i + 1, H[u]);
        if(not --D[A[u]]) q.push(A[u]);
        G[A[u]].push_back(H[u]);
    }
    cout << H[1];
    return 0;
}

Measured memory_bytes: 6912