akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n;
  	cin>>n;
  	cout<<(1000-(n%1000))%1000<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

#define INT_MAX 2147483647

long gcd(long m, long n);
long lcm(long m, long n);

int main(void) {

	int ans = 0;

	int n, m;
	cin >> n >> m;
	vector<int> v(m+1);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int tmp;
			cin >> tmp;
			v[tmp]++;
		}
	}
	for (int i = 0; i < v.size(); i++) {
		if (v[i] == n) ans++;
	}

	cout << ans << endl;
	return 0;

}

//std::string result = s.substr(2, 3);  // 2番目から3要素だけ抜き出した部分文字列を取得する

//最大公倍数
long gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
long lcm(long m, long n)
{
	return m * n / gcd(m, n);
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll N,A,B,C,D,E;
	cin >> N >> A >> B >> C >> D >> E;
	chmin(B,A);
	chmin(C,B);
	chmin(D,C);
	chmin(E,D);
	ll ans = 4 + (N%E==0?N/E:N/E+1);
	cout << ans << endl;
	return 0;
}


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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
int n;

int a[Sz];

int L;

int main() 
{
  Read_rap ();   
  cin >> n >> L;
  for (int i = 1; i <= n; i++)
    cin >> a[i];              
  int pos = -1;
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i + 1] >= L) {
      pos = i;
      break;
    }
  }       
  if (pos < 0) {
    cout << "Impossible";
  }
  else
  {
    cout << "Possible" << endl;   
    for (int j = n-1; j > pos; j--)
      cout << j << endl;
    for (int i = 1; i < pos; i++)
      cout << i << endl;
    cout << pos << endl;
  }     
       
  return 0;
} 










// Coded by Z..


Measured memory_bytes: 1280
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
t = []
for _ in range(d):
    t.append(int(input())-1)
v = 0
last = [-1]*26
for i in range(d):
    v += s[i][t[i]]
    last[t[i]] = i
    for j in range(26):
        v -= c[j]*(i-last[j])
    print(v)

Measured memory_bytes: 68508
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
using namespace std;

int main(){

  char c;
  cin >> c;

  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }

  return 0;
}














// EOF


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){

int n;
cin >> n;


bool ans = false;
for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
        if(n==i*j){
            ans = true;
        }

    }
}

if(ans==true)cout << "Yes" << endl;
else cout << "No" << endl;



return 0;
}



Measured memory_bytes: 256
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0

for line in file_input:
    x1, y1, x2, y2 = (map(int, line.split()))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))
        h_num += 1

# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n

    def switch(self, i, d):
        while  i <= self.num:
            self.data[i] += d
            i += i & -i

    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s

    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)

# Sweep
import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        BIT.switch(d_vs_x[p[2]], 1)
    elif e == u:
        BIT.switch(d_vs_x[p[2]], -1)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += BIT.seg_sum(l_x, r_x)
        h_num -= 1
    if h_num == 0:
        break

# Output
print(cnt)

