akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  while(1){
    int H,W;
    cin >> H >> W;
    if(H == 0 && W == 0){
      break;
    }
    for(int i=0; i<H; i++){
      cout << "#";
      for(int j=1; j<W-1; j++){
        if(i == 0 || i==H-1){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << "#";
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3020
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    ll ans = 0;
    if(N < 5 || N%2 == 1){
        cout<<0<<endl;
    }else{
        N /= 2;
        while(N > 0){
            ans += N/5;
            N /= 5;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  lli X,Y,A,B,C;
  cin >> X >>Y>> A>>B>>C;
  vector<lli> red(A);
  vector<lli> blue(B);
  vector<lli> clear(C);
  rep(i, A)
    cin >>red[i];
  rep(i, B)
    cin >>blue[i];
  rep(i, C)
    cin >>clear[i];
  sort(ALL(red));
  sort(ALL(blue));
  sort(ALL(clear));
  reverse(ALL(red));
  reverse(ALL(blue));
  reverse(ALL(clear));
  lli ans=0;
  vector<lli> keep(X+Y+C);
  rep(i, X){
  keep[i]=red[i];
  }
  rep(i, Y){
  keep[i+X]=blue[i];
  }
  rep(i, C){
  keep[i+X+Y]=clear[i];
  }
  sort(ALL(keep));
reverse(ALL(keep));
  rep(i, X+Y){
  ans+=keep[i];
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

	char s[10];
	cin >> s;

	sort(s, s + 4);
	//cout << s;

	if ((s[0] == s[1]) && (s[2] == s[3]) && (s[1] != s[2])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define ios std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long MOD=LLONG_MAX; //1e5+7;
int gcd(int x, int y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}
void solve()
{
	int n,ans=0;
	cin>>n;
	int a[n];
	rep(i,0,n) cin>>a[i];
	sort(a,a+n,greater<int>());
	int t=0;
	rep(i,1,n){
		ans+=a[t];
		if(i%2)t++;
	}
	cout<<ans<<endl;
}

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

Measured memory_bytes: 5212
#include<stdio.h>
#include<math.h>
#include<string.h>

int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    int count=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                    count++;
                }
            }
        }
    }
    printf("%d\n",count);
}

Measured memory_bytes: 128
N = int(input())
A = sorted(list(map(int,input().split())))
P = 10**9+7
if N%2 == 0:
    check = [i if i%2 == 1 else i+1 for i in range(N)]
else:
    check = [i if i%2 == 0 else i+1 for i in range(N)]
if A == check:
    ans = 1
    for i in range(N//2):
        ans *= 2
        ans %= P
else:
    ans = 0
print(ans)


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k; cin >> n >> k;

  //main
  ll ans = 0;
  for(int i=k; i<=n+1; i++){
      ans += i*(n-i+1)+1;
      ans = ans%(MOD);
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
 
 
int main(){
    int64_t n,m;
    cin>>n>>m;
    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
   
 
    
    
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  double v[N];
  double out;
  for(int i=0;i<N;i++){
    cin >> v[i];
  }
  sort(v, v+sizeof(v)/sizeof(v[0]));
  out = v[0];
  for(int i=1;i<N;i++){
    out += v[i];
    out /= 2.0;
  }
  cout << setprecision(10) <<  out << endl;
  return 0;
}

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

#define ll long long

using namespace std;

int main(){


    ll r,d,x;

    cin >> r >> d >> x;

    for(int i = 0; i < 10; i++){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;

}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    K = INT()
    li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(li[K-1])


if __name__ == '__main__':
    main()


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<int(1e9) + 7>;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<num> fact(n+1), ifact(n+1);
	fact[0] = 1;
	for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
	for (int i = 0; i <= n; i++) ifact[i] = inv(fact[i]);
	vector<num> dp(n+1);
	vector<num> ndp(n+1);
	dp[0] = 1;
	for (int i = 0; i < k; i++) {
		int a;
		cin >> a;
		fill(ndp.begin(), ndp.end(), 0);
		for (int s = 0; s <= n; s++) {
			for (int v = 0; v <= a && s+v <= n; v++) {
				ndp[s+v] += dp[s] * fact[n-v] * ifact[n-a] * ifact[a-v] * ifact[v];
			}
		}
		swap(dp, ndp);
	}
	num ans = dp[n] * fact[n];
	cout << ans << '\n';
}


Measured memory_bytes: 256
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}

int32_t main()
{   
     IOS;
     
     ll n,m,i,j,k;
     cin>>n>>m;
     ll a[m];
     ll sum=0;
     for(i=0;i<m;i++) {cin>>a[i];sum+=a[i];}
     	if(sum>n) cout<<-1;
     else cout<<(n-sum)<<endl;
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 3904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

static bool query(ll x){
/*
	static const ll n = 1134;
	const bool a = (x <= n);
	const bool b = (to_string(x) <= to_string(n));
	return a == b;
*/
	cout << "? " << x << endl << flush;
	string s;
	cin >> s;
	return (s == "Y");
}

static int test(int k){
	ll lo = 1, hi = 9;
	for(int i = 1; i < k; ++i){
		lo *= 10;
		hi = (hi * 10 + 9);
	}
	return (query(lo) ? 1 : 0) | (query(hi) ? 2 : 0);
}

static int get_ndigits(){
	vector<int> t(12);
	for(int i = 1; i <= 11; ++i){ t[i] = test(i); }
	for(int i = 10; i >= 1; --i){
		if(t[i] != t.back()){
			if(t.back() == 3){
				return i + 1;
			}else{
				return i;
			}
		}
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false);
	const int m = get_ndigits();
	string answer(m + 1, '0');
	for(int i = 0; i < m; ++i){
		int lo = (i == 0 ? 1 : 0) + (i + 1 == m ? 0 : 1), hi = 10;
		while(lo < hi){
			const int mid = lo + (hi - lo) / 2;
			answer[i] = mid + '0';
			if(query(stoll(answer))){
				hi = mid;
			}else{
				lo = mid + 1;
			}
		}
		answer[i] = (i + 1 == m ? lo : (lo - 1)) + '0';
	}
	cout << "! " << answer.substr(0, m) << endl;
	return 0;
}



Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 233;
pii a[maxn],b[maxn];
string s;
void shit(){
	puts("No");
	exit(0);
}
bool cmp(pii a,pii b){
	return a.fi-a.se>b.fi-b.se;
} 
int main()
{
 	ios::sync_with_stdio(false);
	int n,ca = 0,cb = 0,sum = 0;cin>>n;
	for(int i=1;i<=n;i++){
		a[i].fi = 0;a[i].se = 0;
		int cur = 0,mini = 0;
		cin>>s;
		for(int i=0;i<s.length();i++){
			if(s[i]=='(')cur++;
			else cur--;
			mini=min(mini,cur);
		}
//		cout<<cur<<" "<<mini<<endl;
		if(mini>=0){
			sum += cur;
		}
		else{
			if(cur>=0)a[++ca] = mp(-mini,cur);
			else b[++cb] = mp(cur,mini);
		}
	}
	sort(a+1,a+1+ca);
	for(int i=1;i<=ca;i++){
		if(sum-a[i].fi>=0){
			sum += a[i].se;
		}
		else{
			shit();
		}
	}
	sort(b+1,b+1+cb,cmp);
	for(int i=1;i<=cb;i++){
		if(sum+b[i].se<0){
			shit();
		}
		sum += b[i].fi;
	}
	if(sum==0)puts("Yes");
	else puts("No"); 
}


Measured memory_bytes: 15340
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)



int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,mod=1e9+7;
    cin>>n;
    ll cur=0,ans=0,k;
    for (int i=0;i<n;++i)
    {
        cin>>k;
        ans+=(k*cur);
        cur+=k;
        cur%=mod;
        ans%=mod;
    }
    cout<<ans;
    return 0;
}

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

int N;
int H;
int arr[2000002];
int tmp = 0;

void maxHeapify(int i){
    int l = 2*i;
    int r = 2*i+1;
    int largest;
    if(l <= H && arr[l] > arr[i]){
        largest = l;
    }
    else largest = i;
    if(r <= H && arr[r] > arr[largest]){
        largest = r;
    }
    if(largest != i){
        tmp = arr[i];
        arr[i] = arr[largest];
        arr[largest] = tmp;
        maxHeapify(largest);
    }
}

void heapIncreaseKey(int i, int key) {
    arr[i] = key;
    while(i > 1 && arr[i/2] < arr[i]) {
    tmp = arr[i];
    arr[i] = arr[i/2];
    arr[i/2] = tmp;
    i = i/2;
    }
}

void maxHeapInsert(int key) {
    H++;
    arr[H] = -33333333;
    heapIncreaseKey(H, key);
}

int heapExtractMax() {
    int max = arr[1];
    arr[1] = arr[H];
    H--;
    maxHeapify(1);
    return max;
}

int main()
{
    int i;
    char cccc[20];
    int key;
    N = 0;
  while(scanf("%s", cccc)) {
    if(cccc[2] == 's') {
      scanf("%d", &key);
      maxHeapInsert(key);
    } else if(cccc[2] == 't') {
      printf("%d\n", heapExtractMax());
    } else {
      break;
    }
  }
  return 0;
    return 0;
}




Measured memory_bytes: 5584
#include<cstdio>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
int n,cur; char s[N]; long long ans;
int main()
{
	RI i; for (scanf("%s",s+1),n=strlen(s+1),i=1;i<n;++i)
	if (s[i]=='A') ++cur; else if (s[i]=='B')
	{ if (s[i+1]=='C') ans+=cur,++i; else cur=0; } else cur=0;
	return printf("%lld",ans),0;
}

Measured memory_bytes: 1928
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const int INF = 1e9;

int main(int argc, const char * argv[]) {
  int n, k;
  cin >> n >> k;

  int ans = n;
  vector<int> list(n);
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }
  sort(list.begin(), list.end());

  int sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (sum + list[i] < k) {
      sum += list[i];
    } else {
      ans = min(ans, i);
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N;

    cin >> N;

    int X[N];

    for(int i=0;i<N;++i){
        cin >> X[i];
    }

    int Y[N];

    for(int i=0;i<N;++i){
        Y[i] = X[i];
    }

    sort(Y,Y+N);

    for(int i=0;i<N;++i){
        if(X[i]<=Y[N/2-1]){
            cout << Y[N/2] << "\n";
        }else{
            cout << Y[N/2-1] << "\n";
        }
    }



}

Measured memory_bytes: 3712
#include<iostream>

using namespace std;
int a, b, c, d;

int main(){
  cin >> a >> b >> c >> d;
  while (1){
    c = c - b;
    if (c <= 0){
      cout << "Yes" << endl;
      break;
    }
    a = a - d;
    if (a <=0){
      cout << "No" << endl;
      break;
    }
  }


}


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

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

using ll = long long;
constexpr ll INF = 10000000000;

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

using namespace std;

//fixed << setprecision(10)

/////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int>dp(100010, INF);

int main() {
	int n; cin >> n;
	vector<int>h(n);
	rep(i, n)cin >> h[i];

	dp[0] = 0;

	for (int i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
# 16D8101012J ItoJun dj Python3
count=0
def merge(A, left, mid, right):
    global count
    h=[]
    L=A[left:mid]+[2**32]
    R=A[mid:right]+[2**32]
    i=0
    j=0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            h.append(L[i])
            i += 1
        else:
            A[k] = R[j]
            h.append(R[j])
            j += 1
            if i < len(L)-1:
                count += len(L) - 1 - i
        
def merge_sort(A, left, right):
    if left+1 < right:
        mid=(left+right)//2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

if __name__ == "__main__":
    n=int(input())
    A=list(map(int,input().split()))
    merge_sort(A,0,n)
    print(count)


Measured memory_bytes: 27472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
int main()
{
	priority_queue<ll> q;
	ll N,M;
	ll i=0,j=0,k=0;
	cin >> N>>M;
	for(i=0;i<N;++i)
	{
		cin >> j;
		q.push(j);
	}
	for(j=0;j<M;++j)
	{
		i = q.top();
		q.pop();
		q.push(i/2);
	}
	for(i=0;i<N;++i)
	{
		k+=q.top();
		q.pop();
	}
	cout << k << endl;
	return 0;
}




















Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    string a,b,c;cin>>a>>b>>c;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]) ans+=2;
        else if(a[i]==b[i]&&b[i]==c[i]) continue;
        else ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N, vector<int> (N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cin >> G[i][j];
    }
  }
  vector<vector<int>> G2;
  G2 = G;
  for(int k=0; k<N; k++){
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        chmin(G2[i][j],G2[i][k]+G2[k][j]);
      }
    }
  }
  bool changed = false;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(G2[i][j] != G[i][j]){
        changed = true;
      }
    }
  }
  if(changed){
    cout << -1 << endl;
  }else{
    vector<vector<P>> G3(N);
    priority_queue<pair<int,P>, vector<pair<int,P>>, greater<>> Q;
    for(int i=0; i<N; i++){
      for(int j=i+1; j<N; j++){
        if(i == j) continue;
        Q.push(make_pair(G[i][j],make_pair(i,j)));
      }
    }
    ll ans = 0;
    while(Q.size()){
      auto edge=Q.top();
      Q.pop();
      priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<>> Q2;
      Q2.push(make_pair(0,edge.second.first));
      vector<ll> dist(N,INF);
      dist[edge.second.first] = 0;
      while(Q2.size()){
          auto p = Q2.top();
          Q2.pop();
          if(dist[p.second] < p.first) continue;
          for(auto nv: G3[p.second]){
            if(dist[nv.first]<=p.first+nv.second) continue;
            dist[nv.first] = p.first + nv.second;
            Q2.push(make_pair(dist[nv.first],nv.first));
          }
      }
      int num = dist[edge.second.second];
      if(edge.first != num){
        ans += edge.first;
        G3[edge.second.first].push_back(make_pair(edge.second.second,edge.first));
        G3[edge.second.second].push_back(make_pair(edge.second.first,edge.first));
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b)){
        cout<<"B"<<endl;
    }else{
        cout<<"A"<<endl;
    }
}   




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 
 
 
#define pb push_back
 
