akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define vl vector<long long>
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define**********************************/

/*****************************functions********************************/
ll MAX_N =  100001;
/****************************main function*****************************/
int main(void){
    vector<double> S(MAX_N);
    S[0] = 1;
    for(int i = 1;i <= MAX_N;i++){
        S[i] = S[i-1] * 0.5;
    }

    int N,K; cin >> N >> K;
    double ans = 0; // 最後にNでわる
    for(int i = 1;i <= N;i++){
        if(i >= K){
            ans += 1;
            //cout << 1 << endl;
            continue;
            
        }
        double t = K-1/i;
        ans += S[(int)log2((K-1)/i) + 1];
       // cout << (int)log2(t) + 1  << endl;
        
    }
    printf("%.16lf\n",ans/(double)N);
    return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int d = b / a;

    d >= c ? cout << c : cout << d;
}

Measured memory_bytes: 256
#include<cstdio>;
//入出力を行う関数が使える//(scanf,printf)
#include<cctype>;

int main(){
    char ch;
    
    while(true){
        scanf("%c",&ch);
        if (isalpha(ch)){
            //chがアルファベットならtrueを返す//
            if(islower(ch)) printf("%c",toupper(ch));
            //chが小文字ならtrueを返す// //chの大文字を返す//
            else printf("%c", tolower(ch));
            //chの小文字を返す//
        } else printf("%c",ch);
        //アルファベット以外はそのまま出力//
        
        if (ch == '\n') break;
        //終端文字が現れたら終了//
    }
    return 0;
}


Measured memory_bytes: 2680
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
//#define int long long
#define double long double
#define vec vector
#define vi vector<int>
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first, l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }

int n;
vi w, pre;

void solve() {
	cin >> n;
	w.resize(n); pre.resize(n+1);
	FOR(i, 0, n) cin >> w[i];
	pre[0] = 0;
	FOR(i, 1, n+1) pre[i] = pre[i-1] + w[i-1];

//	FOR(i, 0, n+1) cout << pre[i] << " "; cout << endl;

	int mx = INT_MAX;
	FOR(i, 1, n) {
		int m = (int) abs(pre[i] - (pre[n] - pre[i]));
		mx = min(mx, m);
	}
	cout << mx << endl;
}

