akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto T = S.map!(s => to!int(s - '1')).array;
    auto P = 9.iota.array;
    auto Q = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]];

    auto mp = new int[][](9, 9);
    foreach (i; 0..N-1) mp[T[i]][T[i+1]] += 1;

    int ansv = 1 << 29;
    int[] ans;

    int[] trans(int[] a) {
        auto b = new int[](9);
        foreach (i; 0..9) b[a[i]] = i;
        return b;
    }

    do {
        int tmp = 0;
        foreach (i; 0..9) {
            foreach (j; 0..9) {
                int dist = abs(Q[P[i]][0] - Q[P[j]][0]) + abs(Q[P[i]][1] - Q[P[j]][1]);
                tmp += dist * mp[i][j];
            }
        }
        if (tmp < ansv) {
            ansv = tmp;
            ans = trans(P);
        } else if (tmp == ansv) {
            auto b = trans(P);
            if (b < ans) ans = b.dup;
        }
    } while (nextPermutation(P));

    foreach (i; 0..3) {
        foreach (j; 0..3) {
            write(ans[i*3+j]+1);
        }
        writeln;
    }
}



Measured memory_bytes: 3904
def main():
    x = int(input())

    if x <= 599:
        print("8")
    elif x <= 799:
        print("7")
    elif x <= 999:
        print("6")
    elif x <= 1199:
        print("5")
    elif x <= 1399:
        print("4")
    elif x <= 1599:
        print("3")
    elif x <= 1799:
        print("2")
    else:
        print("1")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int l, r, d;

main () {
	cin >> l >> r >> d;
	cout << r / d - (l - 1) / d;
}
	
        	
//check for the constants

                                                                                   	

                     	             

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int l[11];

int main()
{
	int sum = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> l[i];
		sum += l[i];
	}

	for (int i = 0;i < n;i++) {
		if (sum - l[i] <= l[i]) {
			cout << "No" << endl;
			return 0;
 		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using pii = pair<int, int>;

const int N = 205;

vector<int> g[N];
int flw[N][N], cap[N][N], far[N], f[N];
char mx[N][N];

pii start, halt;
int n, m;

static int left(int nod) {
	return nod; }

static int right(int nod) {
	return nod + n; }

static bool bfs(int src, int snk) {
	static int ptr = 0; ++ptr;
	static deque<int> dq;
	int u;

	dq.push_back(src);
	f[src] = ptr;

	while (!dq.empty()) {
		u = dq.front(); dq.pop_front();

		for (auto v: g[u]) if (f[v] != ptr && cap[u][v] - flw[u][v] > 0) {
			dq.push_back(v);
			far[v] = u;
			f[v] = ptr; } }

	return (f[snk] == ptr); }

static int pump_flow(int src, int snk) {
	int nod, ant, augment;

	ant = 0;
	while (bfs(src, snk)) {
		nod = snk;
		augment = 2e9;
		while (nod != src) {
			augment = min(augment, cap[far[nod]][nod] - flw[far[nod]][nod]);
			nod = far[nod]; }

		nod = snk;
		while (nod != src) {
			flw[far[nod]][nod]+= augment;
			flw[nod][far[nod]]-= augment;
			nod = far[nod]; }

		ant+= augment; }

	return ant; }

int main() {
#ifdef HOME
	freopen("arc079d.in", "r", stdin);
	freopen("arc079d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> (mx[i] + 1);

	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j) {
		switch (mx[i][j]) {
		case 'o': {
			g[left(i)].push_back(right(j));
			g[right(j)].push_back(left(i));
			cap[left(i)][right(j)] = cap[right(j)][left(i)] = 1;
			break; }

		case 'S': {
			start = {i, j};
			break; }

		case 'T': {
			halt = {i, j};
			break; } } }

	if (start.x == halt.x || start.y == halt.y) {
		cout << "-1" << endl;
		return 0; }

	g[0].push_back(left(start.x)); g[left(start.x)].push_back(0);
	g[0].push_back(right(start.y)); g[right(start.y)].push_back(0);
	cap[0][left(start.x)] = cap[0][right(start.y)] = 1e5;
	cap[left(start.x)][0] = cap[right(start.y)][0] = 1e5;

	g[n + m + 1].push_back(left(halt.x)); g[left(halt.x)].push_back(n + m + 1);
	g[n + m + 1].push_back(right(halt.y)); g[right(halt.y)].push_back(n + m + 1);
	cap[n + m + 1][left(halt.x)] = cap[n + m + 1][right(halt.y)] = 1e5;
	cap[left(halt.x)][n + m + 1] = cap[right(halt.y)][n + m + 1] = 1e5;

	cout << pump_flow(0, n + m + 1) << endl;

	return 0; }


Measured memory_bytes: 768
num = int(input())

A = list(map(int, input().split()))
tempA = map(str, A)
print(' '.join(tempA))

for i in range(1, num):
        temp = A[i]
        j = i - 1
        while j >= 0 and A[j] > temp:
                A[j + 1] = A[j]
                j -= 1
        A[j + 1] = temp
        tempA = map(str, A)
        print(' '.join(tempA))


Measured memory_bytes: 5600
a, b, k = map(int, input().split())
if b-a+1 < k*2:
    for i in range(a, b+1):
        print(i)
else:
    for j in range(a, a+k):
        print(j)
    for k in range(b-k+1 , b+1):
        print(k)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string s,t;cin >> s >> t;
    ll ans=INF;
    rep(i,s.size()-t.size()+1){
        ll ret=0;
        rep(j,t.size()){
            if(s[i+j]!=t[j]){
                ret++;
            }
        }
        //cout << ret <<endl;
        chmin(ans,ret);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int ab=sc.nextInt();
    int bc=sc.nextInt();
    int ca=sc.nextInt();
    // ac*ac-(bc+x)*(bc+x)=h*h
    // ab*ab-x*x=h*h
    // ac*ac-ab*ab-bc*bc-2*bc*x=0
    // 2bc*x=ac*ac-ab*ab-bc*bc
    int x=(ca*ca-ab*ab-bc*bc)/(2*bc);
    double high=Math.sqrt(ab*ab-x*x);

    int ans=(int)(bc*high/2);

    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		if (d[0] > 0 || d.Skip(1).Any(x => x == 0)) { Console.WriteLine(0); return; }
		var c = d.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
		var max = c.Keys.Max();
		if (c.Count <= max) { Console.WriteLine(0); return; }

		var r = 1L;
		for (int i = 0; i < max; i++) r = MMul(r, MPow(c[i], c[i + 1]));
		Console.WriteLine(r);
	}

	const int M = 998244353;
	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
	static long MMul(long x, long y) => x * y % M;
}


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

int main(){
    int r;
    cin >> r;
    cout << 2.0*M_PI*r << endl;
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;
  cin>>a>>b;
  ll p,q,r;
  cin>>p>>q>>r;
  ll dist=b*p-(b-a)*q;
  printf("%.10f\n",(double)b+(double)dist/((double)q+(double)r));
  return 0;
}



Measured memory_bytes: 3248
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    char s[10];
    scanf("%s", s);
    
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){printf("Yes\n");}
    else if (s[0] == s[2] && s[2] != s[1] && s[1] == s[3]){printf("Yes\n");}
    else if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2]){printf("Yes\n");}
    else{printf("No\n");}
    
    return 0;
}


