akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

ll N,M;
vector < int > G[100010];
int col[100010];
bool used[100010];

void dfs(int v, int color) {
	if (used[v]) return;
	used[v] = true;
	col[v] = color % 2;
	REP(i,G[v].size()) {
		dfs(G[v][i], color + 1);
	}
}

int main() {

	cin >> N >> M;
	REP(i,M) {
		int a,b; cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	fill(col, col + 100010, -1);
	fill(used, used + 100010, false);
	dfs(1, 0);

	for (int i = 1; i <= N; i++) {
		REP(j,G[i].size()) {
			if (col[i] == col[G[i][j]]) {
				cout << N * (N - 1) / 2 - M << endl;
				return 0;
			}
		}
	}

	ll one = 0, zero = 0;
	for (int i = 1; i <= N; i++) {
		if (col[i] == 0) zero++;
		else one++;
	}

	cout << one * zero - M << endl;

	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int n, q;
vector<int> dat;
int n_ = 1;
void init(int n, int& n_){
    while(n_ < n){
        n_ *= 2;
    }
    dat.resize(n_ * 2 - 1);
    for(int i = 0; i < n_ * 2 - 1; i++)dat[i] = pow(2, 31) - 1;
}

void update(int k, int a){
    k += n_-1;
    dat[k] = a;
    while(k > 0){
        k = (k-1)/2;
        dat[k] = min(dat[2*k+1], dat[2*k+2]);
    }
}

int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l){
        return pow(2, 31) - 1;
    }
    if(a <= l && r <= b) return dat[k];
    
    int vl = query(a, b, 2*k+1, l, (l+r)/2);
    int vr = query(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
}



int main(void){
    cin >> n >> q;
    init(n, n_);
    for(int i = 0; i < q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            update(x, y);
        }else{
            cout << query(x, y+1, 0, 0, n_) << endl;
        }
    }
}


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

int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  if(x == w / 2.0 && y == h / 2.0){
    cout << fixed << setprecision(100) << (double)(w * h / 2.0) << " " << 1 << endl;
  }else{
    cout << fixed << setprecision(100) << (double)(w * h / 2.0) << " " << 0 << endl;
  }
}

Measured memory_bytes: 3756
//Moh_K_Imar .......
//26/08/2020  ... 3,40.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll x=a-b;
    if(x<=c)cout<<c-x;
    else cout<<0<<endl;

    return 0;
}



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