//#undef int
signed main() {
//#define int long long
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

// int t; cin >> t;
//  while (t--)
  {
		solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
int A[2000000],C[N],B[2000001];
int main()
{
  int i,n;

  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++){
    C[i]=0;
  }
  for(i=1;i<n+1;i++){
    C[A[i]]+=1;
  }
  for(i=0;i<N;i++){
    C[i]+=C[i-1];
  }
  for(i=n+1;i>0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]-=1;
  }

  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d",B[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 18256
import Control.Monad (replicateM_, liftM)
import Text.Printf (printf)

main = do
    n <- readLn
    replicateM_ n (input >>= output . solve)

type Point = (Double, Double)
type Radius = Double

input :: IO (Point, Point, Point)
input = do
    line <- getLine
    let
        [ox,oy,ax,ay,bx,by] = map read $ words line
    return ((ox,oy),(ax,ay),(bx,by))

output :: (Point, Radius) -> IO ()
output ((cx,cy),r) = printf "%.3f %.3f %.3f\n" cx cy r

solve :: (Point, Point, Point) -> (Point, Radius)
solve ((ox',oy'),(ax',ay'),(bx',by')) = (center, radius)
    where
    center = (cx', cy')
    radius = sqrt (cx*cx + cy*cy)

    cx' = ox' + cx
    cy' = oy' + cy

    cx = s * ax + t * bx
    cy = s * ay + t * by

    s = (a2 * b2 - ab * b2) / 2.0 / (a2 * b2 - ab * ab)
    t = (a2 * b2 - ab * a2) / 2.0 / (a2 * b2 - ab * ab)

    a2 = ax * ax + ay * ay
    b2 = bx * bx + by * by
    ab = ax * bx + ay * by

    ax = ax' - ox'
    ay = ay' - oy'
    bx = bx' - ox'
    by = by' - oy'

Measured memory_bytes: 4484
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a;
  cin>>a;
  cout<<a+(a*a)+(a*a*a)<<endl;

  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

//しっかり制約確認したか?
int main()
{
    int n; cin >> n;
    map<ll, int> m;
    for(int i = 1; i <= 110; i++){
        for(int j = 1; j <= 110; j++){
            for(int k = 1; k <= 110; k++){
                ll t = (i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
                m[t]++;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << m[i] << endl;
    }
    system("pause");
}


Measured memory_bytes: 6528
A = input()
B = input()
if A == "1":
    if B == "2":
        print("3")
    else:
        print("2")
elif A == "2":
    if B == "1":
        print("3")
    else:
        print("1")
else:
    if B == "1":
        print("2")
    else:
        print("1")


Measured memory_bytes: 38256
import scala.io.StdIn.readLine

object Main extends App {
  def calc(op:String,x:Int,y:Int) = {
    op match {
      case "+" => x+y
      case "-" => x-y
      case "*" => x*y
    }
  }

  val l = readLine.split(" ")

  def revP(n:Int,stack:List[Int]):Int =  {
    if(n==l.length) stack(0)
    else {
      val s = l(n)
      val stack2 =
        if(s.forall(_.isDigit)) s.toInt::stack
        else {
          val x::y::tail = stack
          calc(s,y,x)::tail
        }
      revP(n+1,stack2)
    }
  }

  println(revP(0,List()))

}

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

using namespace std;

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 1000
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

char str1[100111], str2[100111];
ll p1bc[100111], p1ac[100111], p2ac[100111], p2bc[100111], q;

pair<ll,ll> getNorm(ll ac, ll bc) {
	ac+=999999LL, bc+=999999LL;
	ac %= 3LL, bc %= 3LL;
	if(ac == 0 && bc == 0)	return {0,0};
	if(ac == 1 && bc == 0)	return {1,0};
	if(ac == 2 && bc == 0)	return {0,1};
	if(ac == 0 && bc == 1)	return {0,1};
	if(ac == 1 && bc == 1)	return {0,0};
	if(ac == 2 && bc == 1)	return {1,0};
	if(ac == 0 && bc == 2)	return {1,0};
	if(ac == 1 && bc == 2)	return {0,1};
	if(ac == 2 && bc == 2)	return {0,0};



	// while(ac + bc >= 2) {
	// 	if(ac == 2)	ac-=2, bc++;
	// 	if(bc == 2)	bc-=2, ac++;
	// 	if(ac == 1 && bc == 1)	ac = 0, bc = 0;
	// 	ac%=3LL, bc%=3LL;
	// 	// printf("LOOP %lld %lld\n",ac,bc);
	// }
	return {ac,bc};
}

int main () {
	scanf("%s",str1);
	scanf("%s",str2);
	scanf("%lld",&q);
	if(str1[0] == 'A')	p1ac[0] = 1;
	else			p1bc[0] = 1;
	if(str2[0] == 'A')	p2ac[0] = 1;
	else			p2bc[0] = 1;
	ll len = strlen(str1);
	for(int i=1;i<len;i++) {
		p1ac[i] = p1ac[i-1], p1bc[i] = p1bc[i-1];
		if(str1[i] == 'A')	p1ac[i]++;
		if(str1[i] == 'B')	p1bc[i]++;
	}	
	len = strlen(str2);
	for(int i=1;i<len;i++) {
		p2ac[i] = p2ac[i-1], p2bc[i] = p2bc[i-1];
		if(str2[i] == 'A')	p2ac[i]++;
		if(str2[i] == 'B')	p2bc[i]++;
	}


	// for(int i=0;i<strlen(str1);i++)
	// 	printf("%lld ",p1bc[i]);
	// printf("\n");

	for(int i=0;i<q;i++) {
		ll a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		ll ac,bc,cc,dc, a2c,b2c,c2c,d2c;
		if(a == 1)	ac = 0, cc = 0;
		else		ac = p1ac[a-2], cc = p1bc[a-2];

		bc = p1ac[b-1];
		dc = p1bc[b-1];



		if(c == 1)	a2c = 0, c2c = 0;
		else		a2c = p2ac[c-2], c2c = p2bc[c-2];

		b2c = p2ac[d-1];
		d2c = p2bc[d-1];

		pair<ll, ll> chk1 = getNorm(bc-ac,dc-cc), chk2 = getNorm(b2c-a2c,d2c-c2c);
		// printf("i %d (%lld %lld) (%lld %lld)\n",i,chk1.fi,chk1.se,chk2.fi,chk2.se);
		// printf("origin %lld, %lld   %lld, %lld\n",bc-ac,dc-cc,b2c-a2c,d2c-c2c);
		// printf("%lld - %lld\n",dc,bc);
		if(chk1 == chk2)	printf("YES\n");
		else			printf("NO\n");
	}
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std ;
int main () {
  int A, B, K;
  cin>>A>>B>>K;
  int cnt=0;
  
  for(int i = min(A, B); i>=1; i--){
    if (A%i==0 && B%i==0){
      cnt++;
    }
    if (cnt == K){
    cout<<i<<endl;
    return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    if(n % 2) return cout << 0, 0;
    ll ans = 0;
    for(ll i = 5; ;){
        ans += n / (2 * i);
        if(i > n / 5) break;
        i *= 5;
    }
    cout << ans;

    return 0;
}


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

using namespace std;

const int N = 1e5+7;

int n, k, r, s, p;
int a[N];
string str;

int main()
{
    cin >> n >> k >> r >> s >> p >> str;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (str[i] == 'r') {
            if (i-k >= 0 && str[i-k] == 'r' && !a[i-k]) {
                a[i] = 1;
            } else {
                res += p;
            }
        } else if (str[i] == 's') {
            if (i-k >= 0 && str[i-k] == 's' && !a[i-k]) {
                a[i] = 1;
            } else {
                res += r;
            }
        } else if (str[i] == 'p') {
            if (i-k >= 0 && str[i-k] == 'p' && !a[i-k]) {
                a[i] = 1;
            } else {
                res += s;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
typedef long long ll ;
int a[maxn];
int b[maxn];
int n,m;
priority_queue<int>q;
vector<int>v[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        v[a[i]].push_back(b[i]);
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<v[i].size();j++)
            q.push(v[i][j]);
        if(q.empty())
            continue;
        ans+=q.top();
        q.pop();
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    sort(p.begin(), p.end(), greater<int>());
    int ans = p[0] / 2;
    for (int i = 1; i < n; ++i) {
        ans += p[i];
    }
    cout << ans << endl;

    return 0;
}


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


int main(){
    LL l,k;cin >> l >> k;
    vector<LL> dp(l+1,0);
    dp[1]=1;
    if(k<=l) dp[k++]=1;
    for (int i = 1; i <= l; i++) {
        if(i+2<=l) dp[i+2]+=dp[i];
        if(i+k<=l) dp[i+k]+=dp[i];
    }
    cout << accumulate(dp.begin()+1,dp.end(),0LL) << endl;
    return 0;
}



Measured memory_bytes: 3120
/*
-----------------------------------------------------------------------------
Author :            ---------------------------------------------------------
    UTKAR$H $AXENA  ---------------------------------------------------------
    GOOGLE          ---------------------------------------------------------
-----------------------------------------------------------------------------
*/
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define fre freopen("0.in", "r", stdin), freopen("0.out", "w", stdout)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007
#define LL signed long long int
#define ps(x) push_back(x)
#define scan(x) scanf("%d", &x)
#define print(x) printf("%d\n", x)
#define scanll(x) scanf("%lld", &x)
#define printll(x) printf("%lld\n", x)
#define boost ios_base::sync_with_stdio(0)
vector<int> G[2 * 100000 + 5];
int dead[200000 + 4];
int neigh[200000 + 3][2];
int N, M;
string S;
int f = 0;
bool check(int v) { return neigh[v][0] > 0 and neigh[v][1] > 0; }
void kill(int v) {
  // cout << "Killing " << v << endl;
  dead[v] = 1;
  for (int u : G[v]) {
    neigh[u][S[v - 1] - 'A']--;
  }
  for (int u : G[v]) {
    if (dead[u] == 0 and !check(u)) {
      kill(u);
    }
  }
}
int main() {
  // fre;
  cin >> N >> M;
  cin >> S;
  for (int i = 1; i <= M; ++i) {
    int u, v;
    scan(u);
    scan(v);
    G[u].push_back(v);
    G[v].push_back(u);
    neigh[u][S[v - 1] - 'A']++;
    neigh[v][S[u - 1] - 'A']++;
    // cout << neigh[u][0] << ' ' << neigh[u][1] << endl;
  }
  for (int i = 1; i <= N; ++i) {
    // cout << i << ' ' << check(i) << endl;
    // fflush(stdout);
    if (dead[i] == 0 and !check(i))
      kill(i);
  }
  for (int i = 1; i <= N; ++i)
    if (dead[i] == 0)
      f = 1;
  cout << (f ? "Yes" : "No");
}


Measured memory_bytes: 18692
from sys import stdin
 
readline = stdin.readline
 
def main():
    _, *A = map(int, open(0).read().split())
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 14116
#include <stdio.h>
#include <math.h>

int main(void) {
	double q;
	double x;
	while(1) {
		scanf("%lf",&q);
		if(q==-1)break;
		x=fabs(q/2);
		while(fabs(x*x*x-q)>=0.00001*q) {
			x=x-(x*x*x-q)/(3*x*x);
		}
		printf("%f\n",x);
	}
	return 0;
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 143
typedef long long ll;
const ll inf = 1ll << 40;

ll dist[300][300];
ll ans[300][300];

int main(){

    int N, M, L;
    cin >> N >> M >> L;

    rep(i, N)rep(j, N)if(i != j){
        dist[i][j] = inf;
        ans[i][j] = inf;
    }

    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    rep(k, N)rep(i, N)rep(j, N){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    rep(i, N)rep(j, N){
        if(dist[i][j] <= L)ans[i][j] = 1;
    }
    rep(k, N)rep(i, N)rep(j, N){
        ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
    }

    int Q;
    cin >> Q;
    rep(i, Q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        ll answer = ans[s][t];
        if(answer >= inf)cout << "-1\n";
        else cout << answer - 1 << '\n';
    }

}

Measured memory_bytes: 1920
N, K = map(int, input().split())


def combination(n, r):
    ans = 1
    for i in range(r):
        ans *= n - i
    for i in range(r):
        ans //= i + 1
    return ans


# a+b % K == 0
# b+c % K == 0
# c+a % K == 0

# a が Kで割り切れる場合
#   -> bもcもKで割り切れる
#   -> a,b,cともにKの倍数
#   -> Kの倍数の個数(N//K) ** 3

# a がKで割れきれない場合
#   -> 同じくbもcもKで割り切れない
#   Q. Kが奇数の場合
#     -> それを満たす(a,b,c)の組み合わせはあり得ない
#   よってKは偶数
#     K=2のとき例より (a,b,c)=(1,1,1),(1,3,3),...
#     K=4のとき(a,b,c)=(2,2,2),(2,6,6),...
#     K=6のとき(a,b,c)=(3,3,3),(3,3,9),...
#   よりa % K == K/2である必要がある
#     a = x*K+K/2 (x=0以上の整数)

num_double = N//K
if K % 2 == 1:
    # Kが奇数の場合
    #  (1) (a,b,c)ともにKの倍数
    print(num_double ** 3)
else:
    # Kが偶数の場合,
    #  (1) (a,b,c)ともにKの倍数
    #  (2) (a,b,c)がいずれも Kで割った余りがK/2となる
    s = K // 2
    nums = [a for a in range(s, N+1, K)]
    n = len(nums)
    count = 0
    count += 6 * combination(n, 3)  # a,b,cがいずれも異なる値になるケースはnC3通り 順列は6倍
    count += 3 * n * (n-1)   # a,b,cのうち2つが同じ値になるケースはn(n-1)通り 順列は3倍
    count += n  # a,b,cが同じ値になるケースはn通り
    print(num_double ** 3 + count)


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

int main(){
    char s;
    cin >> s;
    s=s+1;
    cout << s << endl;

    return 0;
}

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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  cout << (s[0] == s[n - 1] ^ n % 2 ? "First" : "Second") << '\n';
  return 0;
}

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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    int count=0;
    int ac=0;
    int mp[100005]={0};
    rep(i,M){
        int p; string S;
        cin>>p>>S;
        if (mp[p] != -1)
        {
            if (S=="AC") {
                count+=mp[p];
                ++ac;
                mp[p] = -1;
            }
            else ++mp[p];
        }
        
    }

    cout<<ac<<" "<<count<<endl;
    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
LL = inpl()
if max(LL)*2 >= sum(LL):
    print('No')
else:
    print('Yes')


Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a(0), b(0), c(0), ret(0);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int l = s.length();
    if (s[l - 1] == 'A' && s[0] == 'B') c++;
    else if (s[0] == 'B') b++;
    else if (s[l - 1] == 'A') a++;
    for (int i = 0; i < l - 1; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B') ret++;
    }
  }
  if (a && b) ret += min(a + c, b + c);
  else if (a) ret += min(a + c - 1, c);
  else if (b) ret += min(b + c - 1, c);
  else ret += max(c - 1, 0);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s,t;
    cin>>s>>t;
    if (s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0])
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define N 64

int main()
{
    //lol result{0};
    lol x; cin >> x;
    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    bool fl = true;
    for(int i = 0; i < INF && fl; i++)
    {
        for(int j = -64; j < INF; j++)
        {
            if(pow(i, 5) - pow(j, 5) == x)
            {
                cout << i << " " << j << endl;
                fl = false;
                break;
            }
            if(j >= 0 && pow(i, 5) - pow(j, 5) < x)
                break;
        }
    }

    //cout << result << endl;
    return 0;
}

Measured memory_bytes: 4060
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-10;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[320][320];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	int ret=0;
	for(int i=0;i<a;i++){
		bool ok=true;
		for(int j=0;j<a;j++){
			for(int k=0;k<a;k++){
				if(in[j][(k+i)%a]!=in[k][(j+i)%a])ok=false;
			}
		}
		if(ok)ret++;
	}
	ret*=a;
	printf("%d\n",ret);
}

Measured memory_bytes: 384
#include <cstdio>
#include <queue>
#include <vector>
#include <functional>
typedef long long ll;
using namespace std;
priority_queue <ll> que2;
priority_queue <ll, vector<ll>, greater<ll> > que1;
const int maxn = 400000;
ll a[maxn], sum1[maxn], sum2[maxn];
int main()
{
	ll n;
	scanf("%lld",&n);
	for (ll i = 0; i < 3*n; i++)
	{
		scanf("%d",&a[i]);
	}
	
	for (ll i = 0; i <= 2 * n; i++)
	{
		if (i < n)
		{
			que1.push(a[i]);
			if (i > 0) sum1[i] = sum1[i - 1];
			sum1[i] += a[i];
		} 
		else
		{
			que1.push(a[i]);
			ll st = que1.top();
			que1.pop();
			
			sum1[i] = sum1[i - 1] - st + a[i];
			  
		}
	}
	
	for (ll i = 3 * n - 1; i >= n - 1; i--)
	{
		if (i >= 2 * n)
		{
			que2.push(a[i]);
			sum2[i] = sum2[i+1] + a[i];
		}
		else
		{
			que2.push(a[i]);
			ll lt = que2.top();
			que2.pop();
			sum2[i] = sum2[i + 1] -lt + a[i]; 
		} 
	}
	ll ans = -1455678098767896LL;
	for (ll i = n - 1; i <= 2 * n - 1; i++)
	{
		if (sum1[i] - sum2[i + 1] > ans) 
		{
			ans = sum1[i] - sum2[i+1];
		//	printf("i = %lld, sum1[i] = %lld, sum2[i + 1] = %lld, ans = %lld\n",i,sum1[i],sum2[i+1],ans);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 9716
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>
using namespace std;


int main() {
	int A, B;
	cin >> A >> B; 
	if (A >= 13) {
		cout << B << endl;
	}
	else if (A >= 6 && A <= 12) {
		cout << B / 2 << endl;
	}
	else if (A <= 5) {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d=0;
    cin>>a>>b>>c;
    while (b!=0 && c!=0){
        c--;
        b--;
        d+=2;
    }
     while (c==0 && b!=0){
         b--;
         d++;
     }
     while (b==0 && c!=0 && a!=0){
        c--;
        a--;
        d++;
    }
     
     
     if (c!=0){
         c--;
         d++;
     }
     cout<<d;
}

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

void selectionSort(int A[], int N) {

	int counter = 0;

	for(int i=0;i<N;i++) {
		int minj = i;
		for(int j=i;j<N;j++) {
			if(A[j] < A[minj]) {
				minj = j;

			}
		}
		int tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
		if(i != minj) {
			counter++;
		}

	}

	for(int i=0;i<N;i++) {
		cout << A[i];
		if(i != N-1) {
			cout << " ";
		}
	}
	cout << endl;
	cout << counter << endl;
}


int main(void) {

	int n;
	cin >> n;

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

	selectionSort(a, n);


	return 0;
}

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


void solve(long long N, long long X, long long Y){
    vector<vector<int>> cost(N,vector<int>(N,N+1));
    vector<int> count(N,0);
    for(int i=0;i<N;i++){
        for(int j = i;j<N;j++){ 
            cost.at(i).at(j) = j-i;    
        }
        for(int j = 0;j<i;j++){ 
            cost.at(i).at(j) = i-j;    
        }
    }
    cost.at(X-1).at(Y-1) = 1;
//Updata
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            cost.at(i).at(j) = min(cost.at(i).at(j),cost.at(i).at(X-1)+cost.at(Y-1).at(j) + 1);
        }
    }
//count
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            count.at(cost.at(i).at(j))++;
        }
    }
    for(int i=1;i<N;i++){
        cout << count.at(i) << endl;
    }
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


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

using namespace std;

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


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 

 class Main{
             
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             
             while((line=br.readLine())!= null){if(line.isEmpty())break;
                String[] spl=line.split(" ");
                int a=Integer.parseInt(spl[0]);
                int b=Integer.parseInt(spl[1]);
                int n=Integer.parseInt(spl[2]);
                double d=a/(b+0.0);int s=0;
                for(int i=0;i<n;i++){
                    a*=10;
                    s += (a/b)%10;
                    a = a%b;
                    //d*=10;//System.out.println(d);
                    //int k=(int)(d);//System.out.println(k);
                    //s+=k%10;
                }
                 System.out.println(s);
                
             }br.close();
             
         }catch(Exception e){}         
     }
   
 }

Measured memory_bytes: 16952
import sys
N = int(input())
Data = []
for _ in range(N):
    x,y,h = map(int,input().split())
    Data.append([x,y,h])

Data.sort(key=lambda x:x[2],reverse=True)

for cx in range(101):
    for cy in range(101):
        found = True
        ans   = -1
        for i in range(N):
            x,y,h = Data[i]
            if i == 0:
                # h != 0
                ans = h + abs(x-cx)+abs(y-cy)
            else: 
                diff = ans - abs(x-cx)-abs(y-cy)
                if  diff < 0:
                    if h != 0:
                        found = False
                        break
                else: 
                    if diff != h:
                        found = False
                        break
        if found == True:
            print( '{} {} {}'.format(cx,cy,ans))
            sys.exit()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>

using namespace std;
typedef long long ll;
string s,t;
int main(){
	cin >> s >> t;
	t += t;
	int n = s.size();
	for(int i=1;i<=n;i++){
		if(s == t.substr(i,n)){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


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

    int sum = 0;
    int ma = 0;
    for (int i = 1; i <= n; i++) {
        sum += i;
        ma = i;

        if (sum > n) break;
    }
    int diff = sum - n;

    for (int i = 1; i <= ma; i++) {
        if (i != diff)
            cout << i << endl;
    }

}




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

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

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

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    double ans = 0;
    rep(_, 0, n) {
        double d;
        cin >> d;
        ans += 1 / d;
    }
    printf("%.10f\n", 1 / ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

typedef long long ll;

int n;
ll val[200002], ans[200002];
int md(int x)
{
    if(x <= n)
        return x;
    if(x - 1 == n)
        return 1;
    if(x - 2 == n)
        return 2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; ++i)
        cin >> val[i], sum += val[i];
    ll summ = 0;
    for(int i = 1; i <= n; i += 2)
        summ += val[i];
    summ *= 2;
    int st = 1;
    int dr = n;
    do{
        ans[st] = summ - sum;
        summ -= 2 * val[st];
        summ += 2 * val[md(dr + 2)];
        st += 2;
        dr += 2;
        st = md(st);
        dr = md(dr);
    }while(st != 1);
    for(int i = 1; i <= n; ++i)
        cout << ans[i] << " ";
    return 0;
}


Measured memory_bytes: 2944
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input = '';
process.stdin.on('data', function (chunk) {
  input += chunk;
});
process.stdin.on('end', function () {
  var lines = input.split('\n');
  var l = 0;
  while (true) {
    var n = Number(lines[l++]);
    if (n === 0) {
      break;
    }
    for (var i = 0; i < n; i++) {
      var values = lines[l++].split(' ').map(Number);
      var pm = values[0];
      var pe = values[1];
      var pj = values[2];
      var ans = 'C';
      if (pm === 100 || pe === 100 || pj === 100) {
        ans = 'A';
      } else if ((pm + pe) / 2 >= 90) {
        ans = 'A';
      } else {
        var average = (pm + pe + pj) / 3;
        if (average >= 80) {
          ans = 'A';
        } else if (average >= 70) {
          ans = 'B';
        } else if (average >= 50 && (pm >= 80 || pe >= 80)) {
          ans = 'B';
        }
      }
      console.log(ans);
    }
  }
});

Measured memory_bytes: 10916
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
struct edge
{
    long long to;
    long long cost;
};
typedef pair<long long, long long> P; //P.first:最短距離,P.second:頂点の番号
//頂点V個の負閉路なし重み付きグラフGにおける始点sからの最短距離を求める
long long VV;
vector<vector<edge>> G;
void dijkstra(vector<long long> &dist, long long s)
{
    //greater<P>によってfirstが小さい順に取り出される
    priority_queue<P, vector<P>, greater<P>> que;
    for (long long i = 0; i < VV; i++)
        dist[i] = 1e18;
    dist[s] = 0;
    que.push(P(0, s));
    //queが空になるまで繰り返す
    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (dist[v] < p.first)
            continue; //すでに最短距離ならスルー
        for (long long i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            //更新作業
            if (dist[e.to] > dist[v] + e.cost)
            {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
}
int main()
{
    cout << fixed << setprecision(30);
    long long N, M, S;
    cin >> N >> M >> S;
    VV = N * 2501; //とりあえず2500枚あれば安泰(0~2500の遷移)
    G.resize(VV);  //グラフを確保
    //入力受け取り
    vector<long long> U(M), V(M), A(M), B(M);
    vector<long long> C(N), D(N);
    for (long long i = 0; i < M; i++)
    {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--;
        V[i]--;
    }
    for (long long i = 0; i < N; i++)
        cin >> C[i] >> D[i];
    //まずは同じ頂点の上部(銀貨が多い方向)へ向かう有向辺を結ぶ
    for (long long i = 0; i < N; i++)
    {
        for (long long j = 0; j < 2500; j++)
        {
            edge e;
            if (j + C[i] >= 2501)
                e.to = i * 2501 + 2500; //行きすぎたら切り捨てる(max2500枚)
            else
                e.to = i * 2501 + (j + C[i]);
            e.cost = D[i];
            G[i * 2501 + j].push_back(e);
        }
    }
    //次に違う頂点間を渡るとき銀貨の必要枚数だけ下るような有向辺を結ぶ(頂点の最下部(銀貨0)より下にいったら結ばない)
    for (long long i = 0; i < M; i++)
    {
        //uからvへの有向辺
        for (long long j = 2500; j >= 0; j--)
        {                                  //j=2500~>0,jはuの現在のコインの枚数
            long long nextcoin = j - A[i]; //nextcoin:vの現在のコインの枚数
            if (nextcoin < 0)
                break;
            edge e;
            e.to = V[i] * 2501 + nextcoin;
            e.cost = B[i];
            G[U[i] * 2501 + j].push_back(e);
        }
        //vからuへの有向辺
        for (long long j = 2500; j >= 0; j--)
        {                                  //j=2500~>0,jはvの現在のコインの枚数
            long long nextcoin = j - A[i]; //nextcoin:uの現在のコインの枚数
            if (nextcoin < 0)
                break;
            edge e;
            e.to = U[i] * 2501 + nextcoin;
            e.cost = B[i];
            G[V[i] * 2501 + j].push_back(e);
        }
    }
    vector<long long> dist(VV);
    dijkstra(dist, min(S, 2500ll)); //頂点0でコインをmin(S,2500)持っている状態からスタート
    //都市t(t=1~>N-1)について、各コインの状態を全探索(一応)
    for (long long i = 1; i < N; i++)
    { //i=1~>N-1
        long long ans = 1e18;
        for (long long j = 0; j <= 2500; j++)
            ans = min(dist[i * 2501 + j], ans);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 23736
def main():
    S = input()
    result = 0
    cnt = 0
    for s in S:
        if s in ['A', 'G', 'C', 'T']:
            cnt += 1
        else:
            cnt = 0
        if result < cnt: result = cnt
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

int main()
{
	using namespace std;
	long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0, count = 0,nagax=0,nagay=0;
	int once[100020] = {}, info[100020] = {};
	std::string str,strs;
	
	bool okada =false, okada2 = true;
	cin >> a>>b;
	for (int i = 1; i <= 3; i++) {
		if ((a*b*i) % 2 == 1) {
			okada = true;
			break;
		}
		else {

		}
	}

	if (okada) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}





Measured memory_bytes: 256
# b棟f階r番目の部屋にv人追加
doms = [[[0 for i in range(10)] for j in range(3)]for k in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = input().split()
    doms[int(b) - 1][int(f)-1][int(r)-1] += int(v)

for i, tou in enumerate(doms):
    for floor in tou:
        # print("floor : {}".format(floor))
        for room in floor:
            print(" {}".format(room), end="")
        print("")
    if i < 3:
        print("#" * 20)


Measured memory_bytes: 5624
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, s: str):
    nb = len(list(filter(lambda c:c=='B', s)))
    ans = YES if N - nb > nb else NO
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()


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

using namespace std;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;


int N;
ll A[212345], CA[212345];

V<pair<ll, ll>> splits() {
	V<pair<ll, ll>> ans;
	ll rs = 0;
	FO(i, N) {
		rs += A[i];
		int lo = 0, hi = i;
		while (lo < hi) {
			int mid = (lo+hi+1)/2;
			if (CA[mid] <= rs-CA[mid]) {
				lo = mid;
			} else {
				hi = mid-1;
			}
		}
		assert(lo < N-1);
		if (abs(CA[lo+1]-(rs-CA[lo+1])) < abs(CA[lo] - (rs-CA[lo])))
			ans.emplace_back(CA[lo+1], rs-CA[lo+1]);
		else
			ans.emplace_back(CA[lo], rs-CA[lo]);
	}
	return ans;
}


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

	cin >> N;
	FO(i, N) cin >> A[i];
	partial_sum(A, A+N, CA);


	auto l = splits();
	
	reverse(A, A+N);
	partial_sum(A, A+N, CA);

	auto r = splits();

	reverse(r.begin(), r.end());

	// for (auto e : r) {
	// 	cout << e.first << "," << e.second << " ";
	// }
	// cout << endl;

	ll ans = 1e18;

	for (int i = 1; i < N-2; ++i) {
		auto lp = l[i];
		auto rp = r[i+1];
		ll mm = min(lp.first, lp.second);
		mm = min(mm, rp.first);
		mm = min(mm, rp.second);
		ll mx = max(lp.first, lp.second);
		mx = max(mx, rp.first);
		mx = max(mx, rp.second);
		ans = min(ans, abs(mm - mx));
		// cout << i << " " << mm << " " << mx << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 15212
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

i_i sz[200];
i_i st[1000];

bool my(i_i qwe, i_i rty){
  if(qwe.X != rty.X)return qwe.X < rty.X;
  return qwe.Y < rty.Y;
}
bool issame(i_i qwe, i_i rty, int w, int h){
  return (qwe.X + w == rty.X) && (qwe.Y + h == rty.Y);
}

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(m);
    if(!m)break;
    rep(i, m)scanf("%d%d", &sz[i].X, &sz[i].Y);
    int(n);
    rep(i, n)scanf("%d%d", &st[i].X, &st[i].Y);

    sort(sz, sz + m, my);
    sort(st, st + n, my);

    rep(i, n){
      i_i nowm = sz[0];
      i_i nown = st[i];
      j = 0;
      int k = i;
      for(;k < n && j < m;){
        if(issame(sz[j], st[k], nown.X - nowm.X, nown.Y - nowm.Y))++j;
        ++k;
      }
      if(k == n)continue;
      if(j == m){
        printf("%d %d\n", nown.X - nowm.X, nown.Y - nowm.Y);
        break;
      }
    }


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3196
<?php
$N = trim(fgets(STDIN));
$memo = [];
$res=0;

foreach(range(1, $N) as $num){
    if($num % 2 == 0) continue;
    $count=0;

    for($i=1; $i<=$num; $i++) {
        if($num % $i == 0) $count++;
    }

    if($count==8) $res++;
}

echo $res;


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N;cin>>N;
    vector<int> p(N+1,2);
    int X,A,ans=0;
    rep(i,3){
        cin>>X;
        rep(j,X){
            cin>>A;
            if(i==0)++p[A];
            if(i==1)p[A]-=2;
            if(i==2&&p[A]<3) ++ans;
        }
    }
    put(ans);
}


Measured memory_bytes: 3088
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		BinaryIndexedTree bit = new BinaryIndexedTree(n + 1);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int type = sc.nextInt();
		    int x = sc.nextInt();
		    int y = sc.nextInt();
		    if (type == 0) {
		        bit.add(x, y);
		    } else {
		        sb.append(bit.getSum(x, y)).append("\n");
		    }
		}
		System.out.print(sb);
	}
}

class BinaryIndexedTree {
    int size;
    int[] tree;
    
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new int[size];
    }
    
    public void add(int idx, int value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] += value;
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public int getSum(int from, int to) {
        return getSum(to) - getSum(from - 1);
    }
    
    public int getSum(int x) {
        int mask = 1;
        int ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans += tree[x];
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}


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

using namespace std;

vector <int> coin;

int dp[100005];

int go(int cur) {
  if(cur < 0) return 1e5 + 10;
  if(cur == 0) return 0;
  if(dp[cur] != -1) return dp[cur];
  int res = 1e5 + 5;
  for(int i = 0; i < coin.size(); i++) {
    if(coin[i] <= cur) res = min(res, 1 + go(cur - coin[i]));
  }
  return dp[cur] = res;
}

int main() {
  int n; scanf("%d", &n);
  coin.push_back(1);
  for(int i = 6; i <= n; i *= 6) {
    coin.push_back(i);
  }
  for(int i = 9; i <= n; i *= 9) {
    coin.push_back(i);
  }
  //sort(coin.begin(), coin.end());
  //cout << coin.size() << '\n';
  memset(dp, -1, sizeof dp);
  printf("%d\n", go(n));
  return 0;
}


Measured memory_bytes: 3712
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from copy import deepcopy
def main():
    n, *a = map(int, read().split())

    if n == 2:
        r = [abs(a[1] * 2), abs(a[0] * 2)]
        print(*r, sep='\n')
        sys.exit()

    amin = min(a)
    # 全aiを移動するコストを出す
    # 便宜のため、aの前後に0座標を追加する。
    a.insert(0, 0)
    a.append(0)
    # 単純化のため、aにマイナス座標がある(＝左の端がマイナス)なら、
    # 左の端＝座標0のコピーをつくる。マイナスではないなら単純コピー。
    if amin < 0:
        a2 = [i - amin for i in a] # aminが正負どちらでもこれでOK
    else:
        a2 = deepcopy(a)
    # aを全て回った場合のコストを出す
    cost = 0
    for i1 in range(n + 1):
        cost += abs(a2[i1] - a2[i1 + 1])
    # rに答を格納する。aの前後に１要素足しているので長さを合わせる。
    r = [cost] * (n + 2)
    # a[i]それぞれをパスする場合のコストを出す。場合分けする。
    for j in range(1, n + 1):
        if a2[j - 1] <= a2[j] <= a2[j + 1]:
            continue
        elif a2[j - 1] >= a2[j] >= a2[j + 1]:
            continue
        elif a2[j - 1] <= a2[j] and a2[j + 1] <= a2[j]:
            nearer_dis = min(abs(a2[j - 1] - a2[j]), abs(a2[j] - a2[j + 1]))
            r[j] -= nearer_dis * 2
        else:
            nearer_dis = min(abs(a2[j] - a2[j - 1]), abs(a2[j + 1] - a2[j]))
            r[j] -= nearer_dis * 2
    print(*r[1:-1], sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 21632
from math import floor, log2
from collections import deque

def main():
    H = int(input())
    n = floor(log2(H))
    ct = 0
    for i in range(n+1):
        ct += pow(2, i)
    print(ct)
    # M = deque([H])
    # ct = 0
    # while M:
    #     v = M.popleft()
    #     if v > 1:
    #         new_v = floor(v/2)
    #         M.append(new_v)
    #         M.append(new_v)
    #     ct += 1
    # print(ct)

        
    

main()

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

int main(){
  int n,i,j,count=0,min;
  cin>>n;
  int a[n];
  for (i=0;i<n;i++)cin>>a[i];

  for (i=0;i<n;i++){
    min=i;
    for (j=i;j<n;j++){
      if (a[j]<a[min])min=j;
    }
    swap(a[i],a[min]);
    count+=(min!=i);
  }
  for (i=0;i<n;i++){
    if (i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
  cout<<count<<endl;
}



Measured memory_bytes: 3080