akhauriyash/Code-Regression huggingface dataset:
Array.prototype.insertOrderedDesc = function(item) {
	//if(this.length == 0) { this.push(item); return; }
	var range = Math.floor(this.length / 2);
	var dir = 1;
	var index = 0;
	while(range > 1) {
		index += dir * range;
      	var sub = this[index] - item;
		if(sub > 0) { dir = 1;}
		else if(sub < 0) { dir = -1; } else {
			this.splice(index, 0, item); return;
		}
		range = Math.floor(range / 2)
	}
	for(;0 <= index && index < this.length; index += dir) {
		if(dir * (this[index] - item) < 0) break;
	}	
	this.splice(index + (dir < 0 ? 1 : 0), 0, item);
};

var input = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n").map((s)=>{return s.split(" ");});
var N = input[0][0]-0;
var Days = input[0][1]-0;
input.shift();

var works = new Array(Days);
input.forEach((item) => {
	var DFI = item[0]-0;
	if(works[DFI] == undefined) works[DFI] = [];
	works[DFI].push(item[1]-0);
});

var G = [];
var D = 1;
var Gain = 0;

var insertG = (income) => {
	var index = 0;
	for(; index < G.length; index++) {
		if(G[index] < income) break;
	}
	G.splice(index, 0, income);
};

for(;D <= Days; D++) {
	if(works[D] !== undefined) {
		works[D].forEach((income) => { G.insertOrderedDesc(income); });
	}
	if(G.length > 0) {
		Gain += G[0];
		G.shift();
	}
}
console.log(Gain);


Measured memory_bytes: 73812
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll h,w,ch,cw,dh,dw;
char tb[1005][1005];
ll mp[1005][1005];
vector<ll> v[1000005];
map<pair<ll,ll>,ll> mp2;
map<ll,ll> mp3;
void dfs(ll rw,ll col,ll ind)
{
	if(rw<=0||rw>h||col<=0||col>w)
	return;
	if(mp[rw][col]!=0)
	return;
	if(tb[rw][col]=='#')
	return;
	mp[rw][col]=ind;
	dfs(rw-1,col,ind);
	dfs(rw+1,col,ind);
	dfs(rw,col-1,ind);
	dfs(rw,col+1,ind);
}

void func(ll start_row,ll start_col,ll end_row,ll end_col,ll rw,ll col)
{
	ll i,j;
	for(i=start_row;i<=end_row;i++)
	{
		for(j=start_col;j<=end_col;j++)
		{
			if(((mp2.find({mp[i][j],mp[rw][col]})==mp2.end())&&(mp[i][j]!=mp[rw][col]))&&(mp[i][j]!=0))
			{
				v[mp[rw][col]].push_back(mp[i][j]);
				v[mp[i][j]].push_back(mp[rw][col]);
				mp2[{mp[i][j],mp[rw][col]}]++;
				mp2[{mp[rw][col],mp[i][j]}]++;
			}
		}
	}
}