// #define mp make_pair 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define itt iterator
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define isvowel(a) (a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_upda
#define MAX 1000001
 
#define maxn 1000005
#define eps 0.0000001

int n,m;
int a[22][22];
int ans=0;


void bfs(int x,int y)
{
	if(!a[x][y]) return;

	int vis[n][m];
	initialise(vis,0);

	int mx[n][m];
	initialise(mx,0);

	mx[x][y]=0;
	vis[x][y]=1;

	queue<pii> q;
	q.push({x,y});

	while(q.size())
	{
		int i=q.front().fi;
		int j=q.front().se;
		int s=mx[i][j];

		q.pop();

		if(i-1>=0 and vis[i-1][j]==0 and a[i-1][j])
		{
			vis[i-1][j]=1;
			mx[i-1][j]=s+1;
			q.push({i-1,j});
		}
		if(i+1<n and vis[i+1][j]==0 and a[i+1][j])
		{
			vis[i+1][j]=1;
			mx[i+1][j]=s+1;
			q.push({i+1,j});

		}
		if(j-1>=0 and vis[i][j-1]==0 and a[i][j-1])
		{
			vis[i][j-1]=1;
			mx[i][j-1]=s+1;
			q.push({i,j-1});

		}
		if(j+1<m and vis[i][j+1]==0 and a[i][j+1])
		{
			vis[i][j+1]=1;
			mx[i][j+1]=s+1;
			q.push({i,j+1});

		}
	}

	
	int ret=0;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) ret=max(ret,mx[i][j]);

	ans=max(ret,ans);


}




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

	// freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 

	
	cin>>n>>m;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char c;
			cin>>c;
			if(c=='.') a[i][j]=1;
			else a[i][j]=0;
		}
	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			bfs(i,j);
		}
	}

	cout<<ans<<'\n';

	
	
	
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X), B(Y), C(Z);
  for (int i = 0; i < X; ++i) cin >> A[i];
  for (int i = 0; i < Y; ++i) cin >> B[i];
  for (int i = 0; i < Z; ++i) cin >> C[i];

  // A + B の上位 K 個
  vector<long long> AB;
  for (int i = 0; i < X; ++i)
    for (int j = 0; j < Y; ++j) AB.push_back(A[i] + B[j]);
  sort(AB.begin(), AB.end(), greater<long long>());
  AB.resize(K);

  // AB と C
  vector<long long> ABC;
  for (int i = 0; i < AB.size(); ++i)
    for (int j = 0; j < Z; ++j) ABC.push_back(AB[i] + C[j]);
  sort(ABC.begin(), ABC.end(), greater<long long>());

  // 出力
  for (int k = 0; k < K; ++k) cout << ABC[k] << endl;
}


