akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <stdio.h>

using namespace std;

int main() {

	int q;
	cin >> q;
	vector<string> s(q);
	for (int i = 0; i < q; i++) cin >> s[i];

	// 16進数
	vector<double> ans(q, 0.0);

	vector<vector<int>> beg(q, vector<int>(32, 0));

	// 2進数に直す？
	for (int i = 0; i < q; i++) {
		//cout << i << endl;
		for (int j = 7; j >= 0; j--) {
			int value;

			switch (s[i][j]) { // めちゃきたない
			case 'a':
				value = 10;
				break;
			case 'b':
				value = 11;
				break;
			case 'c':
				value = 12;
				break;
			case 'd':
				value = 13;
				break;
			case 'e':
				value = 14;
				break;
			case 'f':
				value = 15;
				break;
			default:
				value = s[i][j] - '0';
				break;
			}
			//cout << value << endl;

			int tmp = 8;
			for (int k = 0; k < 4; k++) {
				if (value >= tmp) {
					beg[i][(7 - j) * 4 + 3 - k] = 1;
					value -= tmp;
				}
				tmp /= 2;
			}
		}
	}

	/*
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 32; j++) {
			if (j % 4 == 0) cout << " ";
			cout << beg[i][31 - j];
		}
		cout << endl;
	}*/

	vector<bool> syou(q, false);

	// こっから計算
	for (int i = 0; i < q; i++) {
		double cnt = 1.0;
		for (int j = 7; j >= 0; j--) {
			// 小数点の計算
			if (beg[i][j] == 1) {
				ans[i] += cnt;
				if(j != 7)
					syou[i] = true;
			}
			cnt *= 0.5;
		}

		cnt = 2.0;
		for (int j = 8; j < 31; j++) {
			// 整数の計算
			if (beg[i][j] == 1) {
				ans[i] += cnt;
			}
			cnt *= 2.0;
		}

		// 最後に符号
		if (beg[i][31] == 1)
			ans[i] *= -1.0;
	}

	// .0が必要
	for (int i = 0; i < q; i++) {
		if (beg[i][0] == 1) printf("%.7lf\n", ans[i]);
		else if (beg[i][1] == 1) printf("%.6lf\n", ans[i]);
		else if (beg[i][2] == 1) printf("%.5lf\n", ans[i]);
		else if (beg[i][3] == 1) printf("%.4lf\n", ans[i]);
		else if (beg[i][4] == 1) printf("%.3lf\n", ans[i]);
		else if (beg[i][5] == 1) printf("%.2lf\n", ans[i]);
		else printf("%.1lf\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}
#define imax 10000005
ll arr[imax];
void pre(){
  for(ll i=1;i<imax;i++){
    arr[i]=i;
  }
  
  for(ll i=2;i*i<imax;i++){
    if(arr[i]==i){
        for(int j=i*i;j<imax;j+=i){
            arr[j]=i;
        }
    }
  }
  return ;
}
ll find(ll num){
  map<ll,ll>mymap;
  while(num>1){
    mymap[arr[num]]++;
    num=num/arr[num];
  }
  ll ans=1;
  for(auto k:mymap){
    ans=ans*(k.second+1);
  }
  return ans;

}
int main(){
FIO
 pre();
 ll n;
 cin>>n;
 ll ans=0;
 for(ll i=1;i<=n;i++){
    ll s=find(i);
    ans+=(i*s);
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 81784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a,ans;
vector<pair<ll,ll> > v;
int main() {
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>a;
		v.push_back({a,i});
	}
	sort(v.begin(),v.end());
	for(auto i : v)
		cout<<i.second<<" ";
}

Measured memory_bytes: 2544
/*input
5
1 1 2 2
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
vector<int> v[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP1(i,n-1){
        int x;
        cin>>x;
        --x;
        v[x].pb(i);
    }
    REP(i,n){
        cout<<sz(v[i])<<'\n';
    }
}


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    int n,k;cin>>n>>k;
    if(k>=n-1){
        long long ans=0;
        for(int i=0;i<n;++i){
            ans+=COM(n,i+1)*COM(n-1,i);
            ans%=MOD;
        }
        cout<<ans<<endl;
    }
    else{
        long long ans=0;
        for(int i=n-k-1;i<n;++i){
            ans+=COM(n,i+1)*COM(n-1,i);
            ans%=MOD;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 12160
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    x = lmis()
    print(x.index(0)+1)
    

main()



Measured memory_bytes: 9920
from itertools import*
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
def f():
 for d,e in list(combinations(a,2)):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[k]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


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

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

  int ub= min(N+1, INT_MAX);
  int lb= K;
  double Dnumer;
  double Ddenom= 1.0*(double)N;
  double ans= 0.0;
  while(ub > 1){
    int Nlen= max(ub-lb, 0);
    Dnumer= (double)Nlen;

    ans+= Dnumer/ Ddenom;

    ub= min(N+1, lb);
    lb= (lb+1)/2;
    Ddenom*= 2.0;
  }

  cout << fixed;
  cout << setprecision(9) << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

void dfs(const int v, std::vector<bool> &visited, std::vector<int> &res,
         const std::vector<std::vector<std::pair<int, int>>> &adj) {
  visited[v] = true;
  for (int k = 0; k < adj[v].size(); ++k) {
    int c, w;
    std::tie(c, w) = adj[v][k];
    if (visited[c])
      continue;
    res[c] = (w % 2 == 0) ? res[v] : 1 - res[v];
    dfs(c, visited, res, adj);
  }
}

int main() {
  // Input
  int N;
  std::cin >> N;
  std::vector<std::vector<std::pair<int, int>>> adj(N + 1);
  for (int i = 1; i <= N - 1; ++i) {
    int u, v, w;
    std::cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }

  // Main
  std::vector<bool> visited(N + 1);
  std::vector<int> res(N + 1, -1);
  res[1] = 0;
  dfs(1, visited, res, adj);

  // Output
  for (int i = 1; i <= N; ++i)
    std::cout << res[i] << std::endl;

  return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  ll a,b,n;cin >> a >> b >> n;
  ll s=min(n,b-1);
  cout << a*s/b << endl;
}

Measured memory_bytes: 3588
import bisect

n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()

ans = 0
for b in li_b:
    aa = bisect.bisect_left(li_a, b)
    cc = len(li_c) - bisect.bisect_right(li_c, b)
    ans += aa * cc

print(ans)


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

int main() {
  int h, w, dh, dw;
  cin >> h >> w >> dh >> dw;
  int ans;
  ans = h * w;
  ans -= dh * w + dw * h;
  ans += dh * dw;
  cout << ans << endl;

  return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll dp[100009][2]; 

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n;
    cin >> n;
    vector<ll> A(n);
    REP(i, n) cin >> A[i];
    dp[0][0] = A[0];
    dp[0][1] = -A[0];
    FOR(i, 1, n-1) {
        dp[i][0] = max(dp[i-1][1] - A[i], dp[i-1][0] + A[i]);
        dp[i][1] = max(dp[i-1][0] - A[i], dp[i-1][1] + A[i]);
    }
    cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main() {
    cin>>N;
    vec h(N);
    rep(i,N) cin>>h.at(i);
    ll ans = 0;
    bool cansee;
    rep(i,N){
        cansee = true;
        rep(j,i){
            if(h.at(j)>h.at(i)){
                cansee = false;
                break;
            }
        }
        if(cansee) ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#python3
INF = int(1e9)
def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    b.insert(0, INF)
    b.append(INF)
    ans = 0
    for i in range(len(b)-1):
        ans += min(b[i], b[i+1])
    print(ans)
main()


Measured memory_bytes: 3060
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std ;

#define all(x) x.begin() , x.end()

#define int ll

#define _sz(x) (int)x.size()
#define F first
#define S second
#define PB push_back

#define debug(x) cerr << #x << " = " << ans << "\n"

typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;

const int N = 5 * 1000 + 19 ;
const int inf = 1e9 + 19 ;
const ll INF = 1e18 + 19 ;

int n ;
pii p[N] ;

int32_t main() {
      ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
      cin >> n;
      for (int i = 0 ; i < n ; i ++)
              cin >> p[i].F >> p[i].S ;
      sort(p , p + n) ;
      ld ans = 0 , fact = 1 ;
      do {
              for (int i = 0 ; i < n - 1 ; i ++) {
                      ld d1 = p[i + 1].F - p[i].F , d2 = p[i + 1].S - p[i].S ;
                      ld d3 = sqrt((d1 * d1) + (d2 * d2)) ;
                      ans += d3 ;
              }
      } while (next_permutation(p , p + n)) ;
      for (int i = 1 ; i <= n ; i ++)
              fact *= i ;
      debug(ans) ;
      debug(fact) ;
      cout << fixed << setprecision(8) << ans / fact ;
      return 0;
}

/* THINGS TO CHECK */

// Runtime -> Checked
// Overflows -> Checked
// Time Complexity -> n + m
// Memory Complexity -> OK

/* READ PROBLEM STATEMENT CAREFULLY */


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

use std::collections::BTreeMap;

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [i64; n],
  }
  let mut map = BTreeMap::new();
  let mut a: Vec<_> = a.into_iter().enumerate().map(|(i, x)| (x, i)).collect();
  a.sort();
  let mut mini = n;
  for &(x, i) in a.iter().rev() {
    mini = cmp::min(mini, i);
    let e = map.entry(x).or_insert((i, 0));
    e.0 = cmp::min(e.0, mini);
    e.1 += 1;
  }
  let mut ans = vec![0; n];
  let mut prev = 0;
  let mut count = n;
  for (&size, &(front, c)) in &map {
    ans[front] += count as i64 * (size - prev);
    prev = size;
    count -= c;
  }
  for &x in &ans {
    puts!("{}\n", x);
  }
}


Measured memory_bytes: 17404
N = int(input())
num_list = list(map(int, input().split()))
l = sorted(num_list)

count = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i < j and j < k:
                if l[i]<l[j] and l[j]<l[k] and l[i]+l[j]>l[k]:
                    count += 1
print(count)

Measured memory_bytes: 9140
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]

M = 2*N+2
s = 2*N
g = 2*N+1
E = [[False]*M for _ in range(M)]

for ir, (rx, ry) in enumerate(R):
    for ib, (bx, by) in enumerate(B):
        if rx<bx and ry<by:
           E[ir][ib+N] = True

for i in range(N):
    E[s][i] = True
    E[i+N][g] = True

while True:
    K = [None]*M
    K[s] = -1
    queue = [s]
    while queue and (K[g] is None):
        queue_new = []
        for q in queue:
            for e, f in enumerate(E[q]):
                if not f: continue
                if K[e] is not None: continue
                K[e] = q
                queue_new.append(e)

        queue = queue_new

    #print(K)
    #input("aa")

    if K[g] is None:
        break
    else:
        i = g
        while K[i]!=-1:
            #print(i,end=' ')
            E[K[i]][i] = False
            E[i][K[i]] = True
            i = K[i]

ans = 0
for ir in range(N):
    if not E[s][ir]: ans += 1
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define L long long
#define ff first
#define ss second
using namespace std;
const int N=100005;
int a[N],b[N],sum[N];
int n,K,idx=0,onz,zero;

int main() {
cin>>n>>K;
string x;
cin>>x;
for(int i=0;i<n;i++)
{
    if(x[i]=='0')
    {
        if(onz)idx++,b[idx]=1,sum[idx]=sum[idx-1]+onz,onz=0;
        zero++;
    }
    else
    {
        if(zero)idx++,b[idx]=0,sum[idx]=sum[idx-1]+zero,zero=0;
        onz++;
    }
}
if(onz)idx++,b[idx]=1,sum[idx]=sum[idx-1]+onz;
else if(zero)idx++,b[idx]=0,sum[idx]=sum[idx-1]+zero;
int k=K,y;
n=idx;
int Max=0;
for(int i=1;i<=n;i++)
{
  if(b[i]==0)
  {
      int t=k-1;
      y=min(i+2*t+1,n);
      Max=max(Max,sum[y]-sum[i-1]);
  }
  else
  {
      y=min(i+2*k,n);
      Max=max(Max,sum[y]-sum[i-1]);
  }
}
cout<<Max<<endl;
//1010
return 0;
}


Measured memory_bytes: 1280
using static System.Math;
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var n = int.Parse(line[0]);
		var a = int.Parse(line[1]);
		var b = int.Parse(line[2]);
		Console.WriteLine(Min(n * a, b));
	}
}

