akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  multiset<int> s;
  int sum = 0;
  REP(i, n) {
    int x;
    cin >> x;
    sum += x;
    s.insert(x);
  }
  int pos = round(double(sum) / n);
  int ans = 0;
  for(auto itr = s.begin(); itr != s.end(); ++itr) {
    ans += pow(pos - *itr, 2.0);
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    vector<int> dp(100100, 0);
    for(int i = 0; i < N; i++)cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l, r, d;
  cin >> l >> r >> d;
  
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


int main(int argc, char **argv) {
    long long N, X;
    cin >> N >> X;
    vector<int> A;
    A.resize(N, 0);
    REP(i, N) cin >> A[i];

    long long ans=0;


    REP(i, N-1){
        if(A[i] + A[i+1] > X){
            if(A[i+1]){
                if(A[i] > X){
                    ans += A[i+1];
                    A[i+1] = 0;
                }
                else{
                    ans += A[i]+A[i+1]-X;
                    A[i+1] -= A[i]+A[i+1]-X;
                }
            }
            if(A[i] > X){
                ans += A[i]-X;
                A[i] -= A[i]-X;
            }
        }

}

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



Measured memory_bytes: 768
#include<iostream>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int>P;

int main() {
	int n;
	while (cin >> n,n) {
		P a[300];
		a[0] = P(0, 0);
		for (int i = 1; i < n; i++) {
			int m, d;
			cin >> m >> d;
			if (d == 0) {
				a[i] = P(a[m].first - 1, a[m].second);
			}
			else if (d == 1) {
				a[i] = P(a[m].first, a[m].second - 1);
			}
			else if (d == 2) {
				a[i] = P(a[m].first + 1, a[m].second);
			}
			else {
				a[i] = P(a[m].first, a[m].second + 1);
			}
		}
		int xm=1e-8, xs=1e8, ym=1e-8, ys=18;

		for (int i = 0; i < n; i++) {
			xm = max(a[i].first, xm);
			xs = min(xs, a[i].first);
			ym = max(a[i].second, ym);
			ys = min(a[i].second, ys);
		}
		cout << xm - xs + 1 << ' ' << ym - ys + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 1e5 + 10;

int n;
vector<int> x(N);
int m;
ll k;
vector<int> nxt(N);
vector<int> diff(N);

vector<int> nxt_perm(vector<int> v, vector<int> nxt) {
	 int len = v.size();
	 vector<int> ret(len);

	 for (int i = 0; i < len; i++) {
	 	ret[i] = v[nxt[i]];
	 }

	 return ret;
}

vector<int> perm_pow(vector<int> v, ll e) {
	int len = v.size();
	vector<int> ret;

	if (e == 0) {
		ret.resize(len);
		iota(ret.begin(), ret.end(), 0);
		return ret;
	}

	if (e % 2 == 1) {
		ret = v;
		return nxt_perm(perm_pow(ret, e - 1), v);
	}

	vector<int> root = perm_pow(v, e / 2);
	ret = nxt_perm(root, root);
	return ret;

}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}

	cin >> m >> k;
	
	iota(nxt.begin(), nxt.end(), 0);
	for (int i = 0; i < m; i++) {
		int at;
		scanf("%d", &at);
		at--;

		swap(nxt[at - 1], nxt[at]);
	}

	nxt = perm_pow(nxt, k);

	for (int i = 0; i < n - 1; i++) {
		diff[i] = x[nxt[i] + 1] - x[nxt[i]];
	}

	ll curr = x[0];	
	printf("%lld\n", curr);
	for (int i = 1; i < n; i++) {
		curr += diff[i - 1];
		printf("%lld\n", curr);
	}
 
	return 0;
}

Measured memory_bytes: 68864
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

int n,m;
long long a,ans=0;
priority_queue<long long ,vector<long long> > que;
int main() {
	cin>>n>>m;
	for(int i=0;i<n;++i){
		cin>>a;
		que.push(a);
	}
	for(int i=0;i<m;++i){
		long long g=que.top();que.pop();
		g/=2;
		que.push(g);
	}
	for(int i=0;i<n;++i){
		ans+=que.top();que.pop();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,c,k;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&k);
	while(a>=b && k)b<<=1,--k;
	while(b>=c && k)c<<=1,--k;
	if(a<b && b<c)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  ll x;
  cin >> x;
  for(int i = -118; i <= 119; i++){
    for(int j = -119; j <= 118; j++){
      if(pow(i,5)-pow(j,5) == x){
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define lld long double
#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 pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
#define endl '\n'
 
// void print_vi(vi a){
//     for (auto i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }
 
void solve(){

    int n;
    cin >> n;
    vi ans (n+1 , 0);
    int val;
    for (int a = 1 ; a < 101 ;  a++){
        for (int b= 1 ; b < 101 ; b++){
            for (int c = 1 ; c < 101 ; c++){
                val = a*a + b*b + c*c + a*b + b*c + c*a;
                if (val > n){
                    continue;
                }
                ans [val]++;
            }
        }
    }
    for (int i = 1 ; i <= n ; i++){
        cout << ans[i] << endl;
    }
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    int t = 1;
    // cin >> t;
    
    while(t--){ 
        solve();
        cout << endl;
    }
}

Measured memory_bytes: 3684
#include <cmath>
#include <cstdio>
#include <cmath>
#include <algorithm>
 
using namespace std;

#define ll long long

inline ll read(){
	ll AK=1,IOI=0;
	char ch=0;
	while (ch<'0'||ch>'9'){
		AK=ch=='-'?-1:1;
		ch=getchar();
	}
	while (ch<='9'&&ch>='0'){
		IOI*=10;
		IOI+=ch-'0';
		ch=getchar();
	}
	return AK*IOI;
}
int main(){
	ll n=read(),m=read();
	ll answer=(n*2+m)/4;
	if (answer<n) printf("%lld",m/2);
			else printf("%lld",answer);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N,W;
    cin >> N >> W;
    vector<pair<int,int>> tresure(N+1);
    for ( int i = 0; i < N; ++i ) {
        cin >> tresure[i].first >> tresure[i].second;
    }
    //vector<vector<int>> dp(N);
    int dp[101][10001];

    for ( int w = 0; w <= W; ++w ) {
        dp[0][w] = 0;
    } 

    for ( int i = 0; i < N; ++i ) {
        for ( int w = 0; w <= W; ++w ) {
            if  (w >= tresure[i].second )dp[i+1][w] = max(dp[i][w], dp[i][w-tresure[i].second]+tresure[i].first);
            else dp[i+1][w] = dp[i][w];
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 7036
#include <iostream>

using namespace std;

int main(){
  	char b;
  	cin >> b;
  	if(b == 'A')
      	cout << 'T' << endl;
  	else if(b == 'T')
      	cout << 'A' << endl;
  	else if(b == 'C')
      	cout << 'G' << endl;
  	else
      	cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x, a, b;
    cin >> x >> a >> b;
    
    if(a >= b){
        cout << "delicious" << endl;
    }else if(a + x >= b){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	vector<Int> temp(4);
	Int a, b;
	cin >> a >> b;

	temp[a]++;
	temp[b]++;
	for (Int i = 1; i < 4; i++) {
		if (temp[i]==0) {
			cout << i << "\n";
			return 0;
		}
	}

}


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

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

    char n;
    n = N.at(N.size() - 1);

    if (n == '2' || n == '4' || n == '5' || n == '7' || n == '9')
    {
        cout << "hon" << endl;
    }
    else if (n == '0' || n == '1' || n == '6' || n == '8')
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3580
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

op = ["+","-"]
n = gc
stack = []
op.each do |op1|
  op.each do |op2|
    op.each do |op3|
      str = "#{n[0]}#{op1}#{n[1]}#{op2}#{n[2]}#{op3}#{n[3]}"
      ans = (eval str)
      stack << str+"=7" if ans == 7
    end
  end
end
puts stack.first


Measured memory_bytes: 4348
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

int main() {
  int n; cin >> n;
  vll a(n * 3); Loop(i, n * 3) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0;
  Loop(i, n) {
    ans += a[i * 2 + 1];
  }
  cout << ans << endl;
}

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

func main() {
	var n, d, ind int
  	a := make([]int, 0)
  	fmt.Scan(&n)
  for i := 0; i < n; i++ {
    fmt.Scan(&d)
   		a = append(a, d)
  	}
  b := make([]int, 0)
  for _, v := range a {
    b = append(b, v)
  }
  sort.Sort(sort.IntSlice(b))
  size := len(b)
  max := b[size-1]
  big := b[size-2]
  for i, v := range a {
    if ind == 0 {
      switch {
    	case v == max :
      		ind = i
      }
    }else{
      _, _ = i, v
    }
  }
  switch {
    case max == big:
    for i := 0; i < n; i++{
      fmt.Println(max)
    }
    case max != big:
    	a[ind] = big
      for i, v := range a {
        if i == ind {
          fmt.Println(v)
        }else{
          fmt.Println(max)
        }
      }
    }
}

Measured memory_bytes: 13568
import static java.lang.System.in;

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);
        double a = sc.nextDouble();
        double b = 3.14159265358979;
        System.out.println(String.format("%.6f",a*a*b)+" "+String.format("%.6f",2*a*b));
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  sort(d.begin(), d.end());
  
  int count=1;
  
  rep(i, N-1) {
    if (d[i+1]-d[i]>0) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String a = sc.next();
        char alpha = a.charAt(0);

        if ('a' <= alpha && alpha <= 'z' ) {
            System.out.println("a");
        } else {
            System.out.println("A");
        }

    }
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		int n = (int) nextLong();
		return n;
	}
}


Measured memory_bytes: 32452
#include <stdio.h>
#define SIZE 100

int date[SIZE + 1];

/* prototype declaration */
void init();
void count(int);
int search(int, int);

int main(int argc, const char *argv[])
{
	int i, j, N, Q, M, day, ans;

	while(1)
	{
		/* initialization */
		init();
		ans = 0;

		scanf("%d%d", &N, &Q);	

		if(N == 0 && Q == 0)
		{
			break;
		}

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

			for(j = 0; j < M; j++)
			{
				scanf("%d", &day);
				count(day);
			}
		}

		printf("%d\n", search(N, Q));
	}

	return 0;
}

void init()
{
	int i;
	for(i = 0; i < SIZE; i++)
	{
		date[i] = 0;
	}
}

void count(int day)
{
	date[day] += 1;
}

int search(int N, int quorum)
{
	int i, tmp[N + 1], ans = 0;

	for(i = 0; i < N + 1; i++)
	{
		tmp[i] = SIZE + 1;	
	}

	for(i = 0; i < SIZE; i++)
	{
		tmp[date[i]] = i < tmp[date[i]] ? i : tmp[date[i]];  
	}

	for(i = quorum; i < N + 1; i++)
	{
		if(tmp[i] != SIZE + 1)
		{
			ans = tmp[i];
		}
	}
	
	return ans;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[200008], aa[200008], ia[200008];

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){cin >> a[i];}
	for(ll i = 2; i <= n; i++){a[i] += a[i-1];}
	
	for(ll i = 2; i <= n-2; i++){
		ll high = i-1;
		ll low = 1;
		while(high-low > 1){
			ll mid = (high+low)/2;
			if(a[i]-2*a[mid] < 0){high = mid;}
			else{low = mid;}
		}
		if(abs(a[i]-2*a[low]) < abs(a[i]-2*a[high])){aa[i] = low;}
		else{aa[i] = high;}
	}
	
	for(ll i = 2; i <= n-2; i++){
		ll high = n-1;
		ll low = i+1;
		while(high-low > 1){
			ll mid = (high+low)/2;
			if(a[n]-2*a[mid]+a[i] < 0){high = mid;}
			else{low = mid;}
		}
		if(abs(a[n]-2*a[low]+a[i]) < abs(a[n]-2*a[high]+a[i])){ia[i] = low;}
		else{ia[i] = high;}
	}
	
	ll ans = a[n];
	for(ll j = 2; j <= n-2; j++){
		ll maxmax = max(max(a[aa[j]], a[j]-a[aa[j]]), max(a[ia[j]]-a[j], a[n]-a[ia[j]]));
		ll minmin = min(min(a[aa[j]], a[j]-a[aa[j]]), min(a[ia[j]]-a[j], a[n]-a[ia[j]]));
		ans = min(maxmax-minmin, ans);
		//cout << aa[j] << " " << j << " " << ia[j] << endl; 
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N;
    string s;
    cin >> N >> s;
    int cnt=0, left=0, right=0;
    for (int i=0; i<N; i++){
        if (s[i] == '('){
            if (cnt < 0) {
                left += -cnt; 
                cnt = 1;}
            else{
                cnt++;
            }
        }
        else if (s[i] == ')'){
            cnt--;
        }
    }
    if (cnt > 0) right += cnt;
    else left += -cnt;

    string ans = s;
    for (int i=0; i<left; i++){
        ans = '(' + ans;
    }
    for (int i=0; i<right; i++){
        ans += ')';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll mypow(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = mypow(m, p / 2);
    if (p & 1) return tmp * tmp * m;
    else return tmp * tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    ll ans = 1;
    for (ll i = 2; i < x; i++) {
        for (ll j = 2; ; j++) {
            ll tmp = mypow(i, j);
            if (tmp > x) break;
            chmax(ans, tmp);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

//--------------------------------------------
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

//--------------------------------------------

LL divNine = 1000000007;

LL calc (LL m) {
  if (m == 1) return 1;
  else return ((m * calc(m - 1)) % divNine);
}

int main(){
  LL n;
  scanf("%lld",&n);
  printf("%lld\n",calc(n));
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vvll a(26, vll(0));
  for(int i = 0; i < N; i++){
    a.at(S.at(i) - 'a').push_back(i);
  }
  ll ans = 0LL;
  for(int i = 0; i < 26; i++){
    int num = a.at(i).size();
    for(int j = 0; j < num-1; j++){
      for(int k = j+1; k < num; k++){
        ll counter = 0;
        int jj = a.at(i).at(j), kk = a.at(i).at(k);
        if(jj-1 >= 0 && kk-1 >= jj+1 && S[jj-1] == S[kk-1]) continue; 
        while(jj+counter < kk && kk+counter < N && S[jj+counter] == S[kk+counter]){
          counter++;
        }
        chmax(ans, counter);
      }
    }
  }
  cout << ans << endl;
}

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

int N;
vector<int> H, W;
string Area[4];

int d[1<<16];

int main(){
    cin >> N;
    H.resize(N); W.resize(N);
    for(int i=0; i<N; i++)
        cin >> H[i] >> W[i];
    
    vector<set<int>> edges(N);
    for(int k=0; k<N; k++){
        for(int h=-4; h<=4; h++){
            for(int w=-4; w<=4; w++){
                int t = 0;
                for(int i=0; i<H[k]; i++){
                    for(int j=0; j<W[k]; j++){
                        int nh = h+i;
                        int nw = w+j;
                        if(0<=nh && nh<4 && 0<=nw && nw<4){
                            t |= 1<<(4*nh + nw);
                        }
                    }
                }
                edges[k].insert(t);
            }
        }
    }
    
    int RGB[3] = {};
    for(int i=0; i<4; i++){
        cin >> Area[i];
        for(int j=0; j<4; j++){
            if(Area[i][j] == 'R')
                RGB[0] |= (1<<(4*i + j));
            if(Area[i][j] == 'G')
                RGB[1] |= (1<<(4*i + j));
            if(Area[i][j] == 'B')
                RGB[2] |= (1<<(4*i + j));
        }
    }
    
    queue<int> que;
    memset(d, -1, sizeof(d));
    d[0] = 0;
    que.push(0);
    
    while(!que.empty()){
        auto x = que.front(); que.pop();
        
        for(int i=0; i<N; i++){
            for(auto v: edges[i]){
                for(int j=0; j<3; j++){
                    int y = x;
                    for(int k=0; k<3; k++){
                        if(j == k){
                            y |= RGB[k] & v;
                        }else{
                            y &= ~(RGB[k] & v);
                        }
                    }
                    if (d[y] < 0){
                        que.push(y);
                        d[y] = d[x] + 1;
                        if(y == (RGB[0] | RGB[1] | RGB[2])){
                            cout << d[y] << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ld l;
	cin >> l;
	l /= 3.0;
	cout << fixed << setprecision(8) <<  l * l * l;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll gcd(ll a, ll b) {
    if(a < b)
        gcd(b, a);
    ll r = 1;
    while(r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll sign(ll n) {
    if(n >= 0) {
        return 1;
    } else {
        return -1;
    }
}
int main() {
    int n;
    cin >> n;
    map<pair<ll, ll>, ll> cnt;
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) {
            cnt[make_pair(0, 0)]++;
        } else if(a == 0 && b != 0) {
            cnt[make_pair(0, 1)]++;
        } else if(a != 0 && b == 0) {
            cnt[make_pair(1, 0)]++;
        } else {
            ll g = gcd(abs(a), abs(b));
            ll sig = sign(a) * sign(b);
            cnt[make_pair(sig * abs(a) / g, abs(b) / g)]++;
        }
    }
    ll ans = 1;
    for(auto e : cnt) {
        if(e.second == 0) {
            continue;
        }
        if(e.first == make_pair(0LL, 0LL)) {
            continue;
        }
        pair<ll,ll> ort;
        if(e.first == make_pair(0LL, 1LL)) {
            ort = make_pair(1, 0);
        } else if(e.first == make_pair(1LL, 0LL)) {
            ort = make_pair(0, 1);
        } else {
            ort = make_pair(-sign(e.first.first) * abs(e.first.second),
                            abs(e.first.first));
            ;
        }
        ans *= modpow(2, e.second) + modpow(2, cnt[ort]) - 1;
        ans %= MOD;
        cnt[ort] = 0;
        cnt[e.first] = 0;
    }
    cout << (cnt[make_pair(0, 0)] + ans - 1 + MOD) % MOD << endl;
}

Measured memory_bytes: 28520
N=int(input())
for i in range(N):
    a,b,c=map(int,input().split())
    A=a**2
    B=b**2
    C=c**2
    if A+B==C:print('YES')
    elif A+C==B:print('YES')
    elif B+C==A:print('YES')
    else:print('NO')

Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 3e5 + 233;
int top = 0, st[N], val[N];
int n, a[N];

inline void init(void) {
  top = 0;
  memset(st, 0, sizeof st);
  memset(val, 0, sizeof val);
}

inline bool add(int x, int mid, int fff = 0) {
  if (!x) return false;
  // cout << x << " " << mid << "ss\n";
  if (st[top] != x) {
    st[++ top] = x;
    val[top] = fff;
  }
  if (top && st[top] == x) {
    if (val[top] == mid) {
      -- top;
      if (!add(x - 1, mid, 1))
        return false;
      st[++ top] = x;
      val[top] = 1;
    } else {
      ++ val[top];
    }
  }
  return true;
}

inline bool check(int mid) {
  init();
  rep (i, n) {
    if (!top || st[top] <= a[i]) {
      if (!add(a[i], mid))
        return false;
    } else {
      while (top && st[top] > a[i])
        -- top;
      if (st[top] != a[i]) {
        st[++ top] = a[i];
        val[top] = 1;
      } // else {
      //   if (val[top] == mid) {
      //     -- top;
      //     if (!add(a[i] - 1, mid))
      //       return false;
      //     st[++ top] = a[i];
      //     val[top] = 0;
      //   } else {
      //     ++ val[top];
      //   }
      // }
      // rep (i, top) cout << st[i] << " "; cout << "\n";
      // rep (i, top) cout << val[i] << " "; cout << "\n";
      if (!add(a[i], mid))
        return false;
    }
  }
  return true;
}

int main(void) {
  read(n);
  rep (i, n) read(a[i]);
  int f = 1;
  rep (i, n - 1) f &= a[i] < a[i + 1];
  if (f) {
    cout << "1\n";
    return 0;
  }
  int l = 2, r = 1e9;
  while (l < r) {
    int mid = l + (r - l) / 2;
    if (check(mid)) r = mid;
    else l = mid + 1;
  }
  cout << r << "\n";
}


Measured memory_bytes: 3328
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
def era_primes(n):
    is_prime = [-1] * (n + 1)
    is_prime[1]=1
    for i in range(2, int(n**0.5) + 1):
        if is_prime[i]!=-1:
            continue
        for j in range(i * 2, n + 1, i):
            if is_prime[j]==-1:
                is_prime[j] = i
    for i in range(n):
        if is_prime[i+1]==-1:
            is_prime[i+1]=i+1
    return is_prime

def factorize(N,prime_list):  # prime_listに素数のリストをぶち込め！
    lst = []
    # N==1のときも
    # if N==1:
    #     lst.append(1)
    while prime_list[N]!=1:
        lst.append(prime_list[N])
        N//=prime_list[N]
    return lst

lst=era_primes(10**6+10)

ans=0
for i in range(n-1):
    c=i+1
    ab=factorize(n-c,lst)
    dic={}
    tmp=1
    for i in ab:
        if i in dic:
            dic[i]+=1
        else:
            dic[i]=1
    for j in dic.values():
        tmp*=j+1
    # print(tmp)
    ans+=tmp
    # print(ab)
print(ans)

Measured memory_bytes: 77640
const exec = (input) => {
  const red = input.split("").filter((i) => i === "1").length
  const blue = input.length - red
  const cnt = Math.min(red, blue)
  return cnt * 2
}

// @ts-ignore
require("fs").readFile("/dev/stdin", "utf8", (err, input) => {
  const inp = input.replace("\n", "")
  const cnt = exec(inp)
  console.log(cnt)
})


Measured memory_bytes: 19020
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll N; cin >> N;
    multiset<ll, greater<ll>> s; rep(i, N) {ll a; cin >> a; s.insert(a);};
//    s.insert(1ll<<60);
    
    ll ans = 0;
    auto it = s.begin();
    while(!s.empty() && it != s.end()){
        bool found = false;
        rep(i, 35){
            if((1ll<<i) - *it <= 0) continue;
            auto r = s.equal_range((1ll<<i) - *it);
            for(auto sit = r.ff; sit != r.ss; sit++){
                if(sit == it) continue;
                if(*it+*sit == (1ll<<i)){
                    ans++;
                    found = true;
                    s.erase(sit);
                    break;
                }
            }
            if(found) break;
        }
        it = s.erase(it);
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>

int main() {
	int n; std::cin >> n;
	int ga, sa, ba, gb, sb, bb; std::cin >> ga >> sa >> ba >> gb >> sb >> bb;
	std::vector<int> buy_for_a(n + 1, 0);
	buy_for_a[n] = n;
	long long int max = 0;
	for (int i = n; i >= 0; --i) {
		if (buy_for_a[i] != 0) {
			if (max < buy_for_a[i]) max = buy_for_a[i];
			if (ga <= i && buy_for_a[i - ga] < buy_for_a[i] - ga + gb) {
				buy_for_a[i - ga] = buy_for_a[i] - ga + gb;
			}
			if (sa <= i && buy_for_a[i - sa] < buy_for_a[i] - sa + sb) {
				buy_for_a[i - sa] = buy_for_a[i] - sa + sb;
			}
			if (ba <= i && buy_for_a[i - ba] < buy_for_a[i] - ba + bb) {
				buy_for_a[i - ba] = buy_for_a[i] - ba + bb;
			}
		}
	}
	std::vector<long long int> buy_for_b(max + 1, 0);
	buy_for_b[max] = max;
	for (int i = max; i >= 0; --i) {
		if (buy_for_b[i] != 0) {
			if (max < buy_for_b[i]) max = buy_for_b[i];
			if (gb <= i && buy_for_b[i - gb] < buy_for_b[i] - gb + ga) {
				buy_for_b[i - gb] = buy_for_b[i] - gb + ga;
			}
			if (sb <= i && buy_for_b[i - sb] < buy_for_b[i] - sb + sa) {
				buy_for_b[i - sb] = buy_for_b[i] - sb + sa;
			}
			if (bb <= i && buy_for_b[i - bb] < buy_for_b[i] - bb + ba) {
				buy_for_b[i - bb] = buy_for_b[i] - bb + ba;
			}
		}
	}
	std::cout << max << std::endl;
}



Measured memory_bytes: 195584
// Problem : A - Kyu in AtCoder
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;


#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar))
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define mod 1000000007
#define maxn 1000003

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main(){
	
	fastio;
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	bool ans=false;
	
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			for(int t =0;t<=k;t++){
				if(i+j+t<=k && a*(1<<i) < b*(1<<j) && b*(1<<j)< c*(1<<t))ans =true;
			}
		}
	}
	if(ans)cout<<"Yes";
	else cout<<"No";
	
	}


	
	
	
	



Measured memory_bytes: 3624
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[1000][1000];
ll x[200000] = {};
ll y[200000] = {};
ll x2[200000] = {};
ll y2[200000] = {};

int main() {
	ll h, w; cin >> h >> w;

	rep(i, 0, h)rep(j, 0, w) {
		ll v;
		cin >> v;
		a[i][j] = v % 2;
	}

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] % 2) {
				a[i][j]--;
				a[i][j + 1]++;

				y[cnt] = i + 1;
				x[cnt] = j + 1;
				y2[cnt] = i + 1;
				x2[cnt] = j + 2;
				cnt++;
			}
		}
	}

	rep(i, 0, h - 1) {
		if (a[i][w - 1] % 2) {
			a[i][w - 1]--;
			a[i + 1][w - 1]++;

			y[cnt] = i + 1;
			x[cnt] = w;
			y2[cnt] = i + 2;
			x2[cnt] = w;
			cnt++;
		}
	}
	cout << cnt << endl;
	rep(i, 0, cnt) {
		cout << y[i] << " " << x[i] << " " << y2[i] << " " << x2[i] << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll N;
  cin >> N;
  vi b(N);
  for (ll i = 0; i < N; i++) {
    cin >> b[i];
  }

  vi ans;
  for (ll i = 0; i < N; i++) {
    ll j = -1;
    for (ll k = 0; k < b.size(); k++) {
      if (k + 1 == b[k]) {
        j = k;
      }
    }
    if (j == -1) {
      cout << -1 << endl;
      return 0;
    }
    vi new_b;
    for (ll k = 0; k < b.size(); k++) {
      if (j != k) {
        new_b.push_back(b[k]);
      }
    }
    b.swap(new_b);
    ans.push_back(j + 1);
  }

  reverse(ans.begin(), ans.end());
  for (auto i: ans) cout << i << endl;
}

Measured memory_bytes: 764
# coding: utf-8
    
def main():
    N = int(input())
    A1 = tuple(map(int, input().split(' ')))
    A2 = tuple(map(int, input().split(' ')))

    A_sum = A1[0]
    for i in range(N):
        A_sum += A2[i]

    A_sum_max = A_sum
    for i in range(N - 1):
        A_sum = A_sum + A1[i + 1] - A2[i]
        if A_sum > A_sum_max:
            A_sum_max = A_sum

    print(A_sum_max)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//
// Created by Hideaki Imamura on 2020-03-16.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
const ll mod = 1000000007;

inline ll take_mod(ll a) {
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b) {
    return take_mod(a + b);
}

inline ll sub(ll a, ll b) {
    return take_mod(a - b);
}

inline ll mul(ll a, ll b) {
    return take_mod(a * b);
}

inline ll mod_pow(ll x, ll n) {
    ll res = 1LL;
    while (n > 0) {
        if (n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x) {
    return mod_pow(x, mod - 2);
}

int H, W;
vector<string> a;

int main() {
    cin >> H >> W;
    a.assign(H, "");
    for (int i = 0; i < H; ++i) cin >> a[i];

    vector<vector<ll>> dp(H, vector<ll>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i + 1 < H && a[i+1][j] == '.') dp[i+1][j] = add(dp[i+1][j], dp[i][j]);
            if (j + 1 < W && a[i][j+1] == '.') dp[i][j+1] = add(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9216
package main

import (
        "fmt"
        "time"
)

func solution(h1, m1, h2, m2, k int) int {
        d1 := time.Date(2020, 1, 1, h1, m1, 0, 0, time.Local)
        d2 := time.Date(2020, 1, 1, h2, m2, 0, 0, time.Local)

        duration := d2.Sub(d1)
        return int(duration.Minutes()) - k
}

func main() {
        var h1, m1, h2, m2, k int
        fmt.Scan(&h1, &m1, &h2, &m2, &k)
        fmt.Println(solution(h1, m1, h2, m2, k))
}

Measured memory_bytes: 1908
N,x,*as=$<.read.split.map(&:to_i)

i = 1
ret = 0
while i < N
    d = as[i-1] + as[i] - x
    if 0 < d
        as[i] -= [d,as[i]].min
        ret += d
    end
    i += 1
end

puts ret

Measured memory_bytes: 21592
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        cv: Chars
    };

    let mut res = 0;
    let mut l = 0;
    let mut r = n - 1;
    while l < r {
        if cv[l] == 'W' {
            if cv[r] == 'R' {
                res += 1;
                l += 1;
                r -= 1;
            } else {
                r -= 1;
            }
        } else {
            l += 1;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    double a = (double) (n / 2) / n;
    cout << 1.0 - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>

using namespace std;
using ll = long long int;



int main(void){
  
  ll n;
  cin>>n;
  vector<ll> a(n);
  
  for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a[i] = x;
  }

  map<ll, ll> m;

  for(ll i=0;i<n;i++){
    m[a[i]]++;
  }
  ll ans = 0;

  for(auto j=m.begin();j!=m.end();j++){
    ans += j->second*(j->second-1)/2;
  }


  for(ll i=0;i<n;i++){
    
    cout<<ans - m[a[i]]*(m[a[i]]-1)/2 + (m[a[i]]-1)*(m[a[i]]-2)/2<<endl;; 

  }

  return 0;
}

Measured memory_bytes: 11008
#include <stdio.h>

void swap(int *x,int *y);

int gcd(int x,int y);

void swap(int *x,int *y){

int temp;

temp = *x;
*x = *y;
*y = temp;

}

int gcd(int x,int y){
    int r = 0;
    if(x<y){
        swap(&x,&y);
    }
    while(y>0){
        r = x % y;
        x = y;
        y = r; 

    }

    return x;

}




int main(){


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

if(b>=a){
    swap(&a,&b);
}



printf("%d\n",gcd(a,b));




return 0;

}


Measured memory_bytes: 2140