Measured memory_bytes: 43112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int[] card = new int[9];
        for (int i = 0; i < 9; i++) {
            card[i] = sc.nextInt();
        }

        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int b = sc.nextInt();
            for (int j = 0; j < 9; j++) {
                if (card[j] == b) {
                    card[j] = -1;
                }
            }
        }

        // 横
        for (int i = 0; i < 9; i+=3) {
            if (card[i] == -1 && card[i+1] == -1 && card[i+2] == -1) {
                System.out.println("Yes");
                return;
            }
        }

        // 縦
        for (int i = 0; i < 3; i++) {
            if (card[i] == -1 && card[i+3] == -1 && card[i+6] == -1) {
                System.out.println("Yes");
                return;
            }
        }

        // 斜め
        if (card[0] == -1 && card[4] == -1 && card[8] == -1 ||
                card[2] == -1 && card[4] == -1 && card[6] == -1)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

int main() {
  int n,m;  cin>>n>>m;
  vector<int> v(n+1,0), vec(n+1,1);
  v[1]=1;
  rep(i,m){
    int a,b; cin>>a>>b;
    if(v[a]==1){
      v[b]=1;
    }
    vec[a]--;vec[b]++;
    if(vec[a]==0){v[a]=0;}
  }
  int c=0;
  rep(i,n){
    if(v[i+1]==1 &&vec[i+1]!=0){c++;}
  }
  cout<<c;
}

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

