akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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 mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

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

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

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

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

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

// use std::io::{stdout, Write, BufWriter};
// use std::cmp::min;

fn main() {
    input! {
        n: usize,
        x: i32,
        a: [i32; n],
    }
    a.sort();
    let mut ans = 0;
    for (i, demand) in a.into_iter().enumerate() {
        x -= demand;
        ans += 1;
        if x < 0 || (x > 0 && i == n - 1) {
            println!("{}", ans - 1);
            break;
        } else if i == n - 1 {
            println!("{}", ans);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int N = 100005;
int a[N], b[N], c[N];

int main() {
	LL ans = 0;
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%d", &a[i]);
	REP(i, n)scanf("%d", &b[i]);
	REP(i, n)scanf("%d", &c[i]);
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	int ia = 0, ic = 0;
	REP(ib, n) {
		while (ia < n && a[ia] < b[ib])ia++;
		while (ic < n && b[ib] >= c[ic])ic++;
		ans += (LL)ia * (n - ic);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    int N, mean_i;
    int ans = 0;
    double sum, mean, a;
    std::cin >> N;
    
    vector<double> hito(N);

    for(int i = 0; i < N; i++){
        std::cin >> a;
        hito[i] = a;
        sum = sum + a;
    }

    mean = sum/(double)N;
    mean_i = round(mean);
    
    for(int i = 0; i < N; i++){
        ans = ans + (int)round(pow(hito[i]-mean_i, 2.0));
    }

    std::cout << ans;



  
}


Measured memory_bytes: 3728
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=(n); ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n;cin>>n;
    double ans = pow(floor(sqrt(n)),2);
    cout<<(int)ans<<endl; return 0;
}


Measured memory_bytes: 256
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def toi(h,w):
	return h*10000 + w
	
def fromi(v):
	return v//10000, v%10000

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	ch, cw = tin()
	start_h,start_w = ch-1,cw-1
	dh,dw = tin()
	goal_h, goal_w=dh-1, dw-1
	ll=[input() for _ in range(h)]
	pll=[[-1]*w for _ in range(h)]
	egg = [[] for _ in range(w*h)]
	
	mark=-1
	for hi in range(h):
		for wi in range(w):
			if ll[hi][wi]=='#':
				continue
			if pll[hi][wi] >= 0:
				continue
			mark+=1
			qq=collections.deque()
			qq.append(toi(hi,wi))
			open_list=set()
			open_list.add(toi(hi,wi))
			while len(qq)>0:
				nv = qq.popleft()
				nh, nw = fromi(nv)
				pll[nh][nw] = mark
				for dh,dw in [[1,0], [-1,0], [0,1], [0,-1]]:
					if nh + dh < 0 or nh + dh >= h:
						continue
					if nw + dw < 0 or nw + dw >= w:
						continue
					if toi(nh+dh,nw+dw) in open_list:
						continue
					if ll[nh + dh][nw+dw]=='#':
						egg[mark].append([nh,nw,dh,dw])
						continue
					if pll[nh + dh][nw+dw] > 0:
						continue
					qq.append(toi(nh + dh, nw+dw))
					open_list.add(toi(nh+dh,nw+dw))
					
	#print(pll)
	if pll[start_h][start_w] == pll[goal_h][goal_w]:
		return 0
	#for l in egg:	
	#	print(l)
	
	qqq=collections.deque()
	qqq.append((pll[start_h][start_w],0))
	g_pos=pll[goal_h][goal_w]
	open_list=set()
	open_list.add(-1)
	#pa('tttt')
	while len(qqq)>0:
		pos, cost = qqq.popleft()
		if pos == g_pos:
			return cost
		for [nh,nw,_h,_w] in egg[pos]:
			for dh in [-2,-1,0,1,2]:
				for dw in [-2,-1,0,1,2]:
					nnh = nh + dh
					nnw = nw + dw
					if nnh < 0 or nnh >= h:
						continue
					if nnw < 0 or nnw >= w:
						continue
					vv = pll[nnh][nnw]
					if vv in open_list:
						continue
					qqq.append((vv, cost+1))
					open_list.add(vv)
					#pa((vv,g_pos))
		
	return -1
		
		
			
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n) cin>>a[i];
	int mn=10e9+1;
	int mx=0;
	rep(i,n){
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	cout << mx-mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<int>vec;
int main(){
	cin>>n;
	rep(i,n){
		int a; cin>>a; vec.pb(a);
	}
	vector<int>ans;
	for(int i=0;i<n;i++){
		for(int j=vec.size()-1;j>=0;j--){
			if(vec[j] == j+1){
				    ans.pb(j+1);
					vector<int>nw;
					for(int w=0;w<vec.size();w++){
						if(w == j) continue;
						nw.pb(vec[w]);
					}
					vec = nw;
					goto nxt;
			}
		}
		if(true){
				puts("-1");
				return 0;
		}
		nxt:;
					
					
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

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

int main(void){
	int H, W;
	string f[2][1010];
	cin >> H >> W;
	queue<PII> que[2];
	REP(i, H){
		cin >> f[0][i];
		REP(j, W){
			if(f[0][i][j] != '.')
				que[0].push(PII(i, j));
		}
	}
	int cnt = 0;
	ll res = 0;
	while(1){
		cnt = 0;
		set<PII> st;
		REP(i, 1010){
			f[(res+1)%2][i] = f[res%2][i];
		}
		while(que[res%2].size()){
			PII p = que[res%2].front(); que[res%2].pop();
			int sarati = 0;
			REP(i, 8){
				if(f[res%2][p.first+dy[i]][p.second+dx[i]] == '.')
					sarati++;
			}
			if(f[res%2][p.first][p.second] != '.' && sarati >= f[res%2][p.first][p.second]-'0'){
				f[(res+1)%2][p.first][p.second] = '.';
				REP(i, 8){
					if(f[res%2][p.first+dy[i]][p.second+dx[i]] != '.')
						st.insert({p.first+dy[i], p.second+dx[i]});
				}
				cnt++;
			}
		}
		for(auto x : st){
			que[(res+1)%2].push(x);
		}
		if(cnt == 0) break;
		else res++;
	}
	cout << res << endl;
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
S = str(input())

w = '.'
b = '#'

white = [0 for i in range(n+1)]
black = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
for i in range(n):
    if S[i] == b:
        black[i+1] = black[i] + 1
    else:
        black[i+1] = black[i]
    if S[-i-1] == w:
        white[-i-2] = white[-i-1] + 1
    else:
        white[-i-2] = white[-i-1]

for i in range(n+1):
    ans[i] = white[i] + black[i]
print(min(ans))


Measured memory_bytes: 20948
# AtCoder Beginner Contest 134 E - Sequence Decomposing

import sys

N = int(input())
now = int(sys.stdin.readline().strip())
ans = [now]

for n in range(N - 1):
    now = int(sys.stdin.readline().strip())

    if now > ans[0]:
        ans[0] = now
    elif ans[-1] >= now:
        ans.append(now)
    else:
        # 2部探査で行進位置を探る
        left = 0  # 挿入不可能
        right = len(ans) - 1  # 挿入可能

        while right - left > 1:
            mid = (right + left) // 2
            if now > ans[mid]:
                right = mid
            else:
                left = mid

        ans[right] = now

print(len(ans))


Measured memory_bytes: 12696
#include <cstdio>

typedef long long ll;

ll Q, H, S, D;
ll N;

ll solve() {
    if (Q*4 <= H*2 && Q*4 <= S && Q*8 <= D) return Q * 4 * N;
    if (H*2 <= Q*4 && H*2 <= S && H*4 <= D) return H * 2 * N;
    if (S <= Q*4 && S <= H*2 && S*2 <= D) return S * N;
    if (N % 2 == 0) return D * N / 2;
    
    N /= 2;
    if (Q*4 <= H*2 && Q*4 <= S) return D * N + Q * 4;
    if (H*2 <= Q*4 && H*2 <= S) return D * N + H * 2;
    return D * N + S;
}

int main(void)
{
    scanf("%lld%lld%lld%lld", &Q, &H, &S, &D);
    scanf("%lld", &N);
    
    printf("%lld\n", solve());
    return 0;
}

Measured memory_bytes: 128
a,b,c,x = 4.times.map{gets.to_i}

cnt = 0

(0..a).each do |i|
  (0..b).each do |m|
    (0..c).each do |n|
      cnt += 1 if i * 500 + m * 100 + n * 50 == x
    end
  end
end
  
puts cnt

Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define ass_on_fire          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               a.begin(),a.end()
#define rall(a)              a.rbegin(),a.rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=1;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ass_on_fire
    char ch;cin>>ch;
    if(isupper(ch)) cout<<"A";
    else cout<<"a";
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int a, b, c, ops = 0;
	cin >> a >> b >> c;

	{
		int arr[3] = {a, b, c};
		sort(arr, arr + 3);
		a = arr[0], b = arr[1], c = arr[2];
	}
	
	{
		int op = (c - a) / 2;
		ops += op, a += op * 2;
	}
	{
		int op = (c - b) / 2;
		ops += op, b += op * 2;
	}
	
	{
		int arr[3] = {a, b, c};
		sort(arr, arr + 3);
		a = arr[0], b = arr[1], c = arr[2];
	}

	if (a == b && b != c) {
		ops++;
	} else if (a != b && b == c) {
		ops++; ops++;
	}
	cout << ops << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define maxn 1000010
using namespace std;
char s[maxn];
struct node{
	int l,r;
}a[maxn];
int tot;
int cmp(node a,node b){
	return a.l-a.r>b.l-b.r;//((((((让左括号剩得尽可能多
}
int main(){
	int n,i,j,l,r,ln,rn;
	ln=rn=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		l=r=0;
		scanf("%s",s+1);
		for(j=1;s[j];j++){
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;//匹配
				else r++;
			}
		}
		if(l&&!r)ln+=l;
		else if(!l&&r)rn+=r;
		else if(l&&r) a[++tot]=(node){l,r};
	}
	sort(a+1,a+1+tot,cmp);
	for(i=1;i<=tot;i++)
		if(ln<a[i].r)return printf("No\n"),0;
		else ln-=a[i].r,ln+=a[i].l;
	if(ln!=rn)return printf("No\n"),0;
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3120
h,w=map(int, input().split())
alist=['']*h
for i in range(h):
  alist[i]=input()
hlist=[]
wlist=[]
for i in range(h):
  flag=False
  for j in range(w):
    if alist[i][j]=='#':
      flag=True
  if flag:
    hlist.append(i)
for i in range(w):
  flag=False
  for j in range(h):
    if alist[j][i]=='#':
      flag=True
  if flag:
    wlist.append(i)
for i in hlist:
  ans=[]
  for j in wlist:
    ans.append(alist[i][j])
  print(''.join(ans))

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

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

ll a[100005], b[100005];
int n, k;

void solve()
{
    for (int i = 2; i <= n; ++i)
    {
        if (a[i] == -1)
            continue;
        b[i] = (b[i - 1] + b[i - 2]) % 1000000007;
    }
}

int main()
{
    cin >> n >> k;
    b[0] = 1;
    b[1] = 1;
    int x;
    for (int i = 0; i < k; ++i)
    {
        sf(x);
        a[x] = -1;
    }
    if (a[1] == -1)
        b[1] = 0;

    solve();
    cout << b[n] << endl;
return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long
int main(){
	ll s, n;
	cin >> s >> n;
	ll a[200001];
	ll sum = 0;
	ll mx = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i > 1){
			sum += abs(a[i] - a[i - 1]);
			mx = max(mx, abs(a[i] - a[i - 1]));
		}
	}
	ll sd = abs(a[n] - s) + a[1];
	if(mx > sd) sum = (sum - mx) + sd;
	cout << sum << endl;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll n;
  cin >> n;
  vec<ll> a(n);
  scan(a);

  map<ll, ll> c;
  rep(i, 0, n) { c[a[i]]++; }

  ll two = 0;
  for (auto& p : c) {
    if (p.second % 2 == 0) two += 1;
  }

  put(sz(c) - (two % 2));
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long

const int MOD = 1e9 + 7;

int main()
{
    int a, b, n;
    cin >> a >> b;
    if(a == b) {
        cout << "Draw" << endl;
    } else if (a == 1) {
        cout << "Alice" << endl;
    } else if (b == 1) {
        cout << "Bob" << endl;
    } else if(a > b) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    string s;
    cin >> s;
    ll n = s.length();
    ll a[26] = {};
    REP(i,n){
        a[s[i]-'a']++;
    }
    ll ans = n * (n-1) / 2 + 1;

    REP(i,26){
        ans -= a[i] * (a[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    rep(i, N) cin >> x[i];
    x.push_back(X);

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

    vector<int> y;
    rep(i, N) y.push_back(x[i+1]-x[i]);

    int l = y.size();
    if (l == 1) {
        cout << y[0] << endl;
        return 0;
    }

    // cout << "l: " << l << endl;
    // cout << "here?" << endl;
    int d = gcd(y[0], y[1]);
    for (int i = 2; i < l; i++) {
        // cout << "here?" << endl;
        d = gcd(d, y[i]);
    }

    cout << d << endl;
    return 0;
}

Measured memory_bytes: 4576
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pprint import pprint as pp
from pprint import pformat as pf

def solve_odd(n, m):
    for i in range(m):
        print(i + 1, n - (i + 1))

def solve_even(n, m):
    offset = 1
    half = int(n / 2)
    diff = half - 1
    for i in range(m):
        start = offset
        end = start + diff
        if i % 2 != 0:
            start += half
            end += half
            # for next 2 loop
            offset += 1
        print(start, end)
        # for next loop
        diff -= 1



if __name__ == '__main__':
    n, m = map(int, input().split())
    if n % 2 == 0:
        solve_even(n, m)
    else:
        solve_odd(n, m)


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

int main(){
  string s;
  cin>>s;
  int x=0;
  int y=0;
  
  rep(i,s.size()){
    if(s[i] == '0')
      x++;
    else
      y++;
  }
  int res = min(x,y)*2;
  cout<<res<<endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
const int INF = 1e9;

struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];//高さを更新
      data[y] = x;//親を更新
    }
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};

int main(){
  int N;
  while(cin >> N && N){
    vector< vector<int> > G(N, vector<int>(N, INF));
    for(int i = 0; i < N; ++i) G[i][i] = 0;
    vector<double> P(N);
    int m;
    for(int i = 0; i < N; ++i){
      cin >> P[i] >> m;
      int v;
      for(int j = 0; j < m; ++j){
        cin >> v;
        G[i][v-1] = 1;
      }
    }
    for(int k = 0; k < N; ++k){
      for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
          G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
        }
      }
    }
    UnionFind uf(N);
    vector<int> d_in(N, 0);
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < i; ++j){
        if(G[i][j] < INF && G[j][i] < INF){
          uf.unite(i, j);
        }
      }
    }
    for(int i = 0; i < N; ++i){
      if(i != uf.find(i)) P[uf.find(i)] *= P[i];
    }
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
        if(G[i][j] == 1 && !uf.same(i, j)) ++d_in[j];
      }
    }
    double ans = 1;
    for(int i = 0; i < N; ++i){
      if(uf.find(i) == i && d_in[i] == 0) ans *= 1 - P[i];
    }
    printf("%.12f\n", ans);
  }
  return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll x;
    cin >> x;
    ll now = 100, ans = 0;
    while(now < x){
        now += now/100;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
import sys
from collections import deque


def main():
    n, m = map(int, sys.stdin.readline().split())

    out_list = [[] for _ in range(n + 1)]
    in_cnt = [0] * (n + 1)
    in_cnt[0] = -1
    for _ in range(n - 1 + m):
        a, b = map(int, sys.stdin.readline().split())
        out_list[a].append(b)
        in_cnt[b] = in_cnt[b] + 1
    root = in_cnt.index(0)
    ans = [0] * (n + 1)
    que = deque([])
    que.append(root)

    while que:
        p = que.popleft()
        for i in out_list[p]:
            in_cnt[i] = in_cnt[i] - 1
            if in_cnt[i] == 0:
                que.append(i)
                ans[i] = p

    for i in ans[1:]:
        print(i)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21564
def solve():
    N, M = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    A.sort(reverse = True)
    BC = []
    for i in range(M):
        Bi, Ci = [int(_) for _ in raw_input().split()]
        BC.append([Bi, Ci])
    BC.sort(key = lambda x: x[1], reverse = True)
    ind_BC = 0
    ind_A = 0
    merged = []
    while ind_A < N and ind_BC < M:
        Bi = BC[ind_BC][0]
        Ci = BC[ind_BC][1]
        if A[ind_A] > Ci:
            merged.append(A[ind_A])
            ind_A += 1
        else:
            merged.extend([Ci] * Bi)
            ind_BC += 1
        if len(merged) >= N:
            break
    if len(merged) < N:
        if ind_A < N:
            merged.extend(A[ind_A:])
        elif ind_BC < M:
            for i in range(ind_BC, M):
                Bi = BC[ind_BC][0]
                Ci = BC[ind_BC][1]
                merged.extend([Bi] * Ci)
                if len(merged) >= N:
                    break
    merged = merged[:N]
    print sum(merged)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 62624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c;
  long long ans=0;
  cin>>n>>m;
  vector<int> a(n);
  priority_queue<int> pque;
  for(int i=0;i<n;i++){
    cin>>a[i];
    pque.push(a[i]);
  }
  for(int i=0;i<m;i++){
    c=pque.top(); pque.pop();
    c/=2;
    pque.push(c);
  }
  for(int i=0;i<n;i++){
      c=pque.top();pque.pop();
      ans+=c;
  }
  cout<<ans;
}


Measured memory_bytes: 1276
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int inp(){
	int Ans;char C;bool O=false;
	while((C=getchar())<'0'||C>'9')if(C=='-')O=true;Ans=C-48;
	while((C=getchar())>='0'&&C<='9')Ans=(Ans<<3)+(Ans<<1)+C-48;
	return O==true?-Ans:Ans;
}

int main()
{
	int k=inp(),x=inp();
	if(k*500>=x)cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
#define r  1000001
int main()
{
    ll n;
    cin>>n;

    ll mini=n-1;

    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll d=n/i;
            mini=min(mini,i+d-2);
        }
    }
    cout<<mini<<"\n";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main()
{
int e,f,g;
cin>>e>>f>>g;
if(e==f && e!=g)
{
cout<<"Yes";
}
else if(f==g && g!=e)
{
 cout<<"Yes";
}
else if(e==g && e!=f)
{
 cout<<"Yes";
}
else
{
 cout<<"No";
}
return 0;
}

Measured memory_bytes: 256
#import<iostream>
#define l long
l N,M,c,n=1,i=2,o=1e9+7;l m(l a){l g=1,h=2*o-4;for(;h/=2;h&1?g=g*a%o:0,a=a*a%o);return g;}l C(l b){l r=1,d=1;for(;b;r=r*(N-1+b)%o,d=d*b--%o);return r*m(d)%o;}main(){for(std::cin>>N>>M;i*i<=M;++i,n=n*C(c)%o)for(c=0;M%i<1;++c,M/=i);std::cout<<n*(M^1?N:1)%o<<std::endl;}

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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  int min = 200001;
  int ans = 0;
  for(int i=0; i<n; i++) {
    int p;
    cin >> p;
    if(p < min) {
      ans++;
      min = p;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int ara[100009];
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>ara[i];
    sort(ara,ara+n);
    int ans=(ara[n/2]-ara[n/2-1]);
    cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		new Main().run();
	}
	public void run() {
		try {
			// ??????????????????????????????
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			while(true){
				int imputNumber = Integer.parseInt(br.readLine());
				if(imputNumber == 0){
					break;
				} else {
					System.out.println(calc(imputNumber));
				}
			}
		} catch (Exception e) {
			e.getStackTrace();
			System.exit(0);
		}
	}
	private static int calc(int inputNumber){
		int count = 0;
		int maxNum = inputNumber !=1 ?(inputNumber%2 == 0 ? inputNumber/2 : inputNumber/2 + 1): 0;
		int nTmp = 0;
		
		for (int presentMaxNum = maxNum; presentMaxNum > 0; presentMaxNum--){
			for (int content = presentMaxNum; content > 0; content--) {
				nTmp = nTmp + content;
				if(nTmp < inputNumber) {
					if(content == 1){
						nTmp = 0;
						break;
					} else {
						continue;
					}
				} else if (nTmp == inputNumber) {
					count++;
					nTmp = 0;
					break;
				} else if (nTmp > inputNumber) {
					nTmp = 0;
					break;
				}
			}
		}
		return count;
	}
}

Measured memory_bytes: 24308
s = input()
f, b = int(s[:2]), int(s[2:])
if ((0 < f and f <= 12) and (b > 12 or b == 0)): print("MMYY")
elif ((0 < b and b <= 12) and (f > 12 or f == 0)): print("YYMM")
elif (f == 0 or b == 0 or (f > 12 and b > 12)): print("NA")
else: print("AMBIGUOUS")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	int n,m;
	cin>>n>>m;
	if(n>m){
		for(int i=1;i<=n;i++) cout<<m;
	}else if(m>=n){
		for(int i=1;i<=m;i++)cout<<n;	
	}
}

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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int c=-1,d=-1;
    for(int i=0;i<n-1;i++){
        if(a[i+1]<a[i]){
            if(c!=-1){
                swap(a[i+1],a[c]);
                c=-1;
                break;
            }
            else if(c==-1){
                c=i;
            }
        }
    }
    if(c!=-1){
        swap(a[c+1],a[c]);
    }
    int flag=0;
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            flag=1;
            break;
        }
    }
    if(flag==1){
        cout << "NO";
    }
    else{
        cout << "YES";
    }