Measured memory_bytes: 128
N, K = map(int, input().split())
a = list(map(int, input().split()))
 
a = sorted(a)
ans = N
t = 0

for i in range(N-1, -1, -1) :
    if t+a[i] < K :
        t += a[i]
    else :
        ans = min(ans, i)
 
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int h,w,n;
    cin >> h >> w >> n;
    priority_queue<int,vector<int>,greater<int>> que;
    rep(i,n){
        int a;cin >> a;
        rep(j,a)que.push(i+1);
    }
    rep(i,h){
        if(!(i%2)){
            for (int j = 0; j < w; ++j){
                int o = que.top();
                cout << o << " ";
                que.pop();
            }
            cout << endl;
        }else{
            vector<int> out;
            for (int j = w; j > 0; --j){
                out.push_back(que.top());
                que.pop();
            }
            reverse(out.begin(),out.end());
            for(int o : out)cout << o << " ";
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    string S;
    cin >> S;

    llong N = S.length();
    llong ans = INF;
    FOR(i, N - 1) {
        if(S[i] != S[i + 1]) {
            llong b = max(i + 1, N - i - 1);
            ans = min(ans, b);
        }
    }

    if(ans == INF) {
        ans = N;
    }
    cout << ans << endl;

    return 0;
}

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

vector<pair<LL, LL>> prime_factorize(LL N){
   vector<pair<LL, LL>> res;
   for (LL a = 2; a * a <= N;a++) {
	   if(N % a != 0) continue;
	   LL ex = 0; //指数

	   //割れる限り割り続ける
	   while (N % a == 0) {
		   ++ex;
		   N /= a;
	   }

	   res.push_back(make_pair(a, ex));
   }

   //最後に残った数について
   if ( N != 1) res.push_back(make_pair(N, 1));
   return res;
}
	   
int main(){
	LL N;
	cin >> N;
	auto res = prime_factorize(N);
	int ans = 0;
	for(auto p : res) {
		int tmp = 1;
		while(p.second - tmp >= 0) 
		{
			p.second -= tmp;
			tmp++;
			ans++;
		}

			
	}
	cout << ans << endl;
}














Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}