ll bfs(ll ind,ll dest)
{
	if(ind==dest)
	return 0;
	bool flag=false;
	ll i,j,z=1,ans=0;
	queue<ll> q;
	q.push(ind);
	mp3[ind]++;
	while(!q.empty())
	{
		j=0;
		z=q.size();
		while(j<z)
		{
			ll x=q.front();
			if(x==dest)
			{
				flag=true;
				break;
			}
			q.pop();
			ll p=v[x].size();
			for(i=0;i<p;i++)
			{
				if(mp3[v[x][i]]==0)
				{
					mp3[v[x][i]]++;
					q.push(v[x][i]);
				}
			}
			j++;
		}
		if(flag)
		break;
		ans++;
	}
	
	if(flag)
	return ans;
	return -1;
}
int main()
{
	ll i,j,ind=1;
	cin>>h>>w>>ch>>cw>>dh>>dw;
	
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			cin>>tb[i][j];
			mp[i][j]=0;
		}
	}
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			if(mp[i][j]==0&&(tb[i][j]=='.'))
			{
				dfs(i,j,ind);
				ind++;
			}
		}
	}
	
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			ll sr=max(i-2,(ll)1);
			ll sc=max(j-2,(ll)1);
			ll er=min(i+2,h);
			ll ec=min(j+2,w);
			if(tb[i][j]!='#')
			func(sr,sc,er,ec,i,j);
		}
	}
	
	/*for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			cout<<mp[i][j]<<" ";
		}
		cout<<"\n";
	}
	
	
	
	for(i=1;i<=ind;i++)
	{
		cout<<i<<": ";
		for(j=0;j<v[i].size();j++)
		{
			cout<<v[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	
	ll x=mp[ch][cw];
	ll y=mp[dh][dw];
	cout<<bfs(x,y);
}

Measured memory_bytes: 73336
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,k,a[200000],b[200000]={0},cnt=0,ans=0;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    b[a[i]-1]++;
  }
  for(int i=0; i<=200000; i++) {
    if(b[i]>0) {
      cnt++;
    }
  }
  if(cnt<=k) {
    cout << 0 << endl;
    return 0;
  }
  sort(b,b+n);
  int c=cnt-k;
  for(int i=0; i<=200000; i++) {
    if(b[i]>0) {
      ans+=b[i];
      c--;
    }
    if(c==0) {
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
/* Karen {{{
 ___  ____
|_  ||_  _|
  | |_/ /    ,--.   _ .--.  .---.  _ .--.
  |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
 _| |  \ \_ // | |, | |    | \__., | | | |
|____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define rrep(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef pair<int, int> P;
typedef pair<int, P> PP;
inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

const int mod = 1e9 + 7;
const int inf = 1e18 + 9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

struct edge
{
  edge() {}
  edge(int a, int b) { to = a; cost = b; }
  int to, cost;
};

int n, m, x;
int t[10000];
vector<edge> G[10000];

int d[10000][512];

void dijkstra()
{
  priority_queue<PP, vector<PP>, greater<PP>> q;
  rep(i, n) rep(j, 512) d[i][j] = inf;
  q.push(PP(0, P(0, -x)));
  d[0][0] = 0;

        int cnt = 0;
  while (!q.empty()){
    PP p = q.top(); q.pop();
    int v = p.se.fi;
                int T = p.se.se;

    for (int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if (T + e.cost < 0 && t[e.to] == 2) continue;
      if (T - e.cost > 0 && t[e.to] == 0) continue;

      int temp;
      if (t[e.to] == 2){
        temp = x;
      } else if (t[e.to] == 0){
        temp = -x;
      } else {
        if (T > 0){
          temp = max(T - e.cost, 0ll);
                                } else {
          temp = min(T + e.cost, 0ll);
        }
      }

      if (d[e.to][temp + x] > d[v][T + x] + e.cost){
        d[e.to][temp + x] = d[v][T + x] + e.cost;
        q.push(PP(d[e.to][temp + x], P(e.to, temp)));
      }
    }
  }
}

signed main()
{
  cin >> n >> m >> x;
  rep(i, n) cin >> t[i];

  rep(i, m){
    int a = in() - 1, b = in() - 1, c = in();
    G[a].pb(edge(b, c));
    G[b].pb(edge(a, c));
  }

  dijkstra();

  int ans = inf;
  rep(j, 512) ans = min(ans, d[n - 1][j]);

  cout << ans << endl;
}

Measured memory_bytes: 44352
#include<iostream>
#include <bits/stdc++.h>
#include<vector>
#include<cstdlib>
#include<fstream>

using namespace std;

int main(){
  int a,b;char op;
  cin>>a>>op>>b;
  if(op=='+')cout<<a+b<<endl;
  else cout<<a-b<<endl;

return 0;}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h> 
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

int a[4];
int main() {
	for (int i = 0; i < 4; i++) scanf("%d", &a[i]);
	sort(a, a+4);
	if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) return 0*puts("YES");
	puts("NO");
	return 0;
} 

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif

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

    ll a, b, v, w, t;

    cin >> a >> v;
    cin >> b >> w;
    cin >> t;

    ll d = std::abs(a - b);

    v -= w;

    // v * t >= d

    cout << (d == 0 || v * t >= d ? "YES" : "NO") << "\n";

    return 0;
}


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

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

  // C >= 1 なので A*B < N であればよい
  ll cnt = 0;
  for (ll a = 1; a <= n - 1; a++) {
    if (n % a == 0) {
      cnt += n / a - 1;
    } else {
      cnt += n / a;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3640
use proconio::input;

fn main() {
    input! {
        n: u16,
    }

    solve(n);
}

fn solve(n: u16) {
    if n / 100 == 7 {
        println!("Yes");
        return;
    }
    if (n % 100) / 10 == 7 {
        println!("Yes");
        return;
    }
    if (n % 10) == 7 {
        println!("Yes");
        return;
    }

    println!("No");
}


Measured memory_bytes: 2172
#[allow(unused_macros)]
macro_rules! input {
  ($($r:tt)*) => {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
      bytes
        .by_ref()
        .map(|r|r.unwrap() as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect()
    };
    input_inner!{next, $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

  ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
    #[allow(unused_mut)]
    let mut $var = read_value!($next, $t);
    input_inner!{$next $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
    ( $(read_value!($next, $t)),* )
  };

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

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

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

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

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

fn main() {
  let stack_size = 104_857_600;
  let thd = std::thread::Builder::new().stack_size(stack_size);
  thd.spawn(|| work()).unwrap().join().unwrap();
}

fn work() {
  input! {
    n: usize,
    a: [u32; n],
  }
  a.sort();
  let mut ans = 0;
  for i in 2..n {
    let mut j = i - 1;
    let mut k = 0;
    loop {
      while k < j && a[k] + a[j] <= a[i] {
        k += 1;
      }
      if k == j {
        break;
      }
      ans += j - k;
      j -= 1;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define _itr ::iterator
#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define ford(i, x, y) for (ll i = x; i > y; --i)
#define forne(i, x, y) for (ll i = x; i <= y; ++i)
#define forde(i, x, y) for (ll i = x; i >= y; --i)
#define rd(x) cin >> x; cin.ignore();
#define rdstr(x) getline(cin, x);
#define rdarr(x, y) for (ll i = 0; i < y; ++i) cin >> x[i];
#define rdmtr(x, y, z) for (ll i = 0; i < y; ++i) for (ll j = 0; j < z; ++j) cin >> x[i][j];
#define pb push_back

#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;

const ll MaxN = 2e5 + 7;
const ll MaxM = 5e3 + 7;
const ll MDL = 1e9 + 7;
const ll INF = 1e18 + 7;

typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef ll arr[MaxN];

ll REPIT = 1;

const bool MQ = false;

ll par[MaxN];

ll Find(ll u)
{
    if (u == par[u]) return u;
    par[u] = Find(par[u]);
    return par[u];
}

void Union(ll u, ll v)
{
    u = Find(u); v = Find(v);
    if (u == v) return;
    if (u > v) swap(u, v);
    par[v] = u;
}

ll n, m;
ll cnt[MaxN];

void Solve()
{
    cin >> n >> m;
    forne(i, 1, n) par[i] = i;
    while (m--)
    {
        ll u, v;
        cin >> u >> v;
        Union(u, v);
    }
    fill(cnt + 1, cnt + n + 1, 0);
    forne(i, 1, n)
    {
        ++cnt[Find(i)];
    }
    cout << *max_element(cnt + 1, cnt + n + 1);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    if (MQ == true)
    {
        rd(REPIT);
    }
    while (REPIT--) Solve();
    cout.flush();
    #ifdef OFFLINE
    fclose(stdin);
    #endif
}


Measured memory_bytes: 6764
//2019.5.17 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-10
#define RG register
inline int read() {
    res s=0,ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline LL Read() {
    RG LL s=0;
    res ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=1e9+7;
namespace MAIN {
    int n;
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    int ans;
    inline int qpow(res x,res y){
        res ret=1;
        while(y){
            if(y&1)ret=mul(ret,x);
            x=mul(x,x),y>>=1;
        }
        return ret;
    }
    int pw=1;
    inline void MAIN(){
        n=read();
        for(res i=0;i<n;i++)pw=mul(pw,3),add(ans,qpow(mul(pw,n-i),kcz-2));
        printf("%d\n",mul(ans,qpow(n,kcz-2)));
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("graph.in","r",stdin);
//    freopen("graph.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
from collections import deque

d = deque([(0, i) for i in range(1, 10)])
K = int(input())
cnt = 0

while len(d) > 0:
    s, i = d.popleft()
    # print(d)

    cnt += 1
    ns = 10*s + i
    # print(ns)
    if cnt == K:
        print(10*s + i)
        break

    l = max(0, i-1)
    r = min(10, i+2)
    for i in range(l, r):
        d.append((ns, i))


Measured memory_bytes: 50268
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


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

  cout << min(a*n,b) << endl;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------


int main(void){
	string s;
	int k;

	cin >> s >> k;

	vector<string> l;
	for(int i = 0; i < s.size(); i++){
		for(int j = 1; j <= k; j++){
			string tmp = s.substr(i, j);
			bool same = false;
			for(int a = 0; a < l.size(); a++){
				if(l[a] == tmp){
					same = true;
					break;
				}
			}
			if(!same){
				l.push_back(tmp);
			}
		}
	}

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

	cout << l[k - 1] << endl;


}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double db;

#define ft first
#define sd second
#define flag bool fl=true

#define mod 1000000007
#define N 100001
#define MX 1000000001
#define MXX 1000000000000000001

#define pb push_back
#define For(i, a, b) for(int i=a;i<=b;i++)
#define T int t, qq=0; cin>>t; while(qq++<t)
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define scarr(array, size) for(int i=0;i<size;i++) cin>>array[i]

#define deg(rad) (rad*180.0)/pi
#define pi acos(-1)
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)


/*
//----------useful_functions----------

long long extended_euclid(ll a, ll b, ll &x, ll &y){//ax+by=c
    if(b==0)
    {
        x=1, y=0;
        return a;
    }

    ll x1, y1;
    ll d=extended_euclid(b, a%b, x1, y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
long long bigMod(ll a, ll b){//(a^b)%mod
    ll ans=1;
    while(b)
    {
        if(b%2==1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
long long modInverse(ll a, ll b){//a*x=1 mod b
    ll x, y;
    ll gcd=extended_euclid(a, b, x, y);

    if(gcd==1) return ((x%b)+b)%b;
    else return 1;
}
long long nCr(ll n, ll r){//n<=1e6
    //declare globally-> ll fact[1000001];
    fact[1]=1;
    for(ll i=2;i<1000001;i++)
        fact[i]=(i*fact[i-1])%mod;

    return (fact[n]*modInverse(fact[r], mod)*modInverse(fact[n-r], mod))%mod;
}
long long josephus(ll n, ll k){//k'th person is killed out of n in the circle
    if(n==1) return 1;
    else return (josephus(n-1, k)+k-1)%n+1;
}

vector<int> sieve(ll n){
    bool fl[n+1];
    vector<int> primes;
    for(int i=0;i<=n;i++) fl[i]=false;

    for(int i=3;i*i<=n;i+=2)
        for(int j=i+i;j<=n;j+=i)
            fl[j]=true;

    primes.pb(2);
    for(int i=3;i<=n;i+=2) if(!fl[i]) primes.pb(i);
    return primes;
}
*/

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

    int a[n+1];
    for(int i=0;i<=n;i++) cin>>a[i];

    ll sum=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;

        if(x>a[i])
        {
            sum+=a[i], x-=a[i];
            if(a[i+1]>x) a[i+1]-=x, sum+=x;
            else  sum+=a[i+1], a[i+1]=0;
        }
        else sum+=x;
    }

    cout<<sum<<endl;
