akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int N;
    ll ans=0;
    string S;

    cin>>N>>S;

    int r=0,g=0,b=0,R[4010]={},G[4010]={},B[4010]={};

    for(int i=0;i<S.length();i++){
        if(S[i]=='R'){
            r++;
        }else if(S[i]=='G'){
            g++;
        }else{
            b++;
        }
        R[i]=r;
        G[i]=g;
        B[i]=b;
    }


    for(int i=0;i<S.length();i++){
        if(S[i]=='R'){
            ans+=G[i]*(b-B[i]);
            ans+=B[i]*(g-G[i]);
        }else if(S[i]=='G'){
            
            ans+=R[i]*(b-B[i]);
            ans+=B[i]*(r-R[i]);
        }else{
            ans+=G[i]*(r-R[i]);
            ans+=R[i]*(g-G[i]);
        }
    }

    int d=1;

    while(1+2*d<=N){
        for(int i=0;i<(N-2*d);i++){
            if(S[i]!=S[i+d]
            &&S[i]!=S[i+2*d]
            &&S[i+d]!=S[i+2*d])ans--;
        }
        d++;
    }


    cout<<ans<<endl;



    return 0;
}

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

int main() {
    ll a, b, x, ans = 1;
    cin >> a >> b >> x;
    for (int i = 0; x*i <= b; i++)
    {
        if (a <= x * i)
        {
            cout << ((b - x * i) / x) + 1 << endl;
            return 0;
        }
    }
    
    cout << 0 << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> id(N+1, vector<int>(N+1, 0));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            id[i][j] = min(i, j) * N + max(i, j);
        }
    }
    
    vector<int> in((N+1)*(N+1), 0);
    vector<vector<int>> edge((N+1)*(N+1));
    for (int i = 1; i <= N; i++) {
        vector<int> game(N-1);
        for (int j = 0; j < N-1; j++) {
            cin >> game[j];
            if (j >= 1) {
                edge[id[i][game[j-1]]].push_back(id[i][game[j]]);
                in[id[i][game[j]]]++;
            }
        }
    }
    int cnt = 0;
    
    queue<int> q;
    vector<int> day((N+1)*(N+1), 0);
    for (int i = 1; i <= N-1; i++) {
        for (int j = i+1; j <= N; j++) {
            if (in[id[i][j]] == 0) {
                q.push(id[i][j]);
                day[id[i][j]] = 1;
                cnt++;
            }
        }
    }
    
    int ans = 1;
    
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int g : edge[now]) {
            in[g]--;
            if (in[g] == 0) {
                day[g] = day[now]+1;
                if (day[g] > ans) ans = day[g];
                q.push(g);
                cnt++;
            }
        }
    }
    
    if (cnt < N*(N-1)/2) cout << "-1\n";
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51072
#!/usr/bin python3
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
mn = 1000
for i in range(N-1):
    if A[i+1]>A[i]:
        buy = mn//A[i]
        mn += buy*(A[i+1]-A[i])
print(mn)


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {

    ll n, h;
    cin >> n >> h;

    vector<ll> sword_slices(n);
    vector<ll> sword_throws(n);
    rep(i, n) {
        cin >> sword_slices[i];
        cin >> sword_throws[i];
    }

    ll slice_max = *max_element(sword_slices.begin(), sword_slices.end());

    sort(sword_throws.rbegin(), sword_throws.rend());

    ll throw_count = 0;

    for (ll i = 0; i < n; i++) {
        if (sword_throws[i] < slice_max) break;
        ll t = sword_throws[i];
        h -= t;
        throw_count++;
        if (h <= 0) {
            cout << throw_count << endl;
            return 0;
        }
    }

    ll slice_count = (h + slice_max - 1) / slice_max;

    cout << throw_count + slice_count << endl;

}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

int i,j,k,n,t,a,b;

int main(){
	scanf("%d %d %d", &n,&a, &b);
	if((b-a)%2==0){
		puts("Alice");
	}
	else{
		puts("Borys");
	}
	return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (b-a >= 2*k) {
    for (int i=a; i<a+k; i++) {
        cout << i << "\n";
    }
    for (int i=b-k+1; i<b+1; i++) {
        cout << i << "\n";
    }
  }
  else {
    for (int i=a; i<b+1; i++)
      cout << i << "\n";
  }
  return 0;
}

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

typedef struct node* link;

struct node {
	link p, n;
	int item;
};

typedef struct {
	link h, t;
	int head;
}List;

