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

vector<int> edges[110000];
vector<int> wgt[110000];

int main(){
    int n;
    cin >> n;
    while(n % 2 == 0) n /= 2;
    while(n % 5 == 0) n /= 5;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    LL dist[n];
    LL vis[n];
    for(LL i = 0; i < n; i++){
        dist[i] = 1000000000770000;
        vis[i] = 0;
    }
    dist[1] = 1;
    set<pair<LL,LL> > cur;
    for(LL i = 0; i < n; i++){
        cur.insert(make_pair(dist[i], i));
    }

    for(int i = 0; i < n; i++){
        edges[i].push_back((i+1)%n);
        wgt[i].push_back(1);
        edges[i].push_back((i*10) % n);
        wgt[i].push_back(0);
    }

    while(!cur.empty()){
        pair<LL,LL> v = *cur.begin();
        cur.erase(cur.begin());
        LL a = v.second;
        vis[a] = 1;
        for(int i = 0; i < edges[a].size(); i++){
            LL b = edges[a][i];
            if(vis[b]) continue;
            if(wgt[a][i] + dist[a] < dist[b]){
                cur.erase(make_pair(dist[b], b));
                dist[b] = dist[a] + wgt[a][i];
                cur.insert(make_pair(dist[b], b));
            }
        }
    }
    cout << dist[0] << endl;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector <int> p(n), q(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    vector <vector<int>> pp;
    vector <vector<int>> qq;
    
    vector <int> p2=p;
    vector <int> q2=q;
    sort(p2.begin(), p2.end());
    sort(q2.begin(), q2.end());
    do{
        pp.push_back(p2);
    }while(next_permutation(p2.begin(), p2.end()));
    do{
        qq.push_back(q2);
    }while(next_permutation(q2.begin(), q2.end()));
    
    sort(pp.begin(), pp.end());
    sort(qq.begin(), qq.end());
    int a, b;
    for(int i=0;i<pp.size();i++){
        if(p==pp[i]){
            a=i+1;
            break;
        }
    }
    for(int i=0;i<qq.size();i++){
        if(q==qq[i]){
            b=i+1;
            break;
        }
    }
    cout<<abs(a-b)<<endl;
    return 0;
}

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

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  if (k==1) cout << 0 <<endl;
  else cout << n-k <<endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

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

        while(true){
            int n = scan.nextInt();
            int x = scan.nextInt();

            if(n == 0 && x == 0){
                break;
            }
            int num = 0;

            for(int i = 1; i < n; i++){
                for(int f = i+1; f < n ; f++){
                    for(int y = f+1; y <= n; y++){
                        if(i + f + y == x){
                           // System.out.println(i +" " + f + " " + y);
                            num++;
                        }
                    }
                }
            }
            
            System.out.println(num);
        }
    }
}



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

dic = {}
ans = 'Yes'
last = ''
for _ in range(N):
    s = input()
    if last == s[0] or last == '':
        last = s[-1]
        pass
    else:
        ans = 'No'
        break
    if dic.get(s, 0) == 0:
        dic[s] = 1
    else:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n-1);
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        v[i] = make_pair(a, b);
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    vector<int> c(n);
    for (auto &&i : c) scanf("%d", &i);
    sort(c.begin(),c.end());
    vector<int> ans(n);
    deque<int> Q;
    stack<int> s;
    int cnt = 0;
    vector<int> visited(n, 0), num(n);
    s.emplace(0);
    while(!s.empty()){
        int a = s.top(); s.pop();
        visited[a]++;
        num[a] = cnt++;
        Q.emplace_front(a);
        for (auto &&i : G[a]) {
            if(!visited[i]) s.emplace(i);
        }
    }
    cnt = 0;
    for (int i = 0; i < n; ++i) {
        ans[Q.front()] = c[cnt++];
        Q.pop_front();
    }
    ll a = 0;
    for (auto &&j : v) {
        a += min(ans[j.first], ans[j.second]);
    }
    cout << a << "\n";
    for (int i = 0; i < n; ++i) {
        if(i) cout << " ";
        cout << ans[i];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1152
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
//#define Hsize 100009
#define Hsize (1<<19)
#define MAXN 210001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    T* next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    return (x&(0x0003FFFF));
    if (x<0) x=-x;
    return (x%100007);
}

//add the current sumZ to the hash table
inline void addToHash(ll sumZ)
{
    int HsumZ;
    T *index, *beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=&hashBucket[hashIndex[HsumZ]]; (index->times>0); index=index->next)
        if (index->number==sumZ)
        {
            index->times++;
            return;
        }
    top++;
    hashIndex[HsumZ]=top;
    index=&hashBucket[top];
    index->number = sumZ;
    index->times = 1;
    index->next = beginP;
}

