akhauriyash/Code-Regression huggingface dataset:
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=3e3+100;
const ll INF=1e18;

int w, h;
ll area[N][N];
ll ans;

int movx[4] = {0,1,0,-1};
int movy[4] = {1,0,-1,0};
bool block[N][N][4];
bool vis[N][N];

void check(int i, int j){
	if(i<0 || i>=h || j<0 || j>=w){
		cout<<"INF"<<endl;
		exit(0);
	}
}

void bfs(int i, int j){
	queue<ii> Q;
	Q.push(mp(i,j));
	check(i,j);
	vis[i][j]=1;
	while(!Q.empty()){
		i = Q.front().ff;
		j = Q.front().ss;
		Q.pop();
		ans += area[i][j];
		For(k,0,4) if(!block[i][j][k]){
			int nxti = i + movy[k];
			int nxtj = j + movx[k];
			check(nxti,nxtj);
			if(!vis[nxti][nxtj]){
				vis[nxti][nxtj]=1;
				Q.push(mp(nxti,nxtj));
			}
		}
	}
}

vector<pair<ii, ll> > vert, hor;
vi coordx, coordy;
unordered_map<ll,ll> idx, idy;

int main(){
	fastio;
	int n, m; cin>>n>>m;		
	For(i,0,n){
		ll d, u, x; cin>>d>>u>>x;
		vert.pb(mp(mp(d,u),x));
		coordx.pb(x);		
		coordy.pb(d);
		coordy.pb(u);
	}	
	For(i,0,m){
		ll y, l, r; cin>>y>>l>>r;
		hor.pb(mp(mp(l,r),y));
		coordy.pb(y);
		coordx.pb(l);
		coordx.pb(r);
	}
	coordx.pb(0);
	coordy.pb(0);

	sort(all(coordx));
	coordx.resize(unique(all(coordx))-coordx.begin());
	w = sz(coordx);
	For(i,0,w) idx[coordx[i]]=i;

	sort(all(coordy));
	coordy.resize(unique(all(coordy))-coordy.begin());
	h = sz(coordy);
	For(i,0,h) idy[coordy[i]]=i;
       if(w>=N || h>=N){
              cout<<"xd"<<endl;
       }
	w--, h--;
	For(i,0,h)
		For(j,0,w)
			area[i][j] = (coordy[i+1]-coordy[i])*(coordx[j+1]-coordx[j]);
	for(auto l: vert){
		int d = l.ff.ff, u = l.ff.ss, x = l.ss;
		int izq = idx[x]-1, der = idx[x];
		int i = idy[d];
		int fin = idy[u];
		while(i<fin){
			if(izq>=0) block[i][izq][1]=1; 
			if(der<w) block[i][der][3]=1;
			i++;
		}
	}
	for(auto elem: hor){
		int l = elem.ff.ff, r = elem.ff.ss, y = elem.ss;
		int down = idy[y]-1, up = idy[y];
		int j = idx[l];
		int fin = idx[r];
		while(j<fin){
			if(down>=0) block[down][j][0]=1; 
			if(up<h) block[up][j][2]=1;
			j++;
		}
	}
	bfs(idy[0],idx[0]);
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 119420
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll cnt = 0;
    ll res = 1;
    rep(i,n){
        cnt++;
        if(i>0&&a[i]<2*cnt-1){
            res *= cnt;
            res %= MOD;
            cnt--;
        }
    }
    DEBUG{
        cout << "cnt: "<< cnt << endl;
        cout << "res: "<< res << endl;
    }
    while(cnt>0){
        res *= cnt;
        res %= MOD;
        cnt--;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
  int n,p,i,j;
  int sum=0;
  int m=0;
  for(;;)
    {
      scanf("%d %d",&n,&p);
      int entry[n];  
      for(i=0;i<n;i++) {entry[i]=0; /*printf("entry[%d]=%d\n",i,entry[i]);*/}
      if(n==0)  {if(p==0){break;}} 
      i=0;
      int pk;
      pk=p;
      for(;;)
	{
	  for(i=0;;i++)
	    {
	      if(p>1)
		{
		  p=p-1;
		  entry[i]=entry[i]+1;
		}
	      else if(p==1)
		{
		  /*printf("---------------------------------");*/
		  if(entry[i]==pk-1){m=1;/*printf("............."); */break;}
		  else{p=0; entry[i]=entry[i]+1;}
		}	
	      else if(p==0)
		{
		  p=entry[i];
		  entry[i]=0;	    
		}
	      /*printf("entry[%d]=%d p=%d\n",i,entry[i],p);*/
	      if(i==(n-1)){i=(-1);}
	    }
	  if(m==1){printf("%d\n",i); break;}
	}
    }	  
  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i,k,n) for(int i=k; i<n; i++)
#define iforr(i,k,n) for(int i=n-1; i>=k; i--)
#define rep(i,n) forr(i,0,n)
#define irep(i,n) iforr(i,0,n)
#define aut(i,arr) for(auto& i:arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long 
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("code.in","r",stdin);
    freopen("code.out","w",stdout);
    #endif
}