return 0;
}

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

using namespace std;


int main() {
    long long D = 30LL;
    while(true) {
        long long N; cin >> N;
        if(N == 0LL) return 0;
        vector<long long> free_days;
        for(long long i = 0LL; i < N; ++i) {
            long long m; cin >> m;
            long long day = 0LL;
            for(long long j = 0LL; j < m; ++j) {
                long long f; cin >> f;
                day |= (1LL << f);
            }
            free_days.emplace_back(day);
        }
        vector<vector<long long>> dp_maps;

        vector<long long> day_maps;
        for(long long n = 0LL; n < N; n++) {
            day_maps.emplace_back(1LL << n);
        }
        dp_maps.emplace_back(day_maps);

        for(long long d = 1; d <= D; ++d) {
            long long day_map = 0LL;
            for(long long n = 0LL; n < N; n++) {
                if(free_days[n] & (1LL << d)) {
                    day_map |= dp_maps[d-1][n];
                }
            }
            for(long long n = 0LL; n < N; n++) {
                if(free_days[n] & (1LL << d)) {
                    day_maps[n] = day_map;
                } else {
                    day_maps[n] = dp_maps[d-1][n];
                }
                if(day_maps[n] + 1LL == 1LL << N) {
                    cout << d << endl;
                    goto end;
                }
            }
            dp_maps.emplace_back(day_maps);
        }
        cout << -1 << endl;
        end: continue;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>

int main(void)
{
	int i,t;
	char num[1000];
	
	do{
		i=0;
		t=0;
		scanf("%s",num);
		if(num[0] != '0')
		{
			while(num[i]!='\0')
				t += (num[i++]-'0');
			printf("%d\n",t);
		}
		
	}while(num[0] != '0');
	
	
	return 0;
}

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

int main() {
 int N;
 cin>>N;
vector<int>vec(N-1);
vector<int>answer(N);
for(int i=0; i<N; i++){
answer.at(i)=0;
}
for(int i=0; i<N-1; i++){
cin>>vec.at(i);
}
for(int i=0; i<N-1; i++){
int b=vec.at(i);
answer.at(b-1)++;
}
for(int i=0; i<N; i++){
cout<<answer.at(i)<<endl;
}
}

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

#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int r,c;
int grid[1000][1000];
int visi[1000][1000];
int dx[]={-1,+1,0,0};
int dy[]={0,0,-1,+1};
void dfs(int i,int j,int cnt)
{
    visi[i][j]=1;
    grid[i][j]=cnt;
    for(int x=0;x<4;x++)
    {
        int I=i+dx[x];
        int J=j+dy[x];
        if(I>=0 && I<r && J>=0 && j<c && grid[I][J]==0 && visi[I][J]==0)
        {
            dfs(I,J,cnt);
        }
    }
}
int32_t main() {
    nitin;
    cin>>r>>c;
    int a,b;
    cin>>a>>b;
    int C,d;
    cin>>C>>d;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            char e;
            cin>>e;
            if(e=='#')
            grid[i][j]=-1;
            else
                grid[i][j]=0;
            visi[i][j]=0;
        }
    }
    int cnt=1;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++){
            if(grid[i][j]==0 && visi[i][j]==0)
            {
                dfs(i,j,cnt);
                cnt+=1;
            }
        }
    }