void init()
{
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 6016
#include<iostream>

int main() {

	int i,t,s1=0,s2=0;

	std::string c1,c2;
	
	std::cin >> t;

	for (i=0;i<t;i++) {

		std::cin >> c1 >> c2;

		if (c1 > c2) s1 += 3;
		else if (c1 < c2) s2 += 3;
		else {
			s1++;
			s2++;
		}
	}

	std::cout << s1 << " " << s2 << std::endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int w[110];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    sum += w[i];
  }

  int ans = 1e9;
  int left = 0;
  for (int i = 0; i < n - 1; i++) {
    left += w[i];
    int right = sum - left;
    if (ans >= abs(left - right)) {
      ans = abs(left - right);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int x, y, ans;
	ll K, num=0;

	cin >> x >> y;

	rep(i, x){
		if ((x * 4 >= y)&&(y>=x*2)){
			y = x * 4 - y;
			if (y % 2 == 0){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

template <typename T>
class SegmentTree{
  public:
    int n;
    T element;
    vector<T> dat;
    function<T(T,T)> operate;

    SegmentTree(){}
    SegmentTree(int n_,T element_,function<T(T,T)> operate_){
        element = element_;
        operate = operate_;
        n = 1;
        while(n < n_) n *= 2;
        dat = vector<T>(n*2,element);
    }

    void update(int k,T a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = operate(dat[k*2+1],dat[k*2+2]);
        }
    }

    T query(int a,int b,int k,int l,int r){
        if(r<=a || b<=l) return element;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a,b,k*2+1,l,(l+r)/2);
        T vr = query(a,b,k*2+2,(l+r)/2,r);
        return operate(vl,vr);
    }

    T query(int a,int b) { return query(a,b,0,0,n); }

    T get(int k){ return query(k,k+1); }
};



using P = pair<ll, ll>;
ll ll_max(ll a, ll b){
    return max(a,b);
}

int main(void){
    int n;
    cin >> n;
    vector<P> v(n);
    set<ll> rs = {(ll)-1e11};
    rep(i,n){
        ll x,l;
        cin >> x >> l;
        v[i] = {x-l, x+l}; // [x-l, x+l)
        rs.insert(x-l);
        rs.insert(x+l);
    }
    sort(all(v));
    map<ll, int> r2idx;
    for (auto x : rs){
        int sz = r2idx.size();
        r2idx[x] = sz;
    }
    SegmentTree<ll> st(r2idx.size(), 0, ll_max);
    ll res = 0;
    rep(i,n){
        ll cnt = st.query(0, r2idx[v[i].first]+1);
        ll r = r2idx[v[i].second];
        if (st.query(r, r+1) < cnt+1) {
            st.update(r, cnt+1);
            res = max(res, cnt+1);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 27776
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 300005
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define ff first
#define ss second

int n,a,b;

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	cin>>n>>a>>b;
	if (1ll*a*b<n){puts("-1"); return 0;}
	if (a+b-1>n){puts("-1"); return 0;}
	if (a>b){
		while (n-a>=b-1&&n>0){
			for (int i=n-a+1;i<=n;i++) printf("%d ",i);
			--b,n-=a;
		}
		if (n>0) for (int i=b;i<=n;i++) printf("%d ",i);
		while (--b>0) printf("%d ",b); puts("");
	}
	else{
		int pp=n;
		while (n-b>=a-1&&n>0){
			for (int i=n-b+1;i<=n;i++) printf("%d ",pp-i+1);
			--a,n-=b;
		}
		if (n>0) for (int i=a;i<=n;i++) printf("%d ",pp-i+1);
		while (--a>0) printf("%d ",pp-a+1); puts("");
	}
	return 0;
}


Measured memory_bytes: 2176
import Control.Applicative ((<$>))
import Control.Monad (unless, replicateM)
import Data.List (transpose)

main :: IO ()
main = do
    [n, k] <- map read . words <$> getLine
    unless (n == 0 && k == 0) $ do
        ss <- map read . words <$> getLine
        bs <- map (map read) . map words <$> replicateM n getLine
        let rs = map sum $ transpose bs
        putStrLn $ if all (>= 0) $ zipWith (-) ss rs then "Yes" else "No"
        main

Measured memory_bytes: 7564
n,k = map(int,input().split())

p = list(map(int,input().split()))

def exp(n):
    return n*0.5 + 0.5

ans = 0
for i in range(k):
    ans += p[i]
    tmp = ans

for i in range(n-k):
    tmp = tmp - p[i] + p[i+k]
    if tmp > ans:
        ans = tmp

print(ans*0.5 + k*0.5)

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

int main() {
    int x, y;
    cin >> x >> y;
    if (x < y) { swap(x, y); }
    while (y > 0) {
        int temp = x % y;
        x = y;
        y = temp;
    }
    cout << x << endl;
}



Measured memory_bytes: 3104
import java.io.*;
import java.util.HashSet;
import java.util.LinkedList;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		try{int n=Integer.parseInt(br.readLine());
		String[] str=new String[2];
		HashSet<Long> hs=new HashSet<Long>();		
		long hash;
		char c;
		
		for(int i=0;i<n;i++){
			str=br.readLine().split(" ");hash=0;
			for(int j=0;j<str[1].length();j++){
				c=str[1].charAt(j);
				switch(c){
				case 'A':hash=hash*10+1;break;
				case 'C':hash=hash*10+2;break;
				case 'G':hash=hash*10+3;break;
				case 'T':hash=hash*10+4;break;
				}
			}
			if(str[0].equals("insert")){
				hs.add(hash);
				
			}else if(str[0].equals("find")){
				System.out.println(hs.contains(hash)?"yes":"no");
				
			}
		}
		
		
		
		}catch(IOException e){}




	}


}

Measured memory_bytes: 301336
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int dp[100000+10][13];

int main(void) {
    string s;
    cin>>s;

    int n = s.size();

    dp[0][0] = 1;
    for(int i = 0;i < n;i++) {
        int c;
        if(s[i] == '?')
            c = -1;
        else
            c = s[i]-'0';

        for(int j = 0;j < 10;j++) {
            if(c != -1 && c != j)
                continue;
            for(int ki = 0;ki < 13;ki++) {
                dp[i+1][(10*ki + j) % 13] += dp[i][ki];
            }
        }

        for(int ki = 0;ki < 13;ki++)
            dp[i+1][ki] %= MOD;
    }

    cout<<dp[n][5]<<endl;

    return 0;
}





Measured memory_bytes: 10624
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

num = na()
num.sort()
print(int(0.5 * (num[0] * num[1])))

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

int main(void)
{
   int i,j,y;
   for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
        y=i*j;
        printf("%dx%d=%d\n",i,j,y);
    }
   }
    return 0;
}



Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b;
    cin >> a >> b;

    int c = a + b;
    bool ok = true;
    if(a % 3 && b % 3 && c % 3)
        ok = false;
    cout << (ok ? "Possible" : "Impossible") << endl;
}


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

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){
    ll total = 0;
    for (auto i=B.begin(); i!=B.end(); i++) total += *i;
    ll bp = M;
    ll ans = 0;
    for (ll ap = 0; ap <= N; ap++) {
        while ((total > K) && (bp > 0)) {
            bp--;
            total -= B[bp];
        }
        if (total > K) break;
        ans = max(ans, ap+bp);
        if (ap == N) break;
        total += A[ap];
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


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

const int INF = 1e9;

int main() {
  int N, S; cin >> N >> S;
  deque<int> deq;
  int ans = INF;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    deq.push_back(a);
    sum += a;
    while (sum >= S) {
      ans = min(ans, static_cast<int>(deq.size()));
      int b = deq.front();
      if (sum - b < S) break;
      deq.pop_front();
      sum -= b;
    }
  }
  cout << ( (ans == INF) ? 0 : ans ) << endl;
  return 0;
}



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

#define ll    long long
#define endl  "\n"
#define fast  ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main(){

    fast;
    double n,x,t;
    cin>>n>>x>>t;
    cout<<(int)(ceil(n/x)*t);
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	long int n, l;
	long int i, j;
	long int min_abs = 1000;
	long int min;
	long int sum = 0;
	
	scanf("%ld%ld", &n, &l);
	
	for(i = 1; i <= n; i++) {
		sum += l + i - 1;
		if(min_abs > labs(l + i - 1) ) {
			min_abs = labs(l + i - 1);
			min = l + i - 1;
		}
	}
	
	printf("%ld\n", sum - min);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int a,b;
	
	scanf("%d",&a);
	scanf("%d",&b);
	int i,c;
	if(b==100){
		c = a*1000+b;
	}else if(b >=10){
		c = a*100+b;
	}else {
		c = a*10+b;
	}
	
	for(i=1;i<=1000;i++){
		if(c == i*i){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	
	
	return 0;}

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

int main() {
	long long A, B, C;
	cin >> A >> B >> C;
	if (A == B && A != C) cout << "Yes" << endl;
	else if (B == C && B != A) cout << "Yes" << endl;
	else if (C == A && C != B) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	bool d[128] = { false };
	bool flag = true;
	string s;
	cin >> s;
	for (auto i : s) {
		if (!d[i]) {
			d[i] = true;
		}
		else {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
}

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

const ll INF = 1LL<<62;

int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> ps;
	vector<ll> ng;
	rep(i,n){
		ll x;
		cin >> x;
		if(x < 0) ng.push_back(x);
		if(x >= 0) ps.push_back(x);
	}
	sort(ng.rbegin(),ng.rend());
	ll ans = INF;
	rep(i,k+1){
		ll time = 0;
		int l = k - i;
		if(i > ps.size() || l > ng.size()) continue;
		if(i == 0){
			time += -ng[l-1];
		}else if(l == 0){
			time += ps[i-1];
		}else{
			time += 2*ps[i-1]-ng[l-1];
		}
		ans = min(ans, time);
	}
	rep(i, k+1){
		ll time = 0;
		int r = k - i;
		if(i > ng.size() || r > ps.size()) continue;
		if(i == 0){
			time += ps[r-1];
		}else if(r == 0){
			time += -ng[i-1];
		}else{
			time += -2*ng[i-1] + ps[r-1];
		}
		ans = min(ans, time);
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1656
#include <bits/stdc++.h>
 
using namespace std;
 
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;
 
 
int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("in.txt");
    //std::cin.rdbuf(in.rdbuf());
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S, T;
    cin >> S >> T;
    
    int max_match = 0;
    for (int i = 0; i <= S.length() - T.length(); i++) {
        int k = 0, j = 0;
        while (i + j < S.length() && j < T.length()) {
            if (S[i + j] == T[j]) {
                k++;
            }
            j++;
        }
        max_match = max(max_match, k);
        //cout << i << " " << max_match << endl;
    }
    
    cout << T.length() - max_match  << endl;
    
    
    return 0;
    
}


Measured memory_bytes: 3608
class UnionFind():
    """
    UnionFindTreeのクラス
    
    Attributes:
    n: int: ノード数
    parents: そのノードが属する木の根を格納, 根の場合は-1

    """
    def __init__(self, n):
        """ノード数nで初期化"""
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """ノードxが属するグループの根を返す"""
        if self.parents[x] < 0:
            return x
        else:
            #経路圧縮
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """xが属するグループとyが属するグループを併合"""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """xが属するグループの要素数を返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """x, yが同じグループに属するかどうかを返す"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """xが属するグループ内の要素をリストで返す"""
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """全ての根に対する要素をリストで返す"""
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """グループの総数を返す"""
        return len(self.roots())

    def all_group_members(self):
        """{root: [そのグループの要素リスト]}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """printデバッグ用. root: [要素リスト]をstrで返す"""
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def kruskal(edge_list: list, n_V: int):
    """
    クラスカル法
    edge_list: 各要素が(weight, node1, node2)のリスト
    n_V: ノード数
    sortがボトルネックとなりO(|E|log(|E|))
    """
    edge_list = sorted(edge_list) # 重み昇順に整列
    ret = 0
    uf = UnionFind(n_V) # UnionFind
    n_edges = 0
    for w, s, t in edge_list:
        if n_edges == n_V-1: #全域木になったら終了
            break
        if uf.same(s, t):
            #s, tが同じグループの場合,
            #構築するものが木ではなくなってしまう(閉路ができる)
            #のでcontinue
            continue
        
        uf.union(s, t) # s, tを併合
        ret += w
        n_edges += 1
    
    return ret

N = int(input())
x = []
y = []
for i in range(N):
    a, b = map(int, input().split())
    x.append((a, i))
    y.append((b, i))

edges = []
x.sort()
y.sort()
for i in range(N-1):
    id1 = x[i][1]
    id2 = x[i+1][1]
    cost = abs(x[i][0]-x[i+1][0])
    edges.append((cost, id1, id2))
for i in range(N-1):
    id1 = y[i][1]
    id2 = y[i+1][1]
    cost = abs(y[i][0]-y[i+1][0])
    edges.append((cost, id1, id2))

ret = kruskal(edges, N)
print(ret)

Measured memory_bytes: 124816
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int length = sc.nextInt();
		int count = 0;
		ArrayList<Integer> primeAr = new ArrayList<Integer>();
		
		for (int i = 0; i < length; i++) {
			int num = sc.nextInt();
			if (!primeAr.contains(num) && isPrime(num)) {
				count++;
				primeAr.add(num);
			}
		}
		System.out.println(count);
	}
	
	public static boolean isPrime(int i) {
		
		boolean prime = true;
		for (int j = 2; j <= Math.pow(i, 0.5); j++) {
			if (i % j == 0) {
				prime = false;
				break;
			}
		}
		return prime;
	}
}

Measured memory_bytes: 41692
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	set<int> s;

	sort(a.begin(), a.end());
	for (int i = 0; i < n-1; i++) {
		if (a[i] == a[i + 1]) {
			s.insert(a[i]);
		}
	}
	a.erase(std::unique(a.begin(), a.end()), a.end());
	

	int ans = 0;
	
	n = a.size();
	for (int i = 0; i < n; i++) {
		int v = a[i]; 
		bool f = true;
		for (int j = 1; j*j <= v; j++) {
	
			if (v%j == 0) {
				if (s.find(j)!=s.end()) {
					f = false;
				}

				if (j*j != v) {
					if (s.find(v/j)!=s.end()) {
						f = false;
					}
				}
			}
		}

		if (f) {
			ans++;
		}

		s.insert(v);
	}

	cout << ans << endl;


	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<pair<int, int>> tasks; //deadLine, cost.
  
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    tasks.push_back({b, a});
  }
  
  sort(tasks.begin(),tasks.end());
  
  long long workingTime=0;
  for (auto t: tasks) {
    
    long long deadLine, cost;
    tie(deadLine, cost) = t;
    
    workingTime += cost;
    if(workingTime>deadLine) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
  
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;

	vector<int> dp1(N+2), dp2(N+2);


	dp1[0] = 0;
	for(int i=0; i<N+1; i++){
		dp1[i+1] = S[i]=='o'?1:0;
		if(i>=C) dp1[i+1]+=dp1[i-C];
		dp1[i+1]=max(dp1[i], dp1[i+1]);
	}

	dp2[N+1] = 0;
	for(int i=N-1; i>=0; i--){
		dp2[i+1] = S[i]=='o'?1:0;
		if(i+C+2<N+2) dp2[i+1]+=dp2[i+C+2];
		dp2[i+1] = max(dp2[i+1], dp2[i+2]);
	}

	for(int i=0; i<N; i++){
		if(dp1[i]+dp2[i+2]<K) cout << i+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long * a= new long long[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    long long dp[n][n];
    // memset(dp,0,sizeof(dp));
    for(int l=n-1;l>=0;l--)
    {
        for(int r=l;r<n;r++)
        {
            if(l==r)dp[l][r]=a[l];
            else
        dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
        }
    }
    // for(int i=0;i<n;i++)
    // {
    //     for(int j=0;j<n;j++)
    //     cout<<dp[i][j]<<"\t";
    //     cout<<endl;
    // }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 46464
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**18


if __name__ == "__main__":
    x = int(input())
    if 400<=x<=599:
        print(8)
    elif 600<=x<=799:
        print(7)
    elif 800<=x<=999:
        print(6)
    elif 1000<=x<=1199:
        print(5)
    elif 1200<=x<=1399:
        print(4)
    elif 1400<=x<=1599:
        print(3)
    elif 1600<=x<=1799:
        print(2)
    else:
        print(1)

Measured memory_bytes: 9608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N, K, count=0 ,sum=0;
  	cin >> N >> K;	
  	int A[N], num[N+1] = {0}; 
       
  	for(int i=0; i < N;i++){
       cin >> A[i];
      }
  	for(int i=0; i < N; i++){
    	num[A[i]]++;
    }
  	for(int i=1; i <= N; i++){
       if(num[i])
         count++;
    }
  sort(num, num+(N+1));
   	
  	if(count <= K)
      cout << 0 << endl;
  		else{
          for(int i=1; i <= N - K; i++){

            	sum += num[i];
            	
          }
          cout << sum <<endl;
        }

}
  	

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

using namespace std;

class Game {
private:
	int N, M;
	int m[7][7][7];
public:
	bool inRange(int x, int y, int z) {
		return 0 <= x && x < N && 0 <= y && y < N && 0 <= z && z < N;
	}
	int check(int x0, int y0, int z0, int dx, int dy, int dz) {
		int x = x0, y = y0, z = z0;
		int c = 0, cnt = 0;
		while ( inRange(x, y, z) ) {
			if (m[z][y][x] == c) {
				++cnt;
			}
			else {
				if (cnt >= M && c > 0) {
					return c;
				}
				c = m[z][y][x];
				cnt = 1;
			}
			x += dx, y += dy, z += dz;
		}
		return cnt >= M ? c : 0;
	}
	int check(int X_, int Y_, int Z_) {
		int c = 0;

		for (int X = 0; X < N; ++X) {
			for (int Y = 0; Y < N; ++Y) {
				for (int Z = 0; Z < N; ++Z) {
					c = check(X, 0, Z, 0, 1, 0); if (c) return c;
					c = check(X, Y, 0, 0, 0, 1); if (c) return c;
					c = check(0, Y, Z, 1, 0, 0); if (c) return c;

					c = check(X, Y, Z, 1, 1, 0); if (c) return c;
					c = check(X, Y, Z, 1, 0, 1); if (c) return c;
					c = check(X, Y, Z, 0, 1, 1); if (c) return c;

					c = check(X, Y, Z, -1, 1, 0); if (c) return c;
					c = check(X, Y, Z, 1, 0, -1); if (c) return c;
					c = check(X, Y, Z, 0, -1, 1); if (c) return c;

					c = check(X, Y, Z, 1, 1, 1); if (c) return c;
					c = check(X, Y, Z, -1, 1, 1); if (c) return c;
					c = check(X, Y, Z, 1, -1, 1); if (c) return c;
					c = check(X, Y, Z, 1, 1, -1); if (c) return c;
				}
			}
		}

		return 0;
	}
	int set(int X, int Y, int turn) {
		int Z; for (Z = 0; m[Z][Y][X]; ++Z);
//		cout << X << " " << Y << " " << Z << " " << M <<endl;
		assert(Z < N);
		m[Z][Y][X] = turn;
		return check(X, Y, Z);
	}
	Game(int N, int M) : N(N), M(M) {
		for (int z = 0; z < N; ++z) {
			for (int x = 0; x < N; ++x) {
				for (int y = 0; y < N; ++y) {
					m[z][y][x] = 0;
				}
			}
		}
	}
};

int main() {
	int N, M, P;
	while ( cin >> N >> M >> P, N || M || P ) {
		Game g(N, M);
		int turn = 1;
		int winner = 0, lastTurn = P;
		for (int i = 0; i < P; ++i) {
			int x, y; cin >> x >> y; --x, --y;
			if (winner == 0) {
				winner = g.set(x, y, turn);
				turn = turn == 1 ? 2 : 1;
				lastTurn = i+1;
			}
		}
		if (winner == 0) {
			cout << "Draw" << endl;
		}
		else if (winner == 1) {
			cout << "Black " << lastTurn << endl;
		}
		else {
			cout << "White " << lastTurn << endl;
		}
	}
}

Measured memory_bytes: 1164
n, m = gets.split.map(&:to_i)
map = []
(n+1).times{ map << Array.new }
ans = Array.new(n+1)
checked = Array.new(n+1, false)
$<.map{|l|
  a, b = l.split.map(&:to_i)
  map[a] << b
  map[b] << a
}
#p map

queue = [1]
checked[1] = true
count = 0
until count == n-1
  x = queue.shift
  #puts "x: #{x}"
  map[x].each{|i|
    unless checked[i]
      queue.push(i)
      ans[i] = x
      checked[i] = true
      count += 1
      #p queue
    end
  }
end

puts "Yes"
puts ans[2..n+1]


Measured memory_bytes: 35032
import java.io.*;

class Main {

     private static BufferedReader br;
     private static int W;
     private static int H;
     private static int x;
     private static int y;
     private static int r;
     private static String output;
     private static String[] data = new String[5];

     private static void initialize() {
          br = new BufferedReader(new InputStreamReader(System.in));
          output = "No";
          for (String d : data)
               d = null;
     }

     private static void transInt() {
          W = Integer.parseInt(data[0]);
          H = Integer.parseInt(data[1]);
          x = Integer.parseInt(data[2]);
          y = Integer.parseInt(data[3]);
          r = Integer.parseInt(data[4]);
     }

     private static int judge(int x, int maxX, int r) {
          if (x-r >= 0 && x+r <= maxX) return 0;
          return 1;
     }

     public static void main(String[] args) {
          initialize();
          try {
               data = (br.readLine()).split(" ");
               transInt();
               if ((judge(x, W, r) + judge(y, H, r)) == 0) output = "Yes";
               System.out.println(output);
          } catch(IOException e) {
          } finally {
               try {
                    br.close();
               } catch(IOException e) {
               }
          }
     }

}

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

const int MAXN = 2e5;
int N;
int dp[MAXN];

void update(int a) {
	for (int i = a; i <= N; i++) {
		dp[i] = min(dp[i], dp[i-a] + 1);
	}
}

int main() {
	cin >> N;
	for (int i = 0; i <= N; i++) {
		dp[i] = i;
	}
	for (int z = 1; z <= N; z *= 6) {
		update(z);
	}
	for (int z = 1; z <= N; z *= 9) {
		update(z);
	}
	cout << dp[N] << '\n';

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n, h[100005];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, n-1) {
    if (h[i] > h[i+1]) h[i+1]++;
  }
  rep(i, 0, n-1) {
    if (h[i] > h[i+1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}




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

int card[100050];

int main(){
    int n,m;
    cin >> n >> m;
    int l,r;
    for(int i=0;i<m;i++){
        cin >> l >> r;
        card[l]++;
        card[r+1]--;
    }
    int ans=0;
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=card[i];
        if(sum==m) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n, m, K, M;
llint d[20], dinv[105];
vector<llint> G[1<<16];
llint x[105][105];
llint dist[1<<16];

void bfs()
{
	for(int i = 0; i < M; i++) dist[i] = inf;
	dist[M-1] = 0;
	
	queue<llint> Q;
	Q.push(M-1);
	
	while(Q.size()){
		llint v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			llint u = G[v][i];
			if(dist[u] < inf/2) continue;
			dist[u] = dist[v] + 1;
			Q.push(u);
		}
	}
}

int main(void)
{
	cin >> n >> m >> K;
	for(int i = 0; i < m; i++) cin >> d[i];
	
	for(int i = 1; i <= n; i++) dinv[i] = -1;
	for(int i = 0; i < m; i++) dinv[d[i]] = i;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= K; j++){
			cin >> x[i][j];
		}
	}
	
	M = 1<<m;
	for(int i = 0; i < M; i++){
		for(int j = 1; j <= K; j++){
			llint mask = 0;
			for(int k = 0; k < m; k++){
				if((i & (1<<k)) == 0) continue;
				if(dinv[x[d[k]][j]] == -1) continue;
				mask |= (1 << dinv[x[d[k]][j]]);
			}
			G[i].push_back(mask);
		}
	}
	
	bfs();
	
	cout << dist[0] << endl;
	
	return 0;
}


Measured memory_bytes: 71988
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b,c,d; 
	cin >> a >> b >> c >> d;
	int x = a + b;
	int y = c + d;
	if(x>y){
		cout << "Left" << endl;
	}if(x<y){
		cout << "Right" << endl;
	}if(x==y){
		cout << "Balanced" << endl;
	}
return 0;
}

Measured memory_bytes: 256
# B Crane and Turtle
X, Y = map(int, input().split())
for i in range(X+1):
    for j in range(X+1):
        if X * 2 <= Y:
            if Y % 2 == 0:
                if (i * 2) + (j * 2) == Y:
                    print('Yes')
                    exit()
print('No')


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

// #include "../../template-proj/myMente.h"

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int main(){
	int s;cin>>s;
	int u = s/100;
	int d = s%100;
	bool um = 1<=u && u<=12;
	bool dm = 1<=d && d<=12;
	if(um && dm)ote("AMBIGUOUS");
	else if(!um && dm)ote("YYMM");
	else if(um && !dm)ote("MMYY");
	else ote("NA");
}


Measured memory_bytes: 256
n, k = map(int, input().split())
ans = 0
mod = 10**9+7

for i in range(k, n+2):
    ans += int(n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2 + 1)
print(ans % mod)

'''
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    a = 0.5*i*(i-1)
    b = 0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans += int(b-a+1)

print(ans % (10**9+7))
'''


Measured memory_bytes: 79776
#include<iostream>
using namespace std;
int main (){
int a,b,c,x,y;
y=0;
cin>>a>>b>>c;
for(x = a ; x<=b ; x++){
	if(c%x==0){
		y=y+1;
	}
}
cout<<y<<endl;
	return 0;
}


Measured memory_bytes: 3100
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val result = ArrayDeque<Char>()
    readLine()!!.forEach {
        when (it) {
            'B' -> if (result.isNotEmpty()) { result.pop() }
            else -> result.push(it)
        }
    }
    println(result.reversed().joinToString(""))
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task "A"

using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;

signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    int n;
    string str;
    cin >> n >> str;
    vector<int> cnt(26);
    for (int i=0; i<n; ++i){
        cnt[str[i] - 'a']++;
    }
    int ret = 1;
    for (int i=0; i<26; ++i){
        ret = 1ll * ret * (cnt[i] + 1) % mod;
    }
    cout << ret - 1<< '\n';
}


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

int memo[100'000+5];      /// memo[i] = max length path starting from node i

vector<int> adj[100'000+5];
bool vis[100'000+5];

int dp(int u){
    if(vis[u]) return memo[u];

    vis[u] = true;
    for(int v : adj[u]){
        memo[u] = max(memo[u], dp(v)+1);
    }

    return memo[u];
}

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

    int n, m;
    cin>>n>> m;

    for(int i = 0; i<m; i++){
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
    }

    int ans = 0;
    for(int i = 1; i<=n; i++){
        ans = max(ans, dp(i));
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 11588
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

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

  std::vector<std::pair<int, int>> AB(N);
  for (int i=0; i<N; ++i)
    scanf("%d %d", &AB[i].first, &AB[i].second);

  std::sort(AB.begin(), AB.end());
  printf("%d\n", AB.back().first+AB.back().second);
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a,b;
char mat[105][105];
int main(){
	scanf("%d%d",&a,&b);
	a--,b--;
	for(int i=1;i<=50;i++)
		for(int j=1;j<=100;j++)
			mat[i][j]='.';
	for(int i=51;i<=100;i++)
		for(int j=1;j<=100;j++)
			mat[i][j]='#';
	for(int i=1;i<=50&&b;i+=2)
		for(int j=1;j<=100&&b;j+=2){
			mat[i][j]='#';
			b--;
		}
	for(int i=100;i>50&&a;i-=2)
		for(int j=1;j<=100&&a;j+=2){
			mat[i][j]='.';
			a--;
		}
	puts("100 100");
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++)
			cout<<mat[i][j];
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	map<string,int> m;
	forn(i,n)
	{
		string s; cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<'\n';
	cout<<"WA x "<<m["WA"]<<'\n';
	cout<<"TLE x "<<m["TLE"]<<'\n';
	cout<<"RE x "<<m["RE"]<<'\n';

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,N; cin >> H >> N;
    ll sum=0;
    rep(i,N){
        ll a; cin >> a;
        sum+=a;
    }
    if (sum>=H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int max_n = i_half_inf;
ll n, k;
ll h[max_n];

void solve() {
    sort(h, h + n);
    ll ans = ll_inf;
    rep(i, n - k + 1) {
        ans = min(ans, abs(h[i] - h[i + k - 1]));
    }
    cout << ans << endl;
}

int main() {
    cin >> n >> k;
    rep(i, n) cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1024
n,m,x,y=map(int,input().split())
p=[]
q=[]
p=list(map(int,input().split()))
q=list(map(int,input().split()))
p.sort()
q.sort()
a=p[-1]
b=q[0]
if a<b and x<b and b<=y:
  print('No War')
else:
  print('War')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<sstream>
using namespace std;
typedef long long ll;

const ll INF = 2*1e9;

ll StoLL(string s){
  if(s=="x")return INF+1;
  stringstream ss(s);
  ll res;
  ss >> res;
  return res;
}

int main(){
  ll n,a[1010];
  string s;

  while(cin >> n, n){
    bool f = 0;
    for(int i=0;i<n;i++)cin >> s, a[i] = StoLL(s);
    
    for(int i=1;i<n;i++){
      if(a[i] == a[i-1])f = 1;
      if(a[i]>INF || a[i-1]>INF)continue;
      if((i&1)==1 && a[i] < a[i-1])f = 1;
      if((i&1)==0 && a[i] > a[i-1])f = 1;
    }
    
    if(f){
      cout << "none" << endl;
      continue;
    }
    
    ll l = -INF, r = INF;
    for(int i=0;i<n;i++){
      if(a[i]>INF){
	if(i&1){
	  if(i)l=max(l,a[i-1]+1);
	  if(i+1<n)l=max(l,a[i+1]+1);
	}else{	  
	  if(i)r=min(r,a[i-1]-1);
	  if(i+1<n)r=min(r,a[i+1]-1);
	}
      }
    }
    
    if(l>r)cout << "none" << endl;
    else if(r-l>0)cout << "ambiguous" << endl;
    else cout << l << endl;
  }
}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>

#pragma warning(disable:4996)

using namespace std;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  cout << max(abs(b - a) - w, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 200001;
vi v, L(MAX), R(MAX);
ll merge(int left,int mid,int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	ll cnt = 0;
	rep(i, 0, n1) L[i] = v[left+i];
	rep(i, 0, n2) R[i] = v[mid+i];
	L[n1] = R[n2] = 1e9;
	int i = 0, j = 0;
	rep(k, left, right) {
		if(L[i] < R[j]) {
			v[k] = L[i];
			++i;
		} else {
			v[k] = R[j];
			++j;
			cnt += n1 - i;
		}
	}
	return cnt;
}
ll mergesort(int left,int right)
{
	ll cnt = 0;
	if(left + 1 < right) {
    	int mid = (left + right) / 2;
    	cnt += mergesort(left, mid);
    	cnt += mergesort(mid, right);
    	cnt += merge(left, mid, right);
	}
	return cnt;
}
int main() {
	int n; cin >> n;
	v.resize(n); rep(i, 0, n) cin >> v[i];
	P(mergesort(0, n));
	return 0;
}

Measured memory_bytes: 5168