akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
       int main()
  {   
     int n,h;
     cin>>n;
     cin>>h;
     vector<int>human;
     int temp;
     for(int i=0;i<h;i++)
     {   
         cin>>temp;
         human.push_back(temp);
     }
   int sum=0;
    for(auto x:human)
    {
        sum=sum+x;
    }
    
    
   if(sum>n)
     cout<<"-1"<<endl;
    if(sum==n)
    cout<<"0"<<endl;
     if(sum<n)
     cout<<n-sum<<endl;
  return 0;   
 }

Measured memory_bytes: 3648
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{max,min};
fn main() {
    input! { 
        w: i32, h: i32, n: usize,
        xya: [(i32, i32, i32); n],
    }
    let (mut xmin, mut xmax, mut ymin, mut ymax) = (0, w, 0, h);
    for (x, y, a) in xya {
        match a {
            1 => xmin = max(xmin, x),
            2 => xmax = min(xmax, x),
            3 => ymin = max(ymin, y),
            4 => ymax = min(ymax, y),
            _ => (),
        }
    }
    let area = max(0, xmax - xmin) * max(0, ymax - ymin);
    println!("{}", area);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
    int max=0,count=0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            count++;
            if(count>2)
            max++;
        }        
        else{
            if(count>2)
            max++;
            count=0;
        }
    }
    if(max>0)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>
#include <cmath>

int main(void) {
  int A, B, C, D;
  std::cin >> A >> B >> C >> D;

  int overlap = 0;
  if (C < A) {
    if (D < A) {
      overlap = 0;
    } else {
      if (D < B) {
        overlap = D - A;
      } else {
        overlap = B - A;
      }
    }
  } else {
    /* A <= C */
    if (C <= B) {
      if (D < B) {
        overlap = D - C;
      } else {
        overlap = B - C;
      }
    } else {
      overlap = 0;
    }
  }

  std::cout << overlap << std::endl;
  return 0;
}


Measured memory_bytes: 256
//Name: [[iwi]]
//Level: 2
//Category: 文字列,全探索
//Note:

/**
 * 文字列長が短いので、使う文字の組み合わせを全通り試す。
 *
 * オーダーは O(2^|S|)。
 */
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

bool solve() {
    string s;
    if(!(cin >> s)) return false;

    int iwi = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'i' || s[i] == 'w') {
            iwi |= (1<<i);
        }
    }

    unordered_map<char,char> dict;
    dict['i'] = 'i';
    dict['w'] = 'w';
    dict['('] = ')';
    dict[')'] = '(';
    dict['{'] = '}';
    dict['}'] = '{';
    dict['['] = ']';
    dict[']'] = '[';

    int ans = 0;
    const int P = (1 << s.size());
    vector<int> buf;
    for(int i = 0; i < P; ++i) {
        const int pat = i | iwi;
        buf.clear();
        for(int j = 0; j < s.size(); ++j) {
            if(pat & (1<<j)) {
                buf.push_back(j);
            }
        }
        int l = 0, r = (int)buf.size()-1;
        while(l <= r) {
            if(dict[s[buf[l]]] != s[buf[r]]) goto next;
            l++;
            r--;
        }
        ans = max(ans, (int)buf.size());
next:
        ;
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 998244353;

using p = pair<ll, ll>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;

    vector<p> v(k);
    rep(i, k) {
        ll l, r;
        cin >> l >> r;
        v[i] = p(l, r);
    }

    vector<ll> dp(n, 0);
    vector<ll> dp_sum(n, 0);
    dp[0] = 1;
    dp_sum[0] = 1;

    repd(i, 1, n) {
        for (p x : v) {
            ll r = i - x.first, l = i - x.second;
            if (r < 0)
                continue;
            if (l < 0)
                l = 0;

            if (l == 0) {
                dp[i] += dp_sum[r];
            } else {
                dp[i] += dp_sum[r] - dp_sum[l - 1];
            }
            dp[i] = (dp[i] + mod) % mod;
        }
        dp_sum[i] = dp_sum[i - 1] + dp[i];
        dp_sum[i] %= mod;
    }

    cout << dp[n - 1] << endl;
    return 0;
}



Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

map<ll,ll> prime(ll n){  
    map<ll,ll> mp;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n!=1)mp[n]++;
    return mp;
}