void insert(List *list, int item) {
	list->head = (list->head == 0) ? 1 : 0;
	link l;
	l = malloc(sizeof *l);
	l->item = item;
	l->p = l->n = NULL;
	if (list->h == NULL) {
		list->h = l;
		list->t = list->h;
	}
	else {
		if (list->head == 0) {
			list->h->p = l;
			l->n = list->h;
			list->h = l;
		}
		else {
			list->t->n = l;
			l->p = list->t;
			list->t = l;
		}
	}
}

int main(void) {
	List list;
	list.h = list.t = NULL;
	list.head = 1;
	int i, n, a;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		insert(&list, a);
	}
	link l;
	if (list.head == 0) {
		l = list.h;
		for (i = 0; i < n; i++) {
			printf("%d", l->item);
			if (i < n - 1) {
				printf(" ");
				l = l->n;
			}
		}
	}
	else {
		l = list.t;
		for (i = 0; i < n; i++) {
			printf("%d", l->item);
			if (i < n - 1) {
				printf(" ");
				l = l->p;
			}
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <unordered_map>
#include <exception>

typedef long long ll;
using namespace std;

int main(){
  ll n, m;
  std::cin >> n >> m;

  vector<ll> p(m);
  vector<string> s(m);
  for(ll i=0; i<m; i++){
    std::cin >> p[i];
    std::cin >> s[i];
  }

  unordered_map<ll, pair<ll,ll> > counter;
  for(ll i=0; i<m; i++){
    try{
      if( 0 == counter.at(p[i]).first ){
        if( s[i] == "WA" ) counter.at(p[i]).second += 1;
        else counter.at(p[i]).first += 1;
      }
    }catch(exception e){
      counter[p[i]] = make_pair(0,0);
      if( s[i] == "AC" ) counter[p[i]].first += 1;
      else counter[p[i]].second += 1;
    }
  }
  long long ansAC = 0, ansWA = 0;
  unordered_map<ll, pair<ll,ll> >::iterator iter = counter.begin();
  for(; iter != counter.end(); iter++){
    if(iter->second.first){
      ansAC += iter->second.first;
      ansWA += iter->second.second;
    }
  }
  std::cout << ansAC << ' ' << ansWA << '\n';
  return 0;
}


Measured memory_bytes: 8864
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int b = 0;
	int cnt = 0;
	for (int r = 0; r <= 3000; r++) {
		for (int g = 0; g <= 3000; g++) {
			if ((N - r * R - g * G) % B == 0) {
				b = (N - r * R - g * G) / B;
				if (0 <= b && b <= 3000) {
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d", $num);
$cal=($num-($num%500))/500*1000;
$m = 2;  //->下位から数えて`$m`桁目から
preg_match_all("/(?=(.{3}))/", "$num", $m);
$array=array_map(function($num){return (int)$num;}, $m[1]);

$i= count($array);
if($array[$i-1] >= 500){
  $num2 =$array[$i-1]-500;
  $cal2=($num2-($num2%5))/5*5;
}else{
    $cal2=($array[$i-1]-($array[$i-1]%5))/5*5;
}
echo $cal+$cal2
?>

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;

ll n,k;
vl v;

void input(void){
   cin>>n>>k;
   inputv(v,n);
}

void solve(void){
    ll ans=0,a;
    rep(i,n){
        rep(j,i){
            if(v[i]<v[j]){
                a=((k*(k+1))%MOD*500000004)%MOD;
                ans=(ans+a)%MOD;
            }
            else if(v[i]>v[j]){
            	a=((k*(k-1))%MOD*500000004)%MOD;
                ans=(ans+a)%MOD;
            }
        }
    }
    cout<<ans<<endl;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}

Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Array(readLine()!)
    let t = Array(readLine()!)
    
    var ans = 0
    for i in 0..<s.count {
        if s[i] != t[i] {
            ans += 1
        }
    }
    
    print(ans)
}

main()


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

int main()
{
	int a,b,c;
	while(cin >> a >> b >> c)
	{
		int n = a * 10000 + b * 100 + c;
		if(n < 18680908)
		{
			cout << "pre-meiji" << endl;
		}
		else if(18680908 <= n && n < 19120730)
		{
			cout << "meiji " << a - 1867 << " " << b << " " << c << endl;
		}
		else if(19120730 <= n && n < 19261225)
		{
			cout << "taisho " << a - 1911 << " " << b << " " << c << endl;
		}
		else if(19261225 <= n && n < 19890108)
		{
			cout << "showa " << a - 1925 << " " << b << " " << c << endl;
		}
		else if(19890108 <= n)
		{
			cout << "heisei " << a - 1988 << " " << b << " " << c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
def longest_common_subseq(S, T):
    if not S and not T: return 0
    len_S, len_T = len(S), len(T)
    dp = [0] * (len_T + 1)
    prev = [0] * (len_T + 1)
    for s in S:
        for j in range(len_T):
            if s == T[j]: dp[j+1] = prev[j] + 1
            elif dp[j] > dp[j+1]: dp[j+1] = dp[j]
        prev = dp[:]
    return dp[len_T]

Q = int(input())
ans = []
for _ in range(Q):
    X = input()
    Y = input()
    ans.append(longest_common_subseq(X, Y))
print(*ans, sep='\n')


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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto & a : A) cin >> a;

    ll res = 0;

    for (auto a : A) {
        while ((a % 2) == 0) {
            a /= 2;
            ++res;
        }
    }

    cout << res << endl;

}


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

using namespace std;

int main()
{
   string S;
   cin>>S;
   if(S.length()==6){
       if(S[2]==S[3]&&S[4]==S[5]){
           cout<<"Yes";
       }
       else{
           cout<<"No";
       }
   }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    double h,n;
    cin >> h >> n;
    vector <int> a(n);
    int sum= 0;
    REP (i,n) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum>=h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 225;

int n, m;
char s[N][N];
int f[N][N][N], g[N][N][N];

int main() {
	scanf("%d %d", &n, &m);
	fo(i, 1, n) scanf("%s", s[i] + 1);
	fd(k, m, 1) {
		fo(i, 1, n) {
			int ky = 1;
			fo(j, i, n) {
				if(j > i && s[j][k] != s[j - 1][k]) ky = 0;
				if(!ky) f[k][i][j] = 0; else {
					f[k][i][j] = k;
					if(k < m && s[i][k] == s[i][k + 1]) {
						f[k][i][j] = max(f[k][i][j], f[k + 1][i][j]);
					}
				}
			}
		}
	}
	fo(ans, 0, 16) {
		if(f[1][1][n] == m) {
			pp("%d\n", ans);
			return 0;
		}
		fo(k, 1, m) fo(i, 1, n) fo(j, i, n)
			g[k][i][j] = f[k][i][j];
		fo(k, 1, m) fo(i, 1, n) fo(j, i, n) {
			if(g[k][i][j]) f[k][i][j] = max(f[k][i][j], g[g[k][i][j] + 1][i][j]);
			int as = i - 1;
			for(int l = i, r = j - 1; l <= r; ) {
				int m = l + r >> 1;
				if(g[k][i][m]>= g[k][m + 1][j])
					as = m, l = m + 1; else r = m - 1;
			}
			f[k][i][j] = max(f[k][i][j], min(g[k][i][as], g[k][as + 1][j])),
			f[k][i][j] = max(f[k][i][j], min(g[k][i][as + 1], g[k][as + 2][j]));
		}
	}
}

Measured memory_bytes: 75520
#include <stdio.h>
#define limit 100000

int par[limit];
int rank[limit];

void init(int N){
  for(int i = 0;i < N;i++){
    par[i] = i;
    rank[i] = 0;
  }
}

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

int same(int x,int y){
  if(root(x) == root(y))
    return 1;
  return 0;
}

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

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

int main(void){
  int N, M;
  scanf("%d%d", &N, &M);

  init(N);

  int x, y, z;
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &x, &y, &z);
    unite(x-1, y-1);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if(i == par[i]) ans++;
  }

  printf("%d\n", ans);
   

  return 0;
}

Measured memory_bytes: 896
package main
import(
    "fmt"
    "sort"
)

func main(){
    var n int
    fmt.Scan(&n)
    arr := make([]int, n)
    for i, _ := range arr {
        fmt.Scan(&arr[i])
    }
    sort.Slice(arr, func(i, j int) bool {
        if arr[i] > arr[j] {
            return true
        }
        return false
    })
    alice, bob := 0, 0
    for i, v := range arr {
        if i % 2 == 0 {
            alice += v
        } else {
            bob += v
        }
    }
    fmt.Println(alice - bob)
}

Measured memory_bytes: 1844
#include <stdio.h>
#include <string.h>
int main(void)
{
int n;
int m;
char s[101][101];
char t[101][101];
int i,j,k;
int a=0;
int x=0,y=0;
int q=0;

scanf("%d",&n);
for(i=0;i<n;i++){

scanf("%s%*c",s[i]);

}
scanf("%d",&m);
for(i=0;i<m;i++){

scanf("%s%*c",t[i]);

}
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		if(strcmp(s[i],s[j])==0){
			
			x++;
			
			
			
		}
		
		
		
		
	}
	for(k=0;k<m;k++){
		if(strcmp(s[i],t[k])==0){
			
			x--;
			
			
			
		}
		
		
		
		
		
	}
	if(a<x){
		//printf("%d",x);
		a=x;
		//printf("!\n");
	}
	x=0;
}
printf("%d\n",a);
return 0;
}


Measured memory_bytes: 128
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_SIZE_MAX		405										// 最大サイズ
#define D_MASS_BLACK	'#'										// マス - 黒
#define D_MASS_WHITE	'.'										// マス - 白

// 内部変数
static FILE *szpFpI;											// 入力
static char sc2Mass[D_SIZE_MAX][D_SIZE_MAX];					// マス
static int siW, siH;											// 幅・高さ

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// マス数 - 取得
int
fGetMCnt(
	int piX						// <I> 位置X
	, int piY					// <I> 位置Y
	, char pcMass				// <I> 対象マスの色
	, int *pipBCnt				// <O> 黒数
	, int *pipWCnt				// <O> 白数
)
{
	// 対象マスの色 - チェック
	if (sc2Mass[piY][piX] != pcMass) {
		return 0;
	}

	// 処理済
	sc2Mass[piY][piX] = 0;

	// 色数・次の色
	if (pcMass == D_MASS_BLACK) {		// 黒
		(*pipBCnt)++;
		pcMass = D_MASS_WHITE;
	}
	else {								// 白
		(*pipWCnt)++;
		pcMass = D_MASS_BLACK;
	}

	// 上下左右へ
	fGetMCnt(piX + 1, piY, pcMass, pipBCnt, pipWCnt);
	fGetMCnt(piX - 1, piY, pcMass, pipBCnt, pipWCnt);
	fGetMCnt(piX, piY + 1, pcMass, pipBCnt, pipWCnt);
	fGetMCnt(piX, piY - 1, pcMass, pipBCnt, pipWCnt);

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	memset(sc2Mass, 0, sizeof(sc2Mass));						// マス

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 幅・高さ - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siH, &siW);

	// マス - 取得
	for (i = 1; i <= siH; i++) {
		fgets(&sc2Mass[i][1], sizeof(sc2Mass[0]) - 1, szpFpI);
	}

	// パターン数 - 取得
	long long llPCnt = 0;
	for (i = 1; i <= siH; i++) {
		for (j = 1; j <= siW; j++) {

			// マス数 - 取得
			int liBCnt = 0;
			int liWCnt = 0;
			fGetMCnt(j, i, D_MASS_BLACK, &liBCnt, &liWCnt);

			// パターン数 - 加算
			llPCnt += (long long)liBCnt * (long long)liWCnt;
		}
	}

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", llPCnt);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 10368
#include <iostream>
using namespace std;
 
#define ll long long
 
int main(){
	int n,x,y;
	cin>>n;
	ll s=0;
	int a[n+1];
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>x;
		y=min(x,a[i]);
		s+=y;
		x-=y;
		y=min(x,a[i+1]);
		s+=y;
		a[i+1]-=y;
	}
	cout<<s<<"\n";
}

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

using namespace std;


int main()
{
    while (true) {
        int m, nmin, nmax;
        cin >> m >> nmin >> nmax;
        if (m == 0 and nmin == 0 and nmax == 0) {
            break;
        }
        vector<int> score(m);
        for (int i = 0; i < m; i++) {
            cin >> score[i];
        }
        int maxi = nmin - 1;
        int gap = numeric_limits<int>::min();
        for (int i = nmin - 1; i < nmax; i++) {
            if (gap <= score[i] - score[i + 1]) {
                gap = score[i] - score[i + 1];
                maxi = i;
            }
        }
        cout << maxi + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a;
    vector<int> v;
    
    for(int i = 0;i < 10;i++){
        cin >> a;
        v.push_back(a);
    }
    
    sort(v.begin(), v.end(), greater<int>());
    
    for(int i = 0;i < 3;i++){
        cout << v.at(i) << endl;
    }
    
    
    return 0;
}

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

using namespace std;

const int N = 1e7 + 1000;
long long int a[N], b[N] , c[N] , ansa , ans;
pair <long long int , long long int> p[N];

int main () {
    long long int n , a , b;
    cin >> n >> a >> b;
    cout << min(min(a , b) , n) << ' ';
    if(n - a - b < 0) {
        cout << a + b - n;
    }
    else {
        cout << 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[200005]; 
int main() {
	scanf ("%d", &n); 
	for (int i = 0; i < n; i ++) {
		cin >> a[i]; 
		a[i] -= i + 1; 
	}
	sort (a, a + n); 
	long long ans = 0;
	for (int i = 0; i < n; i ++)
		ans += abs(a[i] - a[n >> 1]); 
	printf ("%lld\n", ans);
	return 0; 
}

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

int main(void){
  
    int N,maxv;
    cin >> N;
    string s;
    map<string,int> mp{};
    for(int i=0;i<N;i++){
        cin >> s;
        if(mp.count(s) == 0) mp[s] = 1;
        else mp[s]++;
        
        if(i == 0){
            maxv = mp[s];
        }
        else{
            if(maxv < mp[s]) maxv = mp[s];
        }
    }
    
     for (const auto& [key, value] : mp){
         if(value == maxv) cout << key <<endl;
    }
    
}

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

int main(){
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 0; i < 100000; i++){
		if(i * 108 / 100 - i == A && i * 110 / 100 - i == B){
			printf("%d\n", i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

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

map<int, int> Dic(const vector<int>& v, vector<int>& sorted) {
	sorted = v;
	sort(sorted.begin(), sorted.end());
	sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
	map<int, int> res;
	for (int i = 1; i <= sorted.size(); i++) {
		res[sorted[i - 1]] = i;
	}
	return res;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> x(n), sx, y(n), sy;
	x.push_back(-INF); y.push_back(-INF);
	for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	x.push_back(INF); y.push_back(INF);

	map<int, int> xdic = Dic(x, sx), ydic = Dic(y, sy);
	vector<vector<int>> sum(sx.size() + 1, vector<int>(sy.size() + 1, 0));
	for (int i = 1; i <= n; i++) {
		sum[xdic[x[i]]][ydic[y[i]]]++;
	}
	for (int i = 1; i <= sx.size(); i++) {
		for (int j = 1; j <= sy.size(); j++) {
			sum[i][j] += sum[i - 1][j];
		}
	}
	for (int i = 1; i <= sx.size(); i++) {
		for (int j = 1; j <= sy.size(); j++) {
			sum[i][j] += sum[i][j - 1];
		}
	}


	for (int i = 0, x1, y1, x2, y2; i < m; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		x1 = xdic[*lower_bound(sx.begin(), sx.end(), x1)];
		x2 = xdic[*(upper_bound(sx.begin(), sx.end(), x2) == sx.begin() ? sx.begin() : upper_bound(sx.begin(), sx.end(), x2) - 1)];
		y1 = ydic[*lower_bound(sy.begin(), sy.end(), y1)];
		y2 = ydic[*(upper_bound(sy.begin(), sy.end(), y2) == sy.begin() ? sy.begin() : upper_bound(sy.begin(), sy.end(), y2) - 1)];
		cout << sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 101352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      if(map.containsKey(a)) {
        map.put(a, map.get(a) + 1);
      } else {
        map.put(a, 1);
      }
    }
    int ans = 0;
    for(int key : map.keySet()) {
      if(map.get(key) % 2 == 1) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 61140
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

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

			int N = sc.nextInt();
			int K = sc.nextInt();

			int ans = 1;
		    for(int i = 0; i < N; i += 1){
		        if(ans < K){
		        	ans = ans * 2;
		        }else{
		        	ans = ans + K ;
		        }
		    }
		    System.out.println(ans);

		}
}


Measured memory_bytes: 22484
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &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<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N; R(N);
    map<string,int>AA;
    LL an=0;
    REP(i,N){
        string s;
        R(s);
        sort(ALL(s));
        an+=AA[s];
        AA[s]++;
    }
    W(an);
    return 0;
}


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

using namespace std;

int S, n0, s1, mod, ans, N, Q, ap[500009], P[500009], aib[500009], fac[500009];

int mul (int x, int y) {return 1LL * x * y % mod;}
void U (int pos) {while (pos <= N) aib[pos] ++, pos += pos - (pos & (pos - 1));}
int Qry (int pos) {int sum = 0; while (pos) sum += aib[pos], pos &= pos - 1; return sum;}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), mod = 1e9 + 7, fac[0] = 1;
for (int i=1; i<=N; i++)
    fac[i] = mul (fac[i - 1], i);
long long S2 = 0;
for (int i=1; i<=N; i++)
    scanf ("%d", &P[i]), Q += (P[i] == 0), S2 += P[i], ap[P[i]] ++;
ans = fac[Q], ap[0] = 0, S = (1LL * N * (N + 1) / 2 - S2 - Q) % mod;
for (int i=1; i<=N; i++)
    ap[i] += ap[i - 1];
for (int i=1; i<=N; i++)
{
    if (P[i]) ans += mul (fac[N - i], mul (fac[Q], P[i] - 1));
    else ans += mul (fac[N - i], mul (fac[Q - 1], S));
    if (ans >= mod) ans -= mod;
}
int coef00 = 0;
if (Q >= 2) coef00 = mul ((1LL * Q * (Q - 1) / 2) % mod, fac[Q - 2]);
for (int i=1; i<=N; i++)
{
    int ways = 0;
    if (P[i] != 0)
        ways = mul (Qry (P[i]), fac[Q]) + mul (n0, mul (P[i] - ap[P[i]], fac[Q - 1]));
    else
        ways = s1 + mul (n0, coef00);
    if (ways >= mod) ways -= mod;
    ans -= mul (ways, fac[N - i]);
    if (ans < 0) ans += mod;
    if (P[i] != 0)
    {
        U (P[i]), s1 += mul (Q - (P[i] - ap[P[i]]), fac[Q - 1]);
        if (s1 >= mod) s1 -= mod;
    }
    else n0 ++;
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 8064
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(ulong.Parse).ToArray();
        var h = vars[0];
        var w = vars[1];

        if(h == 1 || w == 1)
        {
            System.Console.WriteLine(1);
            return;
        }

        if(w % 2 == 0)
        {
            System.Console.WriteLine((w/2) * h);
            return;
        }

        else
        {
            var ans = ((w / 2) + 1) * (h / 2);
            ans += ((w / 2)) * (h / 2);
            if(h % 2 == 1)
            {
                ans += (w / 2) + 1;
            }
            System.Console.WriteLine(ans);
            return;
        }

        

    }
}



Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <deque>
#include <utility>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    bool direct{true};
    uint n;
    deque<uint> d{};
    cin >> n;
    for (auto &&i: irange(0U, n)){
        uint a;
        cin >> a;
        if (direct)d.emplace_back(a); else d.emplace_front(a);
        direct=!direct;
    }
    if (direct){
        for (auto &&i: irange(0U, (uint)d.size())){
            cout << d.at(i);
            if (i != (uint)d.size()-1){
                cout << " ";
            }
        }
    } else {
        for (auto &&i: irange(0U, (uint)d.size()) | adaptors::reversed) {
            cout << d.at(i);
            if (i != 0){
                cout << " ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>

int main()
{
  std::string S="";
  std::cin>>S;
  
  if(S=="Sunny")
  {
    std::cout<<"Cloudy"<<std::endl;
    return 0;
  }
  else if(S=="Cloudy")
  {
    std::cout<<"Rainy"<<std::endl;
    return 0;
  }
  else if(S=="Rainy")
  {
    std::cout<<"Sunny"<<std::endl;
    return 0;
  }
  
  return -1;
}

Measured memory_bytes: 256
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,0,n-1) cin>>v[i];
    vi full(n,0),curr(n,0);
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            if(v[i]>v[j]) curr[i]++;
        }
    }
    rep(i,0,n-1){
        rep(j,0,n-1){
            if(v[i]>v[j]) full[i]++;
        }
    }
    ll ans=0;
    rep(i,0,n-1){
        ans=(ans+k*curr[i])%hell;
    }
    rep(i,0,n-1){
        ans=(ans+(((k*(k-1))/2)%hell)*full[i])%hell;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;

	deque<char> de;
    for(auto x:s)
      de.push_back(x);

	int q,t,f;
	char c;

	cin >> q;

	bool flag(false);

	for(int i=0;i<q;i++)
	{
        cin >> t;

        if(t==1) flag = !flag;
        else
        {
        	cin >> f >> c;
        	if(f==1)
        	{
        		if(flag)
        			de.emplace_back(c);
        		else
        			de.emplace_front(c);
        	}
        	else
        	{
        		if(flag)
        			de.emplace_front(c);
        		else
        			de.emplace_back(c);
        	}

        }


	}


	if(flag)
		reverse(de.begin(),de.end());
   
     for(auto j:de)
       cout<<j;
    return 0;
}


Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main() {
    vector<int> ans(10001);
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int res = x * x + y * y + z * z + x * y + y * z + z * x;
                if (res <= 10000) {
                    ans[res] += 1;
                }
            }
        }
    }
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << "\n";
    }
    cout << flush;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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

    string s;
    cin >> s;

    int zero_start_num = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (i % 2 == 0) {
            if (s[i] != '0') zero_start_num++;
        } else {
            if (s[i] != '1') zero_start_num++;
        }
    }

    int oen_start_num = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (i % 2 == 0) {
            if (s[i] != '1') oen_start_num++;
        } else {
            if (s[i] != '0') oen_start_num++;
        }
    }

    int ans = min(zero_start_num, oen_start_num);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, k = map(int, input().strip().split())
  s = input().strip()
  score = 0
  for i in range(n-1):
    if s[i:i+2] in ['LL', 'RR']:
      score += 1
  print(min(score + 2*k, n-1))