int main() {
  long long n;
  cin>>n;
  long long a[n];
  for (int i=1;i<=n;i++){
    cin>>a[i];
  }
  long long ans=1000;
  for (int i=1;i<n;i++){
    if (a[i]<a[i+1]){
      long long num=0;
      num=ans/a[i];
      ans+=(a[i+1]-a[i])*num;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){

  int size;

  cin >> size;

  int *array = new int[size];

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

  int min, minj, count = 0, temp;

  for(int i = 0; i < size - 1; i++){
    min = array[i];
    minj = i;
    for(int j = i + 1; j < size; j++){
      if(min > array[j]){
        min = array[j];
        minj = j;
      }
    }
    if(minj != i){
      temp = array[i];
      array[i] = array[minj];
      array[minj] = temp;
      count++;
    }
  }

  for(int i = 0; i < size - 1; i++){
    cout << array[i] << " ";
  }
  cout << array[size - 1] << endl;

  cout << count << endl;

  delete[] array;
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

struct Point {
	int x, y;
	Point() {}
	Point(int x, int y) : x(x), y(y) {}
	bool operator<(const Point &a) const {
		if (y == a.y) return x < a.x;
		return y < a.y;
	}
};

int A[310][310];
int memo[100000];

signed main() {
	int H, W, D;
	cin >> H >> W >> D;

	rep(y, H) rep(x, W) cin >> A[y][x];
	map<int, Point> m;

	rep(y, H) rep(x, W) {
		m[A[y][x]] = Point(x, y);
	}

	REP(i, 1, H * W - D) {
		memo[i + D] = abs(m[i].x - m[i + D].x) + abs(m[i].y - m[i + D].y);
	}
	REP(i, 1, H * W - D) {
		memo[i + D] += memo[i];
	}

	int Q;
	cin >> Q;

	rep(_, Q) {
		int L, R;
		cin >> L >> R;

		int valR = memo[R];
		int valL = L > D ? memo[L] : 0;

		cout << valR - valL << endl;
	}
}


Measured memory_bytes: 8192
//mst
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<limits>
#include<utility>

//#define c11
#ifdef c11
#include<unordered_set>
#include<unordered_map>
#endif

using namespace std;
typedef long long ll;
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define initz(x) memset(x,0,sizeof(x))
#define initm(x) memset(x,0x7f,sizeof(x))
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define fore(i, l, r) for(int i = (int) l; i <= (int) r; ++i)
#define rforn(i, n) for(int i = (int) n - 1; i>= 0; --i)
#define fi first
#define se second

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

const int INF = 0x7f7f7f7f;
const int MAX_N = 30;
const int MAX_M = 50000;

typedef pair<int, int> P;

struct E{
  E() {}
  E(int uu, int vv, double cc): u(uu), v(vv), c(cc) {}
  bool operator > (const E& e) const {
    return c < e.c;
  }
  int u, v;
  double c;
};

int fa[MAX_M];

priority_queue<E, vector<E>, greater<E> > pq;

int find(int x) {
  if(x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}

double Kruskal(int n) {
  for(int i = 1; i <= n; ++i) {
    fa[i] = i;
  }
  int cnt = 1;
  double ans = 0;

  while(cnt < n && !pq.empty()) {
    const E& e = pq.top();
    int u, v;
    double c;
    u = e.u;
    v = e.v;
    c = e.c;
    pq.pop();

    u = find(u);
    v = find(v);
    if(u == v) continue;
    fa[u] = v;
    ans += c;
    ++cnt;
  }
  return ans;
}

double x[MAX_M], y[MAX_M];

int main() {
	int n, m;
  double ans = 0;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; ++i) {
    scanf("%lf%lf", &x[i], &y[i]);
  }
  while(m--) {
    int u, v;
    double c;
    scanf("%d%d", &u, &v);
    c = sqrt((x[u]-x[v])*(x[u]-x[v]) + (y[u]-y[v])*(y[u]-y[v]));
    ans += c;
    pq.push(E(u, v ,c));
  }
  ans -= Kruskal(n);
  printf("%.3f\n", ans);
	return 0;
}



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

template <typename T>
void print(const T &v);

int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double border = 1.0 * E / (100 + E);
    double max = 0;
    int max_w = 0, max_s = 0;
    for (int a = 0; a <= F / (A * 100); a++)
    {
        for (int b = 0; b <= (F - (a * A * 100)) / (B * 100); b++)
        {
            for (int c = 0; c <= (F - (a * A * 100) - (b * B * 100)) / C; c++)
            {
                for (int d = 0; d <= (F - (a * A * 100) - (b * B * 100) - (c * C)) / D; d++)
                {
                    int water = (a * A * 100) + (b * B * 100);
                    int suger = (c * C) + (d * D);
                    double node = (1.0 * suger) / (water + suger);
                    if (node <= border)
                    {
                        if (node >= max)
                        {
                            max = node;
                            max_w = water;
                            max_s = suger;
                        }
                    }
                }
            }
        }
    }
    cout << max_w + max_s << ' ' << max_s << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int minusCount = 0;
    long sum = 0;
    int min = 1001001001;
    for (int i = 0; i < N; i++) {
      int A = sc.nextInt();
      sum += Math.abs(A);
      min = Math.min(min, Math.abs(A));
      if (A < 0) {
        minusCount++;
      }
    }
    System.out.println(minusCount%2 == 0 ? sum : sum-2*min);
  }    
}

Measured memory_bytes: 48520
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  cout << fixed << setprecision(12);
  int a, b, c;
  cin >> a >> b >> c;
  double pi = acos(-1);
  double s, l, h;
  s = a * b * 0.5 * sin(pi * c / 180);
  l = sqrt(a * a + b * b - 2 * a * b * cos(pi * c / 180)) + a + b;
  h = 2 * s / a;
  cout << s << endl;
  cout << l << endl;
  cout << h << endl;

  return 0;
}



Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    int r=n-2, l=1;
    int ans = a[n-1] - a[0];
    for(int i=1;i<n-1;i++) ans += abs(a[i]);
    cout<<ans<<endl;
    int plus=a[n-1], minus = a[0];
    vector <int> mi, pl;
    rep(i,n-2) if(a[i+1]<=0) mi.push_back(a[i+1]); else pl.push_back(a[i+1]);
    rep(i, mi.size()){
        cout<<plus<<' '<<mi[i]<<endl;
        plus -= mi[i];
    }
    rep(i,pl.size()){
        cout<<minus<<' '<<pl[i]<<endl;
        minus -= pl[i];
    }
    cout<<plus<<' '<<minus<<endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    map <int, int> mp;
    for (int i = 0; i < n; ++ i) {
        int x; cin >> x;
        mp[x] ++;
    }
    int kill = 0;
    for (pair <int, int> p : mp) {
        kill += max(0, p.second - 1);
    }
    if (kill & 1) cout << mp.size() - 1 << endl;
    else cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	vector<int> w,h;
	for(int i=0;i<10;i++)
	{
		int k;
		cin >> k;
		w.pb(k);
	}
	for(int i=0;i<10;i++)
	{
		int k;
		cin >> k;
		h.pb(k);
	}
	sort(w.begin(),w.end(),greater<int>());
	sort(h.begin(),h.end(),greater<int>());
	int sumw=0,sumh=0;
	for(int i=0;i<3;i++)
	{
		sumw+=w[i];
		sumh+=h[i];
	}
	cout << sumw << ' ' << sumh << endl;
	return 0;
}