int main(){
    int k,n;
    cin>>k>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int max=k-a[n-1]+a[0];
    for(int i=1;i<n;i++){
        if(max<a[i]-a[i-1]){
            max=a[i]-a[i-1];
        }
    }
    cout<<k-max<<endl;
}

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

void show(int*A, int N);

int bubblesort(int* A, int N) {
	int flag = 1;
	int Count = 0;

	while (flag) {
		flag = 0;
		

		for (int i = N - 1; i > 0; --i) {
			if (A[i] < A[i - 1]) {
				int Case = A[i - 1];
				A[i - 1] = A[i];
				A[i] = Case;
				++Count;
				flag = 1;
			}
		}
	}


	return Count;
}

void show(int* A, int N) {
	for (int i = 0; i < N; ++i) {
		if (i > 0) { cout << ' '; }
		cout << A[i];
	}
	cout << endl;
}

int main() {
	int N;
	cin >> N;

	int* A = new int[N];
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int s = bubblesort(A, N);
	show(A, N);
	cout << s <<endl;


	delete[] A;

}


Measured memory_bytes: 3140
#include<iostream>

using namespace std;

int main(){
int x[3],MAX,tmp;
for(int i=0;i<3;i++){
cin>>x[i];
}

for(int i=0;i<3;i++){
 for(int j=i;j<3;j++){
 if(x[i]>x[j]){
   tmp=x[i];
   x[i]=x[j];
   x[j]=tmp;
  }
 }
}

cout << x[0]<<" "<<x[1]<<" "<<x[2] <<endl;

return 0;
}


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

