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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;


int main(){
    int n, k, a = 0;
    string s;
    cin >> n >> k >> s;
    for (int i = 0; i < n - 1; i++){
        if (s[i] == s[i + 1])a++;
    }
    cout << min(k * 2 + a, n - 1) << endl;
    //幸せな人が一人増えるときは，端の人のどちらかを入れ替えて全ての人の向きが同じになり幸せな人がn-1人になる場合のみで，それ以外の操作では二人ずつ幸せな人が増えるため．
}


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

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    string s, t;cin>>s>>t;
    vvint n;
    initvv(n, s.length()+1, 26, -1);
    for(int i = s.length()-1;i>=0;i--){
        for(char c = 'a';c <= 'z';c++){
            if(s[i]==c){
                n[i][c-'a'] = i;
            }else{
                n[i][c-'a'] = n[i+1][c-'a'];
            }
        }
    }
    //rep(i, s.length()+1){
    //    cout << n[i]['t'-'a'];
    //}
    //cout << endl;
    
    ll np = 0;
    ll loop = 0;
    rep(i, t.length()){
        if(n[0][t[i]-'a'] == -1){
            cout << -1 << endl;
            return 0;
        }
        if(n[np][t[i]-'a'] == -1){
            debug("up i:%d t:%c np:%d n:%d\n", i, t[i], np, n[np][t[i]-'a']);
            loop++;
            np = 0;
            i--;
        }else{
            debug("up i:%d t:%c np:%d n:%d\n", i, t[i], np, n[np][t[i]-'a']);
            np = n[np][t[i]-'a']+1;
        }
    }
    cout << loop * s.length() + (np) << endl;
    return 0;
}