Measured memory_bytes: 1216
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 300010;
int dx, dy, total, qx[N], qy[N], n, use[N], nd[N], cnt, now[N], ths[N], nxt[N];
char s[N];
void moveto(int x){
	if (x > dx) for (int i = dx + 1; i <= x; i++) qx[++total] = i, qy[total] = dy;
		else for (int i = dx - 1; i >= x; i--) qx[++total] = i, qy[total] = dy;
	dx = x;
}

void moveup(){
	qx[++total] = dx, qy[total] = ++dy;
}
void movedown(){
	qx[++total] = dx, qy[total] = --dy;
}
int main(){
	read(n);
	scanf("\n%s", s);
	bool flag = true;
	for (int i = 0; i < (1 << n); i++)
		if (s[i] == '0'){
			if (use[i] == 0) nd[++cnt] = i; 
			for (int j = 0; j < (1 << n); j++)
				if ((i | j) == j){
					if (s[j] == '1') flag = false;
					use[j] = true;
				}
		}
	if (flag == false){
		puts("Impossible");
		return 0;
	}
	
	dx = 0, dy = 0;
	for (int i = 1; i <= cnt; i++){
		int num = 0, len = 2, nlen;
		for (int j = 1; j <= n; j++)
			if (nd[i] & (1 << (j - 1))) now[++num] = j;
		ths[1] = now[num]; ths[2] = -now[num];
		for (int j = num - 1; j >= 1; j--){
			nxt[nlen = 1] = now[j];
			for (int k = 1; k <= len; k++) nxt[++nlen] = ths[k];
			nxt[++nlen] = now[j];
			nxt[++nlen] = -now[j];
			for (int k = len; k >= 1; k--) nxt[++nlen] = ths[k];
			nxt[++nlen] = -now[j];
			len = nlen;
			for (int k = 1; k <= len; k++) ths[k] = nxt[k];
		}
		for (int j = 1; j <= len; j++){
			int x = abs(ths[j]);
			if (dx < x){
				moveto(x - 1); 
				if (ths[j] > 0) moveup(), moveto(x), movedown();
					else moveto(x);
			}
			else{
				moveto(x);
				if (ths[j] > 0) moveup(), moveto(x - 1), movedown();
					else moveto(x - 1);
			}
		}
		moveto(0);
	}
	
	puts("Possible");
	printf("%d\n", total);
	for (int i = 0; i <= total; i++)
		printf("%d %d\n", qx[i], qy[i]);
	return 0;
}

Measured memory_bytes: 6400
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int sum = sc.nextInt();
        int n = sc.nextInt();
        int tmpsum = 0;
        for (int i = 0; i < n; i++) {
            tmpsum += sc.nextInt();
        }
        
        
        if (tmpsum >= sum) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 46852
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s,t,u;
    cin >> s >> t >> u;
    string ans;
    ans += toupper(s[0]);
    ans += toupper(t[0]);
    ans += toupper(u[0]);
    cout <<ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  vector<int> a(3);
  for(int i=0; i<3; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << 10 * a[2] + a[1] + a[0] << endl;

  return 0;
}