int main(){
    ll n,p;
    cin >>n >> p;
    auto r = prime(p);
    ll ans = 1;
    for(auto t : r) if(t.second>=n){
        rep(i,t.second/n) ans *= t.first;
    }
    cout <<ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

	vector<int> A(N);
	rep(i, N) cin >> A[i];

	rep(i, N)
	{
		if (A[i] % 2 == 1)
		{
			cout << "first" << endl;
			return 0;
		}
	}

	cout << "second" << endl;

	return 0;
}

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

bool chmin(long long &a, long long b) { if (a > b) { a = b; return true; } else return false; }
bool chmax(long long &a, long long b) { if (a < b) { a = b; return true; } else return false; }

typedef pair<int,int> pint;

int n, s;
long long l[510], r[510];
long long w[510][510];
const long long INF = 1LL<<59;

long long dp[510];

long long rec(int v) {
  if (dp[v] != -1) return dp[v];
  long long res = 0;
  for (int nv = 1; nv < n; ++nv) {
    if (nv == v) continue;
    long long arrive = r[v] + w[v][nv];
    if (r[nv] <= arrive) continue;
    chmax(res, rec(nv) + (r[nv] - max(arrive, l[nv])));
  }
  //cout << v << ": " << res << endl;
  return dp[v] = res;
}


long long solve() {
  memset(dp, -1, sizeof(dp));
  return rec(0);
}


int main() {
  while (cin >> n >> s) {
    for (int i = 0; i < n; ++i) cin >> l[i+1] >> r[i+1];
    l[0] = r[0] = 0;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> w[i+1][j+1];
    for (int i = 0; i < n; ++i) w[0][i+1] = w[s][i+1], w[i+1][0] = INF;
    w[0][0] = 0;
    ++n;

    // w[i][i] = 0 is guaranteed
    for (int k = 0; k < n; ++k)
      for (int i = 0; i < n; ++i)
	for (int j = 0; j < n; ++j)
	  chmin(w[i][j], w[i][k] + w[k][j]);
    cout << solve() << endl;
  }
}


Measured memory_bytes: 5112
package main

import (
	"fmt"
	"math"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var n int
	fmt.Scan(&n)
	a:=make([]int,n)
	sum:=1
	for i:=0;i<n;i++{
		fmt.Scan(&a[i])
	}
	sort.IntSlice(a).Sort()
	for i := 0; i < n; i++ {
		if a[i]!=0 && int(math.Pow(10.0, 18.0))/a[i] <sum {
			fmt.Println(-1)
			return
		}
		sum *= a[i]
	}
	fmt.Println(sum)

}


Measured memory_bytes: 6340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
using namespace std;

#define N 100000

int n;
int a[N + 1];