Measured memory_bytes: 13140
// include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k>>s;
  if (s.size()<=k){
  cout<<s<<endl;
  }else{
    string ans;
    ans=s.substr(0,k)+"...";
    cout<<ans<<endl;
  }
  return 0;
}


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

const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];


void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long N, A, B, K;

int main() {
    COMinit(); // テーブルを作る

    cin >> N >> A >> B >> K;
    long long res = 0;
    for (long long a = 0; a <= N; ++a) { // A の個数を全探索
        long long rem = K - a * A;
        if (rem % B != 0) continue;
        long long b = rem / B;
        if (b > N) continue;
        long long tmp = COM(N, a) * COM(N, b) % MOD;
        res += tmp;
        res %= MOD;
    }

    cout << res << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int MAX = 2000;
vector<int> G[MAX];

int calc(int v, int prev, int K, int d = 0) {
	int res = d <= K;
	for (auto to : G[v]) if (to != prev) {
		res += calc(to, v, K, d + 1);
	}
	return res;
}

int main()
{
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B; --A, --B;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	if (K % 2 == 0) {
		int ma = 0;
		for (int i = 0; i < N; i++) {
			ma = max(ma, calc(i, -1, K / 2));
		}
		cout << N - ma << endl;
		return 0;
	}
	K /= 2;
	int ma = 0;
	for (int i = 0; i < N; i++) {
		int all = 1, d = 0;
		for (auto to : G[i]) {
			int a = calc(to, i, K, 1), b = calc(to, i, K + 1, 1);
			all += a;
			d = max(d, b - a);
		}
		ma = max(ma, all + d);
	}
	cout << N - ma << endl;
	return 0;
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    if(s.size() == 2){
        ppp(s);
    }
    else{
        reverse(s.begin(), s.end());
        ppp(s);
    }



    return 0;
}


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

const int MOD = 1000000007;

lint F(lint a, lint b) {
    lint da = log10(a);
    lint db = log10(b);
    return max(da+1, db+1);
}

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

    lint res = 1LL << 40;

    for (lint i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            res = min(res, F(i, N/i));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n;
	cin >> n;
	int a[n], b[n], c[n-1];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	int ans = b[a[0] - 1];
	for (int i = 1; i < n; i++) {
		ans += b[a[i] - 1];
		if (a[i] == a[i-1] + 1) {
			ans += c[a[i-1] - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;

int sz;

void upd(vector<int>& seg, int l, int r, int val) {
    for (l+=sz, r+=sz; l<r; l/=2, r/=2) {
        if (l&1) seg[l] = min(seg[l], val), l++;
        if (r&1) --r, seg[r] = min(seg[r], val);
    }
}

int query(vector<int>& seg, int i) {
    int ans;
    for (ans=seg[i+=sz]; i/=2; ) ans = min(ans, seg[i]);
    return ans;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, q;
    cin >> n >> q;

    sz = 1 << (32-__builtin_clz(n-1));
    vector<int> seg(2*sz, n-1), seg2(2*sz, n-1);

    ll ans = (n-2) * (n-2);

    for (int i=0; i<q; i++) {
        int x, y;
        cin >> x >> y;
        if (x == 1) {
            int duh = query(seg, y-1);
            ans -= duh-1;
            upd(seg2, 0, duh, y-1);
        } else {
            int duh = query(seg2, y-1);
            ans -= duh-1;
            upd(seg, 0, duh, y-1);
        }
    }
    cout << ans << "\n";
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i=0;i<H;i++){
    cin >> S.at(i);
  }
  vector<vector<int>> pos(0, vector<int>(2));
  vector<vector<int>> A(H, vector<int>(W, 0));
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      if (S.at(i).at(j) == '#'){
        A.at(i).at(j) = 1;
        pos.push_back({i, j});
      }
    }
  }
  int n = pos.size();
  int point = 0;
  int cnt = -1;
  int x, y;
  while (n != point){
    cnt += 1;
    for (int i = point;i<n;i++){
      x = pos.at(i).at(0);
      y = pos.at(i).at(1);
      if (x > 0){
        if (A.at(x-1).at(y) == 0){
          A.at(x-1).at(y) = 1;
          pos.push_back({x-1, y});
        }
      }
      if (x < H - 1){
        if (A.at(x+1).at(y) == 0){
          A.at(x+1).at(y) = 1;
          pos.push_back({x+1, y});
        }
      }
      if (y > 0){
        if (A.at(x).at(y-1) == 0){
          A.at(x).at(y-1) = 1;
          pos.push_back({x, y-1});
        }
      }
      if (y < W-1){
        if (A.at(x).at(y+1) == 0){
          A.at(x).at(y+1) = 1;
          pos.push_back({x, y+1});
        }
      }
    }
    point += n - point;
    n = pos.size();
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 60964
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;


int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int N = 5;

	//注文してから届くまでの時間
	vector<int> Time = { a, b, c, d, e };
	//注文してから次に注文出来るまでの時間
	vector<int> nextTime(N);
	for (int i = 0; i < N; i++)
	{
		if (Time[i] % 10 == 0) nextTime[i] = Time[i];
		else nextTime[i] = Time[i] - Time[i] % 10 + 10;

		//nextTime[i] = (Time[i] + 9) / 10 * 10;
	}

	int BestTime = 999999999; //大きい値を適当に入れる
	//最後に注文するものを全通り計算
	for (int i = 0; i < N; i++)
	{
		int SumTime = 0;
		for (int j = 0; j < N; j++)
		{
			if (i == j) {
				//最後の処理
				SumTime += Time[j];
			}
			else {
				//最後以外の処理
				SumTime += nextTime[j];
			}
		}
		BestTime = min(BestTime, SumTime);
		//if (BestTime > SumTime) BestTime = SumTime;
	}

	cout << BestTime << endl;
}



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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	map<int, int>m;
	int i, j, k, s;

	cin >> s;
	k = 1;
	i = s;
	while (m.find(i) == m.end()) {
		m.insert(make_pair(i, k));
		k++;
		if (i % 2 == 0) {
			i /= 2;
		}
		else {
			i = i * 3 + 1;
		}
	}

	cout << k;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def solve():
    ofs = 700
    h, w = map(int, readline().split())
    A = [list(map(int, readline().split())) for i in range(h)]
    B = [list(map(int, readline().split())) for i in range(h)]
    dp = [0 for _ in range(w+1)]
    x = abs(A[0][0]-B[0][0])
    dp[0] = 1 << ofs

    for i in range(h):
        for j in range(w):
            x = abs(A[i][j]-B[i][j])
            t = dp[j] | dp[j-1]
            dp[j] = (t << x) | (t >> x)

    b = list(map(lambda s: s == '1', list(bin(dp[w-1])[-ofs-1:-ofs+100])))
    for i, s in enumerate(b):
        if(s):
            print(i)
            return


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)

int main(){
    int n; cin>>n;
    vector<int> a(n);
    bool differ = true;
    rep(0,i,n){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());

    rep(0,i,n-1){
        if(a.at(i)==a.at(i+1)){
            differ = false;
            break;    
        }
    }

    if(differ)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;    
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, b, a) for(int i = (b); i >= (a); i--)
using namespace std;
const int N = 2005;
int n, m, q, a[N][N], sum1[N][N], sum2[N][N], sum[N][N];
char s[N];
int main(){
    scanf("%d%d%d", &n, &m, &q);
    rep(i, 1, n) {
        scanf("%s", s);
        rep(j, 1, m) a[i][j] = s[j - 1] - '0';
    }
    rep(i, 1, n) rep(j, 1, m) {
        sum1[i][j] = sum1[i][j-1] + sum1[i-1][j] - sum1[i-1][j-1] + (a[i][j] && a[i][j-1]),
        sum2[i][j] = sum2[i][j-1] + sum2[i-1][j] - sum2[i-1][j-1] + (a[i][j] && a[i-1][j]),
        sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j];
    }
    rep(i, 1, q){
        int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int num1 = y1 == y2 ? 0 : sum1[x2][y2] - sum1[x2][y1] - sum1[x1-1][y2] + sum1[x1-1][y1];
        int num2 = x1 == x2 ? 0 : sum2[x2][y2] - sum2[x2][y1-1] - sum2[x1][y2] + sum2[x1][y1-1];
        //cout << num1 << " " << num2 << endl;
        printf("%d\n", sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1] - num1 - num2);
    }
    return 0;
}