//


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,ans;
  cin >> a;
  for(int i=0;i<a.size();i++){
    if((i+1)%2!=0)ans+=a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 592
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return low

def binarySearchRight(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == len(nums) - 1 or target != nums[mid + 1]:
                return mid
            else:
                low = mid + 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return high

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for j in range(N):
         i = binarySearchRight(A, B[j] - 1)
         k = binarySearchLeft(C, B[j] + 1)
         ret += (i + 1) * (N - k) if 0 <= i < N and 0 <= k < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)


Measured memory_bytes: 105572
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

#define bs(n) (1ull<<(ull)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)

ll n, k, a[200000], cnt[3];

ll cnt_less_neg(ll x) {
    auto nb = a;
    auto ne = a + cnt[0];
    auto pb = a + (cnt[0] + cnt[1]);
    auto pe = a + n;
    ll r = 0;
    auto cmp = [x](ll a, ll b) { return a * b >= x; };
    for (auto i = nb; i != ne; i++) {
        auto t = lower_bound(pb, pe, *i, cmp);
        r += (pe - t);
    }
    return r;
}

ll cnt_less_zero(ll x) {
    return cnt[0] * cnt[2];
}

ll cnt_less_pos(ll x) {
    auto nb = a;
    auto ne = a + cnt[0];
    auto pb = a + (cnt[0] + cnt[1]);
    auto pe = a + n;
    ll r = 0;
    auto cmp1 = [x](ll a, ll b) { return a * b < x; };
    auto cmp2 = [x](ll a, ll b) { return a * b >= x; };
    for (auto i = nb; i != ne; i++) {
        auto t = lower_bound(i + 1, ne, *i, cmp2);
        r += (ne - t);
    }
    for (auto i = pb; i != pe; i++) {
        auto t = lower_bound(pb, i, *i, cmp1);
        r += (t - pb);
    }
    return r + cnt[0] * cnt[2] + cnt[1] * (cnt[0] + cnt[2]) + (cnt[1] * (cnt[1] - 1)) / 2;
}

ll cnt_less(ll x) {
    if (x < 0) return cnt_less_neg(x);
    else if (x > 0) return cnt_less_pos(x);
    else return cnt_less_zero(x);
}

int main() {
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if (a[i] > 0) cnt[2]++;
        else if (a[i] < 0) cnt[0]++;
        else cnt[1]++;
    }
    sort(a, a + n);
    ll l = -2000000000000000000, r = 2000000000000000000;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (cnt_less(m) < k) l = m;
        else r = m;
    }
    cout << r-1 << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
	int a[3];
	int tmp = 0;
	int n = 0;
	scanf("%d",&n);
	
	for(int i = 0; i < n; i++){
		scanf("%d %d %d",&a[0],&a[1],&a[2]);
		
		if(a[0] > a[1]){
			tmp = a[0];
			a[0] = a[1];
			a[1] = tmp;
		}
		if(a[1] > a[2]){
			tmp = a[1];
			a[1] = a[2];
			a[2] = tmp;
		}
		if(a[0] > a[1]){
			tmp = a[0];
			a[0] = a[1];
			a[1] = tmp;
		}

		if(a[2] * a[2] == a[0] * a[0] + a[1] * a[1]){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}

	}
	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
using namespace std;
typedef long long ll;
ll n, mx, a[105];

void f(ll p) {
	ll i, s, b[105];
	if(p==n+1) {
		s = 0;
		for(i=1; i<=n; i++) s += a[i];
		mx = max(mx, s);
		return;
	}
	if(a[p]<0) {
		for(i=1; i<=n; i++) b[i] = a[i];
		for(i=p; i<=n; i+=p) a[i] = 0;
		f(p+1);
		for(i=1; i<=n; i++) a[i] = b[i];
	}
	f(p+1);
}