//    for(int i=0;i<r;i++){
//        for(int j=0;j<c;j++){
//            cout<<grid[i][j];
//        }
//        cout<<endl;
//    }
    int N=cnt-1;
    set<int>v[N];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++)
        {
            if(grid[i][j]!=-1)
            {
                int X=i-2;
                int Y=j-2;
                for(int a=0;a<5;a++)
                {
                    for(int b=0;b<5;b++)
                    {
                        int nX=X+a;
                        int nY=Y+b;
                        //cout<<nX<<" "<<nY<<endl;
                        if((!(nX==i && nY==j ))&& nX>=0 && nX<r && nY>=0 && nY<c && grid[nX][nY]!=-1)
                        {
                            v[grid[i][j]-1].insert(grid[nX][nY]-1);

                        }
                    }
                }
            }
        }
    }
    int start=grid[a-1][b-1];
    queue<int>q;
    vector<int>dist(N,INT_MAX);
    dist[0]=0;
    q.push(start-1);
    start--;
    dist[start]=0;
    while(!q.empty())
    {
        int node=q.front();
        q.pop();
        for(auto c:v[node])
        {
            if(dist[c]==INT_MAX)
            {
                dist[c]=dist[node]+1;
                q.push(c);
            }
        }
    }
//    for(int i=0;i<N;i++){
//        for(auto c:v[i])
//            cout<<c<<" ";
//        cout<<endl;
//    }
    int end=grid[C-1][d-1];
    end--;
    if(dist[end]!=INT_MAX)
    cout<<dist[end]<<endl;
    else
        cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 45944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();

		if (N <= D) {
			System.out.println(1);
			return;
		}

		int count = 1, idx = D + 1;
		while (idx < N) {
			idx += D + 1;
			if(idx <= N) count++;
			idx += D;
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 23764
pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                std::cmp::Ordering::Less => {
                    low = mid + 1;
                }
                std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {
                    low = mid + 1;
                }
                std::cmp::Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

#[test]
fn test_binary_search() {
    let v = vec![1, 3, 4, 4, 4, 6, 7, 12, 54, 60];

    assert_eq!(v.lower_bound(&4), 2);
    assert_eq!(v.upper_bound(&4), 5);
    assert_eq!(v.lower_bound(&2), 1);
    assert_eq!(v.upper_bound(&2), 1);
}

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        mut a_s: [usize; n],
    }
    a_s.sort();
    for _ in 0..m {
        let last = a_s.pop().unwrap();
        let new_num = last / 2;
        let index = a_s.lower_bound(&new_num);
        a_s.insert(index, new_num);
    }
    let ans = a_s.iter().sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(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 all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;



int main(void) {
  int h, w; cin >> h >> w;
  V<string> s(h);
  V<string> t(h);
  rep(i,h) cin >> s[i];
  rep(i,h) rep(j,w) t[i] += '.';
  dump(s,t);
  const int dx[4] = {1, 0, -1, 0};
  const int dy[4] = {0, 1, 0, -1};
  rep(i,h) {
    rep(j,w) {
      rep(k,4) {
        int x = j + dx[k];
        int y = i + dy[k];
        if (x < 0 || x >= w) continue;
        if (y < 0 || y >= h) continue;
        if (s[i][j] == '#' && s[y][x] == '#') {
          t[i][j] = '#';
          t[y][x] = '#';
        }
      }
    }
  }
  rep(i,h) if (s[i] != t[i]) plexit("No")
  yes(1)
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

const ll INF = 1<<30;
int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> b(n);
  rep(i, n) cin >> b[i];

  sort(all(b));

  ll mi = INF;
  ll ans = 0;
  int cnt = 0;
  rep(i, n) {
    if (b[i] < 0) cnt++;
    cmin(mi, abs(b[i]));
    ans += abs(b[i]);
  }

  if (cnt%2 == 1) {
    ans -= 2*mi;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024