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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dp[2][100000+10];

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

  int N, K;
  cin >> N >> K;

  VI xs(N);
  cin >> xs;

  int crt = 0, nxt = 1;
  dp[crt][0] = 1;
  REP(j,N){
    fill(dp[nxt], dp[nxt]+100000+10, 0);

    for(int i=0;i<=K;++i){
      if(!dp[crt][i]) continue;
      (dp[nxt][i] += dp[crt][i]);
      (dp[nxt][min(K+1,i+xs[j]+1)] += MOD - dp[crt][i]);
    }
    swap(crt, nxt);
    REP(kk,K) (dp[crt][kk+1] += dp[crt][kk]) %= MOD;
    //REP(kk,20) cout << dp[crt][kk] << " ";
    //cout<<endl;
  }

//  REP(k,K) (dp[crt][k+1] += dp[crt][k]) %= MOD;
  cout << dp[crt][K] << endl;

  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int N,K;
int H[300];
long dp[333][333][333];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>H[i];
	vector<int>h(H,H+N);
	h.push_back(0);
	sort(h.begin(),h.end());
	h.erase(unique(h.begin(),h.end()),h.end());
	map<int,int>M;
	for(int i=0;i<h.size();i++)M[h[i]]=i;
	for(int i=1;i<h.size();i++)for(int k=0;k<=K;k++)dp[0][i][k]=1e17;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<h.size();j++)for(int k=0;k<=K;k++)dp[i+1][j][k]=1e17;
		int id=M[H[i]];
		for(int j=0;j<h.size();j++)
		{
			for(int k=0;k<=K;k++)
			{
				if(dp[i][j][k]>=1e17)continue;
				dp[i+1][id][k]=min(dp[i+1][id][k],dp[i][j][k]+max(0,H[i]-h[j]));
				dp[i+1][j][k-1]=min(dp[i+1][j][k],dp[i][j][k]);
			}
		}
	}
	long ans=1e17;
	for(int j=0;j<h.size();j++)ans=min(ans,dp[N][j][0]);
	cout<<ans<<endl;
}


Measured memory_bytes: 262272
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

#define rep(i, n) for(int i=0;i<(int)(n);++i)

using namespace std;

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;
}

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

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

int n;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        } else {
            while (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
}



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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl



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

    int n, a[110], sum = 0, sol = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    for (int i = 0; i < n; i++) {
        if (abs(sum - n * a[sol]) > abs(sum - n * a[i]))
            sol = i;
    }

    cout << sol;

    return 0;
}



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