int main() {
    cin >> n;
    for ( int i = 0; i <= N; i++ ) {
        a[i] = -1;
    }
    
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
    }
    
    for ( int i = 1, j = 1; i <= n + 1; i++ ) {
        if ( a[j] == -1 ) {
            cout << -1 << endl;
            return 0;
        } else if ( a[j] == 2 ){
            cout << i << endl;
            return 0;
        } else {
            j = a[j];
        }
    }
    
    cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 1000005;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    LL ans = 0;
    string s;   
    vector<LL> n(MXN, 0);
    cin >> s;
    s = '0' + s;
    FOR(i, 0, s.size())
    {
        n[i] = int(s[s.size() - 1 - i] - '0');
    }
    FOR(i, 0, s.size())
    {
        n[i + 1] += n[i] / 10;
        n[i] %= 10;
        if(n[i] > 5 || (n[i] == 5 && n[i + 1] >= 5))
        {
            ans += 10 - n[i];
            n[i] = 0;
            n[i + 1] += 1;
        }
        else
        {
            ans += n[i];
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 10140
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"
int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}
int n,m,q,a[55],b[55],c[55],d[55],ans=0;
map<vector<int>,int>mm;
void solve (vector<int>v)
{
    if(sz(v)==n)
    {
       
        int temp=0;
        f(i,1,q)
        {
            
            if(v[b[i]-1]-v[a[i]-1]==c[i])
                temp+=d[i];
            
        }
        ans=max(ans,temp);
        return;
    }
    if(mm.find(v)!=mm.end())
        return;
    mm[v]=1;
        for(int i=1;i<=m;i++)
        {
            if(v.empty() || i>=v[sz(v)-1])
            {
                v.pb(i);
 
                solve(v);
                v.pop_back();
            }
        }
    
}
int32_t main()
{
    speed upp
    cin>>n>>m>>q;
    f(i,1,q)
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    vector<int>v;
    solve(v);
    cout<<ans;
}

Measured memory_bytes: 17704
import numpy as np
i = input()
N = list(set(map(int, input().split(' '))))
def one_turn(l):
  l.sort()
  n = l[0]
  return np.array(list(set([n]+[ l[i]%n for i in range(1,len(l)) if ((l[i]%n != 0))])))

if len(set(N)) == 1 :
  print(N[0])
else :
  N = np.array(N)
  while True :
    N = one_turn(N)
    if N[0] == 1 :
      print(1)
      break
    if len(N) == 1 :
      print(N[0])
      break

Measured memory_bytes: 28644
n, a, b = map(int, input().split(' '))

max = 0
min = 0

if a > b:
  max = b
  min = b - (n - a)
else:
  max = a
  min = a - (n - b)

if min < 0:
  min = 0

# print(n, a, b)
print('{} {}'.format(max, min))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; i < (i64)(n); ++i)
#define WHOLE(x) std::begin(x), std::end(x)
#define LEN(a) int((a).size())

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

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename T>
istream &operator>>(istream &is, vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template <typename Container>
ostream &pprint(const Container &a, string_view sep = " ",
                string_view ends = "\n", ostream *os = nullptr) {
  if (os == nullptr) os = &cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  return pprint(a, ", ", "", &(os << "[")) << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

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

  int N;
  cin >> N;
  V<int> A(N), B(N);
  cin >> A >> B;
  reverse(WHOLE(B));
  int dupnum = -1, l = -1, r = -1;
  REP(i, N) {
    if (A[i] == B[i]) {
      assert(dupnum == -1 or dupnum == A[i]);
      dupnum = A[i];
      if (l == -1) l = i;
      r = i;
    }
  }
  if (dupnum != -1) {
    int head = 0, tail = N - 1;
    for (int i = l; i <= r; ++i) {
      if (B[head] != dupnum and A[head] != dupnum) {
        swap(B[head], B[i]);
        ++head;
        continue;
      }
      if (B[tail] != dupnum and A[tail] != dupnum) {
        swap(B[tail], B[i]);
        --tail;
        continue;
      }
      {  // Impossible.
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
  pprint(B);
}


Measured memory_bytes: 4768
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
long long  INF=1'0000'0000'0000'0000'00;
using namespace std;

int main(){

int K,X;
cin >> K>>X;

for(int i=max(X-K+1,-100'0000);i<X ;i++){
    cout<<i<<" ";
} 
cout<<X<<" ";

for(int i=X+1;i<min(100'0001,X+K);i++){
    cout<<i<<" ";
} 


 return 0;
}

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

int main() {

	int m,nmin,nmax;
	int *p;
	int a,n;
	int w=0;
	int answer[1000];
	int i;

	for(;;) {
		scanf("%d %d %d",&m,&nmin,&nmax);
		if(m==0&&nmin==0&&nmax==0)
			break;
		p=(int *)malloc(m * sizeof(int));
		for(i=0;i<m;i++)
			scanf("%d",&p[i]);

		a=0;
		n=0;
		for(i=nmin-1;i<nmax;i++) {
			if(a<=p[i]-p[i+1]) {
				a=p[i]-p[i+1];
				n=i+1;
			}
		}
		answer[w]=n;
		w++;
		free(p);
	}

	for(i=0;i<w;i++)
		printf("%d\n",answer[i]);

	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int n, d;
  cin >> n >> d;
  vector<vector<double> > x(n, vector<double>(d,0));

  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> x[i][j];
    }
  }

  int ans = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(i != j){
        int sum = 0;
        for(int z=0; z<d; z++){
          sum += pow( x[i][z] - x[j][z], 2);
        }
        double dist = sqrt(sum);
        if( int(dist) >= dist ) ans += 1;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (x >= a[i]) {
            x -= a[i];
            if (i == n-1 && x != 0) break;
            cnt++;
        } else break;
    }
    cout << cnt << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    cout << a/b << " " << a%b << " " << fixed << setprecision(9) << double(a)/(b) << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ------------------------------------------------- "<<endl
#define LL long long
#define DB double
#define LDB long double
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
inline int read(){
	int nm=0; bool fh=true; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return fh?nm:-nm;
}
#define M 200020
#define IT set<int>::iterator
int n,m,f[M],u[M],v[M],hd,tl,cnt;
int tot=0;
inline LL ID(int x,int y){if(x>y)swap(x,y);return x*(LL)(n+1)+y;}
set<int>to[M]; map<LL,int>CT;
inline int fd(int x){return f[x]==x?x:f[x]=fd(f[x]);}
inline void add(int x,int y){
	if((x=fd(x))==(y=fd(y))) return;
	to[x].insert(y),to[y].insert(x);
	if(++CT[ID(x,y)]==2) u[tl]=x,v[tl++]=y;
}
inline void del(int x,int y){
	x=fd(x),y=fd(y),CT[ID(x,y)]=0;
	to[x].erase(to[x].find(y));
	to[y].erase(to[y].find(x));
}
int main(){
	n=read();
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1,x,y;i<n;i++) x=read(),y=read(),add(x,y);
	for(int i=1,x,y;i<n;i++) x=read(),y=read(),add(x,y);
	for(int x=u[hd],y=v[hd];hd<tl;x=u[++hd],y=v[hd],++cnt){
		x=fd(x),y=fd(y); if(to[x].size()>to[y].size()) swap(x,y); del(x,y);
		for(IT it=to[x].begin();it!=to[x].end();it=to[x].begin()){
			int k=(*it); del(x,k),add(y,k);
		} f[x]=y;
	} puts((cnt<n-1)?"NO":"YES"); return 0;
}

Measured memory_bytes: 43520
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
using namespace std;


int main() {
	int x, y;
	int g1[] = { 1, 3, 5, 7, 8, 10, 12 };
	int g2[] = { 4, 6, 9, 11 };
	int g3[] = { 2 };
	int one=0, two=0, three=0;
	cin >> x >> y;
	for (int i = 0; i < 7; i++){
		if (x == g1[i] || y == g1[i]){
			one = 1;
		}
	}
	for (int i = 0; i < 4; i++){
		if (x == g2[i] || y == g2[i]){
			two = 1;
		}
	}
	if (x == 2 || y == 2){
		three = 1;
	}
	if (one + two + three == 1){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
	

	return 0;
}

Measured memory_bytes: 764
# AOJ 0002 Digit Number

sums = ARGF.each_line.map {|line| line.split(" ").map {|x| x.to_i} \
                           .reduce(0, :+)}
sums.map {|s|
  if s.zero?
    1
  else
    Math.log10(s).to_i + 1
  end
}.each {|d| puts d}

Measured memory_bytes: 6164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back

int main(){
    int n;
    cin>>n;
    int count[101]={};
    vector <string> str;
    int num=0;
    rep(i,n){
        string s;
        cin>>s;
        if(str.size()){
            bool flag=true;
            rep(j,str.size()){
                if(s==str[j]){
                    count[j]++;
                    flag=false;
                    break;
                }
            }
            if(flag){
                str.pb(s);
                count[num++]++;
            }
        }else{
            str.pb(s);
            count[num++]++;
        }

    }
    int m;
    cin>>m;
    rep(i,m){
        string s;
        cin>>s;
        if(str.size()){
            rep(j,str.size()){
                if(s==str[j]){
                    count[j]--;
                    break;
                }
            }
        }
    }
    sort(count,count+101);
    reverse(count,count+101);
    if(count[0]<0){
        count[0]=0;
    }
     cout<<count[0]<<endl;
    
    return 0;

}


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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	lli n, k = 2;
	cin >> n;
	
	vcL num(n);
	for (auto &x : num) cin >> x;
	
	vcL dp(n, 0);
	for (int i = 1; i < n; ++i) {
		dp[i] = I_MAX;
		for (int j = 1; i-j >= 0 and j <= k; ++j) {
			dp[i] = min(dp[i], dp[i - j] + abs(num[i] - num[i - j]));
		}
	}
	
	cout << dp[n - 1] << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}




Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>

static bool isBingo(const std::vector<std::vector<int> > tbl, const std::vector<int>& vals) {
  // generate bool table
  std::vector<std::vector<bool> > btbl;
  int rows = tbl.size();
  int cols = tbl.at(0).size();
  for (int i = 0; i < rows; i++) {
    std::vector<bool> row;
    for (int j = 0; j < cols; j++) {
      row.push_back(false);
    }
    btbl.push_back(row);
  }

  for (auto val : vals) {
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        if (val == tbl.at(i).at(j)) {
          btbl.at(i).at(j) = true;
        }
      }
    }
  }

  bool isBingo = false;
  // hori
  if (btbl.at(0).at(0) && btbl.at(0).at(1) && btbl.at(0).at(2)) isBingo = true;
  if (btbl.at(1).at(0) && btbl.at(1).at(1) && btbl.at(1).at(2)) isBingo = true;
  if (btbl.at(2).at(0) && btbl.at(2).at(1) && btbl.at(2).at(2)) isBingo = true;

  // vert
  if (btbl.at(0).at(0) && btbl.at(1).at(0) && btbl.at(2).at(0)) isBingo = true;
  if (btbl.at(0).at(1) && btbl.at(1).at(1) && btbl.at(2).at(1)) isBingo = true;
  if (btbl.at(0).at(2) && btbl.at(1).at(2) && btbl.at(2).at(2)) isBingo = true;

  // diag
  if (btbl.at(0).at(0) && btbl.at(1).at(1) && btbl.at(2).at(2)) isBingo = true;
  if (btbl.at(0).at(2) && btbl.at(1).at(1) && btbl.at(2).at(0)) isBingo = true;

  return isBingo;
}

int main(void) {

  std::vector<std::vector<int> > tbl;
  for (int i = 0; i < 3; i++) {
    std::vector<int> row(3);
    std::cin >> row.at(0) >> row.at(1) >> row.at(2);
    tbl.push_back(row);
  }


  int n;
  std::cin >> n;

  std::vector<int> vals;
  for (int i = 0; i < n; i++) {
    int val;
    std::cin >> val;
    vals.push_back(val);
  }

  std::cout << (isBingo(tbl, vals) ? "Yes" : "No") << std::endl;

  return 0;
}


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

int main() {
    int n; cin >> n;
    ll ans = 1;
    rep(i, 0, n) {
        ll x;
        cin >> x;
        ans = ans / __gcd(ans, x) * x;
    }
    cout << ans << endl;
}

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

int main(){
    string S;
    cin >> S;

    for (int i = 0; i < 3; i++){
        cout << S[i];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3608
/*ID:PROG:LANG:*/
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 5005
using namespace std;
struct Edge{
	int to,nex;Edge(int _=0,int __=0){to=_,nex=__;}
}e[MAXN<<1];
int n,ans,cnt,rt,S,hd[MAXN],sz[MAXN],dp[2][MAXN];
LL jc[MAXN],njc[MAXN];
int rd(){
	int x=0,tp=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
void adde(int x,int y){e[++cnt]=Edge(y,hd[x]);hd[x]=cnt;}
LL quick_mod(LL a,LL x){LL res=1;while(x){if(x&1)(res*=a)%=MOD;(a*=a)%=MOD,x>>=1;}return res;}
LL C(int n,int m){if(n<m)return 0;return jc[n]*njc[m]%MOD*njc[n-m]%MOD;}
LL C2(int n,int m){LL t=C(n,m);return t*t%MOD;}
void dfs(int now,int fa){
	sz[now]=1;int mx=0;
	for(int i=hd[now];i;i=e[i].nex)
		if(e[i].to!=fa)
			dfs(e[i].to,now),sz[now]+=sz[e[i].to],mx=max(mx,sz[e[i].to]);
	mx=max(mx,n-sz[now]);
	if(!rt && mx*2<=n)rt=now;
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("1.out","w",stdout);
	int x,y;
	n=rd();
	jc[0]=njc[0]=1;
	for(int i=1;i<=n;i++)jc[i]=jc[i-1]*i%MOD;
	njc[n]=quick_mod(jc[n],MOD-2);
	for(int i=n-1;i;i--)njc[i]=njc[i+1]*(i+1)%MOD;
	for(int i=1;i<n;i++){
		x=rd(),y=rd();
		adde(x,y),adde(y,x);
	}
	dfs(1,0),dfs(rt,0);
	dp[0][0]=1;
	bool now=1,las=0;
	for(int i=hd[rt];i;i=e[i].nex){
		for(int j=0;j<=S;j++)
			if(dp[las][j])
				for(int k=0;k<=sz[e[i].to];k++)
					(dp[now][j+k]+=1ll*dp[las][j]*C2(sz[e[i].to],k)%MOD*jc[k]%MOD)%=MOD;
		S+=sz[e[i].to];
		memset(dp[las],0,sizeof(dp[las]));
		now^=1,las^=1;
	}
	for(int i=0;i<=n;i++){
		if(i&1)(ans-=dp[las][i]*jc[n-i]%MOD)%=MOD;
		else (ans+=dp[las][i]*jc[n-i]%MOD)%=MOD;
	}
	printf("%d\n",(ans+MOD)%MOD);
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//Get the highest value and key from a map.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int r, D, x;
void solve(int i, ll sum) {
  if (i == 10) return;
  ll v = r * sum - D;
  cout << v << endl;
  solve(i + 1, v);
}

int main() {
  cin >> r >> D >> x;

  solve(0, x);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

const int INF = 1000000;

struct node
{
	int num;
	int place;  
};

int partition(node *A,int p,int r)
{
	int j,temp;
	node x;

	x = A[r];
	j = p-1;

	for(int i = p; i < r; i++)
	{
		if (A[i].num <= x.num)
		{
			j++;
			temp = A[i].num;
			A[i].num = A[j].num;
			A[j].num = temp;
		}
	}

	temp = A[j+1].num;
	A[j+1].num = A[r].num;
	A[r].num = temp;

	return j+1;
}

void quicksort(node *A,int p,int r)
{
	int q;

	if (p < r)
	{
		q = partition(A,p,r);
		quicksort(A,p,q-1);
		quicksort(A,q+1,r);
	}
}


int main()
{
	int n,sum,minall,mini,sol,cnt,j;
	node a[1000] = {0},b[1000] = {0};

	sol = 0;
	minall = INF;

	scanf("%d", &n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i].num);
		a[i].place = i;
		b[i] = a[i];
		b[i].place = i;

		if (minall > a[i].num)
		{
			minall = a[i].num;
		}
	}

	quicksort(b,0,n-1);

	for(int i = 0; i < n; i++)
	{
		sum = 0;

		if (a[i].num >= 0)
		{
			sum += a[i].num;
			mini = a[i].num;
			cnt = 1;
			j = i;

			while(b[a[j].place].num != a[i].num)
			{
				for(int k = 0; k < n; k++)
				{
					if (a[k].num == b[a[j].place].num)
					{
						j = k;
						sum += a[k].num;
						cnt++;

						if (mini > a[k].num)
						{
							mini = a[k].num;
						}

						a[k].num = -1;
						break;
					}
				}
			}

			a[i].num = -1;

			sol += min(sum + mini * (cnt -2), sum + mini + (cnt + 1) * minall);
		}
	}

	printf("%d\n", sol);


	return 0;
}
	

Measured memory_bytes: 3244
s=input()
n=4-1
for i in range(1<<n):
    lst=list(s)
    for j in range(n):
        if ((i>>j)&1):
            lst.insert(2*j+1,"+")
            # print(lst)
        else:
            lst.insert(2*j+1,"-")
    if(eval("".join(lst))==7):
        print(("".join(lst))+"=7")
        break

Measured memory_bytes: 9012
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll mod = 998244353;
const ll base_num = (1 << 3) - 1;

ll cnt[1 << 3];

ll color_id(char c) {
    if(c == 'R') return 0;
    if(c == 'G') return 1;
    if(c == 'B') return 2;
    assert(false);
}

ll decide_idx(char c) {
    ll id = color_id(c);
    ll high = base_num ^ (1ll << id);
    if(cnt[high]) return high;
    for(ll i = 0; i <= 2; i++) {
        if(id == i) continue;
        ll mid = 1ll << i;
        if(cnt[mid]) return mid;
    }
    return 0;
}

int main() {
    ll N;
    string S;
    cin >> N >> S;
    ll ans = 1;
    for(char c : S) {
        ll id = color_id(c);
        ll idx = decide_idx(c);
        ll add_idx = idx | (1ll << id);
        if(idx == 0) {
            cnt[add_idx]++;
        } else {
            (ans *= cnt[idx]) %= mod;
            cnt[idx]--;
            cnt[add_idx]++;
        }
    }
    for(ll i = 1; i <= N; i++) (ans *= i) %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 720
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int counter = sc.nextInt();
    
    int answer = 0;
    for(int i = 0;i<counter;i++){
      answer += check(sc.nextInt());
    }
    System.out.println(answer);
  }
  
  public static int check(long number){
    int ans = 0;
    while(number%2 == 0) {
      ans++;
      number = number/2;
    }
    return ans++;
  }
}

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

int main(){
    char op;
    int a, b;
    
    while(cin >> a >> op >> b, op != '?'){
        switch(op){
            case '+':
                cout << a + b << endl;
                break;
            case '-':
                cout << a - b << endl;
                break;
            case '/':
                cout << a / b << endl;
                break;
            case '%':
                cout << a % b << endl;
                break;
            case '*':
                cout << a * b << endl;
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
const int maxn = 1e5 + 5;

int main()
{
    ios::sync_with_stdio(false);
    int a , b; cin >> a >> b;
    cout << b + 100 * (10 - min(10 ,a)) << endl;
    return 0;
}


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

int main()
{
    int N, T, A;
    int index = 0;

    cin >> N;
    cin >> T >> A;
    double dif = 1000000;
    for (int i = 0; i < N; i++)
    {
        int height;
        double tempora, old;
        old = dif;
        cin >> height;
        tempora = T - height * 0.006;
        dif = min(dif, abs(A - tempora));
        if (old != dif)
        {
            index = i;
        }
    }

    cout << index + 1;

    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

using ll = long long;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	string s;
	cin >> n >> k >> s;
	rep(i, n) {
	  if (i == k - 1) cout << char(s[i] - 'A' + 'a');
	  else cout << s[i];
	}
	cout << endl;
	
    return 0;
}



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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

bool pairCompare(const P &fItem, const P &sItem)
{
    return fItem.second < sItem.second;
}


int main(){
    // (x,y)
    int n;
    while(cin >> n,n) {
        vector< P > v;
        v.pb(mp(0,0));
        int id,dig;
        rep(i,n - 1){
            cin >> id >> dig;
            if(dig == 0) {
                v.pb(mp(v[id].first - 1,v[id].second));
            }else if(dig == 1) {
                v.pb(mp(v[id].first,v[id].second - 1));

            }else if(dig == 2) {
                v.pb(mp(v[id].first + 1,v[id].second));

            }else{
                v.pb(mp(v[id].first,v[id].second + 1));
            }
        }
        sort(v.begin(),v.end());
        cout << abs(v[0].first - v[n - 1].first) + 1 << " ";

        sort(v.begin(), v.end(),pairCompare);
        cout << abs(v[0].second - v[n - 1].second) + 1 << endl;
    }
    return 0;

}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  ll n;
  cin >> n;
  vl v(n);
  for (ll i=0; i<n; i++){
    cin >> v[i];
    v[i] -= i+1;
  }
  sort(rng(v));
  ll ans=0;
  ll ans1=0;
  ll ans2=0;
  if(n%2==1){
    for (int i=0; i<n; i++){
      ans += abs(v[i]-v[n/2]);
    }
  }
  else {
    for (int i=0; i<n; i++){
      ans1 += abs(v[i]-v[n/2]);
      ans2 += abs(v[i]-v[n/2-1]);
    }
    ans = min(ans1, ans2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std ;
#define N 100010

int n;
int main(){
	scanf("%d",&n) ;
	vector <int> l(n+1),r(n+1) ;
	for (int i=0;i<n;i++) scanf("%d%d",&l[i],&r[i]) ;
	sort(l.rbegin(),l.rend()) ;//反向迭代器
	sort(r.begin(),r.end()) ;
	long long ans=0 ;
	for (int i=0;i<=n;i++){
		if (l[i]<r[i]) break ;
		ans+=l[i]-r[i] ;
	}
	ans*=2 ;
	printf("%lld\n",ans) ;
}

Measured memory_bytes: 1024
'use strict';

function Main(input) {
	let N = Number(input);
	let sum = 0;
	for (let i = 1; i < (N + 1); i++) {
	  if ((i % 3 !== 0) && (i % 5 !== 0)) {
	    sum += i;
	  }
	}
	console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    int s;
    map<int, int> mp;
    cin >> s;

    mp[s] = 1;
    for (int i = 2;; i++)
    {
        if (s % 2 == 0)
        {
            s /= 2;
        }
        else
        {
            s = 3 * s + 1;
        }

        if (mp[s] == 0)
        {
            mp[s] = 1;
        }
        else
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
double p[10],q[10];
void input(double* a){
  REP(i,6) cin>>a[i],a[i]/=100;
}

typedef pair<double,double> pd;
pd doit(pd a,pd b){
  if(a.fr>b.fr) swap(a,b);
  if(a.sc<=b.sc) return mp(-1,-1);
  double d1=b.fr-a.fr,d2=a.sc-b.sc;
  return mp(d1/(d1+d2),(a.fr*d2+a.sc*d1)/(d1+d2));
}
pd ar[1005];

double solve(double a){
  double res=0;
  REP(i,1<<6) chmax(res,ar[i].fr*(1-a)+a*ar[i].sc);
  return res;
}
int main(){
  input(p);input(q);

  REP(i,1<<6){
    double x=0,y=0;
    REP(j,6){
      if(i>>j&1) x+=q[j];
      else y+=p[j];
    }
    ar[i]=mp(x,y);
  }
  const int m =1<<6;
  double res=1;
  REP(i,m) REP(j,m){
    pd cross=doit(ar[i],ar[j]);
    chmin(res,solve(cross.fr));
  }
  chmin(res,solve(0));
  chmin(res,solve(1));

  printf("%.10f\n",res);
  return 0;
}





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

int main() {
    int n, t;
    cin >> n >> t;
    int64_t ans=t;
    vector<int> vec(n);
    for(int i=0; i<n; i++) cin >> vec.at(i);
    for(int i=0; i<n-1; i++) {
        if(t+vec.at(i)>vec.at(i+1)) ans += (vec.at(i+1)-vec.at(i));
        else ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#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() {
  vector<int>a(3);
  int odd = 0;
  rep(i,3){
    cin >> a[i];
    if(a[i]%2 == 0) odd++;
  }
  sort(a.begin(),a.end());
  if(odd == 0 || odd == 3) cout << (2*a[2]-a[1]-a[0])/2 << endl;
  else{
    if(odd == 1){
      rep(i,3){
        if(a[i]%2 == 1) a[i]++;
      }
    }
    if(odd == 2){
      rep(i,3){
        if(a[i]%2 == 0) a[i]++;
      }
    }
    cout << (2*a[2]-a[1]-a[0])/2+1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    cout << n * 800 - 200 * (n/15) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repj(i, j, n) for (int i = (int)(j); i < (int)(n); ++i)
int main(){
  string s;
  int c[3][3];
  int sum=0;
  rep(i,3)rep(j,3){
     cin>>c[i][j];
     sum+=c[i][j]; 
  }
  if(sum%3){
     cout<<"No"; 
  }else{
     int d[3][3];
     rep(i,3){
        int a=0;
        rep(j,2)
          repj(k,j+1,3)
            d[i][a++]=c[i][j]-c[i][k];
     }
     rep(i,3)
        rep(j,2)
          repj(k,j+1,3)
          if(d[j][i]!=d[k][i]){
             cout<<"No";
             return 0; 
          }
    rep(i,3){
        int a=0;
        rep(j,2)
          repj(k,j+1,3)
            d[i][a++]=c[j][i]-c[k][i];
     }
     rep(i,3)
        rep(j,2)
          repj(k,j+1,3)
          if(d[j][i]!=d[k][i]){
             cout<<"No";
             return 0; 
          }
    cout<<"Yes";
  }
  
  return 0;
}

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("in_b.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    int d[100];

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

    sort(d, d+N, greater<int>());

    int cnt = 1;
    for (int i = 1; i < N; i++)
    {
        if (d[i-1] > d[i])
        {
            cnt++;
        }
    }

    cout << cnt;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  string ans="APPROVED";
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a%2==0){
      if(!((a%3==0)||(a%5==0))){
        ans="DENIED";
      }
    }
  }
  
  cout<<ans<<endl;  
}


Measured memory_bytes: 256