vi v;
vvi ed;
void dfs(int i)
{
	v[i]=1;
	aut(j,ed[i])
		if(!v[j])
			dfs(j);
}

int main()
{
	//Fast_IO();
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
		int mod=1e9+7;
		int n;
		cin>>n;
		int m;
		cin>>m;
		vector<string> arr(n);
		rep(i,n)
			cin>>arr[i];
		vvi dp(n,vi(m));
		dp[n-1][m-1]=1;
		irep(i,m-1)
			if(arr[n-1][i]=='#')
				dp[n-1][i]=0;
			else
				dp[n-1][i]=dp[n-1][i+1];
		irep(i,n-1)
			if(arr[i][m-1]=='#')
				dp[i][m-1]=0;
			else
				dp[i][m-1]=dp[i+1][m-1];
		irep(i,n-1)
			irep(j,m-1)
				if(arr[i][j]=='#')
					dp[i][j]=0;
				else
					dp[i][j]=(dp[i+1][j]+(ll)dp[i][j+1])%mod;
		cout<<dp[0][0];
		cout<<E;
	}
	return 0;
}

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

int main(void){
    int n, d; cin >> n >> d;
    int ans;
    
    if(n % (2*d + 1) == 0){
        ans = n / (2*d + 1);
    }else{
        ans = n / (2*d + 1) + 1;
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
// AOJ 2740: Rooted Tree for Misawa-san
// 2018.1.7 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

typedef struct { int n; int l, r; } T;
T node[2000]; int sz;

char a[1005], b[1005];
char ans[1500];

void tree(char *p, int k, int update)
{
	int f;

	if (*p++ != '(') return;
	if (*p == '(') {
		if (!update) node[k].l = sz++, tree(p, sz-1, update);
		else if (node[k].l > 0) tree(p, node[k].l, update);
	} else if (update) node[k].l = 0;
	f = 1; while (1) {
		if (*p == '(') f++;
		else if (*p == ')') { if (--f == 0) break; }
		p++;
	}
	p += 2;								// skip ")["
	node[k].n += atoi(p);			
	while (isdigit(*p)) p++;
	p += 2;								// skip "]("
	if (*p == '(') {
		if (!update) node[k].r = sz++, tree(p, sz-1, update);
		else if (node[k].r > 0) tree(p, node[k].r, update);
		else node[k].r = 0;
	} else if (update) node[k].r = 0;
}

char *cout(char *p, int k)
{
	*p++ = '(';
	if (node[k].l > 0) p = cout(p, node[k].l);
	sprintf(p, ")[%d](", node[k].n);
	while (*p) p++;
	if (node[k].r > 0) p = cout(p, node[k].r);
	*p++ = ')';
	*p = 0;
	return p;
}

int main()
{
	fgets(a, 1005, stdin);
	fgets(b, 1005, stdin);
	sz = 2;
	tree(a, 1, 0), tree(b, 1, 1);
	cout(ans, 1);
	puts(ans);
	return 0;
}


Measured memory_bytes: 1852
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll Z = 1 << 21;
	ll W, H, N; cin >> W >> H >> N;
	ll maxX = 0, minX = Z, maxY = 0, minY = Z;
	rep(i, 0, N) {
		ll x, y, a; cin >> x >> y >> a;
		if (a == 1) {
			if (maxX < x) maxX = x;
		}
		else if (a == 2) {
			if (minX > x) {
				minX = x;
			}
		}
		else if (a == 3) {
			if (maxY < y) maxY = y;
		}
		else if (a == 4) {
			if (minY > y) minY = y;
		}
	}

	if (minX == Z) minX = W;
	if (minY == Z) minY = H;

	if (minX > maxX && minY > maxY) {
		cout << ((minX - maxX)*(minY - maxY)) << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cmath>

int main()
{
    while (1){
        int n;

        scanf(" %d", &n);
        if (n == 0){
            break;
        }

        int score[n];

        for (int i = 0; i < n; i++){
            scanf(" %d", &score[i]);
        }

        int sum = 0;
        double ave;
       
        for (int i = 0; i < n; i++){
            sum += score[i];
        }
        
        ave = (double)sum / n;

        double alpha = 0;

        for (int i = 0; i < n; i++){
            alpha += pow(score[i] - ave, 2);
        }

        printf("%lf\n", sqrt(alpha/n));
    }

    return 0;
}
    

Measured memory_bytes: 1064
#include <cstdio>
#include <tuple>
#include <array>

#define coin_count 4
using namespace std;

array<int, coin_count> calc(int total, array<int, coin_count> ct, array<int, coin_count> cn) {
	int money = 0;
	for (int i = 0; i < ct.size(); i++) {
		money += ct[i] * cn[i];
	}
	int money_to_return = money - total;
	array<int, coin_count> coin_return;
	coin_return.fill(0);
	for (int i = ct.size()-1; i >= 0; --i) {
		while (money_to_return >= ct[i]) {
			money_to_return -= ct[i];
			coin_return[i]++;
		}
	}
	array<int, coin_count> coin_to_pay;
	coin_to_pay.fill(0);
	for (int i = 0; i < ct.size(); i++) {
		coin_to_pay[i] = cn[i] - coin_return[i];
	}
	return coin_to_pay;
}


int main() {
	int total;
	array<int, coin_count> ct{10, 50, 100, 500};
	array<int, coin_count> cn;
	bool first = true;
	while (true) { 
		scanf("%d", &total);
		if (total == 0) break;
		if (!first) printf("\n");
		first = false;
		scanf("%d %d %d %d", &cn[0], &cn[1], &cn[2], &cn[3]);
		array<int, coin_count> res = calc(total, ct, cn);
		for (int i = 0; i < coin_count; i++) {
			if (res[i] > 0) printf("%d %d\n", ct[i], res[i]);
		}
	}
}



Measured memory_bytes: 2564
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

// least common multiple
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int N;
ll A[N_MAX + 1];
ll X[N_MAX + 1];

int main() {
  scanf("%d", &N);
  ll s = 0;
  rep(i,N) {
    scanf("%lld", &A[i]);
    s += A[i];
  }
  ll as = 0;
  for (int i = 1; i < N; i += 2) {
    as += A[i];
  }
  X[0] = s - 2 * as;
  FOR(i, 1, N) {
    X[i] = 2 * A[i - 1] - X[i - 1];
  }
  rep(i, N) {
    printf("%lld ", X[i]);
  }
  printf("\n");
}


Measured memory_bytes: 2816
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;



int main(){
   int n;
   cin >> n;
   REP(i, 1, 100){
      int m = i * 1000;
      if(m >= n){
         cout << m - n;
         return 0;
      }
   }
}


Measured memory_bytes: 3632
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/
struct node
{
	int x, y;
};

int compare(struct node &n1, struct node &n2)
{
	return (n1.x == n2.x) ? (n1.y < n2.y) : (n1.x < n2.x);
}

int compare_r(struct node &n1, struct node &n2)
{
	return (n2.y < n1.y);
}

int compare_b(struct node &n1, struct node &n2)
{
	return (n1.x < n2.x);
}

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

	int n;
	
	cin >> n;

	struct node red[n];
	struct node blue[n];

	rep(i, n)
	{
		cin >> red[i].x >> red[i].y;
	}

	rep(i, n)
	{
		cin >> blue[i].x >> blue[i].y;
	}

	sort(red, red+n, compare_r);

	sort(blue, blue+n, compare_b);

	/*
	cout << endl;
	
	rep(i, n)
	{
		cout << red[i].x << " " << red[i].y << endl;
	}

	cout << endl;
	
	rep(i, n)
	{
		cout << blue[i].x << " " << blue[i].y << endl;
	}
	int i = 0, j = 0;
	*/

	
	int count = 0;

	bool t[n];
	rep(i, n)
	{
		t[i] = false;
	}

	rep(i, n)
	{
		rep(j, n)
		{
			if ((blue[i].x > red[j].x) && (blue[i].y > red[j].y) && !t[j])
			{
				t[j] = true;
				count++;
				break;
			}
		}

	}

	/*
	rep(i, n)
	{
		if (t[i])
		{
			count++;
		}

	}
	*/
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
def calc(x)
  r = 0
  while (x % 100).zero?
    x /= 100
    r += 1
  end
  r
end
d, n = gets.split.map(&:to_i)
cnt = 0
x = 1
loop do
  cnt += 1 if calc(x) == d
  break if cnt == n
  x += 1
end
puts x

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    string S, T;
    cin >> S;
    cin >> T;

    ll ans = 0;
    REP(i, S.size())
    {
        if (S[i] != T[i])
        {
            ans++;
        }
    }

    cout << ans << endl;
}


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

					using namespace std;
					typedef long long ll;
					set<string> ss;
					map<string, int> m, s;
					vector<string> v;
					int n, k;
					int main()
					{
						cin >> n;
						for(int i = 1; i <= n; i++)
						{
							string x;
							cin >> x;
							s[x]++;
							ss.insert(x);
							int g = s[x];
							k = max(k, g);
						}
						for(auto it : ss)
						{
							if(k == s[it] && !m[it])
								v.push_back(it), m[it]++;
						}
						sort(v.begin(), v.end());
						for(int i = 0; i < v.size(); i++)
							cout << v[i] << '\n';
					}

Measured memory_bytes: 48624
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

A_pos = [A[x]+x for x in range(n)]
A_neg = [-A[x]+x for x in range(n)]

C_pos = Counter(A_pos)
C_neg = Counter(A_neg)

ans = 0

for c in C_pos:
    ans += C_pos[c] * C_neg[c]
print(ans)

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



int main(void){
    
    long long N;
    string S;
    cin >> N;
    cin >> S;

    long long r = 0;
    long long g = 0;
    long long b = 0;
    
    for(int i = 0; i < N; i++){

        if(S[i]=='R')r++;
        else if(S[i]=='G')g++;
        else if(S[i]=='B')b++;

    }
    
    //cout << r << g << b<<endl;
    long long sum = 0;
    for(int i = 0; i < N ; i++){
        for(int j = i + 1; j < N; j++){
            //cout << S[2*j-i]<<endl;
            
            if(2*j-i >= N)continue;
            //cout <<"a:"<< 2*j-i <<" "<< N<<endl;
            //cout << i <<" "<< j << " "<< 2*j-i<<endl;
            //cout << S[i] <<" "<< S[j] <<" "<< S[2*j-i] << endl; 
            if(S[i] == S[j] || S[j] == S[2*j-i] || S[i] == S[2*j-i])continue;
            sum++;
            
        }
    }
    //cout << sum <<endl;
    
    cout << r*g*b - sum << endl;
    

    
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
int n,m[1000][1000],col[1000],d[1000],cent[1000];

void prim(){
	lp(i,n){
		d[i]=INF;
	}
	d[0]=0;
	cent[0]=-1;
	while(1){
		int mini=INF,hoge;
		lp(i,n){
			if(col[i]!=2&&d[i]<mini){
				mini=d[i];
				hoge=i;
			}
		}
		if(mini==INF) return;
		col[hoge]=2;
		lp(i,n){
			if(col[i]!=2){
				if(m[hoge][i]==INF) continue;
				if(m[hoge][i]<d[i]){
					d[i]=m[hoge][i];
					cent[i]=hoge;
					col[i]=1;
				}
			}
		}
	}
}

signed main(){
	cin>>n;
	lp(i,n){
		lp(j,n){
			cin>>m[i][j];
			if(m[i][j]==-1) m[i][j]=INF;
		}
	}
	prim();
	int ans=0;
	lp(i,n){
		if(cent[i]==-1) continue;
		ans+=m[i][cent[i]];
	}
	cout<<ans<<endl;
    return 0;
}



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

const int MOD = (int)1e9+7;

int main(){
  long long N,M;
  cin >> N >> M;
  vector<pair<long long,long long>> AB(N);
  for(int i=0;i<N;i++)  cin >> AB.at(i).first >> AB.at(i).second;

  sort(AB.begin(),AB.end());
  long long ans=0;
  for(int i=0;i<N;i++){
    ans+=AB.at(i).first*AB.at(i).second;
    M-=AB.at(i).second;
    if(M<=0){
      ans-=AB.at(i).first*(-M);
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
N = int(input())
P =list( map(int, input().split()))
s = P[0]
t = min(P)
Pmin = [P[0]]
for i in range(N - 1):
  if P[i + 1] < Pmin[i]:
    Pmin.append(P[i + 1])
  else:
    Pmin.append(Pmin[i])

cnt = 0

for j in range(N):
  if P[j] == Pmin[j]:
    cnt += 1
  else:
    pass
print(cnt)

Measured memory_bytes: 25716
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
  return *(int*)b-*(int*)a;
}

int main(){
  int n;
  int a[200001];
  int i;
  long long ans=0;
  int p,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),compare_int);
  p=(n-2)/2;
  q=n%2;
  ans+=a[0];
  for(i=1;i<=p;i++){
    ans+=2*a[i];
  }
  if(q==1) ans+=a[p+1];
  printf("%lld\n",ans);
  return 0;
}


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

int main() {
	int n;
	stack<int>st;
	while (cin >> n) {
		if (n == 0) {
			cout << st.top() << endl;
			st.pop();
		}
		else st.push(n);
	}
	return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define ull unsigned long long int
using namespace std;

/*ll power(ll x,ll y)
{
    ll res = 1;
    while(y>0){
        if(y&1)
            res *= x;
        y>>=1;
        x*=x;
    }
    return res;
}*/

//int a[1010][1010];

int main()
{
    string s,t;
    cin>>s>>t;
    //int a,b,n;
    //cin>>n;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])
            ans++;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll M = 1e9 + 7;
const ll N = 1000;
ll h, w;
ll dp[N + 1][N + 1];

int main() {
    cin >> h >> w;
    // valuu kohtaan dp[1][1]
    dp[0][1] = 1;
    for (ll i = 1; i <= h; i++) {
        for (ll j = 1; j <= w; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                continue;
            }
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
        }
    }
    cout << dp[h][w] << "\n";
    return 0;
}


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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x;
  cin >> x;
  long long ans = x / 11 * 2;
  int rest = x % 11;
  if (rest > 0 && rest <= 6) {
    ans += 1;
  } else if (rest > 6) {
    ans += 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double x1,x2,x3,y1,y2,y3;
		double px,py,r;
		double xa,xb,ya,yb,da,db,s;
		int temp=scan.nextInt();;

		for(int i=0;i<temp;i++){
		x1=scan.nextDouble();
		y1=scan.nextDouble();
		x2=scan.nextDouble();
		y2=scan.nextDouble();
		x3=scan.nextDouble();
		y3=scan.nextDouble();

		xa=x2-x1;
		xb=x3-x1;
		ya=y2-y1;
		yb=y3-y1;

		da=(xa*xa)+(ya*ya);
		db=(xb*xb)+(yb*yb);
		s=(xa*yb)-(xb*ya);

		px=-((ya*db)-(yb*da))/(2*s);
		py=-((xb*da)-(xa*db))/(2*s);

		px+=x1;
		py+=y1;

		r=Math.hypot(px-x1, py-y1);
		System.out.printf("%.3f %.3f %.3f\n",px,py,r);
		}
	}

}

Measured memory_bytes: 20796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define TR(X) ({ if(1) cerr << "Trace: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	map<char, vector<ll> > ind;
	ll ns = sz(s), nt = sz(t);
	for(ll i = 0; i < ns; i++) ind[s[i]].push_back(i);
	ll copies = 1, curidx = -1;
	for(ll i = 0; i < nt; i++) {
		if(sz(ind[t[i]]) == 0) return cout << -1 << endl, 0;
		auto nxt = upper_bound(all(ind[t[i]]), curidx);
		if(nxt == ind[t[i]].end()) {
			copies++;
			curidx = ind[t[i]][0];
		} else {
			curidx = *nxt;
		}
	}
	cout << (copies - 1) * ns + curidx + 1 << endl;
}



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;
long long a[N];

void solve() {
  int n, m, v, p; scanf("%d %d %d %d", &n, &m, &v, &p);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a+i);
  }
  sort(a, a+n, greater<long long>());
  for (int j = 0; j < p-1 && v > 1; ++j) {
    a[j] += m;
    --v;
  }
  int hi = upper_bound(a, a+n, a[p-1], greater<long long>())-a;
  int ans = hi;
  long long s = 0;
  for (int i = p-1; i < hi; ++i) s += a[i];
  for (int i = hi; i < n; ++i) {
    long long x = a[i]+m;
    long long c = max(v-(n-i), 0);
    debug(s);
    debug(c*m);
    debug(x*(i-(p-1))-s);
    debug(i-(p-1));
    debug(x);
    debug(a[p-1]);
    debug(a[i]);
    if (x < a[p-1]) break;
    if (a[i] != a[i-1] && c*m > x*(i-(p-1))-s) break;
    ++ans;
    s += a[i];
  }
  debug(v);
  debug(hi);
  printf("%d", ans);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;	// 入力
  
  // 入力の取り込み
  cin >> a;
  cin >> b;
  
  //　商＋余りを出力
  cout << (a + b) / 2 + (a + b) % 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int n;cin>>n;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    int count=0;
    for(int i=1;i<n-1;i++)if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
        count++;
    }
    cout<<count<<endl;
}





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

using namespace std;

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

    bool kawaisou; kawaisou = false;    

    if (A == B && A != C)  kawaisou = true;
    if (B == C && B != A)  kawaisou = true;
    if (A == C && A != B)  kawaisou = true;

    if (kawaisou) {
        cout <<"Yes"<< endl;
    }
    else {
        cout << "No" << endl;
    }

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int maxM = 100000;
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int m, a, b;
	bool isPrime[maxM+1] = {0}; fill(isPrime, isPrime+maxM+1, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i <= maxM; ++i) {
		for (int j = i*2; j <= maxM; j += i) {
			isPrime[j] = false;
		}
	}
	vector<ll> p;
	REP(i,maxM+1) {
		if (isPrime[i]) p.pb(i);
	}
	int N = p.size();
	while ( cin >> m >> a >> b, m || a || b ) {
		int aw = -1, ah = -1, ans = 0;
		REP(i,N) {
			if (p[i] > m) continue;
			ll th = min(p[i]*b/a, m/p[i]);
			auto it = upper_bound(p.begin()+i, p.end(), th);
			if (it != p.begin()+i) {
				--it;
				int q = *it;
				if (p[i]*q > ans) {
					ans = p[i]*q;
					aw = p[i];
					ah = q;
				}
			}
/*
			FOR(j,i,N) {
				if (p[i]*p[j] <= m && a*p[j] <= b*p[i]  && p[i] <= p[j]) {
					if (p[i]*p[j] > ans) {
						ans = p[i]*p[j];
						aw = p[i];
						ah = p[j];
					}
				}
			}
*/
		}
		cout << aw << " " << ah << endl;
	}
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> s;
}