int main() {
	ll i, j, s;
	cin>>n;
	for(i=1; i<=n; i++) cin>>a[i];
	for(i=n; i; i--) {
		for(j=i; j<=n; j+=i) if(a[j]>0) break;
		if(j>n) for(j=i; j<=n; j+=i) a[j] = 0;
	}
	f(1);
	cout<<mx;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int res = Integer.MAX_VALUE;
		for (int i=0; i<=Math.max(X, Y); i++){
			int total = i*(2*C) + A*Math.max(0, X-i) + B*Math.max(0, Y-i);
			res = Math.min(res, total);
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

int main()
{
    int n;
    cin >> n;
    double x1,y1,x2,y2,x3,y3;
    while(n>0)
    {
        cin >> x1 >> y1 >>x2 >> y2 >> x3 >> y3;
        double s,v1x,v1y,v2x,v2y,h1x,h1y,h2x,h2y;
        v1x = y2-y1;
        v1y = x1-x2;
        v2x = y3-y1;
        v2y = x1-x3;
        h1x = (x2+x1)/2;
        h1y = (y2+y1)/2;
        h2x = (x3+x1)/2;
        h2y = (y3+y1)/2;

        double detA = v1x*v2y-v1y*v2x;
        //double hx = (x2+x1)/2;
        //double hy = (y2+y1)/2;
        s = (v2y*(h2x-h1x) -v2x*(h2y-h1y))/detA;
        double ox,oy;
        ox = h1x + s*v1x;
        oy = h1y + s*v1y;
        if(-0.0005<ox&&ox<0)ox = 0;
        if(-0.0005<oy&&oy<0)oy = 0;
        double r = sqrt((x1-ox)*(x1-ox)+(y1-oy)*(y1-oy));
        printf("%.3f %.3f %.3f\n",ox,oy,r);
        --n;
    }
    return 0;
}

Measured memory_bytes: 0
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int n;
vector<int> G[205];
vector<vector<int>> d(205, vector<int>(205, inf));

bool check() {
  vector<int> c(n, -1);
  c[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u: G[v]) {
      if (c[u] == -1) {
        c[u] = c[v] ^ 1;
        q.push(u);
      }
      else {
        if (c[u] == c[v]) return false;
      }
    }
  }
  return true;
}

int calc() {
  rep(k, n) {
    rep(i, n) {
      rep(j, n) {
        chmin(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  rep(i, n) {
    rep(j, i) {
      chmax(ans, d[i][j]);
    }
  }
  return ans + 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, n) {
      if (s[j] == '1') {
        G[i].push_back(j);
        d[i][j] = 1;
      }
    }
  }

  cout << (check() ? calc() : -1) << '\n';
  






  
  return 0;
}

Measured memory_bytes: 640
import math
import sys

def insertion_sort(a, n, g):
    ct = 0
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j-g
            ct += 1
        a[j+g] = v
    return ct

n = int(input())
a = list(map(int, sys.stdin.readlines()))
m = 1
b = 0
ct= 0
g = []
while True:
    b = math.ceil( ((9**m) - (4**m))/(5 * (4**(m-1))) )
    if b > n:
        break
    g.append(b)
    m += 1
g = g[::-1]

for i in g:
    ct += insertion_sort(a, n, i)

print(m-1)
print(*g, sep=" ")
print(ct)
print(*a, sep="\n")

Measured memory_bytes: 118500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  if (a == "000")
    cout << 0 << endl;
  else if (a == "001" || a == "010" || a == "100")
    cout << 1 << endl;
  else if (a == "011" || a == "101" || a == "110")
    cout << 2 << endl;
  else
    cout << 3 << endl;
}

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

using namespace std;

template< typename T >
struct PairingHeap
{
  struct Node
  {
    T key;
    Node *head, *next;
  } *root = nullptr;
  bool rev;

  PairingHeap(bool rev = false) : rev(rev) {}

  Node *merge(Node *x, Node *y)
  {
    if(!x || !y) return x ? x : y;
    if((x->key > y->key) ^ rev) swap(x, y);
    y->next = x->head;
    x->head = y;
    return x;
  }

  Node *push(const T &key)
  {
    auto t = new Node({key, nullptr, nullptr});
    root = merge(root, t);
  }

  T top()
  {
    return root->key;
  }

  Node *_pop(Node *s)
  {
    Node *p = nullptr;
    while(s) {
      Node *a = s, *b = nullptr;
      s = s->next;
      a->next = nullptr;
      if(s) {
        b = s;
        s = s->next;
        b->next = nullptr;
      }
      a = merge(a, b);
      a->next = p;
      p = a;
    }
    while(p) {
      Node *j = p;
      p = p->next;
      s = merge(j, s);
    }
    return s;
  }

  void pop()
  {
    auto *temp = root;
    root = _pop(root->head);
  }

  bool empty() const
  {
    return !root;
  }

  void merge(PairingHeap< T > &p)
  {
    root = merge(root, p.root);
  }
};

int main()
{
  char buff[100];
  int key;

  PairingHeap< int > que(true);
  for(;;) {
    scanf("%s", buff);
    if(buff[0] == 'e' && buff[1] == 'n') break;
    if(buff[0] == 'i') {
      scanf("%d", &key);
      que.push(key);
    } else {
      printf("%d\n", que.top()), que.pop();
    }
  }
}


Measured memory_bytes: 50068
#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <unordered_map>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last)
			out << ",";
	}
	out << "]";
	return out;
}