Measured memory_bytes: 2764
//abc126_c.cpp
//Sat May 25 19:01:14 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	double ans = 0;
	if (n>=k){
		ans += (n-k+1)/n;
//		printf("%.10f\n",ans);
	}

	double i=1;
	double ntemp = n;
	if (k<=n){
		ntemp = k-1;
	}
	while (1){
		double temp = 0;
		if (ceil(k/pow(2,i))<=n){
			temp = ntemp-ceil(k/pow(2,i))+1;
			ans += (temp/n)*pow(0.5,i);
//			printf("%.10f\n",ans);
			ntemp = ceil(k/pow(2,i))-1;
		}
//		cout << temp << endl;
		if(ntemp==0){
			break;
		}else {
			i++;
		}
	}

	printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int n,a,b;
vector<int> ar;
bool ok(int x)
{
	int ct=0;int bx=b*x;
	int c=a-b;
	for(int i=0;i<n;i++)
	{
		ct+=max(0LL, (ar[i]-bx+c-1)/c);
	}
	return ct<=x;
	
}
int32_t main()
{
	n=in();a=in();b=in();
	ar=vector<int>(n);
	trav(i,ar)i=in();
	int lo=0;int hi=1e9+5;
	int mid;
	int ans=-1;
	while(lo<=hi)
	{
		mid=lo+(hi-lo)/2;
		if(ok(mid)){hi=(ans=mid)-1;}
		else lo=mid+1;
	}
	cout<<ans;
	
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 40000000;
ll dp[MAX_N],dp2[MAX_N];
// dp[i]は、i個のどんぐりを最大何個まで変換できるかを記録する
void chmax(ll &a, ll b){ if( a < b ){ swap(a,b);} return;}
int main(){
  ll N; cin >> N;
  vector<ll> a(3),b(3);
  for(ll i = 0; i < 3; i++){ cin >> a[i];}
  for(ll j = 0; j < 3; j++){ cin >> b[j];}
  
  for(ll i = 0; i <= N; i++){ 
    // AからBの遷移にかけて、どんぐりi個を最大何個まで変換できるかを考える
    chmax(dp[i],i); //何も変換しないとき
    for(ll j = 0; j < 3; j++){
      if( i-a[j] >= 0 ){ 
      chmax(dp[i], dp[i-a[j]]+b[j]);
      }
    }// fo-j
  }//for-i
  
  ll M = dp[N];
  
  for(ll i = 0; i <= M; i++){
    chmax(dp2[i],i);
    for(ll j = 0; j < 3; j++){
      if( i-b[j] >= 0 ){
        
        chmax( dp2[i], dp2[i-b[j]]+a[j] );
      }
    }
  }
  
  cout << dp2[M] << endl;
  
  return 0;
}

Measured memory_bytes: 198912
#include<cstdio>
#include<functional>
#include<vector>


using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vpii=vector<pii>;


vi calc_ele(int x)
{
	vi ret;

	if(x<=0) return ret;

	for(int i=1;i<=x;i<<=1)
	{
		if(x&i) ret.push_back(x^i);
	}

	return ret;
}


void calc(vi&a, vpii&fs, int x)
{
	auto t=calc_ele(x);
	auto&w=fs[x];
	pii c;

	if(a[0]>a[x]) w=make_pair(0, x);
	else w=make_pair(x, 0);

	if(t[0]==0) return;

	for(int y:t)
	{
		auto&c=fs[y];
		if(a[w.second]>=a[c.first]) continue;

		if(a[w.first]<a[c.first])
		{
			if(a[w.first]<a[c.second])
			{
				w=c;
			}
			else
			{
				w=make_pair(c.first, w.first);
			}
		}
		else
		{
			if(w.first!=c.first)
			{
				w=make_pair(w.first, c.first);
			}
		}
	}
	fs[x]=w;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		int m=1<<n;
		vi a(m);
		vpii fs(m);
		int ans=0;

		scanf("%d", &a[0]);
		fs[0]=make_pair(0, 0);
		for(int i=1;i<m;i++)
		{
			scanf("%d", &a[i]);

			calc(a, fs, i);
			int x=a[fs[i].first]+a[fs[i].second];
			if(ans<x) ans=x;
			printf("%d\n", ans);
		}
	}

	return 0;
}


