akhauriyash/Code-Regression huggingface dataset:
n, w = gets.split.map(&:to_i)
wv = []
n.times do
  wv << gets.split.map(&:to_i)
end
wv.sort_by! { |y| y[0] }
dp = Array.new(w+1, 0)
wv.each do |tw, tv|
  w.downto(tw).each do |cw|
    dp[cw] = dp[cw-tw] + tv if dp[cw] < dp[cw-tw] + tv
  end
end
puts dp.last

Measured memory_bytes: 2556
#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 n;
vll p, q;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    p.resize(n), q.resize(n);
    for (ll i = 0; i < n; i++) {
        cin >> p[i]; p[i]--;
    }
    for (ll i = 0; i < n; i++) {
        cin >> q[i]; q[i]--;
    }

    vll order(n); iota(ALL(order), 0LL);
    ll pi = 0;
    do {
        if (order == p) break;
        pi++;
    } while (next_permutation(ALL(order)));

    iota(ALL(order), 0LL);
    ll qi = 0;
    do {
        if (order == q) break;
        qi++;
    } while (next_permutation(ALL(order)));

    cout << abs(pi - qi) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <sstream>
//#include <boost/math/common_factor_rt.hpp>
#include<fstream>
#define EPS (1e-7)
using namespace std;
#define ll long long



class Employee {
public:
	int id;
	int parent;
	vector<int> children;
	int salary;

	Employee() {
		
	}

	Employee(int num, int nparent) {
		id = num;
		parent = nparent;
		salary = -1;
	}



};



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



int main() {
	int N;
	cin >> N;
	vector<int>  H(N);
	vector<int>  A(N,0);
	for (auto i = 0; i < N; i++) {
		cin >> H[i];
	}
	A[N - 1] = 0;
	for (auto i = N-2;  i >-1 ; i--)
	{
		if (H[i] >= H[i + 1])A[i] = A[i + 1] + 1;
	}

	int ans = *std::max_element(A.begin(), A.end());

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1152
a = gets.to_i
#n = 10 ** 5
n = 2

def power2(a, n)
  return 1 if n == 0
  k = power2(a, n >> 1)
  k *= k
  return k if n & 1 == 0
  return k * a
end

sum = 0
(0..n).each{|i|
  #sum += power2(a, i)
  sum = power2(a, i)
}
#sum == a ** (n + 1) / (a - 1)
puts sum.to_i 

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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n+1];
    int b[n+1];
    int x=0;
    rep(i,1,n+1){
        cin >> a[i];
        x^=a[i];
    }
    for(int i=1; i<=n; i++){
        b[i]=a[i]^x;
    }
    for(int i=1; i<=n; i++) cout << b[i] << " ";
    return 0;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

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

ll n1,n2;

int main(){
    cin >> n1 >> n2;
    cout << lcm(n1,n2) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int P[200001];
int mins[200001];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &P[i]);
        //   printf("%d, ", P[i]);
    }
    
    mins[0] = P[0];
    for (int i = 1; i < n; i++) {
        mins[i] = MIN(mins[i-1], P[i]);
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        // printf("%d, ", mins[i]);
        if (mins[i] >= P[i]) count++;
    }

    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1664
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- sort . zipWith (\a b -> b - a) [1..] <$> getIntList
    let a1 = as !! ((n-1) `div` 2)
        a2 = as !! (n `div` 2)
        b1 = (a1 + a2) `div` 2
        b2 = (a1 + a2 + 1) `div` 2
        sad1 = sum $ map (\a -> abs (a - b1)) as
        sad2 = sum $ map (\a -> abs (a - b2)) as
    print $ if n == 1 then 0 else min sad1 sad2

Measured memory_bytes: 32124
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from fractions import gcd
from functools import reduce
def lcm(a,b):
    return a//gcd(a,b)*b