using namespace std;


int main(){
	int n,l;
	cin>>n>>l;
	vector<string> v(n);
	for(int i=0;i<n;++i)
		cin>>v[i];
	sort(begin(v),end(v));
	for(string s:v)
		cout<<s;
	cout<<"\n";
	return 0;
}


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

const int maxn = 1e3+5;
int v[maxn];
int n,k,ans=0;
int main(){
	cin >> n >> k;
	for (int i=1;i<=k;i++){
		int d;
		cin >> d;
		for (int j=1;j<=d;j++){
			int y;
			cin >> y;
			v[y]=1;	
		}
	}
	for (int i=1;i<=n;i++){
		if (v[i] == 0) ans++;	
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0), (-1, -1), (-1, 1), (1, -1), (1,1))
c = [[0]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    cnt = 0
    if S[i][j] == "#":
      c[i][j] = "#"
      continue
    for dy, dx in moves:
      ny = i + dy
      nx = j + dx
      if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == '#':
        cnt += 1
    c[i][j] = cnt

for i in c:
  i = list(map(str, i))
  print("".join(i))

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int bfs();

int h, w;
int mp[105][105];

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

    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char c;
            cin >> c;
            if(c == '.') mp[i][j] = 1;

        }
    }

    int dp[105][105];
    if(mp[1][1] == 0) dp[1][1] = 1;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            if(i == 1 || j == 1) {
                if(i == 1 && j == 1) continue;
                if(i == 1) {
                    if(mp[i][j] == 1) {
                        dp[i][j] = dp[i][j - 1];
                        continue;

                    }
                    if(mp[i][j - 1] == mp[i][j]) {
                        dp[i][j] = dp[i][j - 1];

                    } else {
                        dp[i][j] = dp[i][j - 1] + 1;

                    }
                } else {
                    if(mp[i][j] == 1) {
                        dp[i][j] = dp[i - 1][j];
                        continue;

                    }
                    dp[i][j] = dp[i - 1][j];
                    if(mp[i - 1][j] != mp[i][j]) dp[i][j]++;

                }
            } else {
                if(mp[i][j] == 1) {
                    dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
                    continue;

                }
                int x, y;
                x = dp[i - 1][j];
                y = dp[i][j - 1];
                if(mp[i - 1][j] != mp[i][j]) ++x;
                if(mp[i][j - 1] != mp[i][j]) ++y;
                dp[i][j] = min(x, y);

            }
        }
    }
    cout << dp[h][w] << endl;
    return 0;
}