Measured memory_bytes: 6144
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), k = in();
	for (ll i = a; i <= b; ++i) {
		if ((i - a) >= k && (b - i) >= k) {
			i = b - k + 1;
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)

N = int(input())

q = {}

for i in range(N):
    q[i] = []

for _ in range(N - 1):
    _u, _v, _w = map(int, input().split())

    q[_u - 1].append((_v - 1, _w))
    q[_v - 1].append((_u - 1, _w))

ans = [None] * N
ans[0] = 0


def search(x, parent_num):
    for s in q[x]:
        if ans[s[0]] is None:
            ans[s[0]] = (parent_num + s[1]) % 2
            search(s[0], ans[s[0]])


search(0, 0)

for i in range(N):
    print(ans[i])


Measured memory_bytes: 87784
s = input()

y,m = int(s[:2]), int(s[2:])

if (y == 0 or 12 < y) and (1 <= m <= 12):
    print('YYMM')
elif (1 <= y <= 12) and (m == 0 or 12 < m):
    print('MMYY')
elif (1 <= y <= 12) and (1 <= y <= 12):
    print('AMBIGUOUS')
else:
    print('NA')

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

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


int main(void) {
  SET wa, su;
  ll sa;
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  FOR(i, 0, 31) {
	FOR(j, 0, 31) {
	  if (100 * a*i + 100 * b*j <= f && (i != 0 || j != 0)) wa.insert(100 * a*i + 100 * b*j);
	}
  }

  FOR(i, 0, 1501) {
	FOR(j, 0, 1501) {
	  if (i*c + j * d < 1501) su.insert(i*c + j * d);
	}
  }

  n = 100 * a; m = 0;

  ll mizu, sio;

  for (auto it1 : wa) {
	for (auto it2 : su) {
	  mizu = it1; sio = it2;
	  if (mizu / 100 * e >= sio && mizu + sio <= f) {
		if ((ld)m / (n + m) < (ld)sio / (mizu + sio)) {
		  n = mizu;
		  m = sio;
		}
	  }
	}
  }

  cout << n + m << " " << m << endl;

  return 0;
}

Measured memory_bytes: 256
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int sum=0;
    int n;
    bool flag=false;

    cin >> n;

    int n_ini=n;

    while(n>0){
        sum += n%10;
        n /= 10;
    }

    if(n_ini%sum==0) flag=true;

    cout << (flag ? "Yes" : "No") << endl;
    //cout << ans << endl;
    //printf("%.10f",ans_d);cout<<endl;
}


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