bool isok(string s){
    bool res=true;
    res &= (s[0]=='A');
    bool C=false;
    int j=0;
    for (int i = 2; i < s.length()-1; i++)
    {
        if(s[i]=='C') {C|=true;j=i;}
    }
    res &= C;
    for (int i = 0; i < s.length(); i++)
    {
        if(i==0 || i==j) continue;
        res &= ('a'<=s[i] and s[i]<='z');
    }
    return res;
}

int solve(){
    cout << (isok(s)?"AC":"WA") << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, c, k, sum;

    scanf("%d %d %d %d", &a, &b, &c, &k);

    if(a >= k){
        sum = k;
        printf("%d\n", sum);
    }
    else{
        if((a + b) >= k){
            sum = a;
            printf("%d\n", sum);
        }
        else{
            sum = a - (k - a - b);
            printf("%d\n", sum);
        }
    }
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,a,b,i,j;
	cin>>x>>a>>b;
	i=abs(a-x);
	j=abs(b-x);
	if(i>j){
		cout<<"B"<<endl;
	}
	else{
		cout<<"A"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,m;
  cin>>n>>m;
  vector<int>L(m),R(m);
  int shou=INT_MAX;
  int dai=0;
  rep(i,m){
    cin>>L[i]>>R[i];
  }
  rep(i,m){
    shou=min(shou,R[i]);
    dai=max(dai,L[i]);
  }
  int kotae=shou-dai+1;
  if(kotae<=0){
    cout<<0<<endl;
  }else{
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] S = new String[H];
		for (int i = 0; i < H; i++) {
			S[i] = sc.next();
		}

		int[] x = { 0, 1, 1, 1, 0, -1, -1, -1 };
		int[] y = { 1, 1, 0, -1, -1, -1, 0, 1 };
		for (int i = 0; i < H; i++) {
			StringBuilder buf = new StringBuilder("");
			for (int j = 0; j < W; j++) {
				String str = "#";
				if (!"#".equals(String.valueOf(S[i].charAt(j)))) {
					int count = 0;
					for (int k = 0; k < 8; k++) {
						int dx = j + x[k];
						int dy = i + y[k];
						if (dx < 0 || W <= dx || dy < 0 || H <= dy) {
							continue;
						}
						if ("#".equals(String.valueOf(S[dy].charAt(dx)))) {
							count++;
						}
					}
					str =  String.valueOf(count);
				}
				buf.append(str);
			}
			System.out.println(buf.toString());
		}
	}
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }

    int cnt = 0;

    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            ++cnt;
        }
    }

    if (cnt == 0) {
        return true;
    } else {
        return false;
    }
}