/*
int bfs() {
    queue<pair<pair<P, int>, char>> q;
    q.push(MP(MP(MP(1, 1), 0), '.'));
    int cost[105][105];
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            cost[i][j] = INF;

        }
    }

    while()
}
*/


Measured memory_bytes: 384
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

x, y = mapint()
cnt = 0
if x*y>0:
    if y<x:
        cnt += 2
    cnt += abs(x-y)
elif x*y==0:
    if x<y:
        cnt = y-x
    else:
        cnt = (x-y)+1
else:
    cnt += 1
    x *= -1
    cnt += abs(x-y)
print(cnt)

Measured memory_bytes: 61532
#include <iostream>
using namespace std;
const int maxn = 1e5 + 100;
int n, W;
long long a[maxn], dp[maxn], v[maxn], w[maxn];
int main()
{
    cin>>n>>W;
    for(int i = 1; i <= n; i++) cin>>w[i]>>v[i];
    for(int j = 1; j <= 1e5; j++) dp[j] = 1e18;
    for(int i = 1; i <= n; i++){
        for(int j = 1e5; j >= v[i]; j--){
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }
    for(int i = 1e5; i >= 0; i--){
        if(dp[i] <= W)  {  cout<<i<<endl; return 0; }
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		Queue<Integer> black = new ArrayDeque<Integer>();
		int H=stdIn.nextInt();
		int W=stdIn.nextInt();
		char a[]=new char[H*W];
		String b="";
		boolean fin=false;
		int z=0,y=0,x=0,i=0,j=0;
		while(z<H*W){
			if(z%W==0){
				b=stdIn.next();y=0;
			}
			a[z]=b.charAt(y);
			if(a[z]=='#')
				black.add(z);
			z++;y++;
		}z=1;y=0;x=black.size();
		while(true){
			while(y<x){
				i=black.poll();
				if(i-W>=0)
					if(a[i-W]=='.'){
						black.add(i-W);
						a[i-W]='#';fin=true;
					}
				if(i+W<H*W)
					if(a[i+W]=='.'){
						black.add(i+W);
						a[i+W]='#';fin=true;
					}
				if(i-1>=0&&i%W!=0)
					if(a[i-1]=='.'){
						black.add(i-1);
						a[i-1]='#';fin=true;
					}
				if(i+1<H*W&&i%W!=W-1)
					if(a[i+1]=='.'){
						black.add(i+1);
						a[i+1]='#';fin=true;
					}
				y++;
			}j+=y;y=0;
			x=black.size();
			if(fin==false)
				z--;
			if(x+j==H*W)
				break;
			fin=false;
			z++;
		}
		System.out.println(z);
	}
}

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


/********************************************************************/
#define M1 1000000007	//Standard primes used in modulo operations
#define M2 998244353
#define PI 3.1415926536
const int INF = INT_MAX;
#define ll long long
#define pll pair<ll,ll>
#define REP(i, a, b) for(ll i=a;i<b;i++)
#define REPR(i, a, b) for(ll i=b-1;i>=a;i--)
#define forr(i, n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define space ' '
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl

void FAST() {	//FAST Input Output, DONT use both scnaf,printf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll gcd(ll x, ll y) {	//returns gcd of two long long ints
	if (x == 0) return y;
	return gcd(y % x, x);
}

ll powM(ll x, ll y, ll m) {	//returns (a^b)%m ( ^ is exponent )
	ll ans = 1, r = 1;
	x %= m;
	while (r > 0 && r <= y)
	{
		if (r & y)
		{
			ans *= x;
			ans %= m;
		}
		r <<= 1;
		x *= x;
		x %= m;
	}
	return ans;
}

map<long long, long long> factorize(long long n) {	//returns map containing factor and multiplicity, Eg: 60 = {{2,2},{3,1},{5,1}}
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}
/* **********END OF TEMPLATE*********** */

int main() {
	/*  Codeforces #595 Div.3 :)*/
	FAST();
	int n;
	cin>>n;
	cout<<1-n<<endl;
	}


		


Measured memory_bytes: 3608
import java.io.*;
import java.util.*;
class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
  		String s = sc.next();
  		String t = sc.next();
  		int c=0;
  		for(int i=0;i<s.length();i++){
  			for(int j=i;j<t.length();j++){
  				if(s.charAt(i) == t.charAt(j))
  					c++;
  				break;
  			}
  		}
  		System.out.print(c);
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    String s=sc.next();
    if(a>=3200){
      System.out.println(s);
    }else{
      System.out.println("red");
    }
  }
}

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