Measured memory_bytes: 64640
n, k = map(int, input().split())
x = list(map(int, input().split()))
minX = abs(x[0]) * 2 + abs(x[len(x)-1])
for i in range(n-k+1):
    if x[i] * x[i+k-1] <= 0:
        minX = min(minX, min(abs(x[i]), abs(x[i+k-1]))
                   + abs(x[i]) + abs(x[i+k-1]))
    else:
        minX = min(minX, max(abs(x[i]), abs(x[i+k-1])))
print(minX)


Measured memory_bytes: 62576
#include<stdio.h>
#include <math.h>

typedef long long ll;

int main() {
	int n, x, t;
	scanf("%d %d %d", &n, &x, &t);
	
	int times = (n + x - 1) / x;
	int ans = t * times;
	printf("%d", ans);
	
	
	return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=1e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline ll read(){
    ll x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
ll n,k,p[N],Ans=LONG_LONG_MIN,c[N],f[N][35],g[N][35];
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	n=read(),k=read();
	for(int i=1;i<=n;i++) p[i]=read(); 
	for(int i=1;i<=n;i++) c[i]=read(); 
	for(int i=1;i<=n;i++) f[i][0]=p[i],g[i][0]=c[p[i]];
/*	for(int i=1;i<=30;i++) {
		for(int j=1;j<=n;j++){
			g[j][i]=g[j][i-1]+g[f[j][i-1]][i-1];
			f[j][i]=f[f[j][i-1]][i-1];
		}
	}*/
	for(int i=1;i<=n;i++){
		ll T=0,K=k-1,ans=0,p=i,cnt=1;
		p=f[p][0];
		ans+=c[p];
		Ans=max(ans,Ans);
		for(;p!=i&&K;K--,cnt++){
			p=f[p][0];
			ans+=c[p];
			Ans=max(ans,Ans);
		}
		
		for(int j=1;j<=cnt&&K;j++,K--){
			p=f[p][0];
			ans+=c[p];
			Ans=max(ans,Ans);
		}
		
		if(ans>0) {
			T=floor((double)K/cnt);
			if(T>1){
				ans=(ans/2)*(T+1);
				Ans=max(ans,Ans);
				K=(K%cnt)+cnt;
			}
			while(K--){
				p=f[p][0];
				ans+=c[p];
				Ans=max(ans,Ans);
			}
		}
	} 
	cout<<Ans<<endl;
	return 0;
}


Measured memory_bytes: 6548
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

type node struct {
	item int
	prev *node
	rank int
}

func (n *node) root() *node {
	var parent *node
	for parent = n; parent.prev != nil; parent = parent.prev {
		continue
	}
	if parent != n {
		n.prev = parent
	}
	return parent
}

func issame(nodeX, nodeY *node) bool {
	return nodeX.root() == nodeY.root()

}

func merge(nodeX, nodeY *node) {
	parentX := nodeX.root()
	parentY := nodeY.root()
	if parentX.item == parentY.item {
		return
	}

	if nodeX.rank < nodeY.rank {
		nodeX, nodeY = nodeY, nodeX
	}

	if nodeX.rank == nodeY.rank {
		nodeX.rank += 1
	}

	if parentX.prev != nil || parentY.prev != nil {
		panic(fmt.Sprintf("%v, %v", parentX, parentY))
	}

	parentY.prev = parentX

}

func main() {
	sc.Split(bufio.ScanWords)
	var n, q int
	fmt.Scanf("%d %d", &n, &q)

	groups := make([]*node, n)
	for i := 0; i < n; i++ {
		groups[i] = &node{item: i, prev: nil, rank: 0}
	}

	for i := 0; i < q; i++ {
		com, x, y := next(), next(), next()
		if com == 0 {
			merge(groups[x], groups[y])

		} else {
			if issame(groups[x], groups[y]) {
				fmt.Println("1")
			} else {
				fmt.Println("0")
			}
		}
	}

}




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

int main()
{
	long long n,t=0,y=0,m=100;
	cin>>n;
	
	while(m<n)
	{
		y=m/100;
		m+=y;
		t++;
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int h[N];
    REP(i,N){
        cin>>h[i];
    }
    int dp[N];
    REP(i,N){
        dp[i]=INF;
    }
    dp[0]=0;
    REP1(i,N-1){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>=2){
            chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
        }
   }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,tot,x,y,z,g=2e9,root1,root2,t=2e9;
LL ans;
const int N=100010;
int head[N],to[N<<1],nt[N<<1],len[N<<1],siz[N],mx[N];
void add(int f,int t,int d)
{
	to[++tot]=t;len[tot]=d;nt[tot]=head[f];head[f]=tot;
}
void dfs(int x,int fa)
{
	siz[x]=1;
	for(int i=head[x];i;i=nt[i])
		if(to[i]!=fa)
		{
			dfs(to[i],x);siz[x]+=siz[to[i]];
			mx[x]=max(mx[x],siz[to[i]]);
			ans+=2*(LL)min(siz[to[i]],n-siz[to[i]])*len[i];
		}
	mx[x]=max(mx[x],n-siz[x]);
}
int main()
{
	cin>>n;
	for(int i=1;i<n;++i)
	{
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);add(y,x,z);
	}
	dfs(1,0);
	for(int i=1;i<=n;++i)g=min(g,mx[i]);
	for(int i=1;i<=n;++i)
		if(mx[i]==g){if(!root1)root1=i;else root2=i;}		
	for(int i=head[root1];i;i=nt[i])
		if(!root2||to[i]==root2)t=min(t,len[i]);
	cout<<ans-t;
	return 0;
}

Measured memory_bytes: 7808
#include <stdio.h>
int main() {

	int x;
	int y;
	scanf("%d%d", &x,&y);
	
	 
	 
	 if(x%y==0) {
		printf("%d",(x/y));}
		
	 else if(x>y) {
		printf("%d", (x/y)+1);
	}
	
	else if(x<y) {
			printf("%d", 1);
	}


 return 0;
}

Measured memory_bytes: 1692
#include<stdio.h>

main(){
    int a, b, c, tmp;
    scanf("%d %d %d",&a,&b,&c);
     if(a > b){
        tmp = a;
        a = b;
        b = tmp;
     }
     if(b > c){
        tmp = b;
        b = c;
        c = tmp;
     }
     if(a > b){
      tmp = a;
       a = b;
      b = tmp;
    }
     printf("%d %d %d\n", a, b, c);
     return 0;
}


Measured memory_bytes: 2136
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

 
 
int main() {
    #ifdef sharma
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);      
    #endif
    fastio;
    int n, d;
    cin >> n >> d;
    int x = 2*d+1;
    int y = n / x;
    if(n % x != 0)
        y++;
    cout <<y;
    return 0; 
}

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

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