int main() {

    int x; cin >> x;

    while (!is_prime(x)) {
        ++x;
    }

    cout << x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
	char w[10],t[1000];
	int i,j,cou=0;
	
	scanf("%s",w);
	char end[]="END_OF_TEXT";
	for(i=0;;i++){
		scanf("%s",t);
		if(strcmp(t,end)==0)break;
		for(j=0;;j++){
			if((t[j]>=0x41)&&(t[j]<=0x5a)){
				t[j]=t[j] + 0x20;
			}
			if(t[j]=='\0')break;
		}
		if(strcmp(w,t)==0)cou++;
	}
	printf("%d\n",cou);
		
	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
int ord(int n){
  int ret=0;
  while(n%2==0){
    n/=2;
    ret++;
  }
  return ret;
}
int main(){
  int n;
  cin>>n;
  int ans=1000000007;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans=min(ans,ord(a[i]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i,d,b) for(int i=(d);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(d) memset((d), 0 ,sizeof(d))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int nmax = 100;
vector<VI> d(nmax);
const int inf = 1 << 30 - 1;

void init_d() {
	REP(i, nmax)
	{
		d[i] = VI(nmax);
		REP(j, nmax)
			d[i][j] = inf;
	}

}

void wf() {
	REP(i, nmax) REP(j, nmax) REP(k, nmax)
		d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

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

	REP(i, nmax)
	{
		d[i] = VI(nmax);
		REP(j, nmax)
			d[i][j] = inf;
	}

	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		d[a[i]][b[i]] = c[i];
		d[b[i]][a[i]] = c[i];
	}

	
	REP(i, nmax) REP(j, nmax) REP(k, nmax)
		d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

	//REP(i, nmax) REP(j, nmax) dump(d[i][j]);

	int cnt = 0;
	REP(i, m) {
		//dump(d[a[i]][b[i]]);
		if (d[a[i]][b[i]] < c[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
// {{{
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)x.size())
#define FOR(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using LL=long long;
using PII=pair<int,int>;
using VI=vector<int>;

#ifdef FEI
template<typename T>
void _dump(const char* s, T&& head) { cerr<<s<<"="<<head<<endl; }
template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
    int c=0;
    while (*s!=',' || c!=0) {
        if (*s=='(' || *s=='[' || *s=='{') c++;
        if (*s==')' || *s==']' || *s=='}') c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1, tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, ##__VA_ARGS__); \
} while(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<'[';
    for (auto it=b; it!=e; it++) s<<(it==b?"":",")<<*it;
    s<<']';
    return s;
}

template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) { return s<<"("<<p.first<<","<<p.second<<")";}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &x) { return _out(s,ALL(x)); }
template<typename T, size_t N>
ostream& operator <<(ostream &s, const array<T,N> &x) { return _out(s,ALL(x)); }
template<typename T>
ostream& operator <<(ostream &s, const set<T> &x) { return _out(s,ALL(x)); }
template<typename A, typename B>
ostream& operator <<(ostream &s, const map<A,B> &x) { return _out(s,ALL(x)); }
#else
#define dump(...)
#endif

template<typename T>
void _R(T &x) { cin>>x; }
void _R(int &x) { scanf("%d",&x); }
void _R(LL &x) { scanf("%" PRId64,&x); }
void _R(double &x) { scanf("%lf",&x); }
void _R(char &x) { scanf(" %c",&x); }
void _R(char *x) { scanf("%s",x); }

void R(){}
template<typename T, typename... X>
void R(T& head, X&... tail) { _R(head); R(tail...); }
// }}}

const int N = 500005;
int arr[N], dist[N], safeRange[N];

int main() {
    int n, d;
    R(n, d);
    for (int i=1; i<=n; i++)
        R(arr[i]);

    dist[0] = d;
    for (int i=1; i<=n; i++)
        dist[i] = min(dist[i-1], abs(dist[i-1]-arr[i]));

    safeRange[n+1] = 0;
    for (int i=n; i>0; i--) {
        if (arr[i] > 2*safeRange[i+1]+1)
            safeRange[i] = safeRange[i+1];
        else
            safeRange[i] = min(d, safeRange[i+1]+arr[i]);
    }

//    dump(VI{dist, dist+n+2});
//    dump(VI{safeRange, safeRange+n+2});

    int q;
    R(q);
    while (q--) {
        int v;
        R(v);
        if (dist[v-1] <= safeRange[v+1]) puts("NO");
        else puts("YES");
    }

    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	LL n,ans=0;
	cin>>n;
	vector <LL> a(n);
	rep(i,n)
	{
		cin>>a[i];
		while(a[i]%2==0&&a[i]>0)
		{
			ans++;
			a[i]/=2;
		}
	}
	cout<<ans<<endl;
  rt0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n , x, d =0, ctemp, cnt = 1;
    cin >> n >> x;
    for(int i = 0; i<n ; ++i){
        cin >> ctemp;
        d += ctemp;
        if(d <= x){
            ++cnt;
        }
        else{
            break;
        }
    }
    cout<< cnt;
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

const ll MOD_CONST = 1000000007;
//const ll MOD_CONST = 998244353;


const int INF = 1000000000;
//const ll INF = 1000000000000000000;



int main() {
	int n;
	cin >> n;
	vector<int> c(n + 1);

	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}



	vector<int> dp(n + 1);
	map<int, ll> s;
	dp[0] = 1;
	s[c[1]] = 1;
	for (int i = 1; i <= n; i++) {
		/*for (int j = 0; j <= i; j++) {
			if(c[j] != c[i] && c[j + 1] == c[i])
			dp[i] += dp[j];
		}
		*/
		dp[i] = s[c[i]];

		if (i < n && c[i] != c[i + 1]) {
			s[c[i + 1]] += dp[i];
			s[c[i + 1]] %= MOD_CONST;
		}

	}

	cout << dp[n] << endl;

}



Measured memory_bytes: 14336
//Littleboy123 Template 1.6
#include <bits/stdc++.h>
using namespace std;

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(n) printf("%d\n", (n))
#define COUTLL(n) printf("%lld\n", (n))
#define CIN(n) scanf("%d", &(n))
#define CINLL(n) scanf("%lld", &(n))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

void infile(){
	freopen("input.in", "r", stdin);
}

void outfile(){
	freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll tmp = modex(a, b/2, mod);
	tmp = (tmp * tmp) % mod;
	if(b & 1)
		tmp = (tmp * a) % mod;
	return tmp;
}

//End of template

const ll mod = 1e9 + 7;

int n;
vi awal[100005];
vi adjlist[100005];
int visited[100005];
ll memo[100005][2];

ll dp(int pos, int col){
	int sz = adjlist[pos].size();
	if(sz == 0){
		return 1;
	}
	if(memo[pos][col] != -1)
		return memo[pos][col];
	ll ans = 1;
	if(col == 0){
		FOR(i, 0, sz){
			ans = (ans*(dp(adjlist[pos][i], 0) + dp(adjlist[pos][i], 1))) % mod;
		}
	}
	else{
		FOR(i, 0, sz){
			ans = (ans*dp(adjlist[pos][i], 0))%mod;
		}
	}
	return memo[pos][col] = ans%mod;
}

void dfs(int front){
	int sz = awal[front].size();
	visited[front] = 1;
	FOR(i, 0, sz){
		if(visited[awal[front][i]] == 0){
			adjlist[front].pb(awal[front][i]);
			dfs(awal[front][i]);
		}
	}
}

int main(){
	init();

	cin >> n;
	int u, v;
	FOR(i, 1, n){
		cin >> u >> v;
		awal[u].pb(v);
		awal[v].pb(u);
	}
	MEM(visited, 0);
	dfs(1);
	MEM(memo,-1);
	ll ans = (dp(1, 1) + dp(1, 0))%mod;
	cout << ans << nl;
	return 0;	
}

Measured memory_bytes: 20096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b, c;
  scanf("%d/%d/%d", &a, &b, &c);
  if(2019 <= a && 5 <= b) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();

        long n_div_max = n/b;

        long base = 1;
        long res = 0;
        while(base<=2){
            long x = b*base - 1;
            if(x>n)x=n;
            long floor_xB = base-1;
            long floor_AxB = (a*x)/b;
            res = Math.max(res, floor_AxB-a*floor_xB);
            base++;
        }

        System.out.println(res);

    }
}


Measured memory_bytes: 27080
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;



signed main(){

    char alpha[60];
    int id = 0;
    map<char, int> to_id;
    for(char c = 'a'; c <= 'z'; c++){
        alpha[id] = c;
        to_id[c] = id;
        id++;

    }

    for(char c = 'A'; c <= 'Z'; c++){
        alpha[id] = c;
        to_id[c] = id;
        id++;
    }

    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<int> k(n);
        for(int i = 0; i < n; i++) cin >> k[i];
        string s; cin >> s;

        for(int i = 0; i < (int)s.size(); i++){
            int id = i % n;
            int id2 = to_id[s[i]];
            id2 -= k[id];
            id2 = (id2 + 52) % 52;
            s[i] = alpha[id2];
        }

        cout << s << endl;
    }
    return 0;
}




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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,x,y;
	cin>>n>>x>>y;
	vector<int>ans(n,0);
	queue<pair<int,int>>q;
	for(int i=0;i<n;++i){
		q.push(make_pair(i,0));
		vector<int>tmp(n,0x7FFFFFFF);
		tmp.at(i)=0;
		pair<int,int>p;
		while(q.size()){
			p=q.front();
			q.pop();
			if(p.first+1<n&&p.second+1<tmp.at(p.first+1)){
				tmp.at(p.first+1)=p.second+1;
				q.push(make_pair(p.first+1,tmp.at(p.first+1)));
			}
			if(p.first-1>=0&&p.second+1<tmp.at(p.first-1)){
				tmp.at(p.first-1)=tmp.at(p.first)+1;
				q.push(make_pair(p.first-1,tmp.at(p.first-1)));
			}
			if(p.first==x-1){
				tmp.at(y-1)=min(tmp.at(y-1),p.second+1);
				q.push(make_pair(y-1,tmp.at(y-1)));
			}
		}
		for(int j=i+1;j<n;++j)++ans.at(tmp.at(j));
	}
	for(int i=1;i<n;++i)cout<<ans.at(i)<<"\n"s;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] d = new long[n + 1];
        for (int i = 1; i / 2 <= n; i++) {
            for (int j = 1; i * j <= n; j++) {
                d[i * j]++;
            }
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += i * d[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 116060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a<=b){
        cout << a << endl;
    }
    else cout << a-1 << endl;

    return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N, M);
  vector< int > A(N);
  vector< int > sm(N + 1, 0);
  REP(i, N) {
    cin >> A[i];
    sm[i + 1] = (sm[i] + A[i]) % M;
  }
  
  map< int, int > mp;
  ll ans = 0ll;
  
  REP(i, N + 1) {
    ans += mp[sm[i]];
    mp[sm[i]]++;
  }
  cout << ans << endl;

  /*
  EACH(mi, mp) {
    cout << mi.second << endl;
  }
  */
  
  return 0;
}



Measured memory_bytes: 3968