//        cout<<"Case "<<qq<<": ";
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	char d, e, f;
	d = a[0] - 'a' + 'A';
	e = b[0] - 'a' + 'A';
	f = c[0] - 'a' + 'A';
	cout << d << e << f << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int h,a;
    cin>>h>>a;
    cout<<(h+a-1)/a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 111;
int a[N];
int n;

int solve(int p) {
    int ans = 0;
    rep(i, 1, n) {
        int dist = p - a[i];
        ans += dist * dist;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    int p = 0;
    rep(i, 1, n) {
        p += a[i];
    }
    p /= n;
    int ans = min(solve(p), solve(p + 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int x;
	cin>>x;
	int p,q;
	for(int i=-1000;i<=1000;i++)
	{
		for(int j=-1000;j<=1000;j++)
		{
			if(i<0 && j>0)
			{
				continue;
			}
			else
			{
				if(pow(i,5)-pow(j,5)==x)
				{
					 p = i;
					 q = j;
					 cout<<i<<" "<<j<<endl;
					 return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 4096
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int a[N];

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	cin >> n;
	int mx = -1, smx = -1;
	for(int i = 1; i <= n; i++){
		int p;	cin >> p;
		a[i] = p;
		if(p >= mx){
			smx = mx;
			mx = p;
		}
		else if(p > smx)
			smx = p;
	}	
	for(int i = 1; i <= n; i++){
		if(a[i] == mx)
			cout << smx << endl;
		else
			cout << mx << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
 
using namespace std;
 
using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;
 
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
 
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;
 
 
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}
 
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}
 
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}
 
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
 
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
 
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
 
template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}
 
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}
 
template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}
 
template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}
 
template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}
 
  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};
 