int main(){
  
  string s;
  cin>>s;
  stack<char> st;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S') st.push(s[i]);
    else{
      if(st.size()&&st.top()=='S') st.pop();
      else st.push(s[i]);
    }
  }
  cout<<st.size()<<endl;
  return 0;
} 

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll lcm(ll a, ll b){
  	ll tmp, r, x = a * b;
  	if(a < b){
    	tmp = a;
    	a = b;
    	b = tmp;
  	}
  	r = a % b;
  	while(r != 0){
    	a = b;
    	b = r;
    	r = a % b;
  	}
  	return x / b;
}

ll calc(ll r, ll c, ll d){
    return r - (r / d + r / c - r / lcm(c, d));
}

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll res = calc(b, c, d) - calc(a - 1, c, d);
    cout << res << endl;
    return 0;
}

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

#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
using namespace std;
int mod = 1'000'000'000 + 7;

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

ll H, W, N;
set<pair<int, int>> s, q;
int dx[] = {0, 1, 1, 1, 0, -1, -1, -1, 0}, dy[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};

bool inside(int y, int x) {
    return y >= 0 && y < H && x >= 0 && x < W;
}

ll ans[10];

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> H >> W >> N;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        s.insert(make_pair(a, b));
        rep(j, 9) {
            int y = a + dy[j], x = b + dx[j];
            if (inside(y, x)) {
                q.insert(make_pair(y, x));
            }
        }
    }
    for (auto p:q) {
        int y = p.first, x = p.second;
        int o = 0;
        bool flag = true;
        rep(i, 9) {
            int xx = x + dx[i], yy = y + dy[i];
            if (!inside(yy, xx)) {
                flag = false;
                break;
            }
            if (s.find(make_pair(yy, xx)) != s.end()) {
                o++;
            }
        }
        if (flag) {
            ans[o]++;
        }
    }
    ans[0] = (H - 2) * (W - 2);
    for (int i = 1; i <= 9; i++) {
        ans[0] -= ans[i];
    }
    for (int i = 0; i < 10; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  ll total = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 3636
MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if all(ai < 0 for ai in a):
    ans = 1
    if k & 1:
        for ai in a[-k:]:
            ans = ans * ai % MOD
    else:
        for ai in a[:k]:
            ans = ans * ai % MOD
elif n == k:
    ans = 1
    for ai in a:
        ans = ans * ai % MOD
else:
    ans = 1
    a.sort(key=abs, reverse=True)
    cneg = sum(ai < 0 for ai in a[:k])
    cpos = sum(ai >= 0 for ai in a[:k])
    if cneg & 1 == 0:
        for ai in a[:k]:
            ans = ans * ai % MOD
    else:
        left = []
        r = k
        for ai in a:
            if ai < 0 and cneg > 1:
                ans = ans * ai % MOD
                cneg -= 1
                r -= 1
            elif ai >= 0 and cpos > 1:
                ans = ans * ai % MOD
                cpos -= 1
                r -= 1
            else:
                left.append(ai)
        ngs = [ai for ai in left if ai < 0]
        pss = [ai for ai in left if ai >= 0]
        if r == 1:
            ans = ans * pss[0] % MOD
        else:
            t = -1001001001001001001001
            if len(ngs) >= 2:
                t = ngs[0] * ngs[1]
            if len(pss) >= 2:
                t = max(t, pss[0] * pss[1])
            ans = ans * t % MOD
print(ans)




Measured memory_bytes: 103300