int main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    string s;
    cin >> s;

    for(int i = a;i < c;i++){
        if(s[i] == '#' && s[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = b;i < d;i++){
        if(s[i] == '#' && s[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    if(a < b && d < c || b < a && c < d){
        for(int i = max(a, b);i <= min(c, d);i++){
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}



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

using namespace std;

const int MX = 100000;

multiset<int> G[MX];
int loops = 0;

void remove(int v) {
	int a = *G[v].begin();
	int b = *G[v].rbegin();
	
	G[v].clear();
	
	G[a].erase(v);
	G[b].erase(v);
	
	if (a == b) {
		loops++;
		
		if (G[a].size() == 2) remove(a);
		if (G[b].size() == 2) remove(b);
	}
	else {
		G[a].insert(b);
		G[b].insert(a);
	}
}

int main() {
	int n, m;
	ignore = scanf("%d %d", &n, &m);
	for (int i = 0, u, v; i < m; i++) {
		ignore = scanf("%d %d", &u, &v);
		u--;
		v--;
		G[u].insert(v);
		G[v].insert(u);
	}
	
	bool bad = false;
	for (int v = 0; v < n; v++) {
		if (G[v].size() == 2) remove(v);
		if (G[v].size() % 2 == 1) bad = true;
	}
	
	int V = 0, E = 0;
	for (int v = 0; v < n; v++) {
		if (G[v].empty() == false) V++;
		E += G[v].size() / 2;
	}
	
	bool ok = (E / 2 + loops >= 3);
	
	printf("%s\n", ok && (bad == false) ? "Yes" : "No");
	
	return 0;
}

/*
5 7
1 2
1 3
2 3
2 4
2 5
3 4
3 5
No

7 9
1 3
3 4
4 1
1 2
2 5
5 1
2 6
6 7
7 2
Yes
*/


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> nums(n);
    for(int i = 0; i < n; i++) cin >> nums[i];
    vector<pair<int, int>> snake;
    vector<vector<int>> out(h, vector<int>(w));
    for(int i = 0; i < h; i++){
        if(i % 2){
            for(int j = w - 1; j >= 0; j--){
                snake.push_back(make_pair(i, j));
            }
        }else{
            for(int j = 0; j < w; j++){
                snake.push_back(make_pair(i, j));
            }
        }
    }
    int cur = 0;
    for(int i = 0; i < n; i++){
        int color = i + 1;
        for(int j = 0; j < nums[i]; j++){
            auto itr = snake[cur];
            cur++;
            int ch = itr.first;
            int cw = itr.second;
            out[ch][cw] = color;
        }
    }
    for(int i = 0; i < h; i++){
        cout << "\n";
        for(int j = 0; j < w;j ++){
            cout << out[i][j] << " ";
        }
    }
    cout << "\n";
}

Measured memory_bytes: 3760
#############<------------  Xorcestor_X ---------------->############

from math import *


def is_even(p):
    n=len(p)
    count=0
    for i in range(n):
        index=p.index(i,i,n)
        if i==index:
            pass
        else:
            count+=1
            temp=p[i]
            p[i]=p[index]
            p[index]=temp
    # print(p)
    if count%2==0:
        return True
    else:
        return False



prime=[]

def SieveOfEratosthenes():
    global prime
    prime=[1]*2000010
    prime[1]=0
    p=2
    while p*p<=2000001:
        if prime[p]:
            for i in range(p*p,2000002,p):
                prime[i]=0

lpf=[]

def precompute():
    global lpf
    lpf=[0]*1000001
    for i in range(2,1000001):
        if not lpf[i]:
            for j in range(i,1000001,i):
                if not lpf[j]:
                    lpf[j]=i


def binpow(a,b):
    res=1
    while b>0:
        if b&1:
            res*=a
        a*=a
        b>>=1
    return res


def modpow(a,b,x):
    res=1
    while b>0:
        if b&1:
            res*=a
            res%=x
        a*=a
        a%=x
        b>>=1
    return res

cont=[]

def f(x):
    global cont
    total=0
    for i in cont:
        total+=abs(i-x)
    return total


def bs(low,high,target):
    while low+3<high:
        mid=(low+high)/2
        if arr[mid]<target:
            low=mid
        else:
            high=mid-1
    for i in range(high,low-1,-1):
        if arr[o]<target:
            return i
    return -1


def ternary_search(l,r):
    while r-l>10:
        m1=l+(r-l)/3
        m2=r-(r-l)/3
        f1=f(m1)
        f2=f(m2)
        if f1>f2:
            l=m1
        else:
            r=m2

    mino=f(l)

    for i in range(l,r+1):
        mino=min(mino,f(i))

    return mino

x=int(input())
if 400<=x<=599:
    print(8)
elif 600<=x<=799:
    print(7)
elif 800<=x<=999:
    print(6)
elif 1000<=x<=1199:
    print(5)
elif 1200<=x<=1399:
    print(4)
elif 1400<=x<=1599:
    print(3)
elif 1600<=x<=1799:
    print(2)
else:
    print(1)


Measured memory_bytes: 9336
import java.util.Scanner;

public class Main {

	static final String s1 = "ABC";
	static final String s2 = "ARC";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.equals(s1)) {
			System.out.println(s2);
		} else {
			System.out.println(s1);
		}

	}

}


Measured memory_bytes: 26840
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,x,y,z;
  cin>>a>>b>>c;
  x=a;
  a=b;
  b=x;
  y=a;
  a=c;
  c=y;
  cout<<a<<" "<<b<<" "<<c<<endl;




 return 0;
}


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

int main()
{int N;
 cin >> N;
 int B[200], C[200];
 int pre, ans;
 pre = 0;
 ans = 0;
 for(int i=0; i<N; i++){
   cin >> B[i];}
 for(int i=0; i<N; i++){
   cin >> C[i];}
 pre += B[0];
 for(int i=0; i<N; i++){
   pre += C[i];}
 for(int i=0; i<N-1; i++){
   ans = max(ans, pre);
   pre += B[i+1] - C[i];}
 ans = max(ans, pre);
 cout << ans << endl;
 
   
 }

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

long long n, d[3] = {};
string res;
vector<string> s;

bool solve();

int main() {
  cin >> n;
  for (int i = 0; i < 3; ++i) cin >> d[i];
  s.resize(n);
  for (int i = 0; i < n; ++i) cin >> s[i];
  if (solve()) {
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) cout << res[i] << endl;
  } else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  if (d[0] + d[1] + d[2] == 0) return 0;
  for (int i = 0; i < n; ++i) {
    string now = s[i];
    int x = now[0] - 'A', y = now[1] - 'A';
    if (d[x] > d[y])
      swap(x, y);
    else if (d[x] == d[y]) {
      if (d[x] == 0) return 0;
      if (i + 1 < n && s[i] != s[i + 1] &&
          (y == s[i + 1][0] - 'A' || y == s[i + 1][1] - 'A'))
        swap(x, y);
    }
    ++d[x];
    --d[y];
    res += x + 'A';
  }
  return 1;
}


Measured memory_bytes: 6692
#include <stdio.h>
int main () {
  int i, j, k, l,  n[100], x[100], count1=0;
  i=0;
  while (1) {
    scanf("%d %d", &n[i], &x[i]);
    if (n[i]==0 && x[i]==0) {
      break;
    }
    i++;
  }
    for (l=0; l<100; l++) {
      if (n[l]==0 && x[l]==0) {
        break;
      }
      count1=0;
      for (i=1; i<=n[l]-2; i++) {
        for (j=i+1; j<=n[l]-1; j++) {
          for (k=j+1; k<=n[l]; k++) {
            if (i+j+k==x[l]){
              //   printf ("%d %d %d\n",i,j,k);                                                                                   
              count1++;
            }
          }
        }
      }

      printf("%d\n", count1);
    }

    return 0;
}

Measured memory_bytes: 600
import math
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
def count(m):
    num = 1
    for i in range(n-1):
        num += (m[i]-1)*(math.factorial(n-i-1))
        for j in range(i+1,n):
            if m[i] < m[j]:
                m[j] -= 1
    return num
print(abs(count(p)-count(q)))


Measured memory_bytes: 3060
import math

L = int(input())
r = int(math.log2(L))

# r+1頂点
vertex = r + 1
edge = 2 * r
res = []
for i in range(1,r+1):
    res.append([i,i+1,0])
    res.append([i,i+1,2**(i-1)])

for i in range(r,0,-1):
    if L-2**(i-1)>=2**r:
        L -= 2**(i-1)
        res.append([i,vertex,L])
        edge += 1

print(vertex,edge)
for l in res:
    print(*l)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;

int main() {
  INCANT;
  cin >> N >> M;
  int left=0, right=INF;
  int l,r;
  rep(i, M) {
    cin >> l >> r;
    left = max(left, l);
    right = min(right, r);
  }
  cout << max(0,right-left+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int DY[] = { -1,0,1,0 };
const int DX[] = { 0,1,0,-1 };

int H, W;
string S[301];

bool f(int y, int x) {
    return y >= 0 && x >= 0 && y < H&&x < W&&S[y][x] == '#';
}

ll g() {
    int N = H + W;
    vector<vll> sum(N, vll(N));
    rep(i, N) {
        // x+y=i
        // i-y>=0 y<=i
        rep(y, N - 1) {
            int x = i - y;
            sum[i][y + 1] = sum[i][y] + f(y, x);
        }
    }

    ll res = 0;
    rep(y, H)rep(x, W) {
        if (!f(y, x))continue;
        FOR(i, 1, min(H, W)) {
            int yy = y - i;
            int xx = x + i;
            if (!f(yy, xx))continue;
            for (int j : {i, -i}) {
                if (f(y + j, x + j))res++;
                if (f(yy + j, xx + j))res++;
                int k = x + y + j * 2;
                int lb = max(yy + j + 1, 0);
                int ub = y + j;
                if (k >= 0 && k < N && lb < ub) {
                    res += (sum[k][ub] - sum[k][lb]) * 2;
                }
            }
        }
    }
    return res;
}

void solve() {
    cin >> H >> W;
    rep(y, H)cin >> S[y];
    ll ans = g();
    reverse(S, S + H);
    ans += g();
    ans /= 2;
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

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


int main(){
    int N, M, K; cin >> N >> M >> K;
    bool flag = false;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            if (M * i + (N - i) * j - i * j == K) flag = true;
        
        }
        
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    P = list(map(int, input().split()))
    prev = False
    ans = 0
    for i in range(N):
        if P[i] == i+1 and not prev:
            ans += 1
            prev = True
        else:
            prev = False
    print(ans)


if __name__ == "__main__":
    main()


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

vector<int> ddx = {-1, 0, 1, 0};
vector<int> ddy = {0, -1, 0, 1};

int main() {
    int h, w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    rep(i, h)cin >> s[i];

    vector<vector<int>> d(h, vector<int>(w, 1001001));
    d[ch][cw] = 0;
    priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> que;
    que.push(make_pair(make_pair(ch, cw), 0));
    while(!que.empty()){
        pair<P, int> p = que.top();
        que.pop();
        int y = p.first.first;
        int x = p.first.second;
        int dist = p.second;
        if(dist > d[y][x])continue;
        rep(i, 4){
            if(y+ddy[i]<0 || y+ddy[i]>=h)continue;
            if(x+ddx[i]<0 || x+ddx[i]>=w)continue;
            if(s[y+ddy[i]][x+ddx[i]] == '#')continue;
            if(d[y+ddy[i]][x+ddx[i]] > dist){
                d[y+ddy[i]][x+ddx[i]] = dist;
                que.push(make_pair(make_pair(y+ddy[i], x+ddx[i]), dist));
            }
        }
        for(int dx = -2; dx <= 2; dx++){
            for(int dy = -2; dy <= 2; dy++){
                if(y+dy<0 || y+dy>=h)continue;
                if(x+dx<0 || x+dx>=w)continue;
                if(s[y+dy][x+dx] == '#')continue;
                if(d[y+dy][x+dx] > dist + 1){
                    d[y+dy][x+dx] = dist + 1;
                    que.push(make_pair(make_pair(y+dy, x+dx), dist + 1));
                }
            }
        }
    }
    if(d[dh][dw] == 1001001)cout << -1 << endl;
    else cout << d[dh][dw] << endl;
}

Measured memory_bytes: 9500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

int main() {

	string s,t;
	cin >> s >> t;
	int ans = 0;

	for (int i = 0; i < s.size(); i++)
		if (s[i] == t[i])
			ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x,a;
    cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

H=II()

cntEnem = 1
cntAtk = 0

while H:
    cntAtk += cntEnem
    cntEnem *= 2
    H //= 2

print(cntAtk)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=55;
const int mod=1e9+7;
int C[MAXN][MAXN],f[MAXN][MAXN],n;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	for(int i=0;i<MAXN;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)C[i][j]=C[i-1][j],ad(C[i][j],C[i-1][j-1]);
	}
	n=read();
	f[1][0]=f[1][1]=1;
	for(int i=1;i<n;i++)for(int j=0;j<=i;j++)if(f[i][j])
		for(int x=0;x+i<=n;x++)for(int y=0;x+y+i<=n;y++)if((x+y)&&(x+y>=j)&!((x+y-j)&1))
			ad(f[i+x+y][abs((x+y-j)/2+j-x)],1LL*f[i][j]*C[x+y+i][x+y]%mod*C[x+y][x]%mod);
	pr2(f[n][0]);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var aArray = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
			var bArray = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
			var cArray = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
			aArray = aArray.OrderByDescending(value => value).ToArray();
			bArray = bArray.OrderByDescending(value => value).ToArray();
			cArray = cArray.OrderByDescending(value => value).ToArray();
			long count = 0;

			var bCountList = new List<long>();
			foreach(var b in bArray)
			{
				var startIndex = 0;
				var endIndex = n - 1;
				var index = (startIndex + endIndex) / 2;

				while(startIndex <= endIndex)
				{
					index = (startIndex + endIndex) / 2;

					if(cArray[index] > b)
					{
						startIndex = index + 1;
					}
					else
					{
						endIndex = index - 1;
					}
				}

				if(cArray[index] > b)
				{
					bCountList.Add(index + 1);
				}
				else
				{
					bCountList.Add(index);
				}
			}

			for (var i = 1; i < n; i++)
			{
				bCountList[i] += bCountList[i - 1];
			}

			foreach (var a in aArray)
			{
				var startIndex = 0;
				var endIndex = n - 1;
				var index = (startIndex + endIndex) / 2;

				while (startIndex <= endIndex)
				{
					index = (startIndex + endIndex) / 2;

					if (bArray[index] > a)
					{
						startIndex = index + 1;
					}
					else
					{
						endIndex = index - 1;
					}
				}

				if (bArray[index] > a)
				{
					count += bCountList[index];
				}
				else if(index > 0)
				{
					count += bCountList[index - 1];
				}
			}

			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 42476
n = int(input())
a = list(map(int, input().split()))

l = {}
r = {}

for i, j in enumerate(a):
	if i - j in l:
		l[i-j] += 1
	else:
		l[i-j] = 1
	if i + j in r:
		r[i+j] += 1
	else:
		r[i+j] = 1
ans = 0
for i, j in l.items():
	if i in r:
		ans += r[i] * j

print(ans)

Measured memory_bytes: 57364
def main():
    from operator import mul
    from functools import reduce
    
    def cmb(n,r):
        r = min(n-r,r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1,r + 1))
        return over // under


    # N= int(input())
    M, N = map(int, input().split())
    # A=[0]*N
    # B=[0]*N
    # for i in range(N):
    #     A[i],B[i] = map(int,input().split())
    # for i in range(N):
    #     print(B[i])
    # if N==0 or M == 0:
        
    # else:
    a = cmb(M+N, 2)-M*N
    print(a)
    
main()

Measured memory_bytes: 3828
#
# File    : C.rb
# Author  : Kazune Takahashi
# Created : 3/9/2019, 9:04:53 PM
# Powered by Visual Studio Code
#

n, m = gets.chomp.split(" ").map{|i| i.to_i}
ary = []
n.times{
  ary << gets.chomp.split(" ").map{|i| i.to_i}
}
ary = ary.sort_by{|a, b|
  a
}
ans = 0
m.times{
  if ary[0][1] == 0
    ary.shift
  end
  ary[0][1] -= 1
  ans += ary[0][0]
}
puts ans


Measured memory_bytes: 12664
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, X, Y, x, y, cur, dat[2000][2];
vector<string> ans;
vector<char> apd;

bool ck(int u, int v, int d)
{
	if (abs(u) + abs(v) <= d) return true;
	return false;
}

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

	bool flag0 = false;
	bool flag1 = false;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> dat[i][0] >> dat[i][1];
		if ((abs(dat[i][0]) + abs(dat[i][1]))%2) flag1 = true;
		else flag0 = true;
		if (flag0 && flag1) {
			cout << "-1" << E;
			return 0;
		}
	}
	if (flag1) {
		for (int i = 0; i < n; i++) {
			if (dat[i][0] == 0) {
				if (dat[i][1] > 0) {
					apd.pb('U');
					dat[i][1]--;
				}
				else {
					apd.pb('D');
					dat[i][1]++;
				}
			}
			else if (dat[i][0] > 0) {
				apd.pb('R');
				dat[i][0]--;
			}
			else {
				apd.pb('L');
				dat[i][0]++;
			}
		}
	}
	string s(32, '0');
	int cnt = 0;
	while (cnt < n) {
		X = dat[cnt][0]; Y = dat[cnt][1];
		cnt++;
		x = abs(X); y = abs(Y);
		cur = 30;
		int tmp = (1 << cur);
		while (1) {
			if (ck(x - tmp, y, tmp)) {
				s[cur + 1] = 'R';
				x -= tmp;
			}
			else if (ck(x, y - tmp, tmp)) {
				s[cur + 1] = 'U';
				y -= tmp;
			}
			else if (ck(x + tmp, y, tmp)) {
				s[cur + 1] = 'L';
				x += tmp;
			}
			else {
				s[cur + 1] = 'D';
				y += tmp;
			}
			if (cur == 0) break;
			cur--;
			tmp = tmp / 2;
		}
		if (x == 0) {
			if (y > 0) s[0] = 'U';
			else s[0] = 'D';
		}
		else {
			if (x > 0) s[0] = 'R';
			else s[0] = 'L';
		}
		for (int i = 0; i < 33; i++) {
			if (s[i] == 'L' || s[i] == 'R') {
				if (X < 0) {
					if (s[i] == 'L') s[i] = 'R';
					else s[i] = 'L';
				}
			}
			else {
				if (Y < 0) {
					if (s[i] == 'U') s[i] = 'D';
					else s[i] = 'U';
				}
			}
		}
		ans.pb(s);
	}
	int m = 32;
	if (flag1) m++;
	cout << m << E;
	cout << "1 " << E;
	for (int i = 0; i < 31; i++) cout << (1 << i) << " ";
	if (flag1) cout << 1;
	cout << E;
	for (int i = 0; i < n; i++) {
		cout << ans[i];
		if (flag1) cout << apd[i];
		cout << E;
	}
	//std::system("pause");
	return 0;
}

Measured memory_bytes: 384
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << (s == "abc" ? "Yes" : "No") << endl;
	return 0;
}


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