int main()
{
	int n, h, i;
	int a = 0, b[100005] = {0};

	scanf("%d %d", &n, &h);
	for(i=0;i<n;i++)
	{
		int k;
		scanf("%d %d", &k, &b[i]);
		if(k>a)
			a = k;
	}

	// sort
	qsort(b, n, sizeof(int), cmp);

	// attack
	int ans = 0;
	for(i=0;i<n;i++)
	{
		if(b[i]>a && h>0)
		{
			h -= b[i];
			ans++;
		}
		else
			break;
	}

	if(h>0)
	{
		ans += h/a;
		if(h%a)
			ans++;
	}
	printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 892
import java.util.*;
 
public class Main {
    public static Scanner sc= new Scanner(System.in);
    public static void main(String[] args) {
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=a*b;
        int y=(a+b)*2;
        System.out.println(x+" "+y);
    }
     
}

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

N, M = (int(_) for _ in input().split())

H = [int(_) for _ in input().split()]
H_sort = [(int(__), _) for _, __ in enumerate(H)]

H_sort.sort()
H_sort.reverse()

#print(H)
#print(H_sort)

path = [[] for _ in range(N)]
for m in range(M):
    A, B = (int(_) - 1 for _ in input().split())
    path[A].append(B)
    path[B].append(A)

check = [True] * N
cnt = 0
for _, h in H_sort:
    good = False
    if check[h]:
        good = True
    check[h] = False
    for a in path[h]:
        if H[h] == H[a]:
            good = False
        check[a] = False
    if good:
        cnt += 1


print(cnt)


Measured memory_bytes: 40384
weight_num = int(input())
weight_list = input().split(" ")
heavy_list = []
light_list = []
s1 = 0
s2 = 0
for i in range(len(weight_list)):
    weight_list[i] = int(weight_list[i])
max_sum = sum(weight_list)
for i in range(len(weight_list)):
    s1 += weight_list[i]
    s2 = sum(weight_list[i+1:])
    if (s1-s2)>0:
        absolute_num1 = s1-s2 
        s1 -= weight_list[i]
        s2 = sum(weight_list[i:])
        absolute_num2 = s2-s1
        if absolute_num1>absolute_num2:
            print(absolute_num2)
        else:
            print(absolute_num1)
        break
    else:
        pass

Measured memory_bytes: 3064
#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(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
struct BIT { //1-indexed
private:
    int n;
    vector<ll> bit;

public:
    BIT(vector<ll> v){
        n = v.size();
        rep(i,0,n) bit.push_back(v[i]);
    }

    ll sum(ll i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(ll i, ll x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

vector<ll> compress(vector<ll> v){
    ll n = v.size();
    vector<ll> v2;
    rep(i,0,n) v2.push_back(v[i]);
    sort(v2.begin(), v2.end());
    vector<ll> res;
    rep(i,0,n){
        ll pos = lower_bound(v2.begin(), v2.end(), v[i]) - v2.begin();
        res.push_back(pos + 1); 
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll A[200010];
    rep(i,0,N) cin >> A[i];
    rep(i,0,N) A[i] -= K;
    vector<ll> sum(N+1, 0);
    rep(i,0,N) sum[i+1] = sum[i] + A[i];
    vector<ll> sum_compress = compress(sum);
    vector<ll> init(200010, 0);
    BIT bit(init);
    ll ans = 0;
    rep(i,0,N+1){
        ans += bit.sum(sum_compress[i]);
        bit.add(sum_compress[i], 1);
    }
    print(ans);


    
}

Measured memory_bytes: 11704
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
//typedef complex<long double> com;
 
const ll mod = 1e9+7;
 
void setIO(string name) {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a,b;
	cin >> n >> a >> b;
	cout << n/(a+b)*a + min(n%(a+b),a) << endl;
}

Measured memory_bytes: 256
(let* ((n (read))
       (d (make-array (list n))))
  (loop :for i :from 0 :to (1- n)
        :do (setf (aref d i) (cons (read) (read))))
  ;
  (if (< 0 (loop :for i :from 0 :to (- n 3)
                 :sum (if (and (= (car (aref d i)) (cdr (aref d i)))
                               (= (car (aref d (+ i 1))) (cdr (aref d (+ i 1))))
                               (= (car (aref d (+ i 2))) (cdr (aref d (+ i 2)))))
                          1
                          0)))
      (format t "Yes~%")
      (format t "No~%")))


Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=12e4;

int a[N];
int n;

int p[N][2];

int main()
{
	scanf("%d",&n);
	int oo=0;
	if(n%2==0){
		int half=n/2;
		fo(i,1,n)
		fo(l,1,n)if(i+l!=n+1&&i<l){
			p[++oo][0]=i; p[oo][1]=l;
		}
	} else {
		fo(i,1,n)
		fo(l,1,n)if(i<l&&i+l!=n)p[++oo][0]=i,p[oo][1]=l;
	}
	printf("%d\n",oo);
	fo(i,1,oo){
		printf("%d %d\n",p[i][0],p[i][1]);
	}
}

Measured memory_bytes: 256