if __name__=='__main__':
  main()



Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

static const double PI = 3.1415926536;

class Vector2{
public:
	Vector2() : x( 0.0 ), y( 0.0 ), rad( 0.0 ) {}
	Vector2( double aX, double aY ) : x( aX ), y( aY ), rad( 0.0 ){
		rad = atan2( y, x );
	}
	void rotate( double r ){
		double c = cos( r );
		double s = sin( r );
		double xx = x * cos( r ) - y * sin( r );
		double yy = x * sin( r ) + y * cos( r );
		x = xx;
		y = yy;
	}

	double x, y, rad;
};

int main(){
	Vector2 p1, p2, q;
	char c;

	while ( cin >> p1.x >> c >> p1.y >> c >> p2.x >> c >> p2.y >> c >> q.x >> c >> q.y ){
		Vector2 axis( p2.x - p1.x, p2.y - p1.y );
		Vector2 pq( q.x - p1.x, q.y - p1.y );
		pq.rotate( -axis.rad );
		pq.y = -pq.y;
		pq.rotate( axis.rad );

		cout << setprecision( 6 ) << setiosflags( ios::fixed );
		cout << pq.x + p1.x << " " << pq.y + p1.y << endl;
	}
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 3e5;

void solve() {
  string s; cin >> s;
  int ans = 0;
  int n = s.size();
  for (int i = 0; i <= (n - 1) / 2; i++) {
    ans -= (s[i] == 'p');
  }
  for (int i = (n + 1) / 2; i < n; i++) {
    ans += (s[i] == 'g');
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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

int main() {
	int N;
	cin >> N;
	map<string,int> m;
	m["AC"]=0, m["WA"]=0, m["TLE"]=0, m["RE"]=0;

	rep(i,N) {
		string s;
		cin >> s;
		++m.at(s);
	}

	cout << "AC x " << m.at("AC") << endl;
	cout << "WA x " << m.at("WA") << endl;
	cout << "TLE x " << m.at("TLE") << endl;
	cout << "RE x " << m.at("RE") << endl;
}

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

namespace IO
{
	const int S=(1<<20)+5;
	char buf[S],*H,*T;
	inline char Get()
	{
		if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
		if(H==T) return -1;return *H++;
	}
	inline int read()
	{
		int x=0,fg=1;char c=Get();
		while(!isdigit(c)&&c!='-') c=Get();
		if(c=='-') fg=-1,c=Get();
		while(isdigit(c)) x=x*10+c-'0',c=Get();
		return x*fg;
	}
	inline void reads(char *s)
	{
		char c=Get();int tot=0;
		while(c<'0'||c>'1') c=Get();
		while(c>='0'&&c<='1') s[++tot]=c,c=Get();
		s[++tot]='\0';
	}
	char obuf[S],*oS=obuf,*oT=oS+S-1,c,qu[55];int qr;
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	inline void putc(char x){*oS++ =x;if(oS==oT) flush();}
	template <class I>inline void print(I x)
	{
		if(!x) putc('0');
		if(x<0) putc('-'),x=-x;
		while(x) qu[++qr]=x%10+'0',x/=10;
		while(qr) putc(qu[qr--]);
	}
}

using namespace IO;
const int N=2010;
int sump[N][N],sume1[N][N],sume2[N][N];
bool mp[N][N];

int main()
{
    static char s[N];
    int n=read(),m=read(),q=read();
    for(int i=1;i<=n;i++)
    {
        reads(s);
        for(int j=1;j<=m;j++)
            mp[i][j]=(s[j]=='1');
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            sump[i][j]=sump[i-1][j]+sump[i][j-1]-sump[i-1][j-1]+mp[i][j];
            sume1[i][j]=sume1[i-1][j]+sume1[i][j-1]-sume1[i-1][j-1]+(mp[i][j]&&mp[i][j+1]);
            sume2[i][j]=sume2[i-1][j]+sume2[i][j-1]-sume2[i-1][j-1]+(mp[i][j]&&mp[i+1][j]);
        }
    while(q--)
    {
        int x1=read(),y1=read(),x2=read(),y2=read();
        int n=sump[x2][y2]-sump[x1-1][y2]-sump[x2][y1-1]+sump[x1-1][y1-1];
        int m=sume1[x2][y2-1]-sume1[x2][y1-1]-sume1[x1-1][y2-1]+sume1[x1-1][y1-1];
        m+=sume2[x2-1][y2]-sume2[x2-1][y1-1]-sume2[x1-1][y2]+sume2[x1-1][y1-1];
        print(n-m);putc('\n');
    }
    flush();
    return 0;
}

Measured memory_bytes: 55168
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
dc={}
g,c=GI(n,n-1)
for a,b in c:
    dc[(a,b)]=0

mxd=0
mxi=0
for i in range(n):
    m=len(g[i])
    if m==1:
        mxd=m
        mxi=i
        
#vには最短距離をセット & -1 で未訪問フラグ

v=[-1]*(n)

def bfs(x):
    p=deque()
    p.append(x)
    v[x]=0
    while p:
        c=p.popleft()
        col=0
        for i in g[c]:
            if v[i]==-1:
                if v[c]==col and c!=x:col+=1
                p.append(i)
                v[i]=col
                dc[(c,i)]=col
                dc[(i,c)]=col
#                show(i,c,col)
                col+=1
    return

bfs(mxi)
print(max(v)+1)
for i,j in c:
    print(dc[(i,j)]+1)
    
#show(v)


Measured memory_bytes: 106392
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

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

  vector<int> x;
  x.emplace_back(a);
  x.emplace_back(b);
  x.emplace_back(c);

  SORT(x);


  int ct=0;
  ct+=x[2]-x[1];
  x[0]+=ct;
  if((x[2]-x[0])%2==0) ct+=(x[2]-x[0])/2;
  else ct+=(x[2]-x[0])/2+2;

  


  cout<< ct <<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

struct Edge{
    int v, cost;
    Edge() = default;
    Edge(int v, int cost) : v(v), cost(cost) {}
};
using Pl = pair<ll, int>;

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

    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s, --t;
    vector<vector<Edge>> graph(n);
    vector<vector<Edge>> rev(n);
    for(int i = 0; i < m; ++i){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        graph[u].emplace_back(v, a);
        graph[v].emplace_back(u, a);
        rev[u].emplace_back(v, b);
        rev[v].emplace_back(u, b);
    }
    
    constexpr ll inf = 1e+17;
    vector<ll> dp(n, inf);
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    dp[s] = 0;
    que.push(Pl(0, s));
    while(!que.empty()){
        Pl p = que.top();
        que.pop();
        ll d = p.first;
        int from = p.second;
        if(d > dp[from])    continue;
        for(auto e : graph[from]){
            int to = e.v, cost = e.cost;
            if(dp[to] > dp[from] + cost){
                dp[to] = dp[from] + cost;
                que.push(Pl(dp[to], to));
            }
        }
    }

    vector<ll> dp2(n, inf);
    dp2[t] = 0;
    que.push(Pl(0, t));
    while(!que.empty()){
        Pl p = que.top();
        que.pop();
        ll d = p.first;
        int from = p.second;
        if(d > dp2[from])   continue;
        for(auto e : rev[from]){
            int to = e.v, cost = e.cost;
            if(dp2[to] > dp2[from] + cost){
                dp2[to] = dp2[from] + cost;
                que.push(Pl(dp2[to], to));
            }
        }
    }

    vector<ll> mindist(n);
    for(int i = 0; i < n; ++i)  mindist[i] = dp[i] + dp2[i];
    for(int i = n - 1; i > 0; --i)  chmin(mindist[i - 1], mindist[i]);
    for(int i = 0; i < n; ++i){
        ll ans = 1e+15;
        ans -= mindist[i];
        cout << ans << '\n';
    }
}

Measured memory_bytes: 16756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.HCPC200420
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] aArray= ReadInts();
            int[] bArray = ReadInts();
            WriteLine(Max(aArray.Sum(), bArray.Sum()));
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

int main() {
    long long n,t;
    cin >> n >> t;
    long long a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    long long ans=0;
    for(int i=2;i<=n;i++){
        if(a[i]-a[i-1]<=t) ans+=a[i]-a[i-1];
        else ans+=t;
    }
    ans+=t;
    cout << ans << endl;
}

Measured memory_bytes: 1792