Measured memory_bytes: 35284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int X;
  cin >> X;
  int ans = 1;
  for (int i = 1; i <= 1000; i++) {
    for (int j = 2; j < 1000; j++) {
      double check_val = pow(i, j);
      if (check_val > X) continue;
      ans = max(ans, (int)pow(i, j));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4236
#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>

#define INT_MAX 2147483647
#define INT_MIN -2147483647
using namespace std;

int main()
{
	int num;
	int vals[100];
	cin >> num;
	int idx = 0;
	while (cin >> vals[idx++]);

	int count = 0;
	for (int i = 0; i < num; ++i)
	{
		for (int j = num-1; i < j; --j)
		{
			if (vals[j] < vals[j-1])
			{
				count++;
				std::swap(vals[j], vals[j-1]);
			}
		}
	}

	for (int i = 0; i < num - 1; ++i) cout << vals[i] << " ";
	cout << vals[num - 1] << endl;
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, k , a[101010];

int main(){
	cin >> n >> k;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] >= k) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
	char c = 0;
	while(10 - c){
		scanf("%c", &c);
		if(64 < c && c < 91){
			printf("%c", c + 32);
		}else if(96 < c && c < 123){
			printf("%c", c - 32);
		}else{
			printf("%c", c);
		}
	}
	return 0;
}

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

int main()
{
    int n, ans;
    int cnt,pflg, qflg,pnum,qnum;

    cin >> n;
    vector<int> p(n),q(n);
    rep(i, n)   cin >> p[i];
    rep(i, n)   cin >> q[i];

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... n を設定
    cnt = pnum = qnum = 0;
    do {
        ++cnt;
        pflg = qflg = 0;
        rep(i,n) {
            if (v[i] != p[i]) {
                ++pflg;
            }
            if (v[i] != q[i]) {
                ++qflg;
            }
        }
        if (pflg == 0)  pnum = cnt;
        if (qflg == 0)  qnum = cnt;
        if (pnum > 0 && qnum > 0)   break;
    } while (next_permutation(v.begin(), v.end()));     // 次の順列を生成

    //結果
    ans = abs(pnum - qnum);
    std::cout << ans << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector <int> vec(N, 0);
  for(int i=0; i<N; i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse (vec.begin(), vec.end());
  int alice=0;
  int bob=0;
  for(int i=0; i<N; i++){
    if(i%2==0){
      alice+=vec.at(i);
    }
    if(i%2==1){
      bob+=vec.at(i);
    }
  }
  cout<<alice-bob<<endl;

}

Measured memory_bytes: 3632
from collections import deque
Q = deque()
n = int(input())
for i in range(n):
    x = list(map(int, input().split()))
    if x[0] == 0:
        if x[1] == 0:
            Q.appendleft(x[2])
        if x[1] == 1:
            Q.append(x[2])
    elif x[0] == 1:
        print(Q[x[1]])
    elif x[0] == 2:
        if x[1] == 0:
            Q.popleft()
        if x[1] == 1:
            Q.pop()


Measured memory_bytes: 21984
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define X first
#define Y second
#define pb push_back
const int inf=0x3f3f3f3f;
int lowbit(int x){return x&-x;}
int ppc(int x){return __builtin_popcount(x);}
const int N=100000;
int n;
vector<pair<int,int> > nei[N+1];
int buc[16];
int dfs(int x=1,int fa=0){
	int xsm=0;
	for(int i=0;i<nei[x].size();i++){
		int y=nei[x][i].X,v=nei[x][i].Y;
		if(y==fa)continue;
		xsm^=v;
		buc[dfs(y,x)^v]++;
	}
	return xsm;
}
int dp[1<<15];
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y,z;
		cin>>x>>y>>z;
		x++;y++;
		nei[x].pb(mp(y,z));nei[y].pb(mp(x,z));
	}
	dfs();
	for(int i=1;i<1<<15;i++){
		dp[i]=ppc(i);
		int xsm=0;
		for(int j=1;j<=15;j++)if(i&1<<j-1)xsm^=j;
		if(!xsm)dp[i]=ppc(i)-1;
		for(int j=i-1&i;j;j=j-1&i)dp[i]=min(dp[i],dp[j]+dp[i^j]);
	}
	int ans=0,msk=0;
	for(int i=1;i<=15;i++)ans+=buc[i]>>1,msk|=(buc[i]&1)<<i-1;
	cout<<ans+dp[msk];
	return 0;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

int N;
string s;
int main(){
  cin>>N;
  int a=0,u=0;
  bool flag=true;
  rep(i,N){
    cin>>s;

    if(s=="A"){
      a++;
    }else{
      u++;
    }

    if(a<u)flag=false;
  }
  if(a!=u)flag=false;
  if(flag){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3152
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int G[110][110];

int main() {
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    for (int i = 0;i < N;i++) cin >> A[i];
    memset(G, 0, sizeof(G));
    int idx = 0;
    bool ok = 1;
    vector<int> Q;
    for (int i = 0;i < H;i++) {
    	if (i % 2 == 0) {
    		for (int j = 0;j < W;j++) Q.push_back(j);
    	}
        else {
        	for (int j = 0;j < W;j++) Q.push_back(W - j - 1);
        }
    }
    for (int i = 0;i < N;i++) {
    	for (int j = 0;j < A[i];j++) {
    		G[idx / W][Q[idx]] = i + 1;
    		idx++;
    	}
    }
    for (int i = 0;i < H;i++) {
    	for (int j = 0;j < W;j++) {
    		if (j != 0) cout << ' ';
    		cout << G[i][j];
    	}
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

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

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string S;

int main(){
  cin >> S;
  int N = S.size();
  int ct = 0;
  REP(i, N) {
    if(S[i] - '0' == i % 2 ) ct++;
  }

  cout << min(ct, N - ct) << endl;

  return 0;
}


Measured memory_bytes: 512
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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

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

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

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

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

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

    ($next:expr, [ $t: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")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(n: i64, k: i64);
    let r = n % k;
    puts!("{}\n", min(r, k - r));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
/*Infor {{{
 ******************************************************
 * > File Name: a.cpp
 * > Author: samcompu
 * > Mail: admin@samcompu.com
 * > Created Time: 2018/7/21 12:27:06
 ******************************************************
}}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ull unsigned long long int
/*}}}*/

/*Constant {{{*/
const int MAXN = 100000;
const int MAXM = 100000;
/*}}}*/

/*Class {{{*/
class Line {
  public:
    int a;
    int b;
};
/*}}}*/

/*Variable {{{*/
Line line[MAXM + 1];
/*}}}*/

/*Declare {{{*/
bool camp(Line, Line);
/*}}}*/

/*Main {{{*/
int main() {
  int n, m;
  cini(n), cini(m);
  FOR(i, 1, m) {
    cini(line[i].a), cini(line[i].b);
    if(line[i].a > line[i].b) swap(line[i].a, line[i].b);
  }
  sort(line + 1, line + m + 1, camp);
//  FOR(i, 1, m) coui(line[i].a), SPA, coui(line[i].b), LIN;
  int need = 1;
  int t = line[1].b;
  FOR(i, 1, m) {
    if (line[i].a >= t) {
      need++;
      t = line[i].b;
    }
  }
  printf("%d\n", need);
  return 0;
}
/*}}}*/

/*Define {{{*/
bool camp(Line a, Line b) {
  if (a.b == b.b) return a.a > b.a;
  return a.b < b.b;
}
/*}}}*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<double,double>P;
const int mod =1e9+7;
const double PI=acos(-1);

int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    P apos=P(a*cos(2*PI*(h+1.0*m/60)/12),a*sin(2*PI*(h+1.0*m/60)/12));
    P bpos=P(b*cos(2*PI*m/60),b*sin(2*PI*m/60));
    double ans=sqrt(pow(apos.first-bpos.first,2)+pow(apos.second-bpos.second,2));
    cout<<setprecision(15)<<ans;

}


Measured memory_bytes: 4136
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vl date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vl(2*n-1);
	}
	void Update(int k,ll x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=max(date[k*2+1],date[k*2+2]);
		}
	}
	ll Query(int a,int b){
		a+=n-1;b+=n-1;
		ll m=0;
		while(a<b){
			if(a%2==0) m=max(m,date[a++]);
			if(b%2==0) m=max(m,date[--b]);
			a/=2;b/=2;
		}
		return m;
	}
	ll Open(int k){return date[k+n-1];}
};

int n;
vl a,b;

int main(){
	cin>>n;
	Segment_Tree st(n+1);
	a=b=vl(n);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	ll res=0;
	for(int i=0;i<n;i++){
		ll tmp=st.Query(0,a[i])+b[i];
		st.Update(a[i],tmp);
		res=max(res,tmp);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 7552
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<cfloat>
#include<cstring>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set> 
#include<bitset>
#include<algorithm>
#include<ctime>
#include<functional> 
#include<iomanip>
using namespace std;
int main()
{
    string tr;
    cin>>tr;
    int len=tr.size();
    int ans=tr.size();
    for(int i=1;i<tr.size();i++)
	{
        if(tr[i]!=tr[i-1])
            ans=min(ans,max(i,len-i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
n, m = gets.split.map(&:to_i)
pp = gets.split.map(&:to_i)

edge = Array.new(n+1) {[]}
m.times do 
    x, y = gets.split.map(&:to_i)
    edge[x] << y
    edge[y] << x
end

visit = Array.new(n+1)
i = 0
1.upto(n) do |i|
    next if visit[i]

    que = [i]
    while now = que.shift
        next if visit[now]
        visit[now] = i
        edge[now].each {|e| que << e}
    end

    i += 1
end

p pp.each_with_index.count {|e, i| visit[i+1] == visit[e]}

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

int n, m, l;
vector<vector<ll>> dist(310, vector<ll>(310, 1e18));
vector<vector<ll>> g(310, vector<ll>(310, 1e18));

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

    cin >> n >> m >> l;
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    rep(i, 0, n) rep(j, 0, n) if (dist[i][j] <= l) g[i][j] = 1;
    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    }
    int q;
    cin >> q;
    rep(i, 0, q) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        if (g[s][t] > 1e16)
            cout << -1 << endl;
        else
            cout << g[s][t] - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n; cin >> n;
    vector<int> a(n);
    priority_queue<int> que;
    for(int i=0; i<n; ++i){cin >> a[i]; que.push(a[i]);}
    ll res = 0;
    ll cnt = n-1;
    for(int i=0; i<n-1; ++i){
        if(i==0){res += que.top(); que.pop(); cnt--;}
        else{
            res += que.top(); cnt--;
            if(cnt>0){res += que.top(); cnt--;}
            que.pop();
        }
        if(cnt==0){break;}
    }
    cout << res << endl;
}

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

int main(){
  ll n,a,b; 
  cin >>n >>a >>b;
  if((b-a)%2==0) cout << (b-a)/2 << endl; 
  else{
    ll m = min(a-1, n-b);
    cout << m+1+(b-a-1)/2 << endl;
  }
  return 0; 
}

Measured memory_bytes: 3604
a,b,k = map(int, input().split())


sep = b - a > 2 * (k - 1)

if sep:
    for i in range(a,a+k):
        print(i)

    for i in range(b-k+1,b+1):
        print(i)

else:
    for i in range(a,b+1):
        print(i)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	if(a==b){
		printf("1\n");
		return 0;
	}
	int t;
	for(int i=61;i>=0;i--){
		if(a>=(1LL<<i)){
			a-=(1LL<<i);
			b-=(1LL<<i);
		}
		if(b>=(1LL<<i)){
			t=i;
			break;
		}
	}
	b-=(1LL<<t);
	ll v1=(1LL<<t)-a;
	ll v2=1,v3=0;
	for(int i=t-1;i>=0;i--){
		if((b&(1LL<<i))>0){
			v2=(1LL<<(i+1));
			break;
		}
	}
	v3=a;
	printf("%lld\n",v1+min(v2+(1LL<<t)-v3,(1LL<<t)));
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    ArrayList<String> list = new ArrayList<String>();
    list.add(sc.next());

    for (int i = 1; i < n; i++) {
      String pre = list.get(i - 1);
      String s = sc.next();
      if (list.contains(s) || (s.charAt(0) != pre.charAt(pre.length() - 1))) {
        System.out.println("No");
        return;
      } else {
        list.add(s);
      }
    }

    System.out.println("Yes");

  }
}

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


int main(){
	int a,b,c,x=0;
	cin >> a >> b >> c;
	if(b<c) x=1;
	if(b<c&&c-b>a) x=2;
	
	
	if(x==1) cout << "safe" << endl;
	else if(x==2) cout << "dangerous" << endl;
	else cout << "delicious" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
  {
      char S[2];
      int result = 0;
      int count = 0;
   
      cin >> S;
   
      for (int i = 0; i < 3; i++)
      {
          if(S[i] == 'o') {
              count = count + 1;
          }
      }
   
      result = 700 + (100 * count);
   
      cout << result << "\n";
   
      return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>v;
int main()
{
    ll a,b,ans,i,j,cur,tur,pos;
    cin>>a>>b;
    cur=a-1;
    tur=b+cur;
    pos=b-cur;
    for(i=pos;i<=b;i++){
        v.push_back(i);
    }
    for(i=b+1;i<=tur;i++)
        v.push_back(i);

    ll len=v.size();
    for(i=0;i<len;i++){
        if(i==0)cout<<v[i];
        else cout<<" "<<v[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int place[3][n];
  int a[n];
  int t[n];
  int r[n];
  int possibility;
  possibility = 1;
  
for(int i = 0; i < n; i++){
    for(int j=0; j<3; j++){
    cin >> place[j][i];
    }
}

if(abs(place[1][0])+abs(place[2][0]) <= place[0][0] && (place[1][0]+place[2][0] - place[0][0]) % 2 == 0){
 }else{
        cout << "No" << endl;
        possibility = 0;
        return 0;
}
  
for(int i = 0; i < n - 1; i++){
    a[i] = abs(place[1][i+1]-place[1][i]) + abs(place[2][i+1]-place[2][i]);
    t[i] = place[0][i+1] - place[0][i];
    r[i] = t[i] - a[i];
    if(r[i] >= 0 && r[i] % 2 == 0){
        }else{
        cout << "No" << endl;
        possibility = 0;
        return 0;
    }
}
 
if(possibility == 1){
    cout << "Yes" << endl;
}
}

Measured memory_bytes: 2560
def main():
    n,d = map(int,input().split())
    points = []
    for i in range(n):
        points.append(list(map(int,input().split())))

    pairs = 0

    for i in range(n):
        for j in range(i+1,n):
            dist = 0
            for k in range(d):
                dist += (points[i][k]-points[j][k])**2

            if int(dist**0.5) == dist**0.5:
                pairs += 1

    print(pairs)


main()


Measured memory_bytes: 3188
#include "bits/stdc++.h"
#define PI acos(-1)

using namespace std;

using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;

int main()
{
	int a, b, c, res = 0, cu = 0;
	ll k;
	cin >> a >> b >> c >> k;
	cu = k;
	if (cu >= a) {
		res = a;
		cu -= a;
	}
	else if (cu < a) {
		res = cu;
		cu -= res;
	}
	if (cu >= b) cu -= b;
	else if (cu < b) cu -= cu;
	if (cu <= c) res += (-1 * cu);
	else if (cu > c) res += (-1 * c);
	cout << res;
	
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 3000;
int n;
ll a[MAX_N];
ll dp[MAX_N][MAX_N][2];
bool vis[MAX_N][MAX_N][2];

ll rec(int l, int r, int p) {
  if (vis[l][r][p]) return dp[l][r][p];

  vis[l][r][p] = true;

  if (l == r) {
    return dp[l][r][p] = a[l];
  } else {
    ll v1 = a[l] - rec(l+1,r,1-p);
    ll v2 = a[r] - rec(l,r-1,1-p);

    return dp[l][r][p] = max(v1,v2);
  }
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) cin >> a[i];

  cout << rec(0,n-1,0) << endl;

  return 0;
}


Measured memory_bytes: 158336
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve()
{
	ll k;
	cin>>k;
	string s;
	cin>>s;
	if(s.length()>k)
		cout<<s.substr(0,k)+"..."<<endl;
	else
		cout<<s<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var S = ReadLine();
        var dp = new long[4];
        dp[0] = 1;
        foreach (var c in S)
        {
            var next = new long[4];

            if (c == 'A' || c == 'B' || c == 'C')
            {
                for (int i = 0; i < 4; i++)
                {
                    next[i] = dp[i];
                }
                if (c == 'A')
                {
                    next[1] += dp[0];
                }
                else if (c == 'B')
                {
                    next[2] += dp[1];
                }
                else if (c == 'C')
                {
                    next[3] += dp[2];
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    next[i] = dp[i] * 3;
                }
                next[3] += dp[2];
                next[2] += dp[1];
                next[1] += dp[0];
            }

            for (int i = 0; i < 4; i++)
            {
                dp[i] = next[i];
                dp[i] %= mod;
            }

            //WriteLine(string.Join(" ", dp));
        }
        WriteLine(dp[3]);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 17336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

/**
 * 		縦に3分割(1<h<w-1)
 *
 *				W
 * 		-----------------------------
 *	H	a	|w -a/2		|
 *			|			|
 *		-----------------------------
 *
 *		縦、横で3分割
 *
 *				W
 * 		-----------------------------
 *		a	|
 *	H		|－－－－－－－－－－－－
 *			|
 *		-----------------------------

 * */

		Scanner sc = new Scanner(System.in);
		long H = sc.nextInt();
		long W = sc.nextInt();
		sc.close();

		if (H == 2 && W == 2) {
			System.out.println(1);
			return;
		}

		long S1 = 0;
		long S2 = 0;
		long S3 = 0;

		long ans = Long.MAX_VALUE;

		// 縦3分割
		for(int a=1; a < W-1; a++) {
			long tmpW = (W-a)/2;
			S1 = H * a;
			S2 = H * tmpW;
			S3 = H * (W - a - tmpW);

			long tmpAns = Math.max(S3,Math.max(S1,S2)) -Math.min(S3, Math.min(S1,S2));

			ans = Math.min(tmpAns, ans);
		}

		// 縦横3分割
		for(int a=1; a < W-1; a++) {
			long tmpH = H/2;
			S1 = H * a;
			S2 = (W-a) * tmpH;
			S3 = (W-a) * (H - tmpH);

			long tmpAns = Math.max(S3,Math.max(S1,S2)) -Math.min(S3, Math.min(S1,S2));

			ans = Math.min(tmpAns, ans);
		}

		///WとＨを入れ替える。同じ値なら入れ替え不要
		if(W==H) {
			System.out.println(ans);
			return;
		}


		for(int a=1; a < H-1; a++) {
			long tmpH = (H-a)/2;
			S1 = W * a;
			S2 = W * tmpH;
			S3 = W * (H - a - tmpH);

			long tmpAns = Math.max(S3,Math.max(S1,S2)) -Math.min(S3, Math.min(S1,S2));

			ans = Math.min(tmpAns, ans);
		}

		for(int a=1; a < H-1; a++) {
			long tmpW = W/2;
			S1 = W * a;
			S2 = (H-a) * tmpW;
			S3 = (H-a) * (W - tmpW);

			long tmpAns = Math.max(S3,Math.max(S1,S2)) -Math.min(S3, Math.min(S1,S2));

			ans = Math.min(tmpAns, ans);
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   string S,T;
   cin>>S>>T;
   int count=0;
   for(int i=0;i<3;i++){
       if(S[i]==T[i]){count++;}
   }
   cout<<count<<endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  FOR(i, 1, n) cin >> a[i];
  FOR(i, 1, m) cin >> b[i];
  FOR(i, 1, n) a[i] += a[i - 1];
  FOR(i, 1, m) b[i] += b[i - 1];
  int ans = 0;
  REP(i, n + 1) {
    if (a[i] > k) break;
    if (k - a[i] < 0) continue;
    int l = -1, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      ll sum = a[i] + b[mid];
      if (sum > k) {
        r = mid;
      } else {
        l = mid;
      }
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	set<pair<int, int>> mine, togo;
	
	for(int i = 0; i < (1<<n); i++) {
		int x;
		cin >> x;
		togo.emplace(x, i);
	}
	
	pair<int, int> mx = *togo.rbegin();
	togo.erase(mx);
	int dumb = -1;
	mx.second = dumb;
	mine.insert(mx);
	int m = 0;
	bool ok = true;
	while(togo.size()) {
		vector<pair<int, int>> now;
		for(auto p : mine) {
			auto it = togo.upper_bound(p);
			if(it == togo.begin()) {
				ok = false;
				break;
			}
			it--;
			now.push_back(*it);
			togo.erase(*it);
		}
		
		if(!ok) break;
		for(auto p : now) {
			p.second = dumb--;
			mine.insert(p);
		}
		m++;
	}
	
	
	cout << (ok ? "Yes" : "No") << endl;
	
}


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

typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)

const int N=4;

struct state{
  vector<int> board;
  int dist;
  int bi,bj;
  int miss_cnt;
  int mh_dist;
  int pre;
};

map<vector<int> ,bool> vis;

char h0(const state& s){
  return s.dist;
}
char h1(const state& s){
  return s.dist+s.miss_cnt;
}
char h2(const state& s){
  return s.dist+s.mh_dist;
}

bool operator<(const state& a,const state& b){
  return h2(a) > h2(b);
}

int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};

int ans[N][N]={
  {0,1,2,3},
  {4,5,6,7},
  {8,9,10,11},
  {12,13,14,-1},
};

P ans_ps[N*N];

int main(){

  clock_t start=clock();

  rep(i,N)rep(j,N){
    if(ans[i][j]==-1)continue;
    ans_ps[ans[i][j]].fi=i;
    ans_ps[ans[i][j]].se=j;
  }

  state inistate;
  inistate.board=vector<int>(N*N);
  inistate.dist=0;
  inistate.mh_dist=0;
  inistate.miss_cnt=0;
  inistate.pre=-1;
  rep(i,N)rep(j,N){
    int input;
    cin>>input;
    input--;
    inistate.board[i*N+j]=input;
    if(input==-1){
      inistate.bi=i;
      inistate.bj=j;
    }else{
      int ai=ans_ps[input].fi;
      int aj=ans_ps[input].se;
      inistate.mh_dist+=abs(ai-i)+abs(aj-j);
      inistate.miss_cnt+=(inistate.mh_dist>0?1:0);
    }
  }

  priority_queue<state> que;
  que.push(inistate);
  vis[inistate.board]=true;
  while(que.size()){
    state crtstate=que.top(); que.pop();
    if(crtstate.mh_dist==0){
      cout<<(int)crtstate.dist<<endl;
      break;
    }
    rep(dir,4){
      if(dir==crtstate.pre)continue;
      int bi=crtstate.bi;
      int bj=crtstate.bj;
      int ni=bi+di[dir];
      int nj=bj+dj[dir];
      if(ni<0||ni>=N||nj<0||nj>=N)continue;
      state nxtstate=crtstate;

      int num=crtstate.board[ni*N+nj];
      int ai=ans_ps[num].fi;
      int aj=ans_ps[num].se;
      nxtstate.mh_dist-=abs(ai-ni)+abs(aj-nj);
      nxtstate.miss_cnt+=(abs(ai-ni)+abs(aj-nj)==0?1:0);
      nxtstate.mh_dist+=abs(ai-bi)+abs(aj-bj);
      nxtstate.miss_cnt-=(abs(ai-ni)+abs(aj-nj)==0?1:0);

      swap(nxtstate.board[bi*N+bj],nxtstate.board[ni*N+nj]);
      nxtstate.dist++;
      nxtstate.bi=ni; nxtstate.bj=nj;
      nxtstate.pre=(dir+2)%4;
      if(!vis[nxtstate.board]){
        vis[nxtstate.board]=true;
        que.push(nxtstate);
      }
    }
  }

  clock_t end=clock();
  //cerr<<"duration = "<<(double)(end-start)/CLOCKS_PER_SEC<<" sec."<<endl;

	return 0;
}

Measured memory_bytes: 207980
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    acc = 0
    for b, a in sorted(zip(B, A)):
        acc += a
        if b < acc:
            return NO
    return YES

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    print(solve(N, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 38036
#include<bits/stdc++.h>
using namespace std;
int cnt[26][50];
string s[50];
int main()
{
    int n;
    cin>>n;
    string ans="";
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        for(int j=0;j<s[i].size();j++)
            cnt[s[i][j]-'a'][i]++;
    }
    for(int i=0;i<26;i++)
    {
        sort(cnt[i],cnt[i]+n);
        ans.append(cnt[i][0], 'a'+i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)


{
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a%b;
	f = 1.0*a / b;
	printf("%d %d %f", d, r, f);

	return 0;
}

Measured memory_bytes: 636
A,B,C = map(int, input().split())
K = int(input())

for i in range(K):
  if A < B < C:
    break
  elif A >= B:
    B = B * 2
  elif B >= C:
    C = C * 2
    
if A < B < C:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9164
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn readc() -> char {
    let s: String = read();
    return s.chars().nth(0).unwrap();
}

fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn solve(map: Vec<Vec<char>>) -> usize {
    fn _solve(i: i32, j: i32, map: &Vec<Vec<char>>) -> usize {
        let v_vec: Vec<(i32, i32)> = vec![(1, 0), (-1, 0), (0, 1), (0, -1)];
        let mut next_pos: Vec<(i32, i32)> = Vec::new();

        let mut visited: Vec<Vec<bool>> = (0..map.len()).map(|_| (0..map[0].len()).map(|_| false).collect()).collect();
        visited[i as usize][j as usize] = true;
        let mut cnt = 0;
        loop {
            let tmp_next_pos = next_pos.clone();
            next_pos = Vec::new();
            for pos in tmp_next_pos.iter() {
                let i = pos.0;
                let j = pos.1;
                if i < 0 || i >= map.len() as i32 {
                    continue;
                }
                if j < 0 || j >= map[0].len() as i32 {
                    continue;
                }

                let i = i as usize;
                let j = j as usize;
                if visited[i][j] {
                    continue;
                }
                visited[i][j] = true;


                if map[i][j] == 'g' {
                    return cnt;
                }
                if map[i][j] == '#' {
                    continue;
                }

                let i = i as i32;
                let j = j as i32;
                for v in v_vec.iter() {
                    next_pos.push((i+v.0, j+v.1));
                }
            }

            for v in v_vec.iter() {
                next_pos.push((i+v.0, j+v.1));
            }

            cnt += 1;
        }

        return 0;
    }

    let mut ans = 0;
    for i in 0..map.len() {
        for j in 0..map[0].len() {
            if map[i][j] == '#' {
                continue;
            }
            let mut base_map = map.clone();
            base_map[i][j] = 's';
            for n in 0..map.len() {
                for m in 0..map[0].len() {
                    if base_map[n][m] == 's' || base_map[n][m] == '#' {
                        continue;
                    }
                    let mut tmp_map = base_map.clone();
                    tmp_map[n][m] = 'g';
                    let i = i as i32;
                    let j = j as i32;
                    let cnt = _solve(i, j, &tmp_map);
                    if cnt > ans {
                        ans = cnt;
                    }
                }
            }
        }
    }

    return ans;
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let c_ij: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();

    println!("{}", solve(c_ij));
}


Measured memory_bytes: 4352