int main(void){
  int M,N;
  int *a;
  int count=0;
  int sum=0;
  
  if(scanf("%d %d",&N,&M) != 2){
    printf("***SCANF ERROR***\n");
    exit(1);
  }
  if((a=(int*)malloc(sizeof(int )*N))==NULL){
    printf("***Allocation ERROR***\n");
    exit(1);
  }
  for(int i=0;i<N;i++){
    if(scanf("%d",&a[i]) != 1){
      printf("***SCANF ERROR %d***\n",i);
      exit(1);
    }
    sum+=a[i];
  }
  for(int i=0;i<N;i++){
    if(a[i]*4*M>=sum) count++;
  }
  if(count>=M) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

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

int main() {
    string s;
    cin >> s;

    if(s=="ABC")
        cout << "ARC";
    else
        cout << "ABC";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3620
open Batteries
open Printf
let () =
  let a,b,c = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in

  let sorted = List.sort compare [a;b;c] in

  Printf.printf "%s\n" @@
  if sorted = [5;5;7] then "YES" else "NO"




Measured memory_bytes: 1024
n,m,x=map(int,input().split())

s=[list(map(int, input().split())) for _ in range(n)]
ans=10**9
for i in range(2 ** n):
    cou=0
    a=[0]*(m+1)
    b=bin(i)[2:]
    if len(b)<n:
        b=str("0"*(n-len(b)))+b
    for j in range(len(b)):
        cou=0

        if b[j]=="1":
            for k in range(m+1):
                a[k]+=s[j][k]
        # print(a,cou)
        for l in range(m):
            # print(a[l+1],x)
            if a[l+1]>=x:
                cou+=1
        # print(cou)
        if cou==m:
            ans=min(ans,a[0])
if ans==10**9:
    ans=-1
print(ans)


Measured memory_bytes: 9244
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B && B == C) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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




int main()
{
    /*
    int a[5];
    int ans=0;
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            ans = ++i;
        }
    }

    cout<<ans<<endl;
    */

    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++)
    {
        if(4*i+2*(x-i)==y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){
	int var[5];
    int i;
    
    for (i = 0; i < 5; i++){
    	scanf("%d", &var[i]);
    }
    for (i = 0; i < 5; i++){
    	if (var[i] == 0){
        	printf("%d", i + 1);
        }
    }
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = c - a , y = d - b;
  cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,lec=0,loz=0;
	for(;;){
		if(scanf("%d,%d,%d",&a,&b,&c) == EOF){break;}
		if(a*a+b*b == c*c){lec++;}
		else if(a == b){loz++;}
	}
	printf("%d\n%d\n",lec,loz);
	return 0;
}

Measured memory_bytes: 0
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
num1=Counter(v[0::2])
num2=Counter(v[1::2])
num1sort=sorted(num1.items(),key=lambda x:x[1],reverse=True)
num2sort=sorted(num2.items(),key=lambda x:x[1],reverse=True)
if num1sort[0][0] == num2sort[0][0]:
    if (len(num1) == 1 ):
        if(len(num2) == 1):
            print(n//2)
        else:
            print(n//2-num2sort[1][1])
    elif (len(num2) == 1):
        print(n//2-num1sort[1][1])
    else:
        p1 = num1sort[0][1] + num2sort[1][1]
        p2 = num1sort[1][1] + num2sort[0][1]
        if p1 > p2:
            print(n-p1)
        else:
            print(n-p2)
else:
    print(n-num1sort[0][1]-num2sort[0][1])

Measured memory_bytes: 21184
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func merge(A []int, left int, mid int, right int) int {
	//A[left:right]を、midで2つに分ける
	n1 := mid - left
	n2 := right - mid
	L := make([]int, n1)
	R := make([]int, n2)
	cnt := 0

	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L = append(L, 1000000000)
	R = append(R, 1000000000)
	i := 0
	j := 0

	for k := left; k < right; k++ {
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
		} else {
			//反転
			A[k] = R[j]
			j++
			cnt += n1 - i
			//n1: Lの個数
			//i: Lのindex
			//n1-i: LとRをマージした時、R[j]より後に移動するLの要素数
		}
	}

	return cnt
}

func mergeSort(A []int, left int, right int) int {
	if left+1 < right {
		//fmt.Println(A[left:right])
		mid := (left + right) / 2
		//左半分に対して、マージソート
		a := mergeSort(A, left, mid)
		//右半分に対して、マージソート
		b := mergeSort(A, mid, right)
		//↑をマージ
		c := merge(A, left, mid, right)
		return a + b + c
	} else {
		return 0
	}
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n)
	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	ans := mergeSort(A, 0, n)
	fmt.Println(ans)
	return
}



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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int a, b;
  cin >> a >> b;
  int p = 1;
  for (int i = 0; i < a; i++) p *= 100;
  cout << b * p + (b == 100 ? p : 0) << '\n';
  return 0;
}

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

typedef long long ll;

const int N = 4e6 + 100;
int mod = 998244353;


namespace Combi {
    int fact[N], inv[N];

    int bm(int b, int p, int m) {
        if(p == 0) return 1%m;
        int t = bm(b,p/2,m);
        t = (1ll*t*t)%m;
        if(p&1) return 1ll*t*b%m;
        return t;
    }

    int C(int n, int r) {
        if(n < 0 or r < 0 or r > n) return 0;
        int ret = 1ll*fact[n]*inv[r]%mod;
        ret = 1ll*ret*inv[n-r]%mod;
        return ret;
    }
    // X1 + X2 + ... + Xvar = Sum
    int no_of_eqns(int var, int sum) {
        return C(sum+var-1,var-1); // Xi >= 0
        // return C(sum-1,var-1); // Xi > 0
    }
    void init() {
        fact[0] = 1;
        for(int i = 1; i < N; i++) {
            fact[i] = 1ll*fact[i-1]*i%mod;
        }
        inv[N-1] = bm(fact[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--) {
            inv[i] = 1ll*inv[i+1]*(i+1)%mod;
        }
    }
}


int n, m;

long long f(int var, int odd, int m) {
    if(var < odd) return 0;
    int sum = m-odd;
    if(sum < 0) return 0;
    if(sum&1) return 0;
    sum /= 2;
    return (1ll*Combi::no_of_eqns(var, sum)*Combi::C(var, odd))%mod;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    Combi::init();
    cin >> n >> m;
    long long ans = 0;
    for(int odd = 0; odd <= m; odd++) {
//        cout << "a: " << f(n, odd, 3*m) << endl;
//        cout << "b: " << f(n, odd, m) << endl;
//        cout << "c: " << f(n-1, odd, m) << endl;
        ans += f(n,odd,3*m)-n*f(n,odd,m)+n*f(n-1,odd,m);
        ans %= mod;
    }
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}



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

int main() {
  long long r, D, start;
  cin >> r >> D >> start;
  
  long long temp = start;
  
  for (int i = 0; i<10; i++){
    temp = r*temp-D; 
    cout << temp << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int a,b,c=1,d=1;
  cin>>a>>b;
  c=b-1;
  a=a-1;
  for(int i=0;i<a;i++){
    b=b*c;
  }
  if(a<1) b*(c+1);
  cout<<b<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // Happy candle、x列目を決めたらx+1列目以降のひっくり返す白石も決まる
    ll N, Q;
    cin >> N >> Q;
    vector<int> col(N, -1);
    vector<int> row(N, -1);
    int ccur = N-1, rcur = N-1;
    ll white = 0;
    rep(i, Q) {
        int a, x;
        cin >> a >> x;
        --x;
        if (a == 1) {
            if (x < rcur) {
                white += ccur - 1;
                for (int j = x+1; j < N; j++) {
                    if (col[j] != -1) break;
                    col[j] = ccur - 1;
                }
                rcur = x;
            } else {
                white += col[x];
                assert (col[x] != -1);
            }
        } else {
            if (x < ccur) {
                white += rcur - 1;
                for (int j = x+1; j < N; j++) {
                    if (row[j] != -1) break;
                    row[j] = rcur - 1;
                }
                ccur = x;
            } else {
                white += row[x];
                assert (row[x] != -1);
            }
        }
    }
    ll ans = (N-2) * (N-2) - white;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int n, k, cnt, n1[105], k1[105], a[105];
int main(){
	cin>> n>> k;
	for(int i=1; i<=k; i++){
		cin>> k1[i];
		for(int j=1; j<=k1[i]; j++){
			cin>> n1[j];
			a[n1[j]]++;
		}
	}
	for(int i=1; i<=n; i++){
		if(a[i] == 0) cnt++;
	} 
	cout<< cnt;
	return 0;
} 

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

int digits(int x) { return (int)log10(x) + 1; }

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

    int n;
    cin >> n;

    int ans = 0;
    while (n > 0) {
        int d = digits(n);
        if (d % 2 == 1) { ans += n - (int)pow(10, d - 1) + 1; }
        n = (int)pow(10, d - 1) - 1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{

    int a;
    int b;
    int c;
    int d;

    cin >> a >> b >> c >> d;

    int x;
    int y;

    x=(a+b+c+d)/60;
    y=(a+b+c+d)-(x*60);

    cout << x << endl;
    cout << y << endl;

    return 0;

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int h, w;
string s[1010];
vector<vector<int>> dist(1010,vector<int>(1010, inf));
int main(){
    cout << fixed << setprecision(10);
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    ll ans = 0;
    vector<pair<int,int>> vii;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                // cout << "Yes" << endl;
                dist[i][j] = 0;
                vii.push_back({i,j});
            }
        }
    }
    queue<pair<int,int>> que;
    for(auto u : vii) que.push({u.first, u.second});
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
        rep(i,4){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < h && ny >= 0 && ny < w){
                // cout << "Yes" << endl;
                if(dist[nx][ny] == inf){
                    // cout << "update" << endl;
                    dist[nx][ny] = dist[x][y] + 1;
                    ans = dist[x][y] + 1;
                    que.push({nx,ny});
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25072
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    map<string, ll> M;
    for(int i=0; i<N; i++){
        string S; cin >> S;
        sort(S.begin(), S.end());
        M[S]++;
    }
    
    ll ans = 0;
    for(auto m:M){
        ans += m.sc * (m.sc - 1) / 2;
    }
    
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 11136
#include<stdio.h>

int i, j, N, k, a[3];

void swap(int, int);

int main(){
	N = 3;

	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	

	for(i = 0; i < N-1; i++){
		for(j = i; j < N; j++){
			if(a[i] > a[j]){
				swap(i, j);
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);
}
	void swap(int i, int j){
		k = a[i];
		a[i] = a[j];
		a[j] = k;
	}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define MAX 500000
#define NIL -1
using namespace std;
class Point{
public:
    int id,x,y;
    Point(){}
    Point(int id,int x,int y):id(id),x(x),y(y){}
    bool operator < (const Point &p) const {
        return id<p.id;
    }
    void print(){
        printf("%d\n",id);
    }
};
class Node{
public:
    int location,l,r;
    Node(){}
};
Point p[MAX];
Node T[MAX];
int n,q,np;
vector<Point>ans;
bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}
int make2DTree(int l,int r,int depth){
    if(l>=r)return NIL;
    int mid=(l+r)/2;
    int t=np++;
    if(depth%2==0)
        sort(p+l,p+r,lessX);
    else
        sort(p+l,p+r,lessY);
    T[t].location=mid;
    T[t].l=make2DTree(l,mid,depth+1);
    T[t].r=make2DTree(mid+1,r,depth+1);
    return t;
}
void find(int u,int sx,int tx,int sy,int ty,int depth){
    int i=T[u].location;
    if(sx<=p[i].x && p[i].x<=tx && sy<=p[i].y && p[i].y<=ty)
        ans.push_back(p[i]);
    if(depth%2==0){
        if(T[u].l!=NIL)
            if(sx<=p[i].x)find(T[u].l,sx,tx,sy,ty,depth+1);
        if(T[u].r!=NIL)
            if(p[i].x<=tx)find(T[u].r,sx,tx,sy,ty,depth+1);
    }
    else{
        if(T[u].l!=NIL)
            if(sy<=p[i].y)find(T[u].l,sx,tx,sy,ty,depth+1);
        if(T[u].r!=NIL)
            if(p[i].y<=ty)find(T[u].r,sx,tx,sy,ty,depth+1);
    }
}
int main()
{
    int x,y,sx,tx,sy,ty;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        p[i]=Point(i,x,y);
        T[i].l=T[i].r = NIL;
    }
    np=0;
    make2DTree(0,n,0);
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d%d%d",&sx,&tx,&sy,&ty);
        ans.clear();
        find(0,sx,tx,sy,ty,0);
        //int len=ans.size();
        sort(ans.begin(),ans.end());
        for(vector<Point>::iterator it = ans.begin();it!=ans.end();it++)
            it->print();
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 14572
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    for (ll a=-250;a<=250;++a)
        for (ll b=-250;b<=250;++b)
            if ((a*a*a*a*a)-(b*b*b*b*b)==n)
            {
                cout<<a<<" "<<b;
                return 0;
            }
    return 0;
}

Measured memory_bytes: 3620
// ===========================================
// 20.03.05 backjoon 2437. 저울 (greedy)
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ET "\n"
#define CLR(arr) memset(arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;



int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    
    cout << n / 2 + (n&1) << ET;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;



int main()
{
	int S;
	cin >> S;
	int top, bottom;
	top = S / 100;
	bottom = S % 100;
	if ((top > 12 || top == 0) && (bottom > 12 || bottom == 0)) {
		cout << "NA" << endl;
	}
	else if (top <= 12 && top != 0 && (bottom > 12 || bottom == 0)) {
		cout << "MMYY" << endl;
	}
	else if ((top > 12 || top == 0) && bottom <= 12 && bottom != 0) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
}

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

ll n,b,a,ans;

int main(){
    cin>>n>>b;
    ans=b-1;
    b=1;
    rep(i,n-1){
        cin>>a;
        if(a>b+1){
            ans+=(a-1)/(b+1);
            a=1;
        }
        b=max(a,b);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct trnode
{
    int c,l,r,lc,rc,p;
}tr[20010];int trlen;
inline void update(int now)
{
	int lc=tr[now].lc,rc=tr[now].rc;
	if(tr[lc].c<tr[rc].c)tr[now].c=tr[lc].c,tr[now].p=tr[lc].p;
	else tr[now].c=tr[rc].c,tr[now].p=tr[rc].p;
}
int cnt[10010];
inline void bt(int l,int r)
{
    trlen++;int now=trlen;
    tr[now].l=l;tr[now].r=r;tr[now].lc=tr[now].rc=-1;
    if(l==r)tr[now].c=cnt[l],tr[now].p=l;
    else
    {
        int mid=(l+r)/2;
        tr[now].lc=trlen+1;bt(l,mid);
        tr[now].rc=trlen+1;bt(mid+1,r);
        update(now);
    }
}
inline int findmin(int now,int l,int r)
{
    if(l==tr[now].l && tr[now].r==r)return tr[now].p;
    int lc=tr[now].lc,rc=tr[now].rc,mid=(tr[now].l+tr[now].r)/2;
    if(mid+1<=l)return findmin(rc,l,r);
    else if(r<=mid)return findmin(lc,l,r);
    else return min(findmin(lc,l,mid),findmin(rc,mid+1,r));
}
void change(int now,int x,int k)
{
    if(tr[now].l==tr[now].r){tr[now].c=k;return ;}
    int lc=tr[now].lc,rc=tr[now].rc,mid=(tr[now].l+tr[now].r)/2;
    if(x<=mid)change(lc,x,k);
    else change(rc,x,k);
    update(now);
}
struct node
{
	int x,y,next;
}a[20010];int len,last[10010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
int w[10010],ex[10010];
bool v[10010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    for(int i=1;i<n;i++)
    {
    	int x=read(),y=read();
    	ins(x,y),ins(y,x);cnt[x]++,cnt[y]++;
    }
    for(int i=1;i<=n;i++)w[i]=read();
	sort(w+1,w+n+1);bt(1,n);
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
    	int x=findmin(1,1,n);change(1,x,n+1),v[x]=true;
    	ans+=1LL*cnt[x]*w[i];ex[x]=w[i];
    	for(int k=last[x];k;k=a[k].next)
		{
			int y=a[k].y;
			if(v[y]==false)cnt[y]--,change(1,y,cnt[y]);
		}
    }printf("%lld\n",ans);
    for(int i=1;i<=n;i++)pr1(ex[i]);
   	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define N 100005
#define INF 0x3f3f3f3f 
#define mod 1000000007
using namespace std;
typedef long long ll;
int ans;
int parent[N];

int find(int v){
    if(parent[v] == v) return v;
    return parent[v] = find(parent[v]);
}

void Union(int v, int u){
    parent[find(v)] = find(u);
}

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) parent[i] = i;
    int arr[n+1];
    for(int i=1; i<=n; i++) cin >> arr[i];
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        Union(a,b);
    }
    for(int i=1; i<=n; i++){
        if(arr[i] == i) ans++;
        else{
            if(find(arr[i]) == find(i)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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


int main()
{
  int n, d;
  cin >> n >> d;
  cout << (n + d * 2) / (d * 2 + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
  int a, b, c, n, m;
  n = 0; m = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (a * a + b * b == c * c) n ++;
    if (a == b) m ++;
  }
  printf("%d\n%d\n", n, m);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,m;
  cin>>n>>m;
  long long int a[n],i,k=0;
  
  float j,sum=0;
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i];
  }
  j=(sum/(4*m));
  for(i=0;i<n;i++)
  {
    if(a[i]>=j)
       {
         k++;
       }
    }

       if(k>=m)
       cout<<"Yes";
       else
       cout<<"No";
       }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	cin >> n;
	vector< pair<int,int> > ms;
	if(n == 0) break;
	int c,m,s;
	REP(i,n){
	    cin >> c;
	    ms.PB( pair<int,int>(0,c) );
	    for(int j=0;j<4;j++){
		cin >> m >> s;
		ms[i].first += 60 * m + s;
	    }
	}
	sort(ALL(ms));
	cout << ms[0].second << endl;
	cout << ms[1].second << endl;
	cout << ms[ms.size()-2].second << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define int ll

int a[123456],sumi[123456];
main(){
    std::ios::sync_with_stdio(false); cin.tie(NULL);
    int n,m,v,p;
    cin>>n>>m>>v>>p;
    int i,j;
    f(i,1,n+1){
    	cin>>a[i];
    }
    sort(a+1,a+n+1);
    f(i,1,n+1){
    	if(i<n+1-i)
    		swap(a[i],a[n+1-i]);
    }
    f(i,1,n+1){
    	sumi[i]=sumi[i-1]+a[i];
    }
    i=1,j=1;
    int bad=0,left=0,haha,gg,cnt=0;
    while(j<=n){
    	//cout<<a[i]-a[j]<<" "<<j<<endl;
    	while(a[i]-a[j]>m){
    		bad++;
    		i++;
    	}
    	if(bad>=p)
    		break;
    	left=p-bad-1;
    	haha=v-(n+1-j)-bad-left;
    	//cout<<j<<" "<<bad<<endl;
    	if(haha<=0){
    		cnt++;
    		j++;
    		continue;
    	}
    	gg=sumi[j-1]-sumi[p-1];
    	//cout<<<<endl;
    	if((j-p)*(a[j]+m)-gg>=haha*m)
    	{
    		cnt++;
    	}
    	else{
    		break;
    	}
    	j++;
    }
    cout<<cnt<<endl;
    return 0;   
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[i] = mp(i+1, t);
	}

	sort(ALL(a), [](const pair<int, int>& x, const pair<int, int>& y) {
		return x.second < y.second;
	});

	for (int i = 0; i < n; i++) cout << a[i].first << " ";
	cout << endl;
    return 0;
}


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

using namespace std;

int main(void)
{
    long long n, k, i, sum = 0;
    cin >> n >>k;
    int a[n];
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a+n);
    for(i = 0; i < n-k; i++)
        sum+=a[i];
    cout << sum;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
int main(){
	char At,Tc;
	std::cin>>At>>Tc;
	if(At=='H'){
		if(Tc=='H'){
			std::cout<<"H\n";
			return 0;
		}
		else if(Tc=='D'){
			std::cout<<"D\n";
			return 0;
		}
	}
	else{
		if(Tc=='H'){
			std::cout<<"D\n";
			return 0;
		}
		else if(Tc=='D'){
			std::cout<<"H\n";
			return 0;
		}
	}	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=3e5+5;
int n,s[N];
long long ans;

void init()
{
    int i;
    scanf("%d",&n);
    for(i=1;i<=2*n;++i) scanf("%d",&s[i]);
    sort(s+1,s+2*n+1);
}

void work()
{
    int i;
    for(i=1;i<=2*n;++i) ans+=1LL*(i-1)*s[i];
    printf("%.12lf\n",1.0*ans/(2*n-1));
}

int main()
{
    init();
    work();
    return 0;
}

Measured memory_bytes: 1024
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint n, s;
	cin >> n >> s;

	auto check = [&](lint b) {
		if (b < 2) return false;
		lint tmp = n, sum = 0;
		while (tmp) {
			sum += tmp % b;
			tmp /= b;
		}
		return sum == s;
	};

	auto end = [&](lint b) {
		cout << b << "\n";
		exit(0);
	};

	if (n < s) end(-1);

	for (int i = 2; i < 500000; i++) if (check(i)) end(i);
	for (int i = 500000; i >= 1; i--) {
		lint b = (n - s) / i + 1;
		if (check(b)) end(b);
	}

	if (check(n + 1)) end(n + 1);
	end(-1);

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int arr[1000000];
int main(){
    int a,b,c,i,n;
    cin>>a>>b>>c;
    if(c>=a&&c<=b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
n, y = map(int, input().split())

for a in range(n + 1):
    for b in range(n - a + 1):
        c = n - a - b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(a, b, c)
            exit()
print(-1, -1, -1)

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

int main() {
	int n,m;
	cin>>n>>m;
	int a[n][m], b[m];
	for (int i = 0; i < n; i++)
	{
		for (int j= 0; j < m; j++)
		{
			cin>>a[i][j];/* code */
		}
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>b[i];/* code */
	}

	int c[n-1];
	for (int i = 0; i <n; ++i)
	{
		c[i]=0;/* code */
	}
	for(int j=0;j<n;++j)
	{
		for(int i=0;i<m;++i) 
			{
				
				c[j]+=a[j][i]*b[i];
				
			}
	}
	
	
	for (int i = 0; i < n; ++i)
	{
		cout<<c[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(void){
int X,Y,N;
scanf("%d %d",&X,&Y);

if(X==1&&Y==1)
puts("1000000");

else if((X==2&&Y==2)||(X==1&&Y==3)||(X==3&&Y==1))
puts("400000");

else if((X==3&&Y==3)||(X==2&&Y>3)||(Y==2&&X>3))
puts("200000");

else if((X==1&&Y==2)||(X==2&&Y==1))
puts("500000");

else if((X==2&&Y==3)||(X==3&&Y==2)||(X==1&&Y>3)||(Y==1&&X>3))
puts("300000");

else if((X==3&&Y>3)||(Y==3&&X>3))
puts("100000");

else if(X>3&&Y>3)
puts("0");

return 0;
}

Measured memory_bytes: 128
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, i, j, max, a;
    double[] x, y;
    String s;
    char[] c;

    for(;;out.println(max)){
      n = sc.nextInt(); if(n == 0)break;
      x = new double[n]; y = new double[n];
      for(i = 0;i < n;i++){
        s = sc.next();
        c = new char[s.length()];
        for(j = 0;j < s.length();j++)c[j] = s.charAt(j);
        for(j = 0;j < s.length();j++)if(c[j] == ','){
          x[i] = readdouble(c, 0, j); break;
        }
        y[i] = readdouble(c, j + 1, s.length());
      }
      max = 1;
      for(i = 0;i < n;i++)for(j = i + 1;j < n;j++){
        if((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < 4){
          a = solve(x, y, n, i, j);
          if(max < a)max = a;
        }
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static int solve(double[] x, double[] y, int n, int i, int j){
    int count, res, k;
    double ax, ay, bx, by, hx, hy, lx, ly, s, ah;

    lx = x[j] - x[i]; ly = y[j] - y[i];
    s = lx * lx + ly * ly;
    ah = Math.sqrt(s) / 2;

    hx = x[i] + lx * ah / Math.sqrt(s);
    hy = y[i] + ly * ah / Math.sqrt(s);

    bx = ly * Math.sqrt((1.0 - ah * ah) / s);
    by = -lx * Math.sqrt((1.0 - ah * ah) / s);

    ax = hx + bx; ay = hy + by;
    bx = hx - bx; by = hy - by;

    count = 0;
    for(k = 0;k < n;k++)
      if((ax - x[k]) * (ax - x[k]) + (ay - y[k]) * (ay - y[k]) < 1.00001)count++;
    res = count;
    count = 0;
    for(k = 0;k < n;k++)
      if((bx - x[k]) * (bx - x[k]) + (by - y[k]) * (by - y[k]) < 1.00001)count++;
    if(res < count)res = count;
    return res;
  }
  private static double readdouble(char[] ch, int l, int r){
    int i;
    double res, d, s = 1;
    if(ch[l] == '-'){ s = -1; l++; }
    d = 1.0; res = 0.0;
    for(i = l;i < r;i++){
      if(ch[i] == '.')break;
      d *= 10;
    }
    d /= 10;
    for(i = l;i < r;i++)if(ch[i] != '.'){
      res += d * (double)(ch[i] - '0');
      d /= 10;
    }
    return res * s;
  }
}

Measured memory_bytes: 20456
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()

bus = 0
pas = 0
l = 0
r = 0
while l < N:
    if r == N:
        if pas == 0:
            break
        else:
            bus += 1
            break
    elif T[l] + K >= T[r]:
        pas += 1
        r += 1
        if pas == C:
            bus += 1
            l = r
            pas = 0
    else:
        l = r
        bus += 1
        pas = 0
print(bus)

Measured memory_bytes: 50648
#include <cstdio>
#include <set>
#include <queue>
#include <cstring>
using namespace std;
typedef pair<int,int> pos;
typedef pair<pos,pos> two;
typedef pair<int,two> node;
int map[52][52];
int next[4][4] = {
  { 1, 0, -1, 0 },
  {-1, 0,  1, 0 },
  { 0, 1,  0,-1 },
  { 0,-1,  0, 1 },
};
int main()
{
  for(;;){
    int x,y,tx,ty,kx,ky;
    scanf("%d %d",&x,&y);
    if(x == 0 || y == 0) break;
    memset(map,0,sizeof(map));
    scanf("%d %d",&tx,&ty);
    scanf("%d %d",&kx,&ky);
    set<two> memo;
    two t = make_pair(make_pair(tx,ty),make_pair(kx,ky));
    memo.insert(t);
    queue<node> q;
    node n = make_pair(0,t);
    q.push(n);
    int i,j;
    for(i=1; i<=y; i++){
      for(j=1; j<=x; j++){
        int n;
        scanf("%d",&n);
        map[i][j] = n;
      }
    }
    for(;;){
      if(q.empty()){
        printf("NA\n");
        break;
      }
      node n = q.front();
      q.pop();
      if(n.first > 100){
        printf("NA\n");
        break;
      }
      pos t = n.second.first;
      pos k = n.second.second;
      if(t == k){
        printf("%d\n",n.first);
        break;
      }
      two temp;
      for(int i=0; i<4; i++){
        pos tn = make_pair(t.first+next[i][0], t.second+next[i][1]);
        pos kn = make_pair(k.first+next[i][2], k.second+next[i][3]);
        bool bt = true, bk = true;
        if(tn.second == 0 || tn.second > y || tn.first == 0 || tn.first > x ||
           map[tn.second][tn.first] == 1) bt = false;
        if(kn.second == 0 || kn.second > y || kn.first == 0 || kn.first > x ||
           map[kn.second][kn.first] == 1) bk = false;
        if(!bt && !bk){
          continue;
        }else if(!bt){
          temp = make_pair(t,kn);
        }else if(!bk){
          temp = make_pair(tn,k);
        }else{
          temp = make_pair(tn,kn);
        }
        if(memo.insert(temp).second){
          node nd = make_pair(n.first+1,temp);
          q.push(nd);
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 12164
#include <bits/stdc++.h>
using namespace std;
 
mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());
 
#define st first
#define nd second
#define pb push_back
 
#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
 
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 3e3+5;

#define int long long

int n, m, area;
bool visited[N][N], blocked[N][N][2];
vector<int> xs, ys;
vector<tuple<int, int, int>> ns, ms;
 
bool isOut(int x, int y) {
  if(x == -1 or y == ys.size() or !y or x == xs.size() - 1) return true;
  return false;
}

bool isBlocked(int x, int y, int op) {
  if(x < 0 or x >= xs.size()) return false;
  if(y < 0 or y >= ys.size()) return false;
  return blocked[x][y][op];
}

bool isVisited(int x, int y) {
  if(x < 0 or x >= xs.size()) return false;
  if(y < 0 or y >= ys.size()) return false;
  return visited[x][y];
}

int bfs(int xst, int yst) {
  queue<pair<int, int>> q;
  q.push({xst, yst});
  while(q.size()) {
    int x = q.front().st;
    int y = q.front().nd;
    q.pop();
    if(isVisited(x, y)) continue;
    if(isOut(x, y)) return 0;
    
    visited[x][y] = true;
    area += (xs[x+1] - xs[x]) * (ys[y] - ys[y-1]);

    if(!isBlocked(x, y, 0)) q.push({x, y+1});
    if(!isBlocked(x, y-1, 0)) q.push({x, y-1});
    if(!isBlocked(x+1, y-1, 1)) q.push({x+1, y});
    if(!isBlocked(x, y-1, 1)) q.push({x-1, y});
  }
  return 1;
}

int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  xs.pb(0), ys.pb(0);
  while(n--) {
    int a, b, c;
    cin >> a >> b >> c;
    ns.pb({a, b, c});
    xs.pb(a), xs.pb(b), ys.pb(c);
  } 

  while(m--) {
    int d, e, f;
    cin >> d >> e >> f;
    ms.pb({d, e, f});
    xs.pb(d), ys.pb(e), ys.pb(f);
  }

  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

  for(int i = 0; i < ns.size(); i++) {
    int ai, bi, ci;
    tie(ai, bi, ci) = ns[i];

    int ci_pos = lower_bound(ys.begin(), ys.end(), ci) - ys.begin();
    int pos = lower_bound(xs.begin(), xs.end(), ai) - xs.begin();

    while(pos < xs.size() and xs[pos] < bi) {
      blocked[pos][ci_pos][0] = true;
      pos++;
    }
  }

  for(int i = 0; i < ms.size(); i++) {
    int dj, ej, fj;
    tie(dj, ej, fj) = ms[i];

    int dj_pos = lower_bound(xs.begin(), xs.end(), dj) - xs.begin();
    int pos = lower_bound(ys.begin(), ys.end(), ej) - ys.begin();

    while(pos < ys.size() and ys[pos] < fj) {
      blocked[dj_pos][pos][1] = true;
      pos++;
    }
  }

  int x = lower_bound(xs.begin(), xs.end(), 0) - xs.begin();
  int y = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();

  cout << (bfs(x, y) ? to_string(area) : "INF") << "\n";
}

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

struct position{
    int y, x;
};

int H, W, D;
vector<vector<int>> space;
vector<position> number_position;
vector<int> need_magic_cost;

int fill_need_magic_cost(int now){
    if(now + D >= H * W){
        return need_magic_cost[now] = 0;
    }else{
        return need_magic_cost[now] = fill_need_magic_cost(now + D) + abs(number_position[now].y - number_position[now + D].y) + abs(number_position[now].x - number_position[now + D].x);
    }
}

int main(){
    cin >> H >> W >> D;
    number_position.resize(H * W);
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int num;
            cin >> num;
            number_position[num - 1] = {i, j};
        }
    }
    need_magic_cost.resize(H * W);
    for(int i = 0; i < D; i++){
        fill_need_magic_cost(i);
    }
    int Q;
    cin >> Q;
    cout << endl;
    for(int i = 0; i < Q; i++){
        int left, right;
        cin >> left >> right;
        cout << need_magic_cost[left - 1] - need_magic_cost[right - 1] << endl;
    }
}


Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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 N;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    bool ok = true;
    rep(i,N) {
        if (i) {
            if (A[i] > A[i-1]+1) ok = false;
        } else {
            if (A[i]) ok = false;
        }
    }
    if (!ok) {
        cout << -1 << ln;
        return 0;
    }

    reverse(all(A));
    ll cnt = 0;
    rep(i,N) {
        if (A[i]) {
            if (A[i] == A[i+1]+1) cnt++;
            else cnt += A[i];
        }
    }

    cout << cnt << ln;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    ans = max(ans, i * i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
using namespace std;
int a[110];
int main()
{
    int n,c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
    {int g=i;
    for(int j=i;j<n;j++)
    if(a[j]<a[g])
    g=j;
    swap(a[i],a[g]);
    if(i!=g)c++;
    }
    for(int i=0;i<n;i++)
    {
        if(i>0)printf(" ");;
        printf("%d",a[i]);
    }
    printf("\n%d\n",c);
    return 0;
}

Measured memory_bytes: 3208
import sys
import math
sys.setrecursionlimit(int(1e6))

A, B = map(int, input().split())

pa = A / 0.08
d = 100 / 8

ans = -1
for p in range(int(pa), int(pa + d)+1):
    if (A == int(p * 0.08)) and (B == int(p * 0.10)):
        ans = p
        break

print(ans)


Measured memory_bytes: 3060
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
X,L = Line(N,2)

from operator import itemgetter
def index_sort(A):
    return sorted(enumerate(A),key=itemgetter(1))

B = [X[i]+L[i] for i in range(N)]
C = index_sort(B)
X = [X[c[0]] for c in C]
L = [L[c[0]] for c in C]

count = 0
right = -float('inf')
for i in range(N):
    now = X[i]-L[i]
    if now>=right:
        count += 1
        right = X[i]+L[i]
    else:
        continue

print(count)

Measured memory_bytes: 77660
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int m;
int d;
long long c;
long long digits,sums;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>d>>c;
		digits+=c;
		sums+=d*c;
	}
	cout<<digits-1LL+(sums-1LL)/9LL<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int a,b,c,k;
    cin >> a >> b >>c;
    cin >> k;

    for(int i=-0;i<k;i++){

        if(max({a,b,c})==a){
            a=a*2;
        }else if(max({a,b,c})==b){
            b=b*2;
        }else{
            c=c*2;
        }
    }

    cout << a+b+c << endl;

    return 0;
}

Measured memory_bytes: 256