template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}
 
 
template< typename T >
struct edge {
  int to, id;
 
  edge(int to, T id) : to(to), id(id) {}
 
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
 
  operator int() const { return to; }
};

int main() {
  vector< int > V(4);
  cin >> V;
  sort(begin(V), end(V));
  int ret = inf;
  do {
    ret = min(ret, abs(V[0] + V[1] - V[2] - V[3]));
  } while(next_permutation(begin(V), end(V)));
  cout << ret << endl;
}



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

int main()
{
	int m, fund, year, n, type, charge, maxim;
	double rate;
	
	cin >> m;
	
	for (int i = 0; i < m; i++) {
		cin >> fund >> year >> n;
		maxim = 0;
		for (int j = 0; j < n; j++) {
			cin >> type >> rate >> charge;
			int tmp = fund;
			if (type) {
				for (int k = 0; k < year; k++) {
					tmp += tmp * rate - charge;
				}
			} else {
				int tmp2 = 0;
				for (int k = 0; k < year; k++) {
					tmp2 += tmp * rate;
					tmp -= charge;
				}
				tmp += tmp2;
			}
			
			maxim = maxim < tmp ? tmp : maxim;
		}
		cout << maxim << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
	long long int a, i, j, menor,x , y;
	scanf("%lld", &a);
	double t = sqrt(a);
	menor = a - 1;
	for ( i = 1; i <= t; i++)
	{
		if (a%i == 0 )
		{
			x = a/i;
			if (i + x < menor)
			{
				menor = i + x - 2;
			}
		}
	}
	printf("%lld\n", menor);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    int buf[2][12], n, i, j, *src, *dst;
    int count[13], num[12], cidx, op_cnt;

    while (scanf("%d", &n) == 1 && n) {
        for (i = 0, cidx = 0; i < n; i++) {
            scanf("%d", &(buf[0][i]));
            for (j = 0; j < cidx; j++) {
                if (num[j] == buf[0][i]) {
                    count[j]++;
                    break;
                }
            }
            if (j == cidx) {
                num[j] = buf[0][i];
                count[j] = 1;
                cidx++;
            }
        }
        for (i = 0; i < n; i++) {
            for (j = 0; j < cidx; j++) {
                if (buf[0][i] == num[j]) {
                    buf[1][i] = count[j];
                    break;
                }
            }
        }
        op_cnt = 0;
        while (1) {
            src = buf[op_cnt&1];
            dst = buf[(op_cnt+1)&1];
            for (i = 0; i < n; i++) {
                if (src[i] != dst[i]) break;
            }
            if (i == n) break;
            for (i = 1; i <= n; i++) {
                count[i] = 0;
            }
            for (i = 0; i < n; i++) {
                count[dst[i]]++;
            }
            for (i = 0; i < n; i++) {
                src[i] = count[dst[i]];
            }
            op_cnt++;
        }
        printf("%d\n%d", op_cnt, src[0]);
        for (i = 1; i < n; i++) {
            printf(" %d", src[i]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 612
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Measured memory_bytes: 22956
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    string s,d;
    cin >> s >> d;

    rep(i,0,3){
        if(s[i] != d[2-i]){
            NO;
            ret 0;
        }
    }
    YES;
	
	return  0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t,a;
int b;
int main()
{
	cin>>s;
	cin>>t;
	a=t+s;
	b=s.size()+t.size();
	for(int i=0;i<b;i++)
		cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
total = 0
for i in range(N-1):
    total += abs(A[i] - A[i+1])
total += abs(0 - A[0]) + abs(0 - A[-1]) 

ans = 0
now = 0
next = 0
next2 = 0
for i in range(N):
    next = A[i]
    if i == 0:
        now = 0
    else:
        now = A[i-1]
    
    if i == N-1:
        next2 = 0
    else:
        next2 = A[i+1]
    
    if now <= next <= next2 or now >= next >= next2:
        ans = total
    elif now <= next2 <= next or now >= next2 >= next:
        ans = total - abs(next2-next)*2
    elif next2 <= now <= next or next2 >= now >= next:
        ans = total - abs(now - next)*2
    
    print(ans)

Measured memory_bytes: 14164
def output(n, m):
    n = str(n)
    m = str(m)
    return "0"*(6-len(n)) + n + "0"*(6-len(m)) + m

def main():
    N, M = map(int , input().split())
    P = [0]*M
    Y = [0]*M
    for i in range(M):
        P[i], Y[i] = map(int, input().split())

    si = [[y, p, i] for i, y, p in zip(range(M), Y, P)]
    si.sort()

    ken = [1] * N
    pp = [0] * M
    for y, p, i in si:
        pp[i] = ken[p-1]
        ken[p-1] += 1

    for i in range(M):
        print(output(P[i], pp[i]))

main()

Measured memory_bytes: 30504
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
len = k.bit_length
arr = Array.new(len,0)
a.each do |x|
  len.times do |i|
    arr[i] += 1 if x[i] == 1
  end
end
bit = ""
arr.each do |x|
  if 2*x > n
    bit = "0" + bit
  else
    bit = "1" + bit
  end
end
x = 0
b = len-1
while b >= 0
  if bit[len-1-b] == "1" && x+2**b <= k
    x += 2**b
  end
  b -= 1
end
ans = 0
a.each do |v|
  ans += v ^ x
end
puts ans

Measured memory_bytes: 22236
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    for(int i=0; i<x; i++) cin>>a[i];
    for(int i=0; i<y; i++) cin>>b[i];
    for(int i=0; i<z; i++) cin>>c[i];
    vector<ll> ans(1e6+1,0);
    priority_queue<ll> ans2;
    for(int i=0; i<x; i++){
        for(int j=0; j<y; j++){
            ans[i*y+j]=a[i]+b[j];
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    for(int i=0; i<min(x*y,k); i++){
        for(int j=0; j<z; j++){
            ans2.push(ans[i]+c[j]);
        }
    }
    for(int i=0; i<k; i++){
        cout<<ans2.top()<<endl;
        ans2.pop();
    }

}


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

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

  vector<int> v(n);
  for (int i=0; i<n; i++)
  {
    cin >> v.at(i);
  }

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

  long long cnt=0;
  for (int i=0; i<n-k; i++)
  {
    cnt += v.at(i);
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1152
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    v = f.read_int_list()

    v.sort()
    ans = v[0]
    for vi in v[1:]:
        ans = (ans+vi)/2.0

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 5148
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(chunk){

var line = chunk.split(' ').map(Number);
var  a = Number(line[0]);
var  b = Number(line[1]);

var d = Math.floor(a / b);
var r = a % b;
var f = (a / b).toFixed(5);

console.log(d +' '+ r + ' ' + f);

});

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

int main()
{
  int h, w;

  cin >> h >> w;

  int a, b;
  cin >> a >> b;


  int ans = 0;
  ans = (h * w) - (a * w + b * h) + (a * b);

  cout << ans;
}


Measured memory_bytes: 3680
#include<iostream>

using namespace std;

int main(){
	int fig_num;
	int two_num=0,four_num=0,one_num=0;
	int buf;

	cin >> fig_num;
	for(int i=0;i<fig_num;i++){
		cin >> buf;

		if(buf%4==0)
			four_num++;
		else if(buf%2==0)
			two_num++;
		else
			one_num++;
	}

	if(two_num >0)
		one_num++;

	if(one_num <= four_num+1)
		cout << "Yes";
	else
		cout << "No";
}


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

using namespace std;

int main() {
    int alpha[9];
    bool blank[9] = { false };
    
    for (int i = 0; i < 9; ++i) {
        cin >> alpha[i];
        if (alpha[i] == -1) {
            blank[i] = true;
        }
    }
    
    vector<int> v;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            if (alpha[j] == i)
                break;
            if (j == 8)
                v.push_back(i);
        }
    }
    
    int ans = 0;
    do {
        int s = 0, c, t;
        for (int i = 0; i < 9; ++i) {
            if (blank[i] == false)
                continue;
            alpha[i] = v[s++];
        }
        
        t = alpha[0] + alpha[2] + alpha[5];
        if (t % 10 != alpha[8])
            continue;
        c = t / 10;
        
        t = c + alpha[1] + alpha[4];
        if (t % 10 != alpha[7])
            continue;
        c = t / 10;
        
        t = c + alpha[3];
        if (t % 10 != alpha[6] || t >= 10)
            continue;
        
        ans++;
    } while(next_permutation(v.begin(), v.end()));
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static class FenwickTree {
	    int n;
	    long x[];
	    public FenwickTree(int N) {
	    	this.n = N;
	    	x = new long[N + 1] ;
		}
	    int size()  { return n; }
	    long sum(int i) {
	    	long ret = 0;
	        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
	            ret += x[idx];
	        }
	        return ret;
	    }
	    long sum(int l, int r)  { return sum(r) - sum(l); }
	    void add(int i, long v) {
	        for (int idx = i; idx <= n; idx += (idx & -idx)) {
	            x[idx] += v;
	        }
	    }
	};
	static class FT2{
		FenwickTree bit0;
		FenwickTree bit1;
		public FT2(int N) {
			bit0 = new FenwickTree(N);
			bit1 = new FenwickTree(N);
		}		
		void add(int l , int r, long x){
			bit0.add(l, - x * (l - 1));
			bit1.add(l, x);
			bit0.add(r + 1, x * r);
			bit1.add(r + 1, -x);
		}
		long sum(int i){
			return bit0.sum(i) + bit1.sum(i) * i;
		}
	}

	static class Query implements Comparable<Query>{
		int id;
		int l;
		int r;
		public Query(int idx , int a , int b) {
			id= idx;
			l = a;
			r = b;
		}
		@Override
		public int compareTo(Query o) {
			return r - o.r;
		}
	}
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String arr[] = line.split(" ");
		int N = Integer.parseInt(arr[0]);
		int Q = Integer.parseInt(arr[1]);
		int C[] = new int[N];
		line = br.readLine();
		arr = line.split(" ");
		for(int i = 0 ; i < N ; ++i){
			C[i] = Integer.parseInt(arr[i]);
		}		
		List<Query> queries = new ArrayList<>();
		for(int q = 0 ; q < Q ; ++q){
			line = br.readLine();
			arr = line.split(" ");
			int l = Integer.parseInt(arr[0]);
			int r = Integer.parseInt(arr[1]);
			queries.add(new Query(q, l , r));
		}
		int ans[] = new int[Q];
		Collections.sort(queries);
		FT2 ft2 = new FT2(N);
		int curR = 0;
		Map<Integer, Integer> occurance = new HashMap<Integer, Integer>();
		for(Query query : queries){
			if(curR < query.r){
				for(int r = curR ; r < query.r; ++r){
					int c = C[r];
					if(occurance.containsKey(c)){
						int l = occurance.get(c);
						ft2.add(l + 2, r + 1, 1);						
					}else{
						ft2.add(1, r + 1, 1);
					}
					occurance.put(c, r);
				}
				curR = query.r;
			}			
			long ret = ft2.sum(query.l) - ft2.sum(query.l - 1);
			ans[query.id] = (int)ret;
		}
		StringBuilder sb = new StringBuilder();
		for(int a : ans){
			sb.append(a);
			sb.append('\n');
		}
		System.out.print(sb.toString());
	}
}


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

using namespace std;

int main()
{
    string s1, s2 , s3;
    cin >> s1>> s2>> s3;
    cout <<(char)toupper(s1[0])<<(char)toupper(s2[0])<<(char)toupper(s3[0]);

    return 0;
}


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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif


int main(void)
{
	ll n; cin >> n;
	vector<ll> a(n), b(n), c(n);

	rep(i, 0, n)
	{
		cin >> a[i];
		a[i]--;
	}
	rep(i, 0, n)
		cin >> b[i];
	rep(i, 0, n - 1)
		cin >> c[i];

	ll ans = b[a[0]];
	rep(i, 1, n)
	{
		if (a[i - 1] + 1 == a[i])
			ans += (b[a[i]] + c[a[i] - 1]);
		else
			ans += b[a[i]];
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int com(const void *a,const void *b) {
    return *(int*)a-*(int*)b;
}
int main()
{
    ll n,cen=0;
    scanf("%lli",&n);
    ll num[n];
    fr(i,0,n) {
        scanf("%lli",&num[i]);   
    }
    qsort(num,n,sizeof(ll),com);
    fr(i,0,n-1) {
        if(num[i] == num[i+1]) {
            cen = 1;
            break;
        }
    }
    if (cen == 1) {
        puts("NO");
    } else {
        puts("YES");
    }
    return 0;
}

Measured memory_bytes: 4672
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if((x - r < 0 || x + r > W) || (y - r < 0 || y + r > H)){
        printf("No\n");
    }else if((x - r >= 0 && x + r <= W) && (y - r >= 0 && y + r <= H)){
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 2112
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
constexpr double EPS = 1e-6;
constexpr int MAX_LINE = 50;
std::vector<std::pair<double, double>> lines[MAX_LINE + 1]; //[0]????????¨??¨?????????

int main() {
	int n, m;
	while (std::cin >> n && n) {
		std::vector<int> identical;
		for (auto& x : lines) x.clear();
		for (int i = 0; i < n + 1; i++) {
			std::cin >> m;
			for (int j = 0; j < m; j++) {
				int x, y; std::cin >> x >> y;
				lines[i].push_back(std::make_pair(x, y));
			}
		}

		//??¨???????????????????§????
		for (int i = 0; i < n + 1; i++) {
			double minX = 999999, maxX = -999999, minY = 999999, maxY = -999999;
			for (auto& x : lines[i]) {
				minX = std::min(minX, x.first);
				maxX = std::max(maxX, x.first);
				minY = std::min(minY, x.second);
				maxY = std::max(maxY, x.second);
			}
			for (auto& x : lines[i]) {
				x.first -= (minX + maxX) / 2; x.second -= (minY + maxY) / 2;
			}
		}

		//?????¢??????????????????
		double angle = M_PI_2;
		for (int k = 0; k < 4; k++) {
			for (auto& x : lines[0]) {
				double nx = x.first, ny = x.second;
				nx = x.first * std::cos(angle) - x.second * std::sin(angle);
				ny = x.first * std::sin(angle) + x.second * std::cos(angle);
				x.first = nx; x.second = ny;
			}

			//???????????¨?????´??????????¢??????????
			for (int i = 1; i < n + 1; i++) {
				//???????????°??????????????§?????´???????????¨?????????
				if (lines[0].size() != lines[i].size()) continue;

				bool ok = true;
				for (int j = 0; j < lines[i].size(); j++) {
					if (!(std::abs(lines[i][j].first - lines[0][j].first) < EPS
						&& std::abs(lines[i][j].second - lines[0][j].second) < EPS)) {
						ok = false; break;
					}
				}
				if(!ok) {
					ok = true;
					for (int j = lines[i].size() - 1; j >= 0; j--) {
						if (!(std::abs(lines[i][j].first - lines[0][lines[0].size() - j - 1].first) < EPS
							&& std::abs(lines[i][j].second - lines[0][lines[0].size() - j - 1].second) < EPS)) {
							ok = false; break;
						}
					}
				}

				if (ok && std::find(identical.begin(), identical.end(), i) == identical.end()) {
					identical.push_back(i);
				}
			}
		}
		std::sort(identical.begin(), identical.end());
		for (auto& x : identical) std::cout << x << std::endl;
		std::cout << "+++++" << std::endl;
	}

	return 0;
}

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

const int N = (1e5) + 5;
bool done[N];
int memo[N];
int a[N], n, k;

int dp(int pos) {
	if (pos == n - 1) {
		return 0;
	}
	int &ret = memo[pos];
	if (done[pos]) return ret;
	done[pos] = 1;
	ret = INT_MAX;
	for (int i = 1; i <= k; ++i) {
		if (pos + i < n) {
			ret = min(ret, abs(a[pos] - a[pos + i]) + dp(pos + i));
		}
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	scanf("%d", &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	memset(done, 0, sizeof done);
	printf("%d\n", dp(0));
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    long long a,b,ok=0;
    cin>>n;
    for(long long i=0;ok==0;i++){
        for(long long j=0;j<i;j++){
            if(pow(i,5)-pow(j,5)==n){
                a=i;
                b=j;
                ok=1;
                break;
            }
            if(pow(i,5)-pow(-j,5)==n){
                a=i;
                b=-j;
                ok=1;
                break;
            }
            if(pow(i,5)-pow(j,5)>n&&pow(i,5)-pow(j,5)<0){
                break;
            }
        }
    }
    cout<<a<<" "<<b<<"\n";
	return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	a--;b--;c--;d--;
	string s;
	cin>>s;
	bool ans=true;
	bool flag=false;
	if(c>d){
		//if(s[d-1]=='#'||s[d+1]=='#')s[d]='#';
		int cnt=0;
		for(ll i=a;i<d+2;i++){
			if(i>=n)break;
			if(s[i]=='.'){
				cnt++;
			}else{
				cnt=0;
			}
			if(cnt>=3){
				if(cnt==3&&s[i+1]=='#'&&(i==b)){
					cnt=0;
					continue;
				}
				flag=true;
			}
		}
		if(!flag)ans=false;
		s[d]='.';
		ll a_pos = a;
		for(;;){
			if(s[a_pos+2]=='.'&&a_pos+2<=c){
				a_pos+=2;
			}else if(s[a_pos+1]=='.'&&a_pos+1<=c){
				a_pos+=1;
			}else{
				ans = false;
				break;
			}
			if(a_pos==c)break;
		}

		ll b_pos=b;
		for(;;){
			if(s[b_pos+2]=='.'&&b_pos+2<=d){
				b_pos+=2;
			}else if(s[b_pos+1]=='.'&&b_pos+1<=d){
				b_pos+=1;
			}else{
				ans = false;
				break;
			}
			if(b_pos==d)break;
		}

	}else{
		ll b_pos=b;
		for(;;){
			if(s[b_pos+2]=='.'&&b_pos+2<=d){
				b_pos+=2;
			}else if(s[b_pos+1]=='.'&&b_pos+1<=d){
				b_pos+=1;
			}else{
				//cout<<"aa"<<endl;
				ans = false;
				break;
			}
			if(b_pos==d)break;
		}
		ll a_pos = a;
		for(;;){
			if(s[a_pos+2]=='.'&&a_pos+2<=c){
				a_pos+=2;
			}else if(s[a_pos+1]=='.'&&a_pos+1<=c){
				a_pos+=1;
			}else{
				//cout<<a_pos<<" "<<endl;
				ans = false;
				break;
			}
			if(a_pos==c)break;
		}
	}
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 764
def count_AB(s):
    res = 0
    for j in range(len(s) - 1):
        if s[j] == 'A' and s[j + 1] == 'B':
            res += 1
    return res


N = int(input())
sA, BsA, Bs = (0, 0, 0)
ans = 0
for i in range(N):
    s = input()
    if s[0] == 'B' and s[-1] == 'A':
        BsA += 1
        if len(s[1:-1]) > 0:
            ans += count_AB(s[1:-1])
    elif s[0] == 'B':
        Bs += 1
        if len(s[1:]) > 0:
            ans += count_AB(s[1:])
    elif s[-1] == 'A':
        sA += 1
        if len(s[:-1]) > 0:
            ans += count_AB(s[:-1])
    else:
        ans += count_AB(s)

if BsA == 0:
    ans += min(sA, Bs)
else:
    if sA + Bs == 0:
        ans += BsA - 1
    else:
        ans += BsA
        ans += min(sA, Bs)

print(ans)

Measured memory_bytes: 3064