def resolve():
    n,m=map(int,input().split())
    A=list(map(lambda x:int(x)//2,input().split()))

    l=reduce(lcm,A)
    # A の要素の 2 で割り切れる回数は等しくなければならない
    k=0
    while(l%(1<<(k+1))==0): k+=1
    for a in A:
        if(a%(1<<k)):
            print(0)
            return

    print((m+l)//(2*l))
resolve()

Measured memory_bytes: 89836
# ALDS1_3_C: Doubly Linked List
# collections.deque
# https://docs.python.org/3.8/library/collections.html#collections.deque

#n = 7
#A = [('insert', 5), ('insert', 2), ('insert', 3), ('insert', 1), 
#     ('delete', 3), ('insert', 6), ('delete', 5),]
from collections import deque

n = int(input())
mylist = deque()
for i in range(n):
    myinput = input().split()
    if len(myinput) == 1:
        order = myinput[0]
        x = 0
    else:
        order, x = myinput

    #print(order, x)
    if order == 'insert': 
        mylist.appendleft(x)
    elif order == 'delete':
        try:
            mylist.remove(x)
        except:
            pass
    elif order == 'deleteFirst':
        #mylist.remove(mylist[0])
        mylist.popleft()
    elif order == 'deleteLast':
        mylist.pop()
    #print(mylist)
print(" ".join(map(str, mylist)))


Measured memory_bytes: 69736
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pre = -10
ans = 0
for a in A:
    ans += B[a-1]
    if a == pre + 1:
        ans += C[pre-1]
    pre = a

print(ans)

Measured memory_bytes: 3064
<?php
fscanf(STDIN,"%d",$N);
$A = preg_split("/[\s]/i",trim(fgets(STDIN)), $N);
do{
    $ans = min($A);
    $tA = [];
    reset($A);
    foreach($A as $va){
        if($va % $ans) {
            $tA[] = $va % $ans;
        }
    }
    $tA[] = $ans;
    $A = $tA;
}while($ans != min($tA));
echo $ans."\n";


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-3)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

int d,bc[(1<<10)];
double answer[10];

typedef vector<double> vd;
typedef vector<vd> mat;

vector<double> gauss_jordan(const mat& A,const vd& b){
  int n = A.size();
  mat B(n,vd(n+1));
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j] = A[i][j];

  for(int i=0;i<n;i++) B[i][n] = b[i];

  for(int i=0;i<n;i++) {
    int pivot = i;
    for(int j=i;j<n;j++) if( abs(B[j][i]) > abs(B[pivot][i]) ) pivot = j;
    swap(B[i],B[pivot]);
    if( abs(B[i][i]) < EPS ) return vd();
    
    for(int j=i+1;j<=n;j++) B[i][j] /= B[i][i];
    for(int j=0;j<n;j++) {
      if( i != j )  {
        for(int k=i+1;k<=n;k++) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }
  vd x(n);
  for(int i=0;i<n;i++) x[i] = B[i][n];
  return x;
}

inline double f(const vector<double> &coef,double x){
  double ret = coef.back();
  double multi = x;
  for(int i=(int)coef.size()-2;i>=0;i--) { ret += coef[i] * x; x = x * multi; }
  return ret;
}

bool isValid(const vector<double> &x,const vector<double> &v,int sp,int bitmask,const int wrong){
  if( bc[bitmask] >= d+1 ) {
    //cout << endl;
    vector<vector<double> > A;
    vector<double> b;
    rep(i,d+3) {
      if( (bitmask>>i) & 1 ) {
        b.push_back(v[i]);
        vector<double> tmp;
        tmp.push_back(1);
        rep(j,d) tmp.push_back(tmp.back()*x[i]);
        reverse(tmp.begin(),tmp.end());
        A.push_back(tmp);
      }
    }
    /*
    cout << "A----------" << endl;
    rep(i,A.size()){
      rep(j,A[i].size()){
        if( j ) cout << " ";
        cout << A[i][j];
      } cout << endl;
    }

    cout << endl << "b---------" << endl;
    rep(i,b.size()) cout << b[i] << " "; cout << endl;
    cout << endl;
    */
    vector<double> coef = gauss_jordan(A,b);
    /*
    cout << "coef =" << endl;
    rep(i,coef.size()) cout << coef[i] << " "; cout << endl;
    */
    if( coef.empty() ) return false; // 
    rep(i,d+3) if( i != wrong && !equals(answer[i],f(coef,i)) ){
      //cout << setiosflags(ios::fixed) << setprecision(10) << "invalid : " << i << " : " << answer[i] << " != " << f(coef,i) << endl;
      return false;
    } //else if( i != wrong ) cout << setiosflags(ios::fixed) << setprecision(10) << f(coef,i) << " ";
    //cout << endl;
    return true;
  }
  REP(i,sp,(int)x.size()) if( !isValid(x,v,i+1,bitmask|(1<<i),wrong) ) return false;
  return true;
}

int main(){
  rep(i,(1<<10)) bc[i] = __builtin_popcount(i);
  while( cin >> d, d ){
    rep(i,d+3) cin >> answer[i];
    rep(wrong,d+3){
      //cout << "wrong is " << wrong << "???????????" << endl;
      vector<double> x,v;
      rep(i,d+3) if( i != wrong ) x.push_back(i), v.push_back(answer[i]);
      if( isValid(x,v,0,0,wrong) ) {
        printf("%d\n",wrong);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1248
#include<stdio.h>

int A[1000000],n;

// 二分探索
int binarySearch(int key){
    int left=0,right=n,mid;

    while(left <right){
        mid = (left + right)/2;

        if(key == A[mid]) return 1;
        if(key > A[mid]) left = mid +1;
        else if(key < A[mid]) right = mid;
    }
    return 0;
}

int main(){
    int i,q,k,sum=0;

    scanf("%d", &n);
    for(i=0; i <n; i++){
        scanf("%d" ,&A[i]);
    }
    scanf("%d", &q);
    for(i=0; i <q; i++){
        scanf("%d" ,&k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n" ,sum);
    return 0;
}



Measured memory_bytes: 3068
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

/*-------------------------------------------------*/
// Union Find
typedef struct{
    ll num; //number
    ll par; //parent
    ll height; //height
}UF;
void UFmake(ll n, UF b[n]){for(ll i=0;i<n;i++){
    b[i].par = i;
    b[i].num = i;
    b[i].height = 1;
    }
}
ll UFroot(ll n, ll a,UF b[n]){ return a==b[a].par?a:UFroot(n,b[a].par,b); }
void UFunite(ll n, ll x, ll y, UF b[n]){
    if(b[UFroot(n,x,b)].height > b[UFroot(n,y,b)].height) b[UFroot(n,y,b)].par = UFroot(n,x,b);
    else{ b[UFroot(n,x,b)].par = UFroot(n,y,b); b[UFroot(n,y,b)].height = max2(b[UFroot(n,y,b)].height,b[UFroot(n,x,b)].height+1);}
}
ll UFsame(ll n, ll x, ll y, UF b[n]){ return UFroot(n,x,b) == UFroot(n,y,b) ? 1 : 0; }

int main(void){
    // char ;
    ll n,m,ans=0;
    scanf("%lld%lld",&n,&m);
    ll a[m],b[m];
    rep(i,0,m){
        scanf("%lld%lld",&a[i],&b[i]);
    }
    UF tr[n];
    rep(i,0,m){
        UFmake(n,tr);
        rep(j,0,m){
            if(i==j) continue;
            UFunite(n,a[j]-1,b[j]-1,tr);
        }
        if(UFsame(n,a[i]-1,b[i]-1,tr)==0){
            // printf("%lld ",i);
            ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ts = new int[5];
        for (int i = 0; i < ts.Length; i++)
        {
            ts[i] = int.Parse(Console.ReadLine());
        }

        ts = ts.OrderBy(x => (10 - x % 10) % 10).ToArray();

        var elapsedTime = 0;
        for (int i = 0; i < ts.Length; i++)
        {
            elapsedTime += (10 - elapsedTime % 10) % 10 + ts[i];
            Console.Error.WriteLine(elapsedTime);
        }
        Console.WriteLine(elapsedTime);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
int main(){
	int H,W;
	cin>>H>>W;
	V<int> h(H),w(W);
	V<int> v2h(H*W,-1),v2w(H*W,-1);
	rep(i,H){
		cin>>h[i];
		h[i]--;
		if(v2h[h[i]] != -1){
			cout<<0<<endl;
			return 0;
		}
		v2h[h[i]] = i;
	}
	rep(i,W){
		cin>>w[i];
		w[i]--;
		if(v2w[w[i]] != -1){
			cout<<0<<endl;
			return 0;
		}
		v2w[w[i]] = i;
	}
	int ch=0, cw=0;
	mint ans = 1;
	for(int v=H*W-1;v>=0;v--){
		int done = H*W-1-v;
		if(v2h[v]!=-1 && v2w[v]!=-1){
			ch++;
			cw++;
		}else if(v2h[v]!=-1){
			ch++;
			ans *= cw;
		}else if(v2w[v]!=-1){
			cw++;
			ans *= ch;
		}else{
			int cand = cw*ch-done;
			if(cand<=0) ans = 0;
			ans *= cand;
		}
	}
	cout<<ans<<endl;
}

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

bool my_cmp(tuple<string, int, int> a, tuple<string, int, int> b)
{
	//stringは昇順、int(点数)は降順ソート
	if (get<0>(a) != get<0>(b))
		return ( get<0>(a) < get<0>(b) ); //昇順
	if (get<1>(a) != get<1>(b))
		return ( get<1>(a) > get<1>(b) ); //降順
	else
		return true;
}

int  main()
{
	int n;
	cin >> n;
	vector<tuple<string , int, int>> p(n);
	rep(i, n)
	{
		cin >> get<0>(p[i]) >> get<1>(p[i]);
		get<2>(p[i]) = i + 1;
	}
	sort(p.begin(), p.end(), my_cmp);
	rep(i, n)
		cout << get<2>(p[i]) << endl;
	return (0);
}

Measured memory_bytes: 256
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    int n;
    int z;
    int w;
    cin >> n >> z >> w;
    Vec<int> a(n);
    FOR (i, 0, n) {
        cin >> a[i];
    }

    int ans = 0;
    if (n != 1) {
        ans = max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w));
    } else {
        ans = abs(a[n - 1] - w);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vll> vl2d;
typedef vector <vi> vi2d;
typedef vector <char> vc;
typedef vector <bool> vb;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <long,long> ml;
typedef map <string,string> mss;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define foreach(x,arr) for(auto& x:arr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000LL
#define MOD 1000000007ll
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<"\t"; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define forch(ch,str) for(char& c : str)
#define FILL(a,b) memset(a,b,sizeof(a))
//Swift related stuff
#define append push_back
#define nil nullptr
#define guard(_condition) if (bool(_condition)){}
#define count size()
#define let const auto
#define var auto
#define startsWith(str) rfind(str, 0)
#define prq priority_queue
#define tostr(argument) to_string(argument)
#define alphabet "abcdefghijklmnopqrstuvwxyz"

ll modulo(ll a, ll b, ll n){
    long long x=1, y=a;
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; // multiplying with base
        }
        y = (y*y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
int main() {
    ll n;
    cin>>n;
    vll arr(n);
    bool wrong = false;
    map<ll, ll> dic;
    ll mx = 0;
    rep(i,0,n) {
        ll num;
        cin>>num;
        if(i==0 && num != 0) {
            wrong = true;
        }
        if(i != 0 && num == 0) {
            wrong = true;
        }
        dic[num] += 1;
        mx = MAX(mx, num);
    }
    
    ll res = 1;
    rep(i,1,mx+1) {
        guard(dic[i-1] != 0 && dic[i] != 0) else {
            wrong = true;
            break;
        }
        ll p = modulo(dic[i-1], dic[i],998244353);
        res = (res * p)%998244353;
    }
    if(wrong) {
        cout<<0<<endl;
        return 0;
    }
    cout<<res<<endl;
    return 0;
}


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

int main() {
    long long  n, a, b;
    cin >> n >> a >> b;

    long long div = n / (a + b);
    long long amari = n % (a + b);

    long long ret = div * a;
    ret += min(amari, a);
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int h[n];
  for(int i=0;i<n;i++)cin >> h[i];
  sort(h,h+n);
  int m=2000000000;
  for(int i=0;i<n-k+1;i++){
    if(m>abs(h[i]-h[i+k-1]))m=abs(h[i]-h[i+k-1]);
  }
  cout << m;
}


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 200005
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a[maxN], nxt[maxN];

int main () {
    scanf("%d", &n);
    fto(i, 1, n) scanf("%d", &a[i]);

    nxt[n+1] = n+1;
    fdto(i, n, 1)
        nxt[i] = (a[i] == 0) ? nxt[i+1] : i;


    ll ans = 0;
    fto(i, 1, n) {
        int sum = 0, xorSum = 0, j = i;
        while (j <= n) {
            sum += a[j];
            xorSum ^= a[j];
            if (sum != xorSum) break;
            ans += nxt[j+1]-j;
            j = nxt[j+1];
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 1792
n, a = map(int, input().split())
xlist = list(map(int, input().split()))

j = n
k = n
t = n * a
maxv = max(a, max(xlist))


dp = [[[0 for t in range(n*maxv + 1)] for k in range(k + 1)] for j in range(j + 1)]

dp[1][0][0] = 1
dp[0][0][0] = 1

# for d in dp:
#     print(d)
# print(dp[1][1][15])

for ji in range(0, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki * maxv + 1):
            # print('now', ji, ki, ti)
            if ji == 0 and ki == 0 and ti == 0:
                # print('branch 1')
                dp[ji][ki][ti] = 1
            elif ji >= 1 and ti < xlist[ji - 1]:
                dp[ji][ki][ti] = dp[ji - 1][ki][ti]
                # print('branch 2')
            elif ji >= 1 and ki >= 1 and ti >= xlist[ji - 1]:
                # print('branch 3', ji - 1)
                dp[ji][ki][ti] = dp[ji - 1][ki][ti] + dp[ji - 1][ki - 1][ti - xlist[ji - 1]]
            # print(dp[ji][ki][ti])

count = 0
for i in range(1, k + 1):
    count += dp[j][i][i*a]

print(count)

Measured memory_bytes: 65392
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ( abs(a - b) <= d && abs(b- c) <= d || abs(a-c) <= d ) cout << "Yes" << endl;
    else                                                      cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException  {
        
        int a,h,m,s;
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st = br.readLine();

        a = Integer.parseInt(st);
        h = a / 3600;
        m = a % 3600 / 60;
        s = a % 60;
        
        System.out.println(h+":"+m+":"+s);
        
    
    }
    
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>M;
    cout<<((N*M)&1 ? "Yes" : "No")<<endl;
}


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

int main(void) {
    int a, b;
    std::cin >> a >> b;
    if (a > b) {
        std::cout << a + (a - 1) << std::endl;
    } else if (a < b) {
        std::cout << b + (b - 1) << std::endl;
    } else {
        std::cout << 2 * a << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string s, t; cin >> s >> t;

    t.append(s);

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a, b;
    cin >> n;

    lli vertex = 0, edges = 0;
    for (lli i = 1; i < n; i++) {
        cin >> a >> b;
        if (a > b) {
            swap(a, b);
        }
        edges += (a) * (n - b + 1);
    }

    for (lli i = 1; i <= n; i++) {
        vertex += i * (n - i + 1);
    }

    lli ans = vertex - edges;
    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

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

int main(){
   int n, count = 0,ans = 0;
   bool color[8] = {};
   cin >> n;
   int a[n] = {};
   for(int i = 0; i < n; i++){
       cin >> a[i];
       if(a[i] >= 3200) count++;
       if(0 < a[i] && a[i] <= 399) color[0] = 1;
       else if(399 < a[i] && a[i] <= 799) color[1] = 1;
       else if(799 < a[i] && a[i] <= 1199) color[2] = 1;
       else if(1199 < a[i] && a[i] <= 1599) color[3] = 1;
       else if(1599 < a[i] && a[i] <= 1999) color[4] = 1;
       else if(1999 < a[i] && a[i] <= 2399) color[5] = 1;
       else if(2399 < a[i] && a[i] <= 2799) color[6] = 1;
       else if(2799 < a[i] && a[i] <= 3199) color[7] = 1;
   }
    for(int i = 0; i < 8; i++){
        if(color[i] == 1){
            ans++;
        } 
    }
    if(ans > 0){
        cout << ans << " " << ans + count << endl;
    }else{
        cout << 1 << " " << count << endl;  
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] city = new int[N];
		for(int i=0; i<N; i++){
			city[i] = 0;
		}
		for(int i=0; i<M; i++){
			city[sc.nextInt()-1]++;
			city[sc.nextInt()-1]++;
		}
		for(int i=0; i<N; i++){
			System.out.println(city[i]);
		}
		sc.close();
	}

}


Measured memory_bytes: 21844
from itertools import *
n,q = map(int,input().split())
s = str(input())
k = [ 1 if s[i-1] == "A" and s[i] == "C" else 0  for i in range(n)]
cumsum = list(accumulate(k))
#print(k)
#print(cumsum)
for i in range(q):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    #print(k[a:b+1])
    ans = cumsum[b] - cumsum[a]
    """
    if k[a] == 1:
        ans -= 1
    """
    print(ans)

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

int main() {
	int n; cin>>n;
	bool band=false;
	
	for(int i=1; i<=n; i++){
		if (n%i==0){
			int aux=n/i;
			int aux2=n/aux;
			
			if(aux >= 1 && aux <=9  && aux2 >= 1 && aux2 <= 9){
				band=true;
				break;
			}
		}
	}
	string res=band ? "Yes" : "No";
	cout<<res;
	return 0;
}

Measured memory_bytes: 3632
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))


s = input()

dfs(0, s[0], int(s[0]))

Measured memory_bytes: 9116
fun main(args: Array<String>) {
    a56(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a56(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (Atcoder, Topcoder) = args[0].split(" ")
    println(when {
        Atcoder == "H" -> Topcoder
        else -> if (Topcoder == "H") "D" else "H"
    })
}

Measured memory_bytes: 36348
n,m = map(int,input().split())
memo2 = [False for i in range(n)]
memo = [0 for i in range(n)]
count1,count2 = 0,0
for i in range(m):
    p,l = input().split()
    p = int(p)-1
    if memo2[p]:
        continue
    else:
        if l == 'WA':
            memo[p]+=1
        else:
            memo2[p] = True
            count2 += 1
            count1+=memo[p]
print(count2,count1)

Measured memory_bytes: 85808
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int n=nextInt();
		int bit[]=new int[n+1];
		String s=nextLine();
		int cnt=0;
		for(int i=1;i<=n;i++)
		{
			bit[i]=s.charAt(i-1)-'0';
			if(bit[i]==1)
				cnt++;
		}
		int d1=0;
		if(cnt!=1)
		{
			for(int j=n;j>=1;j--)
			{
				if(bit[j]==1)
					d1=(d1+(int)modpow(2,n-j,cnt-1))%(cnt-1);
			}
		}
		int d2=0;
		for(int j=n;j>=1;j--)
		{
			if(bit[j]==1)
				d2=(d2+(int)modpow(2,n-j,cnt+1))%(cnt+1);
		}
		for(int i=1;i<=n;i++)
		{
			if(bit[i]==1 && cnt==1)
			{
				out.println(0);
				continue;
			}
			int d;
			if(bit[i]==1)
				d=(d1-(int)modpow(2,n-i,cnt-1)+(cnt-1))%(cnt-1);
			else
				d=(d2+(int)modpow(2,n-i,cnt+1))%(cnt+1);
			int ans=1;
			while(d>0)
			{
				d=d%Integer.bitCount(d);
				ans++;
			}
			out.println(ans);
		}
	}
	long modpow(long a,long b,long mod)
	{
	    long ret=1;
	    while(b!=0)
	    {
	        if(b%2==1)
	            ret=(ret*a)%mod;
	        a=(a*a)%mod;
	        b=b/2;
	    }
	    return ret;
	} 
	 
	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 46964
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define pb push_back
int dp[3001][3001];
void solve(){
	string s,p;
	cin >> s >> p;
	forn(i,1,s.size()+1){
		forn(j,1,p.size()+1){
			if(s[i-1]==p[j-1])
				dp[i][j] = dp[i-1][j-1]+1;
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int i=s.size(); int j=p.size();
	string ans;
	while(i&&j){
		if(s[i-1]==p[j-1]){
			ans = s[i-1]+ans;
			--i; --j;
			continue;
		}
		if(dp[i-1][j]>dp[i][j-1])
			--i;
		else
			--j;
	}
	cout<<ans;
	return ;
}

int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

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

//使用する配列の最大要素数
#define MAX_SIZE_N 50
//使用する変数の宣言と初期化
int a=0,b=0,c=0,n;
int d[MAX_SIZE_N]={0};
int result=0;

int main()
{
  //入力
  cin >> n;
  for(int i=0;i<n;++i) cin >> d[i];

  //処理

  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      result += d[i]*d[j];
    }
  }    

  //出力
  cout << result;
    
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

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

var n int   // 最大100000
var A []int // 各要素の最大は1000000000

func main() {
	tmp := NextIntsLine()
	n = tmp[0]
	for i := 0; i < n; i++ {
		tmp = NextIntsLine()
		A = append(A, tmp[0])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	answer1, answer2 := 0, 0
	// 最初が下りのパターンの最大値
	coords := map[int]int{2: 0, 1: 0, -1: 0, -2: 0} // それぞれ+2, +1, -1, -2の数
	if n%2 == 0 {
		coords[1] = 1
		coords[-1] = 1
		coords[2], coords[-2] = n/2-1, n/2-1
	} else {
		coords[1] = 2
		coords[-1] = 0
		coords[2] = n/2 - 1
		coords[-2] = n / 2
	}
	i := 0
	for _, c := range []int{2, 1, -1, -2} {
		for j := 0; j < coords[c]; j++ {
			answer1 += c * A[i]
			i++
		}
	}
	// 最初が上りのパターンの最大値
	coords = map[int]int{2: 0, 1: 0, -1: 0, -2: 0}
	if n%2 == 0 {
		coords[1] = 1
		coords[-1] = 1
		coords[2], coords[-2] = n/2-1, n/2-1
	} else {
		coords[1] = 0
		coords[-1] = 2
		coords[2] = n / 2
		coords[-2] = n/2 - 1
	}
	i = 0
	for _, c := range []int{2, 1, -1, -2} {
		for j := 0; j < coords[c]; j++ {
			answer2 += c * A[i]
			i++
		}
	}

	if answer1 > answer2 {
		fmt.Println(answer1)
	} else {
		fmt.Println(answer2)
	}
}


Measured memory_bytes: 7552
n = int(input())
print(0)
even = input()
if even == "Vacant":
  exit()
elif even == "Male":
  odd = "Female"
else:
  odd = "Male"
print(n-1)
d = input()
if d == "Vacant":
  exit()
left = 1
right = n-2
nex = (left+right)//2
while(True):
  print(nex)
  d = input()
  if d == "Vacant":
    exit()
  if (nex%2==0 and d == even) or (nex%2 == 1 and d == odd):
    left = nex + 1
  else:
    right = nex -1
  nex = (left+right)//2

Measured memory_bytes: 3660
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()

	minInt := func(a int, vs ...int) int {
		for i := range vs {
			v := &vs[i]
			if a > *v {
				a = *v
			}
		}
		return a
	}
	ans := n - 1
	for x := 2; x*x <= n; x++ {
		if n%x == 0 {
			ans = minInt(ans, (n/x-1)+(x-1))
		}
	}

	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(auto i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int, int> mii;
typedef map<st, int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
int main() {
	//freopen("in.txt", "r", stdin);
	int n, h, maxh = 0;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		cin >> h;
		ans += h >= maxh;
		maxh = max(maxh, h);
	}
	cout << ans << 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 n;
    cin >> n;
    int p[n];
    vector<int> num;
    rep(i, n) {
        cin >> p[i];
        if(i + 1 != p[i]) {
            num.push_back(abs(i + 1 - p[i]));
        }
    }
    if(num.size() >= 3) {
        cout << "NO" << endl;
        return 0;
    }

    if(num.size() == 0 or num[0] == num[1]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int n, k;
//int h[20000];       // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> n >> k;
    int h[n];
//    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    sort(h, h + n);  
    int min = 2000000000;

    for(int i = 0; i <= n-k; ++i){
        int delta = h[i+k-1] - h[i];
        if(delta < min) min = delta;
    }

    cout << min << endl;


}

Measured memory_bytes: 640
/*
２つの整数 x, y を読み込み、それらを値が小さい順に出力するプログラムを作成して下さい。
 */

#include <stdio.h>

void swap(int *a, int *b)
{
    int temp;

    temp = *a;
    *a = *b;
    *b = temp;
}

int main(void)
{
    int x, y;
    int i;

    for(i = 0; i < 3000; i++)
    {
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0)
        {
            return (0);
        }
        else
        {
            if (x > y)
                swap(&x, &y);
            printf("%d %d\n", x, y);
        }
    }
    return (0);
}


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

using namespace std;

int main() {
	int A, B;
	string op;

	cin >> A >> op >> B;

	int ans;
	if (op == "+") ans = A + B;
	else ans = A - B;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256