Measured memory_bytes: 13776
#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)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> s;
    int res = 0;
    rep (i, n) {
        vector<int> cnt1(26), cnt2(26);
        rep (j, i) cnt1[s[j] - 'a']++;
        FOR (j, i, n) cnt2[s[j] - 'a']++;
        int tmp = 0;
        rep (j, 26) {
            if (cnt1[j] != 0 && cnt2[j] != 0) tmp++;
        }
        res = max(res, tmp);
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc054/tasks/abc054_c

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

struct C {
    vector<ll> src_{};
    vector<ll> tgt_{};
    ll N_{};
    vector<vector<ll>> e_{};

    void visit(vector<ll>& visited, ll next, ll& count) {
        visited.emplace_back(next);
        if (visited.size() == N_) {
            ++count;
            visited.pop_back();
            return;
        }
        for(auto c : e_[next]) {
            if (std::find(visited.begin(), visited.end(), c) != visited.end()) {
                continue;
            }
            visit(visited, c, count);
        }
        visited.pop_back();
    }
    explicit C(vector<ll> src, vector<ll> tgt, ll N) : src_(move(src)), tgt_(move(tgt)), N_(N){}
    ll resolve() {
        ll M = src_.size();
        e_.resize(N_+1);
        for(int i=0; i < M; ++i) {
            e_[src_[i]].emplace_back(tgt_[i]);
            e_[tgt_[i]].emplace_back(src_[i]);
        }
        vector<ll> visited{};
        ll cur = 1;
        ll count = 0;
        visit(visited, 1, count);
        return count;
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> src{};
    vector<ll> tgt{};
    for (int i=0; i < M; ++i) {
        ll x,y ;
        cin >> x >> y;
        src.emplace_back(x);
        tgt.emplace_back(y);
    }
    C c{move(src), move(tgt), N};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n,m,q; cin >> n >> m >> q;
  vector<vector<ll>> v(q,vector<ll>(4,0));
  rep(i,q){
    rep(j,4){
      cin >> v[i][j];
    }
  }
  vector<vector<ll>> a;
  auto func = [&](auto f, vector<ll> v)-> void{
    if(v.size()==n){
      a.push_back(v);
      return ;
    }
    for(ll i=v[v.size()-1];i<=m; i++){
      vector<ll> t(v);
      t.push_back(i);
      f(f,t);
    }
  };
  for(ll i=1;i<=m;i++){
    vector<ll> u{i};
    func(func, u);
  }
  ll ans=0;
  for(auto aa:a){
    ll temp = 0;
    for(auto cond:v){
      if(aa[cond[1]-1]-aa[cond[0]-1]==cond[2]) temp+=cond[3];
    }
    ans = max(ans,temp);
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 13868
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int A[n];
    
    for(int h = 0; h < n; h++){
        int m;
        cin >> m;
        A[h] = m;
    }
    
    for(int i = 0; i < n; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        
        for(int k = 0; k < n; k++){
            if(k != n-1){
                cout << A[k] << " ";
            } else {
                cout << A[k] << endl;
            }
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(int argc,char* argv[]){
  
  int s_sum;
  double w,len;

  while(scanf("%d,%lf,%lf",&s_sum,&w,&len) != EOF){
    if(w/(len*len) >= 25.0){
      printf("%d\n",s_sum);
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 0
#data input
n = int(input())
i = 0
str = [0] * n # str == 二次元配列
while i <  n: 
    str[i] = input()
    i += 1
    


i = 0
count = 0
x = ""
while i < n-1:
    if str[i][-1] == str[i+1][0]:
        i += 1
    else:
        print("No")
        count = 1
        break
i = 0
while i < n:
    x =  str.count(str[i])
    if x >= 2:
        print("No")
        count = 1
        break
    i += 1



if count == 0:
    print("Yes")


Measured memory_bytes: 3064
S = list(input())
ls = len(S)

a = [0] * (len(S) + 1)


for i in range(ls):
    if S[i] == "<":
        a[i + 1] = max(a[i + 1], a[i] + 1)
        
for i in range(ls - 1, -1, -1):
    if S[i] == ">":
        a[i] = max(a[i], a[i + 1] + 1)
        
print(sum(a))

Measured memory_bytes: 32500
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int X, Y;
int main(void){
    cin >> X >> Y;
    int n = 0, m = 0;
    bool f = true;
    for(;n < 1000000;n++){
        if((X-2*n)*2 == Y - n){
            m = X - 2*n;
            f = false;
            break;
        }
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }else{
        cout << C(n+m, min(n,m)).n << endl;
    }
    return 0;
}



Measured memory_bytes: 14668
#include <iostream>
using namespace std;
int n,c[200001],s[200001];
long long dp[200001],INF=1000000007;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>c[i];
        if(c[i]==c[i-1])i--,n--;
    }dp[0]=1;
    for(int i=1;i<=n;i++){
        dp[i]=(dp[i-1]+s[c[i]])%INF;
        s[c[i]]+=dp[i-1];
        s[c[i]]%=INF;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 3328
from math import cos,radians
from decimal import Decimal
a,b,h,m = map(int,input().split())
x = 6*m
y = Decimal(60*h+m)/2
if x < y: x,y = y,x
z = min(x-y,y+360-x)
print((a**2+b**2-2*a*b*cos(radians(z)))**0.5)

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int A,B;
    cin >> A >> B;

    if(A > 12) cout << B << endl;
    else if( A > 5 ) cout << B/2 << endl;
    else cout << 0 << endl;
}


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

bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}

int main(){
    int n;
    cin >> n;
    vector<int> data(n);
    for (int i=0;i<n;i++){
        cin >> data[i];
    }
    vector<int> total_data(3*n);
    for (int i=0;i<n;i++){
        total_data[3 * i] = data[i];
        total_data[3 * i + 1] = data[i] - 1;
        total_data[3 * i + 2] = data[i] + 1;
    }
    map<int, int> counter;
    for (auto &i : total_data){
        ++counter[i];
    }
    auto maxn = max_element(counter.begin(), counter.end(), compare)->second;
    cout<<maxn<<endl;
    return 0;
}

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

typedef tuple<int, int, int> Bar;

int main() {
  int n, m, h, k;
  while(cin >> n >> m >> h >> k, n | m | h | k) {
    vector<int> s(n);
    for(auto& i: s) cin >> i;

    set<Bar> bar;
    for(int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      bar.insert(Bar(b, a- 1, a));
    }

    vector<int> original(n), goal(n);
    iota(begin(original), end(original), 0);

    set<tuple<int, int>> replaceable;

    for(const auto& i: bar) {
      int z, x, y;
      tie(z, x, y) = i;
      replaceable.insert(tuple<int, int>(min(original[x], original[y]), max(original[x], original[y])));
      swap(original[x], original[y]);
    }
    for(int i = 0; i < n; ++i) goal[original[i]] = i;

    int sum = 0;
    for(int i = 0; i < k; ++i) sum += s[goal[i]];
    int answer = sum;
    for(const auto& i: replaceable) {
      int x, y;
      tie(x, y) = i;
      if(k <= x) break;
      if(y < k) continue;
      answer = min(answer, sum - s[goal[x]] + s[goal[y]]);
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 8144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 406;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int dp[N];
int ndp[N];
int v[N];

void recalc(int A, int B) {
	for (int x = A; x <= B; x++) {
		fill(v, v + N, 0);
		for (int ptk = 0; ptk < N; ptk++) {
			v[ptk] = add(v[ptk], dp[ptk]);
		}
		int c = 0;
		for (int i = 0; i < N; i++) {
			c = add(c, v[i]);
			ndp[i] = add(ndp[i], c);
			c = mul(c, x);
		}
	}
	for (int i = 0; i < N; i++) {
		dp[i] = ndp[i];
		ndp[i] = 0;
	}
}

void init() {
	dp[0] = 1;
}

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

	int n, C;
	cin >> n >> C;
	vector<int> a(n);
	vector<int> b(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (auto &t : b) {
		cin >> t;
	}
	init();
	for (int i = 0; i < n; i++) {
		recalc(a[i], b[i]);
	}
	cout << dp[C] << endl;
}

Measured memory_bytes: 256
s = input()

front = int(s[:2])
back = int(s[2:])

if 1 <= front <= 12:
    if 1 <= back <=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<= back <= 12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int n;
int MOD=1000000007;

int main() {
	//freopen("test.in","r",stdin);
	cin >> n;
	int64 r=-1e18;
	//10**n-9**n-9**n+8**n
	int64 p10=1,p9=1,p8=1;
	REP (i,n) {
		p10=(p10*10)%MOD;
		p9=(p9*9)%MOD;
		p8=(p8*8)%MOD;
	}
	int64 a=(p10-p9-p9+p8)%MOD;
	if (a<0) a+=MOD;
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 3620
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
    };

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

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

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        s: chars,
    }
    let mut v = [false; 26];
    for c in s {
        v[c as usize - 'a' as usize] = true;
    }
    for i in 0..26 {
        if v[i] == false {
            println!("{}", char::from((i + 'a' as usize) as u8));
            return;
        }
    }
    println!("None");
}


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

int main() {
  string str;
  char b[7][3][2] = {
    {{0,1},{1,0},{1,1}},
    {{1,0},{2,0},{3,0}},
    {{0,1},{0,2},{0,3}},
    {{1,-1},{1,0},{2,-1}},
    {{0,1},{1,1},{1,2}},
    {{1,0},{1,1},{2,1}},
    {{0,1},{1,-1},{1,0}},
  };
  bool a[8][8],flg;
  int r,c,nr,nc;

  while (1) {
    for (int i=0; i<8; i++) {
      cin >> str;
      for (int j=0; j<8; j++) {
        char c = str.at(j);
        a[i][j] = (c=='0') ? false : true;
      }
    }
    if (!cin) break;

    flg = false;
    for (int i=0; i<8; i++) {
      for (int j=0; j<8; j++) {
        if (a[i][j]) {
          r = i;
          c = j;
          flg = true;
          break;
        }
      }
      if (flg) break;
    }

    for (int i=0; i<7; i++) {
      int j;
      for (j=0; j<3; j++) {
        nr = r + b[i][j][0];
        nc = c + b[i][j][1];
        if (nr<0||nr>=8||nc<0||nc>=8) break;
        if (!a[nr][nc]) break;
      }
      if (j == 3) {
        cout << (char)('A'+i) << endl;
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b;
        cin >> a >> b;
        if(a > 0 and b > 0){
            cout << "Positive\n";
        }else if(a <= 0 and b >= 0){
            cout << "Zero\n";
        }else{
            if((b - a + 1) % 2){
                cout << "Negative\n";
            }else{
                cout << "Positive\n";
            }
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> card(n);
  long long int total = 0;
  for(int i=0;i<n;i++) {
    cin >> card[i];
    total += card[i];
  }

  long long int x = 0;
  long long int ans = LLONG_MAX;

  for(int i=0;i<n-1;i++) {
    x += card[i];
    long long int y = total - x;

    if(abs(x-y)<ans) ans = abs(x-y);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return a.first < b.first;
}

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

  vector<ll> a(n);
  vector<ll> f(n);
  REP(i, n) { cin >> a[i]; }
  REP(i, n) { cin >> f[i]; }

  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<ll>());

  vector<pair<ll, ll>> sa(n);
  REP(i, n) { sa[i] = make_pair(a[i] * f[i], a[i]); }
  sort(sa.begin(), sa.end(), comp);

  ll ng = -1;
  ll ok = 1100000000000;

  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    auto itr = lower_bound(sa.begin(), sa.end(), make_pair(mid, 0LL), comp);

    ll c = 0;

    for (auto it = itr; it != sa.end(); ++it) {
      auto val = *it;
      c += (val.first - mid + (val.first / val.second) - 1) /
           (val.first / val.second);
    }

    if (c <= k) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;
}


Measured memory_bytes: 6528
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
vector<int> e[111111];
long long int A[111111];
bool dfs(int x,int fat){
	if(e[x].size() == 1){
		return true;
	}
	long long int sum = 0, mx = 0;
	for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){
		int y = *it;
		if(y == fat)continue;
		if(!dfs(y, x))
			return false;
		sum += A[y];
		mx = max(mx, A[y]);
	}
	mx = min(sum - mx, sum/2);

	long long int dec = sum - A[x];
	if(dec < 0 || dec > mx)
		return false;
	A[x] -= dec;
	if(x == fat)return A[x] == 0;
//	A[fat] -= dec;
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		int x;
		scanf("%d",&x);
		A[i] = x;
	}
	for(int i=1; i<n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	if(n == 2){
		puts(A[1] == A[2] ? "YES" : "NO");
		return 0;
	}
	int r = -1;
	for(int i=1; i<=n; i++)
		if(e[i].size() != 1){
			r = i;
			break;
		}
	puts(dfs(r,r) ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 13440
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;

#define ALL(c) (c).begin(), (c).end()

int main(void) {
    const vector<string> WEEKDAY = {"SUN", "MON", "TUE", "WED" , "THU", "FRI", "SAT"};
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    cout << 7 - distance(WEEKDAY.begin(), find(ALL(WEEKDAY), s)) << "\n";
    return 0;
}

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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

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

	string s;
	cin >> s;

	cout << (s == "ABC" ? "ARC" : "ABC") << endl;

	return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <functional>
#include <map>
#include <string>
using namespace std;
#define INF 1000000000;
#define MOD 1000000007;
typedef long long int ll;
int main(void){
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int> >s(n);
    //map<pair<string,int>,int> mp;
    for(int i=0;i<n;i++){
        string a;
        int b;
        cin>>a>>b;
        s[i].first=make_pair(a,-1*b);
        s[i].second=i+1;
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        cout<<s[i].second<<endl;
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

vector< vector<int> > ans;
int h, w, a, b;

bool solve(void){
    cin >> h >> w >> a >> b;

    ans.resize(h, vector<int>(w, -1));

    rep(i, h){
        rep(j, w){
            if((i < b) ^ (j < a)){
                ans[i][j] = 0;
            }else{
                ans[i][j] = 1;
            }
        }
    }

    return true;
}

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

    if(solve()){
        rep(i, h){
            rep(j, w){
                cout << ans[i][j];
            }
            cout << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

int main() {
  int X, N;
  cin >> X >> N;
  unordered_set<int> S;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    S.insert(a);
  }

  int answer = -1000;
  for (int i = -1000; i < 1000; i++) {
    if (S.count(i)) continue;
    if (abs(i - X) < abs(answer - X)) {
      answer = i;
    }
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3632
from operator import itemgetter
import sys
def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a_b = [list(map(int, input().split())) for i in range(m)]
    a_b.sort(key=itemgetter(1))
    end = a_b[0][1]-2
    ans = 1 
    for i in range(m):
        if a_b[i][0]-1 <= end:
            continue
        else:
            end = a_b[i][1]-2
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 29496
#include<stdio.h>
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int a[n],b[n],c[n];
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++){
        scanf("%d",&b[i]);
    }
    for(i=1;i<n;i++){
        scanf("%d",&c[i]);
    }
    int sum=0;
    for(i=1;i<=n;i++){
        sum=sum+b[i];
    }
    int sum1=0;
    for(i=1;i<n;i++){
        if(a[i]+1==a[i+1]){
            sum1=sum1+c[a[i]];
        }
    }
    printf("%d\n",sum+sum1);
    return 0;
}

Measured memory_bytes: 128
package main

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

var dp []int64

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n int
	fmt.Sscan(getNextLine(scanner), &n)
	hList := getIntList(scanner)
	aList := getIntList(scanner)

	segSize := 1
	for segSize < n {
		segSize = segSize << 1
	}
	dp = make([]int64, segSize*2)
	for i := 0; i < n; i++ {
		dp[segSize-1+hList[i]-1] = int64(aList[i]) + query(0, hList[i]-1, 0, 0, segSize)
		update(segSize - 1 + hList[i] - 1)
	}
	fmt.Println(query(0, n, 0, 0, n))
}

func query(a int, b int, k int, l int, r int) int64 {
	if b <= l || r <= a {
		return int64(0)
	}
	if a <= l && r <= b {
		return dp[k]
	}
	vl := query(a, b, k*2+1, l, (l+r)/2)
	vr := query(a, b, k*2+2, (l+r)/2, r)
	if vl < vr {
		return vr
	}
	return vl
}

func update(i int) {
	for i > 0 {
		i = (i - 1) / 2
		dp[i] = dp[i*2+1]
		if dp[i] < dp[i*2+2] {
			dp[i] = dp[i*2+2]
		}
	}
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

int main(){
  LL n;
  cin>>n;
  LL a[200010],b[200010];
  for(LL i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  if(n%2!=0){
    LL m=n/2;
    cout<<b[m]-a[m]+1<<endl;
   
  }
  else{
    LL m=n/2-1;
    cout<<b[m]+b[m+1]-a[m]-a[m+1]+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 6768
L=list(input())
cnt=0
x=[]
import queue
q=queue.Queue()

for l in L:q.put(l)
while not q.empty():
    x.append(q.get())
    if len(x)>1:
        if x[-2:].count("0")==1:
            x.pop(-2)
            x.pop(-1)
            cnt+=2
print(cnt)

Measured memory_bytes: 6412
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int N;
    ll ans = 0;
    cin >> N;
    map <string,int > score;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        score[s]++; 
    }
    for(auto& p : score){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans  << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
 int n;
 cin >> n;
 if(n < 1200){
  cout << "ABC" << endl;
 }else if(n < 2800){
  cout << "ARC" << endl;
 }else{
  cout << "AGC" << endl;
 }
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main() 
{
 int x,y,z,n,tmp; 
 tmp=0;
 scanf("%d",&n); 

while(n-->0)
 { 
scanf("%d",&x);scanf("%d",&y);scanf("%d",&z);  

if(x<y){tmp=y;y=x;x=tmp;} 
if(x<z){tmp=x;x=z;z=tmp;}
 if(y<z){tmp=z;z=y;y=tmp;} 

if(x*x==y*y+z*z)printf("YES\n");
 else printf("NO\n");     
} 
return 0; 
} 

Measured memory_bytes: 1008
#include<stdio.h>

#define MAX 101
#define WHITE 0
#define BLACK 1
#define INF 2001
#define NIL -1

int G[MAX][MAX],n,d[MAX],pi[MAX],color[MAX];


int main(){
  int i,j,sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
	   for(j=1;j<=n;j++){
  	    scanf("%d",&G[i][j]);
  	}
  }
  for(i=1;i<=n;i++){
    d[i]=INF;
    pi[i]=NIL;
  }
  d[1]=0;
  while(1){
	int u,mincost = INF;
	for(i=1;i<=n;i++){
  	if(color[i]!=BLACK && d[i]<mincost){
    mincost = d[i];
    u = i;
  	}
	}

	if(mincost==INF)break;
	color[u]=BLACK;

	for(i=1;i<=n;i++){
  	if(color[i]!=BLACK && G[u][i]<d[i] && G[u][i]!=-1){
    pi[i] = u;
    d[i] = G[u][i];
  	}
	}
  }

  for(i=1;i<=n;i++){
		sum+=d[i];
  }
  printf("%d\n",sum);
  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<double> V(N);

    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
    }

    sort (V.begin(), V.end());

    double s = (V.at(0) + V.at(1)) / 2;

    for (int i = 2; i < N; i++) {
        s = (s + V.at(i)) / 2;
    }

    cout << s << endl;

}

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

int main(){
  string s;
  cin >> s;
  set<int> m;
  rep(i,s.size()){
    int a=s[i]-'a';
    m.insert(a);
  }
  rep(i,26){
    if(m.count(i)==0){
      cout <<  (char)( 'a'+i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;

}


Measured memory_bytes: 512
input()
a=list(map(int,input().split(" ")))

n=len(a)
currMax=0
res=0

for i in range(1,n):
    if a[ i-1 ] >= a[i]:
        res+=1
    else:
        currMax=max(currMax,res)
        res=0

currMax=max(currMax,res)
print(currMax)


Measured memory_bytes: 14252
def solve(s,t):
    if(s == t):
        return "Yes"
    for i in range(len(s)-1,0,-1):
        f = s[i:] + s[:i]
        if(f == t):
            return "Yes"
    return "No"

s = input()
t = input()
print(solve(s,t))

Measured memory_bytes: 3060
import itertools
n,m,q=map(int,input().split())
_q=[ list(map(int,input().split())) for _ in range(q)]

_A=0
for v in itertools.combinations_with_replacement(range(1,m+1), n):
    A=list(v)
    _d=0
    for q in _q:
        a,b,c,d=q
        if A[b-1]-A[a-1]==c:
            _d+=d

    if _d > _A:
        _A = _d

print(_A)

Measured memory_bytes: 9204
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    bytes: Vec<u8>,
    begin: usize,
    end: usize,
}

impl Scanner {
    pub fn new() -> Self {
        use std::io::Read;
        let mut buffer: Vec<u8> = Vec::new();
        let mut stdin = std::io::stdin();
        let mut lock = &mut stdin.lock();
        lock.read_to_end(&mut buffer).unwrap();
        let mut end = 0;
        while end < buffer.len() && !buffer[end].is_ascii_whitespace() {
            end += 1;
        }
        Scanner {
            bytes: buffer,
            begin: 0,
            end: end,
        }
    }
    pub fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
        let ret: T = s.parse::<T>().unwrap();
        self.skip();
        ret
    }
    pub fn next_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
    pub fn next_word(&mut self) -> Vec<u8> {
        let r = Vec::from(&self.bytes[self.begin..self.end]);
        self.skip();
        r
    }
    fn skip(&mut self) {
        let mut begin = self.end;
        while begin < self.bytes.len() && self.bytes[begin].is_ascii_whitespace() {
            begin += 1;
        }
        let mut end = begin;
        while end < self.bytes.len() && !self.bytes[end].is_ascii_whitespace() {
            end += 1;
        }
        self.begin = begin;
        self.end = end;
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
    pans: usize,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    ans[u] = if dp[idx] == i32::max_value() {
        pans + 1
    } else {
        pans
    };
    dp[idx] = a[u];

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge, ans[u]);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge, 0);
    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 39188
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){
	
	int N,A,B;
	cin>>N>>A>>B;
	
	int n = N;
	
	vector<int> num(A,1);
	n-=A;
	num[0] = B;
	n-=B-1;
	
	if(n<0){
		cout<<-1<<endl;
		return 0;
	}
	
	for(int i=1;i<num.size();i++){
		num[i] += min(n,B-1);
		n -= min(n,B-1);
	}
	
	if(n!=0){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int> ans(N);
	for(int i=0;i<N;i++)ans[i] = i+1;
	int sum = 0;
	
	for(int i=0;i<num.size();i++){
		reverse(ans.begin()+sum,ans.begin()+sum+num[i]);
		sum+=num[i];
	}
	
	for(int i=0;i<N;i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

int main(){
  int n,q;
  cin >> n >> q;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> z(n);
  vector<int> r(n);
  vector<long long> l(n);
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i] >> z[i] >> r[i] >> l[i];
  }
  
  vector<int> sx(q);
  vector<int> sy(q);
  vector<int> sz(q);
  vector<int> dx(q);
  vector<int> dy(q);
  vector<int> dz(q);
  for(int i = 0; i < q; i++){
    cin >> sx[i] >> sy[i] >> sz[i] >> dx[i] >> dy[i] >> dz[i];
  }
  for(int i = 0; i < q; i++){
    long long cost = 0;
    double ab = sqrt(pow(sx[i]-dx[i], 2) + pow(sy[i] - dy[i], 2) + pow(sz[i] - dz[i], 2));
    for(int j = 0; j < n; j++){
      double ac2 = pow(sx[i]-x[j], 2) + pow(sy[i]-y[j], 2) + pow(sz[i]-z[j], 2);
      double bc2 = pow(dx[i]-x[j], 2) + pow(dy[i]-y[j], 2) + pow(dz[i]-z[j], 2);
      if(ac2 <= pow(r[j], 2) || bc2 <= pow(r[j], 2)){
        cost += l[j];
      }
      else if(sqrt(ac2 - pow(r[j], 2)) + sqrt(bc2 - pow(r[j], 2)) <= ab){
        cost += l[j];
      }
    }
    cout << cost << endl;
  }
}



Measured memory_bytes: 3112
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,K,count=0,flag=0;
  string S;
  vector<int> V;
  cin>>N>>K>>S;

  if(S[0]=='0') V.push_back(0);
  flag=S[0]-'0';
  for(int i=0;i<N;i++){
    if(flag==S[i]-'0') count++;
    else{
      V.push_back(count);
      count=1;
      flag=(flag+1)%2;
    }
  }
  V.push_back(count);
  if(S[N-1]=='0') V.push_back(0);
  /*for(int i=0;i<V.size();i++){
    cout<<V[i]<<endl;
  }*/
  ll sum=0,ans;
  if(K*2+1>=V.size()){
    cout<<N<<endl;
    return 0;
  }
  for(int i=0;i<K*2+1;i++){
    sum+=V[i];
    //cout<<sum<<endl;
  }
  ans=sum;
  //flag=1;
  int j=0;
  for(int i=K*2+1;i<V.size();i+=2,j+=2){
    sum=sum-V[j]-V[j+1];
    sum+=V[i]+V[i+1];
    //cout<<V[i]<<" "<<V[i+1]<<endl;
    //cout<<sum<<endl;
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1020
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const long long INF = 0xffffffffffff;
 
class union_find {
private:
	vector<int> uf;
	vector<long long> pd;
	vector<long long> C;
 
public:
	union_find(int n):uf(n, -1), pd(n, 0), C(n, 0) {}
 
	inline int find(int x) {
		if(uf[x] < 0) return x;
 
		const int tmp = uf[x];
		uf[x] = find(uf[x]);
		pd[x] += pd[tmp];
		return uf[x];
	}
 
	inline void unite(int xx, int yy, long long d) {
		int x = find(xx), y = find(yy);
		long long c = d;
		if(x != y) {
			d += pd[yy] - pd[xx] + C[yy] - C[xx];
			if(uf[x] < uf[y]) {
				swap(x, y);
				d = -d;
			}
			else if(uf[x] == uf[y]) {
				--uf[y];
			}
 
			uf[x] = y;
			pd[x] = d;
		}

		C[xx] += c;
		C[yy] += c;
	}
 
	inline bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	inline long long get_dist(int x, int y) {
		return same(x, y) ? pd[x] - pd[y] + C[x] - C[y] : INF;
	}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    for(int n, q; cin >> n >> q && n;) {
        union_find uf(n);
        for(int i = 0; i < q; ++i) {
            string s;
            cin >> s;
 
            if(s == "IN") {
                int a, b, c;
                cin >> a >> b >> c;
 
                uf.unite(b - 1, a - 1, c);
            }
            else {
                int a, b;
                cin >> a >> b;
 
                const long long ans = uf.get_dist(a - 1, b - 1);
				if(ans == INF) {
                    cout << "WARNING" << endl;
				}
                else {
                    cout << -ans << endl;
				}
            }
        }
    }
 
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }



void solve(long long N){
	ll res = 0;
	FOR(i, 1, N+1) {
		if (to_string(i).size()%2 != 0) res++;
	}
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var AB = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (A, B) = (AB[0], AB[1]);
            Console.WriteLine((A + B) % 24);
        }
    }
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	vector<int> vec;
	rep(i, n){
		int x;
		cin >> x;
		vec.push_back(x);
	}

	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(vec[1] - vec[0]);

	for(int i = 2; i < n; i++){
		int m = INT_MAX;
		rep(j, k){
			if(0 <= i - j - 1) m = min(m, dp[i - j - 1] + abs(vec[i] - vec[i - j - 1]));
		}
		dp[i] = m;
	}

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

Measured memory_bytes: 1144
#include <iostream> 
using namespace std; 
int main() {
	int A, B;
	cin >> A >> B;
	if (A < B && B % A == 0) {
		cout << B / A << endl;
	}
	else if (A < B && B % A != 0) {
		cout << B / A + 1 << endl;
	}	
	else if (A >= B) {
		cout << 1 << endl;
	}
}


Measured memory_bytes: 3092
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

void solve() {
  int N;
  cin >> N;

  vector<int> v(N);
  int sum = 0;
  for (int &a : v) {
    cin >> a;
    sum += a;
    a = sum;
  }

  int ans = INF;
  for (int i = 0; i < N - 1; i++) {
    ans = min(ans, abs(sum - v[i] - v[i]));
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 1792
def coun(n,r):
    return n*r+1+r-r**2

def sigma(func,frm,too):
    result=0
    for i in range(frm,too+2):
        #print(i)
        result=result+func(too,i)
        #print(result)
    print(result%mod)

n,k=list(map(int,input().split()))
mod=10**9+7

sigma(coun,k,n)

Measured memory_bytes: 9196
from itertools import combinations
import copy

h, w, k = map(int, input().split())
_h = [i for i in range(h)]
_w = [i for i in range(w)]

h_comb = []
w_comb = []
for i, _ in enumerate(_h, 1):
    for j in combinations(_h, r=i):
        h_comb.append(list(j))
h_comb.append([])

for i, _ in enumerate(_w, 1):
    for j in combinations(_w, r=i):
        w_comb.append(list(j))
w_comb.append([])

field = []
for i in range(h):
    field.append(list(input()))

ans = 0
for hc in h_comb:
    for wc in w_comb:
        tmp = copy.deepcopy(field)

        for i in hc:
            for j in range(w):
                tmp[i][j] = '.'
        for j in wc:
            for i in range(h):
                tmp[i][j] = '.'
        count = 0
        for i in range(h):
            for j in range(w):
                if tmp[i][j] == '#':
                    count += 1
        if count == k:
            ans += 1

print(ans)


Measured memory_bytes: 9352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    rep(i, n-1)a[i+1] += a[i];
    map<ll, int> mp;
    rep(i, n)mp[a[i]]++;
    ll ans = 0;
    for(auto p : mp){
        if(p.first == 0){
            ans += p.second;
        }
        ll k = p.second;
        ans += k * (k - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17088
from bisect import bisect_left as bl
INF = 10 ** 20

def main():
  
  w, h = map(int, input().split())
  n = int(input())
  
  xlst = []
  ylst = []
  appx = xlst.append
  appy = ylst.append
  for i in range(n):
    x, y = map(int,input().split())
    appx(x)
    appy(y)
  
  sorted_xlst = sorted(xlst)
  sorted_ylst = sorted(ylst)
  accx = accy = 0
  cum_sum_xlst = []
  cum_sum_ylst = []
  appx = cum_sum_xlst.append
  appy = cum_sum_ylst.append

  for i in range(n):
    accx += sorted_xlst[i]
    accy += sorted_ylst[i]
    appx(accx)
    appy(accy)
  
  if n % 2:
    clx = crx = sorted_xlst[n // 2]
    cly = cry = sorted_ylst[n // 2]
  else:
    clx = sorted_xlst[n // 2 - 1]
    crx = sorted_xlst[n // 2]
    cly = sorted_ylst[n // 2 - 1]
    cry = sorted_ylst[n // 2]
  plx = bl(sorted_xlst, clx)
  prx = bl(sorted_xlst, crx)
  ply = bl(sorted_ylst, cly)
  pry = bl(sorted_ylst, cry)

  xllen = (accx - cum_sum_xlst[plx - 1] * 2 - clx * (n - plx * 2)) * 2 if plx != 0 else (accx - clx * n) * 2
  xrlen = (accx - cum_sum_xlst[prx - 1] * 2 - crx * (n - prx * 2)) * 2 if prx != 0 else (accx - crx * n) * 2
  yllen = (accy - cum_sum_ylst[ply - 1] * 2 - cly * (n - ply * 2)) * 2 if ply != 0 else (accy - cly * n) * 2
  yrlen = (accy - cum_sum_ylst[pry - 1] * 2 - cry * (n - pry * 2)) * 2 if pry != 0 else (accy - cry * n) * 2


  ans = ansx = ansy = INF
  max_sumd = 0
  
  for i in range(n):
    xi = xlst[i]
    yi = ylst[i]

    if xi <= clx:
      cx = crx
      xlen = xrlen
    else:
      cx = clx
      xlen = xllen
    if yi <= cly:
      cy = cry
      ylen = yrlen
    else:
      cy = cly
      ylen = yllen
  
    dx = xi - cx
    if dx < 0:
      dx = -dx

    dy = yi - cy
    if dy < 0:
      dy = -dy

    if max_sumd > dx + dy:
      continue
    else:
      max_sumd = dx + dy
    
    tlen = xlen + ylen - max_sumd

    if ans > tlen:
      ans = tlen
      ansx = cx
      ansy = cy
    elif ans == tlen:
      if ansx > cx:
        ansx = cx
        ansy = cy
      elif ansx == cx:
        if ansy > cy:
          ansy = cy 
  
  print(ans)
  print(ansx, ansy)

main()


Measured memory_bytes: 25128