int found[40] = {0};
int main () {
  char c;
  while(scanf("%c", &c) != EOF) {
    if(found[c] == 1) {
      cout << "no" << endl;
      return 0;
    }
    found[c] = 1;
  }
  cout << "yes" << endl;
  return 0;
}


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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
          ll x, y;
          cin >> x >> y;
          ll a = (y - 2* x)/ 2;
          ll b = x - a;
          if((y - 2* x) % 2 == 0 && y - 2 *x >= 0 && b>=0)
          cout << "Yes" << endl;
          else
          cout << "No" << endl;   
   }
}


Measured memory_bytes: 3644
// Born Sinner
// old but im not that old
// fuck all you hoes get a grip
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            } catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    static class pair<T1, T2>{
        T1 first;
        T2 second;
        pair(T1 first, T2 second){
            this.first = first;
            this.second = second;
        }
    }
    
    public static void main (String[] args) throws java.lang.Exception
    {
        FastReader in = new FastReader();
        int n = in.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++) a[i] = in.nextLong();

        long ans = 0;

        long max = a[0];
        for(int i = 1; i < n; i++){
            ans += Math.max(max - a[i], 0);
            max = Math.max(max, a[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 55848
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const int mod=1e9+7;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL a[55];
int main(){
//    freopen("out.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int f=1;
    LL ans=0;
    while(f){
        f=0;
        for(int i=0;i<n;i++){
            if(a[i]>=n){
                f=1;
                LL k=a[i]/n;
                ans+=k;
                a[i]%=n;
                for(int j=0;j<n;j++){
                    if(i==j) continue;
                    a[j]+=k;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256