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

#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define sortA(a) sort(a.begin(),a.end())
#define sortD(a) sort(a.begin(),a.end(),greater<int>())
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ARC")
      cout<<"ABC";
    else
      cout<<"ARC";
	  return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  REP(i, k) {
    int d;
    cin >> d;
    REP(j, d) {
      int s;
      cin >> s;
      mp[s] += 1;
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(mp[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

vector<int64_t> lun(int64_t n){
  int64_t a = n%10;
  if(a==9) return {n*10+a,n*10+a-1};
  else if(a==0) return {n*10+a+1,n*10+a};
  else return {n*10+a+1,n*10+a,n*10+a-1};
}

int main(){
  int64_t K; cin >> K;
  int64_t k = 9;
  vector<int64_t> A = {1,2,3,4,5,6,7,8,9};
  vector<int64_t> C = {1,2,3,4,5,6,7,8,9};
  vector<int64_t> B, D;
  int64_t s = 9;
  while(k<K){
    for(int64_t i=0; i<C.size(); i++){
      B = lun(C.at(i));
      for(int64_t i=0; i<B.size(); i++){
        int64_t b = B.at(i);
        A.push_back(b);
        D.push_back(b);
      }
      s += B.size();
    }
    k = s;
    C = D;
    D = {};
  }
  sort(A.begin(), A.end());
  cout << A.at(K-1) << endl;
}

Measured memory_bytes: 4432
import decimal

# N
# p1 p2...pN
# -----------
n = int(input())
a = list(map(int, input().split()))

# a = np.array(a)
# print(a)
sum_reciprocal = 0

for i in range(len(a)):
    b = decimal.Decimal(1/a[i])
    sum_reciprocal += b

print(decimal.Decimal(1/sum_reciprocal))


Measured memory_bytes: 5204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            double n = in.nextLong();
            double m = in.nextLong();
            double d = in.nextLong();
            if (d == 0)
                out.printf("%.10f", (n - d) * (m - 1) / (n * n));
            else
                out.printf("%.10f", 2 * (n - d) * (m - 1) / (n * n));
            out.println();
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<string> s(N);

    for(int i = 0; i < N; i ++){
        cin >> s[i];

        for(int j = 9; j >= 0; j --){
            for(int k = 0; k < j; k ++){
                if(s[i][k] > s[i][k + 1]){
                    char t = s[i][k];

                    s[i][k] = s[i][k + 1];
                    s[i][k + 1] = t;
                }
            }
        }
    }
    sort(s.begin(), s.end());

    int count = 1;
    llint ans = 0;
    string t = s[0];

    for(int i = 1; i < N; i ++){
        if(s[i] == t){
            count ++;
        }else{
            ans += (llint) count * (count - 1) / 2;
            count = 1;
            t = s[i];
        }
    }
    ans += (llint) count * (count - 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, char>P;

int f[10][10], x[23], y[23], dat[10][10], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		int p = 0, sx, sy;
		rep(i, n)rep(j, m) {
			scanf("%d", &f[i][j]);
			if (f[i][j] == 1)x[p] = i, y[p] = j, dat[i][j] = p++;
			if (f[i][j] == 2)sx = i, sy = j;
		}
		map<P, int>dp;
		rep(k, 4) {
			for (int nx = sx, ny = sy; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
				if (f[nx][ny] == 1) {
					dp[{1 << dat[nx][ny], dat[nx][ny]}] = 1;
					break;
				}
			}
		}
		int ans = 0, o = 0;
		rep(i, 1 << p)rep(j, p) {
			if (dp.find({ i,j }) == dp.end())continue;
			if (i == (1 << p) - 1) {
				if (x[j] == sx || y[j] == sy)ans += dp[{i, j}];
				continue;
			}
			rep(k, 4) {
				for (int nx = x[j], ny = y[j]; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
					if (f[nx][ny] == 1 && !(i >> dat[nx][ny] & 1)) {
						dp[{i | 1 << dat[nx][ny], dat[nx][ny]}] += dp[{i, j}];
						break;
					}
				}
			}
			if (++o >= 1000)dp.erase({ i,j });
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 8540
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadLong;
            var H = cin.ReadLongArray(N);

            long[] count = new long[N];

            for(long i = N - 2; i > -1; i--)
            {
                if(H[i] < H[i + 1])
                {
                    count[i] = 0;
                }
                else
                {
                    count[i] = count[i + 1] + 1;
                }
            }

            Console.WriteLine(count.Max());

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 27356
import Control.Monad;
import Control.Applicative;

-- bulletin-board.hs --- Bulletin Board

-- author: Seong Yong-ju <sei40kr@gmail.com>

main :: IO ()
main = do
  [n, h, w] <- replicateM 3 $ (read :: String -> Int) <$> getLine
  print $ (n - h + 1) * (n - w + 1)


Measured memory_bytes: 508
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	string s;cin>>n>>s;
	rep(i, s.length()){
		s[i] = (s[i]-'A'+n)%26+'A';
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    println!("{}", (a + b + 1) / 2);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl;
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); cout << (i>0 ? " ":"") << v[i++]); cout << "\n"; return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s1,s2;
    cin >> s1;
    cin >> s2;
    s2.pop_back();
    if(s1 == s2){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes" : "No") << endl;
    
    return 0;
}


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

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

  int sum =0;
  int i=0;
  
 while (i < N+1){
   int x;
   cin >> x;
   sum +=x;
   i++;
   
   if (sum>X){
   break;
   }
 }
   cout << i <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    int64 ans = 0;
    for (int64 a=1; a<=n; a++) {
        for (int64 b=1; a*b<=n; b++) {
            int64 c = n - a*b;
            if (0 < c) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k;
	cin>>n>>k;
	cout << min(n%k,k-n%k);
	// your code goes here
	return 0;
}

Measured memory_bytes: 3636
A, B, M = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ans = min(a) + min(b)
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    ans = min(ans , dv)
print(ans)
        


Measured memory_bytes: 18488
/* ex4_3
   urah  */

#include <stdio.h>

// プロトタイプ宣言
int snow_amount(int west, int east);

int main(void){
    int west, east, ans;

    // 入力受け取り
    scanf("%d\t%d", &west, &east);
    // 関数の呼び出し
    ans = snow_amount(west, east);
    // 出力
    printf("%d\n", ans);

    return 0;
}

//関数の定義
int snow_amount(int west, int east){
    int diff, ans;

    diff = east - west;
    ans = 0;
    // 本来の西側の塔の高さを求める
    for (int i=1; i < diff; i++){
        ans = ans + i;
    }
    ans = ans - west;

    return ans;
}

Measured memory_bytes: 128
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  int n; // to input 

  scan = scanf("%d", &n);

  if (n % 10 == 3) {
    printf("bon");
  } else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
    printf("pon");
  } else {
    printf("hon");
  }

  return (0);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

vector<bool> prime(100000,true);
vector<bool> isprime(int N)
{
    if (N >= 0)
        prime[0] = false;
    if (N >= 1)
        prime[1] = false;
    for (ll i = 2; i * i <= N; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (ll j = i * i; j <= N; j += i)
        {
            prime[j] = false;
        }
    }
    return prime;
}

int main(){
    ll n;cin>>n;
    vector<vector<ll>> prime_num(5,vector<ll>());
    isprime(55556);
    
    rep(i,55556){
        if(prime[i]) prime_num[i%5].push_back(i);    
    }

    /*rep(i,5){
        cout<<prime_num[i].size()<<endl;
    }*/

    rep(i,n){
        cout<<prime_num[1][i];
        if(i!=n-1) cout<<" ";
        else cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    cnt = 0
    for i in range(N):
        d1, d2 = MI()
        if d1 == d2:
            cnt += 1
        else:
            cnt = 0

        if cnt == 3:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    solve()



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

int main(){
	string s;
	cin >> s;
	int g = 0;
	int p = 0;
	for(auto c: s){
		if(c == 'g') g++;
		else p++;
	}
	cout << (g - p) / 2;
	return 0;
}

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

const int _ = 2003;
int A[_] , N , fa[_]; bool clr[_] , vis[_] , ban[_];
int find(int x){return fa[x] == x ? x : (fa[x] = find(fa[x]));}

int czys; map < int , int > zys; vector < int > pot[_ << 1] , fac[_];
int getzys(int x){return zys[x] ? zys[x] : zys[x] = ++czys;}

bool check(int mid){
	while(mid && vis[mid]) --mid;
	if(!mid) return 0;
	for(int i = 1 ; i <= N ; ++i){fa[i] = i; clr[i] = !vis[i] && (ban[i] || i > mid);}
	for(int i = 0 ; i <= czys ; ++i)
		for(int j = 1 ; j < pot[i].size() ; ++j){int p = find(pot[i][0]) , q = find(pot[i][j]); if(p != q){fa[q] = p; clr[p] &= clr[q];}}
	for(int i = 1 ; i <= N ; ++i) if(clr[i] && fa[i] == i) return 0;
	return 1;
}

void factor(int x){
	int p = A[x];
	for(int i = 2 ; i * i <= p ; ++i)
		if(p % i == 0){int t = getzys(i); fac[x].push_back(t); pot[t].push_back(x); while(p % i == 0) p /= i;}
	if(p != 1){int t = getzys(p); fac[x].push_back(t); pot[t].push_back(x);}
}

int main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> A[i];
	sort(A + 1 , A + N + 1); for(int i = 1 ; i <= N ; ++i) factor(i);
	
	for(int i = 1 ; i <= N ; ++i){
		int L = 1 , R = N; while(L < R){int mid = (L + R) >> 1; check(mid) ? R = mid : L = mid + 1;}
		vis[L] = 1; cout << A[L] << ' ';
		for(auto t : fac[L]) pot[t].erase(find(pot[t].begin() , pot[t].end() , L));
		for(int j = 1 ; j <= N ; ++j) if(vis[j] || __gcd(A[j] , A[L]) != 1) ban[j] = 0; else ban[j] |= j > L;
	}
	return 0;
}


Measured memory_bytes: 640
<?php

  $n = trim(fgets(STDIN));
  $p = implode(explode(" ", trim(fgets(STDIN))));
  $q = implode(explode(" ", trim(fgets(STDIN))));

  $permutation = permutationAll(1, $n);
  sort($permutation);

  $pn=0;
  $qn=0;
  for($i=0;$i<count($permutation);$i++){
//    echo $permutation." ".$p.PHP_EOL;
    if($permutation[$i]==$p){
      $pn=$i;
    }
    if($permutation[$i]==$q){
      $qn=$i;
    }
  }
  echo abs($pn-$qn);

  /**
   * 順列の組み合わせを返す
   * @param $n 数
   */
  function permutationAll($start, $end)
  {
    if($end < $start){
      return [];
    }
    $n=[];
    for($i=$start;$i<=$end;$i++){
      $n[$i]=true;
    }

    $arr = appendCount($n, "");

    return $arr;
  }

  function appendCount($n, $str){
    if(count($n)===1){
      return [$str.key($n)];
    }
    $arr = [];
    foreach($n as $key => $value){
      unset($n[$key]);
      $childs = appendCount($n, $str.$key);
      foreach($childs as $child){
        $arr[] = $child;
      }
      $n[$key]=true;
    }
    return $arr;
  }

Measured memory_bytes: 8696
#include <bits/stdc++.h>
using namespace std;
typedef long long int i64;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<vector<pair<int,int>>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u; --v;
    g[u].emplace_back(v, c);
    g[v].emplace_back(u, c);
  }
  vector<int> ans(n, 0);
  ans[0] = 1;
  function<void(int,int)> dfs = [&] (int u, int p) {
    for (auto e: g[u]) if (e.first != p) {
      int v, w;
      tie(v, w) = e;
      ans[v] = ans[u];
      ans[v] ^= w & 1;
      dfs(v, u);
    }
  };
  dfs(0, -1);
  for (int x: ans) cout << x << '\n';
  
  return 0;
}


Measured memory_bytes: 9728
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main() {
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll> > v;
	rep(i,0,n){
		ll a,b;
		cin>>a>>b;
		v.pb(mp(a,b));
	}
	sort(all(v));
	rep(i,0,n){
		if(k-v[i].se<=0){
			cout << v[i].fi << endl;
			return 0;
		}
		k-=v[i].se;
	}
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>

int main(){
  int A, B, C;
  std::cin>>A>>B>>C;
  if(A>C&&B<C) printf("Yes\n");
  if((A<C)&&(B>C)) printf("Yes\n");
  if(A>C&&B>C) printf("No\n");
  if(C>A&&C>B) printf("No\n");
  return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    unordered_map<int,int> mp;
    ll ans{};
    ifr(i,n){
        ans+=mp[a[i]+i];
        mp[i-a[i]]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 19356
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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);
  double N;
  cin >> N;
  for(double h = 1.0; h < 3501; h += 1.0) for(double n = 1.0; n < 3501; n += 1.0)
  {
    double tmp = 4*h*n-N*n-N*h;
    if (tmp <= 0) continue;
    double w = N*h*n/tmp;
    if ((int)w == w)
    {
      cout << h << " " << n << " " << (int)w;
      return 0;
    }
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	m := make(map[[3]int]bool)
	for i := 0; i <= 9; i++ {
		for j := 0; j <= 9; j++ {
			for k := 0; k <= 9; k++ {
				vv := [3]int{i, j, k}
				vk := 0
				for p := 0; p < n; p++ {
					sv, _ := strconv.Atoi(s[p : p+1])
					if sv == vv[vk] {
						vk++
					}
					if vk == 3 {
						m[vv] = true
						break
					}
				}
			}
		}
	}

	fmt.Println(len(m))
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define llong long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
abcdefgh
3
)");
#define cin input
#endif

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

	/*
	string a = "";
	
	REP(i,s.size()/w+1)
	{
		a = s[w*i];
		ans += a;
	}
	*/
	string ans = "";
	REP(i,s.size())
	{
		if(i%w==0)
			ans += s.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
dat_a = [-1] * (n + 1)
for i in range(n):
    a = int(input())
    dat_a[i + 1] = a
cur = 1
f = False
for i in range(n):
    if cur == 2:
        f = True
        break
    cur = dat_a[cur]
if f:
    print(i)
else:
    print("-1")

Measured memory_bytes: 46168
#include <stdio.h>
#include <stdlib.h>
#define MAXOP 100
#define MAXVAL 100
void push(int);
int pop(void);
int main()
{
  char t[100];
  int op2,a;
  char s[MAXOP];

  while(scanf("%s",t)!=EOF) {
	  if(t[0]== '+'){
			push(pop() + pop());
	  }
	  else if(t[0]=='*'){
			push(pop() * pop());
	  }
	  else if(t[0]=='-'){
			op2 = pop();
			push(pop() - op2);
	  }
	  else{
	    push(atoi(t));
	  }
	}
  printf("%d\n",pop());
	return 0;
}


int s = 0;
int val[MAXVAL];

void push(int f)
{
	if (s < MAXVAL)
		val[s++] = f;
}

int pop(void)
{
	if (s > 0)
		return val[--s];
	else {
		return 0;
	}
}





Measured memory_bytes: 2144
N,M,V,P = map(int,input().split())
import numpy as np
A = list(map(int,input().split()))
A = np.array(sorted(A,reverse=True))
ans = P
x = A[P-1]
y=P
z = sum(A[P-1:y])
for i in range(y,N):
  a = A[i]
  d = a+M
  if x<=d:
    b = N-i+P-1
    c = M*(V-b)
    e = z+c
    f = d*(i-P+1)
    if f>=e:
      ans+=1
      
  z+=a
print(ans)

Measured memory_bytes: 23152
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int d = s[0];
        int x = s[1];
        for (int i = 0; i < n; i++) {
            int a = int.Parse(Console.ReadLine());
            for (int j = 0; j*a+1 <= d; j ++) {
                x ++;
            }
        }
        Console.WriteLine(x);
    }
}

Measured memory_bytes: 13268
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String[] ab = line.split(" ");
    int a = Integer.parseInt(ab[0]);
    int b = Integer.parseInt(ab[1]);
    if(a < b) {
      System.out.println("a < b");
    }else if(a > b) {
      System.out.println("a > b");
    }else {
      System.out.println("a == b");
    }

  }
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s;cin>>s;
	map<char,int>a;
	rep(i,4)a[s[i]]++;
	rep(i,4){
		if(a[s[i]]!=2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
n,m,q = map(int,input().split())
abcd = [[*map(int,input().split())] for _ in range(q)]
from itertools import *
ans = 0
for A in combinations_with_replacement(range(1, m+1), n): # nHr
    now = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c: now += d
    ans = max(ans, now)
print(ans)


Measured memory_bytes: 9168
#!/usr/bin/env python3

x, k, d = map(int, input().split(' '))
m = (k * d - x) / (2 * d)
ans = 0

def score(c):
    return abs(x - k * d + 2 * d * c)

if m > k:
    ans = k
else:
    if m < 0:
        ans = 0
    else:
        ans = int(m)
    if score(ans) > score(ans+1):
        ans += 1

print(score(ans))

Measured memory_bytes: 9112
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define all(x) (x).begin(), (x).end()
#define rep(i, x) for (int i = 0; i < (x); ++i)
using namespace std;
using ll = long long;


int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p, q;
    priority_queue<ll> r;

    ll tmp;
    rep(i, a) {
        cin >> tmp;
        p.push_back(tmp);
    }
    rep(i, b) {
        cin >> tmp;
        q.push_back(tmp);
    }
    rep(i, c) {
        cin >> tmp;
        r.push(tmp);
    }
    sort(all(p), greater<ll>());
    sort(all(q), greater<ll>());

    priority_queue<ll, vector<ll>, greater<ll>> best;

    rep(i, x) best.push(p[i]);
    rep(i, y) best.push(q[i]);

    int n = (int)best.size();
    rep (i, n) {
        if (r.empty()) break;
        ll candidate = r.top(); // 候補の最大値
        ll element = best.top(); // 採用の最小値

        if (candidate > element) {
            r.pop();
            best.pop();
            best.push(candidate);
        }
    }

    ll ans = 0;
    while (!best.empty()) {
        ll val = best.top();
        ans += val;
        best.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    double a,b,h,m,angle;
    cin >> a >> b >> h >> m;
    double anglem = 6 * m;
    double angleh = 30 * h + 0.5 * m;
    double pi     = 2.0 * asin(1.0); 
    double unit   = pi / 180.0; 
    if(anglem >= angleh){
        angle = anglem - angleh;
        if(angle > 180){
            angle = 360 - angle;
        }
    }else if(anglem < angleh){
        angle = angleh - anglem;
        if(angle > 180){
            angle = 360 - angle;
        }
    }
    double deg_r  = angle * unit;
    double temp = pow(a,2) + pow(b,2) - 2 *a *b * cos(deg_r); 
    double ans = sqrt(temp);
    printf("%.15f\n",ans);

}

Measured memory_bytes: 4216
let [|N;M;X|] =
    stdin.ReadLine().Split()
    |> Array.map int
let CA =
    [|1..N|]
    |> Array.map (fun _ ->
        stdin.ReadLine().Split()
        |> Array.map int)
let INF = 10000000

[0..int(2.0**float(N)-1.0)]
|> List.fold (fun min item ->
    Array.fold (fun (state,bit) ca ->
        if bit&&&1 = 1 then
            let s =
                Array.zip state ca
                |> Array.map (fun (sum,item) -> sum+item)
            (s, bit>>>1)
        else (state, bit>>>1)) ((Array.create (M+1) 0),item) CA
    |> fun (state,_) -> state
    |> fun ca ->
        let c = ca.[0]
        let a = ca.[1..]
        if c < min then
            let ok = Array.fold (fun state item -> state && (item>=X)) true a
            if ok then c
            else min
        else min) INF
|> function
    | x when x=INF -> -1
    | x -> x
|> stdout.WriteLine

Measured memory_bytes: 47092
#include <iostream>
using namespace std;
int main(){
	int x;
	long long ans;
	cin >> x;
	int cnt1 = 0,cnt2 = 0;
	while(x/500>0){
		x-=500;
		++cnt1;
	}
	while(x/5>0){
		x-=5;
		++cnt2;
	}
	ans = cnt1*1000+cnt2*5;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,ans;
  ans=0;
  cin>>n;
  int fn=n;
  int count=1;
  int a[10000];
  a[0]=n;
  for(;;){
    count++;
    if(fn%2==0){
      fn=fn/2;
      a[count]=fn;
    }else{
      fn=fn*3+1;
      a[count]=fn;
    }
    rep(i,count-1){
      if(fn==a[i]){
        ans=count;
        break;
      }
    }
    if(ans!=0){
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define upadj(i,adj) if (adj.size()>0) up(i,0,adj.size()-1)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << "=" <<X << endl
#define debug2(X,Y)  cerr<< #X << "=" <<X << ", " << #Y << "=" <<Y << endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
const int base= 1e9+ 7;
const int M= 2001;
int n,a[200010],b[200010],f[4003][4003];
int res;

int Add(int a,int b)
{
    return (a+b>= base)?a+b-base: a+b;
}
int Sub(int a,int b)
{
    return (a-b<0)?a-b+base: a-b;
}
void input()
{
    cin>>n;
    up(i,1,n) cin>>a[i]>> b[i];
}
long power(int x,int k)
{
    if (k==1) return x;
    long t= power(x,k/2);
    t= t*t% base;
    if (k%2==1) t= t*x%base;
    return t;
}
void solve()
{

    up(i,1,n) f[-a[i]+M][-b[i]+M]++;// ( -a,-b)
    up(x,-2000,2000)
     up(y,-2000,2000)
      f[x+M][y+M]= Add(f[x+M][y+M], Add(f[x-1+M][y+M],f[x+M][y-1+M]) );

    res= 0;
    up(i,1,n) res= Add(res, f[a[i]+M][b[i]+M]);

    up(x,0,4000) f[x][0]= 1;
    up(y,0,4000) f[0][y]= 1;

    up(x,1,4000)
     up(y,1,4000)
      f[x][y]= Add(f[x-1][y],f[x][y-1]);
    up(i,1,n) res= Sub(res, f[a[i]+a[i]][b[i]+b[i]]);
    cout<<res* power(2,base-2)% base;
}

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

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 64384
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;

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

    int x, n;
    cin >> x >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int y;
        cin >> y;
        mp[y] = 1;
    }
    for(int i = 0; ; i++){
        if(mp.count(x - i) == 0){
            cout << x - i;
            return 0;
        }
        if(mp.count(x + i) == 0){
            cout << x + i;
            return 0;
        }
    }
}



Measured memory_bytes: 3664
N = int(input())
def digitsum(n):
    s = str(n)
    res = 0
    for c in s:
        res += int(c)
    return res
m = float('inf')
digits = [0 for i in range(N)]
for A in range(1,N):
    digits[A] = digitsum(A)
for A in range(1,N):
    m = min(m,digits[A]+digits[N-A])
print(m)

Measured memory_bytes: 3864
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

vector<bool> used;

void dfs(int v,vector<vector<int>> root){
    used[v]=true;
    for(auto next_v:root[v]){
        if (!used[next_v]){
            dfs(next_v,root);
        }
    }
}

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    used.assign(n+1,false);
    used[0]=true;
    vector<pair<int,int>> p(m);
    vector<vector<int>> root(n+1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        pair <int,int> w(a,b);
        p[i] = w;

        root[a].push_back(b);
        root[b].push_back(a);
    }
    int cnt=0;

    rep(i,m){
        used.assign(n+1,false);
        int a = p[i].first;
        int b = p[i].second;
        root[a].erase(remove(root[a].begin(),root[a].end(),b),root[a].end());
        root[b].erase(remove(root[b].begin(),root[b].end(),a),root[b].end());
        dfs(a,root);
        for(int j=1;j<n+1;j++){
            if(used[j]!=true){
                cnt+=1;
                // cout << a << " " << b << endl;
                root[a].push_back(b);
                root[b].push_back(a);
                break;
            }
        
        }
        root[a].push_back(b);
        root[b].push_back(a);

    }
    cout << cnt;
    

    return 0;
}

Measured memory_bytes: 384
import sys
from itertools import accumulate

read = sys.stdin.buffer.read


def main():
    N, *L = map(int, read().split())

    L.sort()
    max_L = L[-1]

    C = [0] * (max_L + 1)
    for l in L:
        C[l] += 1
    C = list(accumulate(C))

    ans = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i + 1 :], i + 1):
            if a + b > max_L:
                ans += N - j - 1
            else:
                ans += C[a + b - 1] - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 73976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }

void yes() { cout << "Yay!\n"; }
void no() { cout << ":(\n"; }

int main() {
    init();

    int x; cin >> x;
    int ans = 0;
    FOR(i, 0, 100000) {
        int sum = 100 * i;
        int cnt = i;
        FOR(j, 0, 6) {
            while (cnt && x - sum >= 5 - j) {
                --cnt;
                sum += 5 - j;
            }
        }
        if (sum == x && cnt == 0)ans = 1;
    }
    cout << ans << "\n";
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;

    bool isPossible = true;
    for (ll i = A; i < C - 1; ++i)
    {
        if (S[i] == '#')
        {
            if (i + 1 < C - 1 && S[i + 1] == '#')
            {
                isPossible = false;
                break;
            }
        }
    }
    if (isPossible)
    {
        for (ll i = B; i < D - 1; ++i)
        {
            if (S[i] == '#')
            {
                if (i + 1 < D - 1 && S[i + 1] == '#')
                {
                    isPossible = false;
                    break;
                }
            }
        }
    }
    if (isPossible)
    {
        if (C > D)
        {
            bool flag = false;
            for (ll i = B - 1; i < D; ++i)
            {
                if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.')
                {
                    flag = true;
                    break;
                }
            }
            isPossible = flag;
        }
    }
    string ans = isPossible ? "Yes" : "No";

    cout << ans << endl;
}


Measured memory_bytes: 3680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskATCG004B solver = new TaskATCG004B();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskATCG004B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int x = in.nextInt();

            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }

            long minSum = 0;
            int m[] = new int[N];
            for (int i = 0; i < N; i++) {
                m[i] = a[i];
                minSum += m[i];
            }

            for (int k = 1; k <= N - 1; k++) {
                long sum = (long) k * x;

                for (int i = 0; i < N; i++) {
                    int p = (i - k) % N;
                    if (p < 0) p += N;

                    m[i] = Math.min(m[i], a[p]);
                    sum += m[i];
                }
                minSum = Math.min(sum, minSum);
            }
            out.println(minSum);
        }

    }
}


Measured memory_bytes: 13668
#include <cstdio>
#include <algorithm>
int N, L, T, p[100001], C = 1;
int main()
{
	scanf("%d%d%d", &N, &L, &T);
	for (int i = 1, x, w; i <= N; i++)
	{
		scanf("%d%d", &x, &w);
		if (w == 1)
		{
			int z = (T + x) / L;
			C = (C + z - 1) % N + 1;
			p[i] = (x + T) % L;
		}
		else
		{
			int z = (T - x - 1 + L) / L;
			C = ((C - z - 1) % N + N) % N + 1;
			p[i] = ((x - T) % L + L) % L;
		}
	}
	std::sort(p + 1, p + N + 1);
	for (int i = C; i <= N; i++)
		printf("%d\n", p[i]);
	for (int i = 1; i < C; i++)
		printf("%d\n", p[i]);
	return 0;
}


Measured memory_bytes: 1536
N,K=(int(i) for i in input().split())
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()
m=abs(h[0]-h[K-1])
for i in range(1,N-K+1):
    if m>abs(h[i]-h[i+K-1]):
        m=abs(h[i]-h[i+K-1])
print(m)

Measured memory_bytes: 7388