void solve() {
	int n;
	cin >> n;
	ll p = 1;
	ll mo = 1e9 + 7;
	for (int i = 1; i <= n; ++i) {
		p = (p * i) % mo;
	}
	cout << p << endl;
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(m);
	rep(i, m)
	{
		cin >> a[i];
	}
	ll sum = 0;
	rep(i, m)
	{
		sum += a[i];
	}
	if (sum <= n)
	{
		cout << n - sum << "\n";
	}
	else
	{
		cout << "-1" << "\n";
	}


	return 0;
}

Measured memory_bytes: 3684
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
 
l = [a, b, c, d, e]
s = []
 
for i in l:
    if i % 10 > 0:
        s.append(10 - (i % 10))
if len(s) > 0:
    s.sort()
    del s[-1]
 
ans = sum(l) + sum(s)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong a, b;
llong aa, bb;
llong ans = 1;

int main() {
    cin >> a >> b;
    aa = a; bb = b;
    for (llong i = 2; i * i <= max(aa, bb); i++) {
        bool f = false;
        
        while (a % i == 0 && b % i == 0) {
            a /= i;
            b /= i;
            f = true;
        }

        while(a % i == 0) a /= i;
        while(b % i == 0) b /= i;

        if (f) ans++;
    }

    if (a > 1 && b % a == 0) ans++;
    else if (b > 1 && a % b == 0) ans++;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,m;cin>>n>>m;
	vector<vector<ll>> a(n,vector<ll>(3));
	ll x,y,z;
	for(int i = 0; i < n; i++) {
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	}
	ll ans = -LINF;
	for(int i = 0; i < 8; i++) {
		vector<ll> s(n);
		for(int k = 0; k < n; k++) {
			ll sum =0;
			for(int j = 0; j < 3; j++) {
				if(( i >> j) & 1){
					sum += a[k][j];
				}
				else{
					sum -= a[k][j];
				}
			}
			s[k] = sum;	
		}
		sort(ALL(s),greater<ll>());
		ll tmp = 0;
		for(int l = 0; l < m; l++) {
			tmp += s[l];
		}
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll m, k, i;
    cin >> m >> k;
    if(k >= (1ll << m))
    {
        cout << -1 << endl;
        return 0;
    }
    if(k == 0)
    {
        for(i = 0; i < (1 << m); i++)
            cout << i << ' ' << i << ' ';
        cout << endl;
        return 0;
    }
    if(m == 1)
    {
        cout << "-1\n";
        return 0;
    }
    for(i = 0; i < (1 << m); i++)
    {
        if(i != k)
            cout << i << ' ';
    }
    cout << k << ' ';
    for(i = (1 << m) - 1; i >= 0; i--)
    {
        if(i != k)
            cout << i << ' ';
    }
    cout << k << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "15 40" => "10"
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        m: usize,
        d: usize,
    }

    let mut ans = 0;
    for i in 1..m+1 {
        for j in 1..d+1 {
            let d1 = j % 10;
            let d10 = j / 10;
            if d1 >= 2 && d10 >= 2 && d1 * d10 == i {
                ans += 1;
            }
        }
    }

    ans.to_string()
}

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

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> vec(N, K - Q);
	for (int i = 0; i < Q; i++) {
		int A;
		cin >> A;
		vec.at(A - 1)++;
	}
	for (int j = 0; j < N; j++) {
		if (vec.at(j) <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}


Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    lr = sorted([LI() for _ in range(n)])
    la = [x[0] for x in lr]
    ra = sorted([x[1] for x in lr])

    rr = 0
    for l, r in lr:
        t = r - l + 1
        tl = la[-1]
        if l == tl:
            tl = la[-2]
        tr = ra[0]
        if r == tr:
            tr = ra[1]
        if tr >= tl:
            t += tr - tl + 1
        if rr < t:
            rr = t

    mr = [lr[0][1]]
    for _, r in lr[1:]:
        if mr[-1] > r:
            mr.append(r)
        else:
            mr.append(mr[-1])

    tl, tr = lr[-1]
    for i in range(n-2, 0, -1):
        r = lr[i][1]
        if tr > r:
            tr = r
        if tr < tl:
            break
        if mr[i-1] < lr[i-1][0]:
            continue
        t = tr - tl + 1 + mr[i-1] - lr[i-1][0] + 1
        if rr < t:
            rr = t

    return rr

print(main())





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

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

    int n, y;
    cin >> n >> y;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(n - i - j >= 0){
                if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
                    cout << i << ' ' << j << ' ' << (n - i - j) << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int a, b, c, d;

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

   if((a >= b)&&(a >= c))
      d = a * 10 + b + c;
   else if((b >= a)&&(b >= c))
      d = b * 10 + a + c;
   else if((c >= a)&&(c >= b))
      d = c * 10 + a + b;

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

   return 0;
}


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

using namespace std;

int main(){
	int a,b;
	cin>> a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	else if(a>b){
		cout<<"a > b"<<endl;
	}
	else{
		cout<<"a == b"<<endl;
	}
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


vector<bool> sosuu; // ←これをグローバル変数にして１度だけ実行する

void searchSosuu(int N) {
	for (int i = 0; i < N; i++) {
		sosuu.emplace_back(true);
	}
	sosuu[0] = false;
	sosuu[1] = false;
	for (int i = 2; i < N; i++) {
		if (sosuu[i]) {
			for (int j = 2; i*j < N; j++) {
				sosuu[i*j] = false;
			}
		}
	}
}

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	int X;
	cin >> X;

	searchSosuu(X+ 100);

	for (int i = 0; i < 100; i++) {
		if (sosuu[X + i]) {
			cout << X + i;
			return 0;
		}
	}


}


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

int main() {
  int N,A,B;
  
  cin >> N >> A >> B ;
  
  int X=N*A;

  if (X>=B) {
    cout << B << endl;
  }

  else{
    cout << X << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;


int main(){
    int n;
    cin>>n;
    string str[n];
    int i, j;
    int a_last[n];
    int a_kazu = 0;
    int b_top[n];
    int b_kazu = 0;
    int daburu[n];
    int dabur = 0;
    int ans = 0;
    int katukatu = 0;
    for(i=0; i<n; i++){
        cin>>str[i];
        a_last[i]=0;
        b_top[i] = 0;
        daburu[i] = 0;
        for(j=0; j<str[i].size()-1; j++){  
            if(str[i][j]=='A'){
                if(str[i][j+1]=='B'){
                    ans++;
                }
            }
        }
        if(str[i][0]=='B'){
            b_top[i] = 1;
            b_kazu++;
        }
        int last = str[i].size()-1;
        if(str[i][last]=='A'){
            a_last[i] = 1;
            a_kazu++;
        }
        if(a_last[i]==1 && b_top[i]==1){
            daburu[i] = 1;
            dabur++;
            if(str[i].size()==2){
                katukatu++;
            }
        }
    }
    //cout<<ans<<" "<<a_kazu<<" "<<b_kazu<<endl;
    //cout<<a_last[0]<<" "<<b_top[0]<<endl;
    int min_h = min(a_kazu, b_kazu);
    if(a_kazu<b_kazu){
        cout<<a_kazu+ans<<endl;
    }
    else if(a_kazu>b_kazu){
        cout<<b_kazu+ans<<endl;
    }
    else{
        if((dabur == a_kazu || dabur == b_kazu) && katukatu != dabur){
            if(ans+a_kazu-1>0){
                cout<<ans+a_kazu-1<<endl;
            }
            else{
                cout<<"0"<<endl;
            }
        }
        else{
            cout<<ans+a_kazu<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;

#define LL long long
const int maxn = 100 + 100;
int H, W, n, cnt;
int num[maxn * maxn];
int ans[maxn][maxn];

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
    #endif // LOCAL

    while(scanf("%d%d", &H, &W) != EOF) {
        cnt = 1;
        scanf("%d", &n);
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &num[i]);
        }
        for(int i = 0; i < H; ++i) {
            if(i % 2 == 0) {
                for(int j = 0; j < W; ++j) {
                    if(num[cnt] == 0) {
                        ++cnt;
                    }
                    --num[cnt];
                    ans[i][j] = cnt;
                }
            } else {
                for(int j = W - 1; j >= 0; --j) {
                    if(num[cnt] == 0) {
                        ++cnt;
                    }
                    --num[cnt];
                    ans[i][j] = cnt;
                }
            }
        }
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j) {
                if(j != 0) {
                    printf(" ");
                }
                printf("%d", ans[i][j]);
            }
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int a[10001],ans[101][101];
int main()
{
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	for (int i=1;i<=n;++i)
		scanf("%d",a+i);
	int curc=1;
	for (int i=1;i<=h;++i)
	{
		if (i&1)
			for (int j=1;j<=w;++j)
			{
				ans[i][j]=curc;
				--a[curc];
				if (!a[curc])
					++curc;
			}
		else
			for (int j=w;j>=1;--j)
			{
				ans[i][j]=curc;
				--a[curc];
				if (!a[curc])
					++curc;
			}
	}
	for (int i=1;i<=h;++i)
	{
		for (int j=1;j<=w;++j)
			printf("%d ",ans[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
int N,p[200010],st[2][18][100010],log[100010];
int minp(int a,int b){return p[a]<p[b]?a:b;}
int qry(int t,int l,int r){
	int k=log[r-l];
	return minp(st[t][k][l],st[t][k][r-(1<<k)]);
}
struct item{
	int l,r,pl,pr;
	bool operator<(const item&it)const{
		return p[pl]>p[it.pl];
	}
};
item get(int l,int r){
	int pl=qry(l%2,l/2,r/2),pr=qry((l+1)%2,(pl+1)/2,(r+1)/2);
	return(item){l,r,pl,pr};
}
std::priority_queue<item>Q;
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",p+i),st[i%2][0][i/2]=i;
	N/=2;
	for(int i=2;i<=N;i++)log[i]=log[i/2]+1;
	for(int t=0;t<2;t++)
		for(int k=1;k<=log[N];k++)
			for(int i=0;i+(1<<k)<=N;i++)
				st[t][k][i]=minp(st[t][k-1][i],st[t][k-1][i+(1<<k-1)]);
	Q.push(get(0,N*2));
	while(!Q.empty()){
		item it=Q.top();Q.pop();
		printf("%d %d ",p[it.pl],p[it.pr]);
		if(it.l<it.pl)Q.push(get(it.l,it.pl));
		if(it.pl+1<it.pr)Q.push(get(it.pl+1,it.pr));
		if(it.pr+1<it.r)Q.push(get(it.pr+1,it.r));
	}
}

Measured memory_bytes: 17396
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n,x,d;
  std::cin>>n>>x>>d;

  if(d==0){
    if(x==0)std::cout<<1<<"\n";
    else std::cout<<n+1<<"\n";
    return 0;
  }

  if(d<0){
    x*=-1;
    d*=-1;
  }

  std::vector<ll> sum(n+1,0);
  rep(i,0,n)sum[i+1]=sum[i]+i;

  std::map<ll,std::map<ll,ll>> seg;

  rep(i,0,n+1){
    ll mod,plus;
    if(x>=0){
      mod=(x*i)%d;
      plus=(x*i)/d;
    }else{
      mod=(d-(-x*i)%d)%d;
      plus=-(mod-x*i)/d;
    }
    seg[mod][plus+sum[i]-sum[0]]++;
    seg[mod][plus+sum[n]-sum[n-i]]--;
  }

  ll ans=0;

  for(auto e:seg){
    ll cnt=0;
    ll prv;
    for(auto s:e.second){
      if(cnt==0)prv=s.first;

      cnt+=s.second;

      if(cnt==0)ans+=s.first-prv+1;
    }
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 51840
def bubble_sort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]


def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]


N = int(input())
cards = input().split()

C1 = cards.copy()
bubble_sort(C1, N)
print(" ".join(C1))
print("Stable")

C2 = cards.copy()
selection_sort(C2, N)
print(" ".join(C2))
if C1 == C2:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 5608
#include <stdio.h>

int main(){
    
    int S,h,m,s;
    
    scanf("%d", &S);
    
    h = S / 3600;
    S -= h * 3600;
    m = S / 60;
    S -= m * 60;
    s = S;
    
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
}

Measured memory_bytes: 2748