akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    A, B = map(int, input().split())
    P = list(map(int, input().split()))
    p1 = 0
    p2 = 0
    p3 = 0
    for p in P:
        if p <= A:
            p1 += 1
        elif p <= B:
            p2 += 1
        else:
            p3 += 1
    print(min(p1, p2, p3))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <iomanip>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

int main()
{
	double L,a,b,c,ans=0;
	string S,T;
	cin>>L;
	a=L/3;
	
	cout<<std::setprecision(100)<<a*a*a;
}


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

int main(){
    int N, A, B;
    int ans = 0;
    bool sw = false;
    cin >> N >> A >> B;
    for (int a = 0; a < 10; a++){
        for (int b = 0; b < 10; b++){
            for (int c = 0; c < 10; c++){
                for (int d = 0; d < 10; d++){
                    if (a * 1000 + b * 100 + c * 10 + d > N) {
                        sw = true;
                        break;
                    }
                    if (a + b + c + d >= A && a + b + c + d <= B)
                        ans += a * 1000 + b * 100 + c * 10 + d;
                }
                if(sw) break;
            }
            if(sw) break;
        }
        if(sw) break;
    }
    if (A == 1 && N == 10000) ans += 10000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>//for cin cout endl
#include <cstdlib>//for abs()
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF=1LL<<60;//1LL is integer one in LongLong
long long dp[100010];

int N;
//what is h?
long long h[100010];

int main(){

    int N;
    cin>>N;
    for (int i =0 ; i<N;++i)cin>>h[i];

    for (int i=0;i<100010;++i)dp[i]=INF;//initialize dp array
    dp[0]=0; //the first pillar


    dp[1]=abs(h[1]-h[0]);
    for (int i=2;i<100010;++i){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<endl;
}

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

typedef long long ll;
ll mod = 998244353LL;
const int maxn = 300010;

ll qpow(ll a, ll x)
{
    ll ret = 1;
    while(x)
    {
        if (x & 1)
        {
            ret = ret * a % mod;
        }

        a = a * a % mod;
        x >>= 1;
    }

    return ret;
}

ll fac[maxn],inv[maxn];
void init()
{
    // 阶乘
    fac[0] = 1;
    for (int i =1; i < maxn; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
    }

    inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 0; i--)
    {
        inv[i] = inv[i+1] * (i+1) % mod;
    }
}

ll c(ll n,ll m)
{
    if (n < m)
    {
        return 0;
    }

    return fac[n] * inv[m] % mod * inv[n-m] % mod;
}

int main()
{
    init();
    ll N, A, B, K;
    cin >> N >> A >> B >> K;
    ll ans = 0;

    for(int x = 0; x <= N; x++)
    {
        ll y = (K - A * x) / B;
        if(y >=0 && y <= N && K == A * x + B * y)
        {
            ans = (ans + c(N, x) * c(N, y)) % mod;
        }
    }
    cout << ans << endl;

    return 0;
}


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

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

  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  } 

  cout << "NG" << endl;

  return 0; 
}


Measured memory_bytes: 3632
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

//#define MOD 1000000007LL
#define MOD 998244353LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	if (n == m)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;

    Graph graph(N + 1, vector<int>());
    ll cnt = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = i; j <= N; ++j) {
            if (i == j) {
                continue;
            }
            if (N % 2 == 1) {
                if (j != N - i) {
                    cnt++;
                    graph[i].push_back(j);
                }
            } else {
                if (j != N - i + 1) {
                    cnt++;
                    graph[i].push_back(j);
                }
            }
        }
    }
    cout << cnt << endl;
    for (int i = 1; i <= N; ++i) {
        for (auto v : graph[i]) {
            cout << i << " " << v << endl;
        }
    }
}

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


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    print(N * (N + 1) // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61876
import java.util.*;
import java.lang.*;

class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			a[i] = sc.next().toCharArray();
		}

		for (int i = 0; i < h; i++) {
			int count = 0;
			for (int j = 0; j < w; j++) {
				if (a[i][j] == 'S' || a[i][j] == 'T') count++;
			}
			if (count >= 2) {
				System.out.println(-1);
				return;
			}
		}


		for (int j = 0; j < w; j++) {
			int count = 0;
			for (int i = 0; i < h; i++) {
				if (a[i][j] == 'S' || a[i][j] == 'T') count++;
			}
			if (count >= 2) {
				System.out.println(-1);
				return;
			}
		}

		Dinic dinic = new Dinic(h + w + 2);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				switch (a[i][j]) {
					case '.':
						break;
					case 'o':
						dinic.addEdge(i, h + j, 1);
						dinic.addEdge(h + j, i, 1);
						break;
					case 'S':
						dinic.addEdge(h + w, h + j, Integer.MAX_VALUE);
						dinic.addEdge(h + w, i, Integer.MAX_VALUE);
						break;
					case 'T':
						dinic.addEdge(h + j, h + w + 1, Integer.MAX_VALUE);
						dinic.addEdge(i, h + w + 1, Integer.MAX_VALUE);
						break;
				}
			}
		}

		long f = dinic.maxFlow(h + w, h + w + 1);
		System.out.println(f);
	}

	static class Dinic {
		private List<Edge>[] g;
		private int[] level;
		private int[] iterator;

		class Edge {
			int to;
			int cap;
			int residualId;

			public Edge(int to, int cap, int residualId) {
				this.to = to;
				this.cap = cap;
				this.residualId = residualId;
			}
		}

		public Dinic(int n) {
			g = new ArrayList[n];
			level = new int[n];
			iterator = new int[n];
			for (int i = 0; i < g.length; i++) {
				g[i] = new ArrayList<>();
			}
		}

		public void addEdge(int from, int to, int cap) {
			g[from].add(new Edge(to, cap, g[to].size()));
			g[to].add(new Edge(from, 0, g[from].size() - 1)); // residual path
		}

		public long maxFlow(int s, int t) {
			long flow = 0;
			while (true) {
				bfs(s);
				if (level[t] < 0) break;
				Arrays.fill(iterator, 0);
				while (true) {
					long f = dfs(s, t, Long.MAX_VALUE);
					if (f == 0) break;
					flow += f;
				}
			}
			return flow;
		}

		private void bfs(int s) {
			Arrays.fill(level, -1);
			Queue<Integer> q = new LinkedList<>();
			level[s] = 0;
			q.offer(s);
			while (!q.isEmpty()) {
				int v = q.poll();
				for (int i = 0; i < g[v].size(); i++) {
					Edge e = g[v].get(i);
					if (e.cap > 0 && level[e.to] < 0) {
						level[e.to] = level[v] + 1;
						q.offer(e.to);
					}

				}
			}
		}

		private long dfs(int s, int t, long f) {
			if (s == t) return f;
			for (int i = iterator[s]; i < g[s].size(); i = ++iterator[s]) {
				Edge e = g[s].get(i);
				if (e.cap > 0 && level[s] < level[e.to]) {
					long d = dfs(e.to, t, Math.min(e.cap, f));
					if (d > 0) {
						e.cap -= d;
						g[e.to].get(e.residualId).cap += d;
						return d;
					}
				}
			}
			return 0;
		}
	}
}


Measured memory_bytes: 26068
#include <algorithm>
#include <cstdio>

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;
    }
    swap(A[i], A[minj]);
    if (i != minj) counter++;
  }
  for (int i = 0; i < N; i++) {
    printf("%d", A[i]);
    if (i != N - 1) printf(" ");
  }
  printf("\n");
  printf("%d\n", counter);
}
int main() {
  int N, A[100];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  selectionSort(A, N);
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e5+10;
const ll inf=0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n,a,b;
    cin>>n>>a>>b;
    ll d=n/(a+b);
    ll x=n-d*(a+b);
    ll ans=d*a;
    ans+=min(n%(a+b),a);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll C[33];

int main(){
  ll N,A[100007],sum=0;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    sum^=A[i];
    ll T=1;
    while(A[i]%2==0){
      T++;
      A[i]/=2;
    }
    C[T]++;
  }
  ll ans=0;
  ll key=1LL<<31;
  rRep(i,32,1){
    if(key&sum){
      if(C[i]){
        ans++;
        sum^=(key<<1)-1;
      }
      else{
        cout << -1 << endl;
        return 0;
      }
    }
    key>>=1;
  }
  cout << ans << endl;
}

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

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

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

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int INF = 1<<30;
const ll mod = 998244353LL;

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

int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    if(c-a-b>=0&&4LL*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3580
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
f = defaultdict(int)
for i in range(m):
    a = I()
    f[a] = 1

dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if f[i]:
        continue
    if i > 1:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod
    else:
        dp[i] = dp[i-1]
        dp[i] %= mod
print(dp[n])

Measured memory_bytes: 50520
#include <bits/stdc++.h>
typedef long long ll;
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++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n) cout << s[i] << t[i];
    cout << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete



main = do
    k <- getInt
    when (k/=0) $ do
        cs <- getInts
        print $ sum cs `div` (k-1)
        main


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,x;
  cin>>n>>x;
  ll cnt=0;
  int a;
  rep(i,n)
  {
    int p;
    if(i>0)p=a;
    cin>>a;
    if(a>x)
    {
      cnt+=a-x;
      a=x;
    }
    if(i==0)continue;
    if(p+a>x)
    {
      cnt+=p+a-x;
      a-=(p+a-x);
    }
  }
  cout<<cnt<<endl;

  return 0;

}


Measured memory_bytes: 892
#ifndef TEMPLATE
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x,v) memset((x),(v),sizeof((x)));
#define A(x) (x).begin(),(x).end()
#define re(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define erp(i,k,n) for(int i=n;i>=k;i--)
#define input(v,n) re(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vi>;
using tp = tuple<int,int,int>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
#endif
// ===================== MANASH =================== //

int n;

void test() {

      cin >> n;
      int K; cin >> K;
      vi v(n); re(i,n) cin >> v[i];
      int dp[n]; mem(dp,0);
      dp[0] = 0; dp[1] = abs(v[1]-v[0]);
      for( int i = 2; i < n; i++) {
            int &me = dp[i];
            me = inf;
            for( int k = i-1; k >= 0 and k >= i-K; k--) {
                  me = min(me,dp[k]+abs(v[i]-v[k]));
            }
      }
      cout << dp[n-1];
}

signed main() {

      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
      int T = 1;
      //cin >> T;
      for( int tt = 1; tt <= T; tt++) {
            //cout << "Case #" << tt << " ";
            test();
            cout << "\n";
      }
      return 0;

}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD= 998244353;

int N;
LL A[314];
LL dp[314][45451];
LL dp2[314][45451];

LL mypow(LL base, LL exp) {
  if (exp == 0) return 1;
  LL res = mypow(base*base%MOD, exp/2);
  if (exp%2) res = res*base%MOD;
  return res;
}

int main() {
  cin >> N;
  LL S = 0;
  reps(i, 1, N+1) {
    cin >> A[i];
    S += A[i];
  }

  dp[0][0] = 1;
  dp2[0][0] = 1;
  int lim = S/2;
  reps(i, 1, N+1) {
    rep(j, lim+1) {
      if (j+A[i] <= lim) {
        dp[i][j+A[i]] += dp[i-1][j]*2;
        dp[i][j+A[i]] %= MOD;
        dp2[i][j+A[i]] += dp2[i-1][j];
        dp2[i][j+A[i]] %= MOD;
      }
      dp[i][j] += dp[i-1][j];
      dp2[i][j] += dp2[i-1][j];
      dp[i][j] %= MOD;
      dp2[i][j] %= MOD;
    }
  }

  LL ans = mypow(3, N);
  rep(j, lim+1) {
    if (j == lim && lim*2 == S) {
      //cout << dp[N][j] << " " << dp2[N][j] << endl;
      ans += MOD - (dp[N][j]-dp2[N][j]*2)*3%MOD;
      ans += MOD - dp2[N][j]*3%MOD;
    } else {
      ans += (MOD - dp[N][j])*3;
    }
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 216960
#include<iostream>
using namespace std;
char a[10][10];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int sum=0;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='#')
                sum++;
        }
    int cnt=0;
    int ans=0;
    for(int i=0; i<(1<<n); i++)
        for(int j=0; j<(1<<m); j++)
        {
            int cnt=0;
            for(int r=0; r<n; r++)
            {
                for(int c=0; c<m; c++)
                {
                    if( ((i&(1<<r)) ||(j&(1<<c))) &&a[r][c]=='#' )
                        cnt++;
                }
            }
            if(cnt==sum-k)
                ans++;
        }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	map<int,bool> mp;
	rep(i,n){
		if(i % 2 == 0){
			mp[a[i]] = true;
		} else {
			mp[a[i]] = false;
		}
	}
	SORT(a);
	int ans = 0;
	rep(i,n){
		if(i%2 == 0){
			if(mp[a[i]]){
			} else {
				ans++;
			}
		} else {
			if(mp[a[i]]) ans++;
		}
	}
	cout << ans/2 << endl;
}


Measured memory_bytes: 8260
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

vector<string>sts;
vector<vector<int>>edges;

void dfs(const int now,const int depth) {
	for (int i = 0; i < depth; ++i)cout << '.';
	cout << sts[now] << endl;
	for (auto e : edges[now]) {
		dfs(e, depth + 1);
	}
}

int main() {
	int N; cin >> N;
	edges.resize(N);
	for (int i = 0; i < N; ++i) {
		int k; string st; cin >> k >> st;
		sts.emplace_back(st);
		if (k) {
			k--;
			edges[k].emplace_back(i);
		}
	}
	dfs(0,0);
	return 0;
}

Measured memory_bytes: 3380
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<ll> T(N),A(N);
    REP(i,N) cin>>T[i];
    REP(i,N) cin>>A[i];
    
    vector<ll> difT(N,-1),difA(N,-1);

    difT[0]=T[0];
    difA[N-1]=A[0];
    REP2(i,1,N){
        if(T[i-1]!=T[i]){
            difT[i]=T[i];
        }
    }

    REPD2(i,N-2,-1){
        if(A[i]!=A[i+1]){
            difA[i]=A[i];
        }
    }

    ll ans=1;
    bool ok=true;
    REP(i,N){
        if(difT[i]!=-1&&difA[i]!=-1){
            if(difT[i]!=difA[i]) ok=false;
            if(difT[i]>A[i]) ok=false;
        }

        if(difT[i]!=-1&&difA[i]==-1){
            if(difT[i]>A[i]) ok=false;
        }

        if(difT[i]==-1&&difA[i]!=-1){
            if(difA[i]>T[i]) ok=false;
        }

        if(difT[i]==-1&&difA[i]==-1){
            ans*=min(A[i],T[i]);
            ans%=MOD;
        }
    }
    if(ok) cout<<ans<<endl;
    else cout<<0<<endl;


}

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

using namespace std;

#define ll  long long
#define vi  vector<int>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

  ll n,c;
  vector<pair<ll,ll> > v(100010);
  vector<ll> Asum(100010,0);
  vector<ll> Bsum(100010,0);
  vector<ll> Amax(100010,0);
  vector<ll> Amax_rep(100010,0);
  ll ans =0;

void solve(int pos){

  Asum[pos] = Asum[pos - 1] + v[pos].second;
  Bsum[n - pos + 1] = Bsum[n - pos + 2] + v[n - pos + 1].second;

 }

int main(){

  cin >> n >>c;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    v[i + 1] = mp(a,b);
  }

  v[n+1]= mp(c,0);

  rep(i,n)solve(i + 1);

  rep(i,n){ // compute on A of rep and nonrep
    Amax[i + 1] = max(Amax[i], Asum[i + 1] - v[i + 1].first);
    Amax_rep[i + 1] = max(Amax_rep[i], Asum[i + 1] - 2*v[i + 1].first);
  }

  rep(i,n + 1){
    int pos = n - i + 1;
    ll ans1 = Amax[pos - 1] + Bsum[pos] - 2*(c - v[pos].first); //A nonrep and B rep
    chmax(ans,ans1);
    ll ans2 = Amax_rep[pos - 1] + Bsum[pos] - (c - v[pos].first); // A rep and B nonrep
    chmax(ans,ans2);
  }

  pr(ans);

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int N;

bool ans;

int main()
{
	cin >> N;
	
	int n2 = 0;
	int n4 = 0;
	for (int i = 0; i < N; i++){
		int buf;
		
		cin >> buf;
		
		if (buf % 4 == 0){
			n4++;
		}else if (buf % 2 == 0){
			n2++;
		}
	}
	
	ans = false;
	int cnt = 0;
	
	cnt += n4 * 2 + 1;
	if (n2 > 1){
		cnt += n2;
	}
	if (n4 > 0 && n2 > 1 && cnt == N){
		cnt--;
	}
	
	if (cnt >= N){
		ans = true;
	}
	
	if (ans){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int ans = 1;
        ll dist = 0;
        ll n, x;

        cin >> n >> x;
        rep(i, 0, n) {
            int tmp;
            cin >> tmp;
            dist += tmp;
            if (dist <= x) ans++;
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
from math import sqrt
from sys import stdin
X = int(stdin.readline().rstrip())

def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    
    return True

while not is_prime(X):
    X += 1

print(X)

Measured memory_bytes: 3060
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Text.RegularExpressions;

namespace Yuzuki
{
    class Yukari
    {
        public static void Main(string[] args)
        {
            string[] buf = Console.ReadLine().Split();
            int n = int.Parse(buf[0]);
            buf = Console.ReadLine().Split();
            var ans = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                ans[i] = 0;
            }
            for (int i = 0; i < n-1; i++)
            {
                ans[int.Parse(buf[i])-1]++;
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(ans[i]);
            }
                
        }
    }
}

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

bool match(int k, string s, string t){
  // sの先頭からk文字目からtを埋め込めるか判定する
  int i;
  for(i = 0; i < int(t.size()); i++){
    if(s[k+i] != '?' && s[k+i] != t[i]){
      return false;
    }
  }
  return true;
}

string construct(int k, string s, string t){
  // 答えとなる文字列を組み立てる
  string ans = s;
  int i;
  for(i = 0; i < int(t.size()); i++){
    ans[k+i] = t[i];
  }
  for(i = 0; i < int(ans.size()); i++){
    if(ans[i] == '?'){
      ans[i] = 'a';
    }
  }
  return ans;
}

int main(){
  string s_dash, t;
  int i, sizediff;
  vector<string> candidates;
  cin >> s_dash >> t;

  sizediff = int(s_dash.size() - t.size());
  for(i = 0; i <= sizediff; i++){
    if(match(i, s_dash, t)){
      candidates.push_back(construct(i, s_dash, t));
    }
  }

  if(candidates.empty()){
    cout << "UNRESTORABLE" << endl;
  } else{
    sort(candidates.begin(), candidates.end());
    cout << candidates.front() << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,h[105],t[105],dp[105][105];
int powM(int val,int pw,LL moD=MOD1){
	if(pw<0) return 0;
    int ret=1;
    while(pw){
        if(pw&1) ret=((LL)ret*(LL)val)%moD;
        val=((LL)val*(LL)val)%moD;
        pw>>=1;
    }
    return ret%moD;
}
int calsum(int r,int l){
	return (powM(2,r)+MOD1-powM(2,l))%MOD1;
}
bool cmp(int A,int B){
	return h[A]<h[B];
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k,res=0;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",h+i);
		t[i]=i;
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
	t[n]=n;
	h[n]=1;
	sort(t,t+n+1,cmp);
	for(i=0;i<=n;++i){
		j=t[i];
		k=t[i+1];
		if(i==n) k=-1;
		if(h[j]<=h[0]){
			dp[0][j]=(2*calsum(h[0]-h[j],(k==-1?-1:(h[0]-h[k]))))%MOD1;
		}
	}
	for(i=0;i<n;++i){
		for(j=0;j<=n;++j){
			if(!dp[i][j]) continue;
			if(i==n-1) res=(res+dp[i][j])%MOD1;
			if(h[j]==h[i]) dp[i][j]=(dp[i][j]*2)%MOD1;
			if(h[i+1]<=h[i]){
				if(h[j]>=h[i+1] && h[j]!=h[i]){
					dp[i][j]=(dp[i][j]*2)%MOD1;
				}
				dp[i+1][(h[j]>=h[i+1])?(i+1):j]+=dp[i][j];
				dp[i+1][(h[j]>=h[i+1])?(i+1):j]%=MOD1;
			}
			else if(h[j]==h[i]){
				for(k=0;k<=n;++k){
					int c=t[k],nx=t[k+1];
					if(k==n) nx=-1;
					if(h[c]>=h[j] && h[c]<=h[i+1]){
						int val=((LL)dp[i][j]*(LL)calsum(h[i+1]-h[c],(nx==-1?-1:h[i+1]-h[nx])))%MOD1;
						dp[i+1][c]+=val;
						dp[i+1][c]%=MOD1;
					}
				}
			}
			else{
				dp[i+1][j]+=((LL)dp[i][j]*(LL)powM(2,h[i+1]-h[i]))%MOD1;
				dp[i+1][j]%=MOD1;
			}
		}
	}
	printf("%d\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

int main()
{
    vector<int> ans;
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            break;
        }

        vector<int> inputList;
        int sum = 0;

        for (int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            inputList.push_back(a);
            sum += a;
        }

        int ave = sum / n;
        int num = 0;

        for (int i = 0; i < n; i++)
        {
            if (inputList[i] <= ave)
            {
                num++;
            }
        }

        ans.push_back(num);
    }

    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3260
//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false
 
int n;
int d[55];
int cnt[13];
vector<int> one, t;
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cnt[0]++;
    rep(i, n) {
        cin >> d[i];
        cnt[d[i]]++;
    }
    rep(i, 13) {
        if (cnt[i] >= 3) {
            cout << 0 << endl;
            return 0;
        }
        else if (cnt[i] == 2) {
            t.push_back(i);
            t.push_back(24 - i);
        }
        else if (cnt[i] == 1) {
            one.push_back(i);
        }
    }
    int m = one.size();
    int ans = 0;
    rep(i, 1<<m) {
        vector<int> tmp = t;
        rep(j, m) {
            if (i>>j & 1) {
                tmp.push_back(24 - one[j]);
            }
            else {
                tmp.push_back(one[j]);
            }
        }
        int mn = 24;
        rep(j, tmp.size()) {
            rep2(k, j + 1, tmp.size()) {
                mn = min(mn, min(abs(24 - abs(tmp[j] - tmp[k])), abs(tmp[j] - tmp[k])));
                //cout << mn << " " << abs(24 - tmp[j] - tmp[k]) << " " << abs(tmp[j] - tmp[k]) << endl;
            }
        }
        //rep(j, tmp.size()) cout << tmp[j] << " ";
        //cout << endl;
        ans = max(ans, mn);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;


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

	ll ans = 0;
	for(i=1;i <= sqrt(n); i++){
		if(n % i == 0){
			ll m = n/i - 1;
			if(m == 0) continue;
			if(n%m == n/m) ans += m;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
   
   long long n,Y,t,f,o = -1;
   
   cin>>n>>Y;
   
   Y = Y / 1000;
   
   for(t = 0 ; t <= n ; t++){
       for(f = 0 ; f <= n-t ; f++){
           if(9*t+4*f+n-Y==0){
               o = n - f - t;
               break;
           }
       }
       if(o!=-1) break;
   }
   
   if(o==-1){
       cout<<"-1 -1 -1";
   } else
    cout<<t<<' '<<f<<' '<<o;
   
   return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define MOD 1000000007

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie();
	
	ll r;
	cin >> r;
	cout << r*r << '\n';
	
	return 0;
}


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

int main()
{
	int n, x;
	scanf("%d%d", &n, &x);
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	long long sum{};
	for (int i = 1; i < n; i++)
	{
		if (a[i] + a[i - 1] <= x) continue;
		sum += a[i] + a[i - 1] - x;
		if (a[i] >= a[i] + a[i - 1] - x)
			a[i] -= a[i] + a[i - 1] - x;
		else
		{
			a[i - 1] -= 2 * a[i] + a[i - 1] - x;
			a[i] = 0;
		}
	}
	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int a[110000];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=-1)
    {
        long long ans=0;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        if(a[0]>m)
        {
            ans+=(a[0]-m);
            a[0]=m;
        }
        for(int i=1;i<n;i++)
        {
            if(a[i-1]+a[i]>m)
            {
                int t=(a[i]+a[i-1]-m);
                ans+=t;
                a[i]-=t;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		
		if(a[i] > i + 1) {
			printf("-1\n");
			return 0;
		}
	}
	
	int tmp = 0;
	std::vector<int> ans(n, 1);
	for(int i = n - 1; i >= 0; i--) {
		if(a[i] == 1) {
			tmp++;
			continue;
		}
		
		int count = 0;
		for(int j = 0; j < n; j++) {
			count += (ans[j] == 1);
			
			if(count == a[i] + tmp) {
				ans[j] = a[i];
				break;
			}
		}
	}
	for(auto v: ans) printf("%d\n", v);
	return 0;
}


Measured memory_bytes: 256
//verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/6/GRL_6_A

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

template <typename T>
struct Dinic {
  const T INF;
  struct edge {
    int to;
    T cap;
    int rev;
  };

  vector<vector<edge>> g;
  vector<int> level;
  vector<int> itr;

  Dinic (int V) : INF(numeric_limits<T>::max()) {
    g.resize(V);
  }

  void add_edge(int from, int to, T cap) {
    g[from].emplace_back((edge){to, cap, (int)g[to].size()});
    g[to].emplace_back((edge){from, 0, (int)g[from].size() - 1});
  }

  bool bfs(int s, int t) {
    level.assign(g.size(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int u = que.front(); que.pop();
      for (auto &e : g[u]) {
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[u] + 1;
          que.push(e.to);
        }
      }
    }
    return level[t] != -1;
  }

  T dfs(int u, int t, T flow) {
    if (u == t) return flow;
    for (int &i = itr[u]; i < g[u].size(); i++) {
      edge &e = g[u][i];
      if (e.cap > 0 && level[u] < level[e.to]) {
        T d = dfs(e.to, t, min(flow, e.cap));
        if (d > 0) {
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  T max_flow(int s, int t) {
    T flow = 0;
    while (bfs(s, t)) {
      itr.assign(g.size(), 0);
      T f = 0;
      while ((f = dfs(s, t, INF)) > 0) flow += f;
    }
    return flow;
  }
};

int main(){ 
  int V, E;
  cin >> V >> E;
  Dinic<int> dinic(V);
  while (E--) {
    int u, v, c;
    cin >> u >> v >> c;
    dinic.add_edge(u, v, c);
  }
  cout << dinic.max_flow(0, V - 1) << endl;
  return 0;
} 


Measured memory_bytes: 3224
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 52;
const int MM = 1000000007;

void add(int &x, int y){ x = (x+y >= MM? x+y-MM : x+y); }

ll I[MX], FI[MX], F[MX];
int ans = 0;

int D[MX][MX][MX][MX];
int H[MX][MX][MX][MX];
int N;

ll get_value(int a, int b, int p, int q){
	int x = a, y = b;
	int d = p-q;
	x -= d, y += d;
	if(x < 0 || y < 0) return 0;
	return FI[x] * FI[y] % MM;
}

int main()
{
	I[1] = F[0] = FI[0] = 1;
	for(int i = 2; i < MX; i++) I[i] = (MM - MM/i) * I[MM%i] % MM;
	for(int i = 1; i < MX; i++){
		F[i] = F[i-1] * i % MM;
		FI[i] = FI[i-1] * I[i] % MM;
	}
	scanf("%d", &N);
	H[0][0][0][0] = 1;
	for(int i = 0; i <= N; i++){
		for(int j = 0; i+j <= N; j++){
			for(int a = 0; a <= N; a++){
				for(int b = 0; a+b <= N; b++){
					if(!H[i][j][a][b]) continue;
					for(int l = 0; l <= N; l++){
						if(a+(l+1)/2 <= N && b+l/2 <= N) H[i+1][j][a+(l+1)/2][b+l/2] |= H[i][j][a][b];
						if(!i && a+l/2 <= N && b+(l+1)/2 <= N) H[i][j+1][a+l/2][b+(l+1)/2] |= H[i][j][a][b];
					}
				}
			}
		}
	}
	D[0][0][1][0] = 1;
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N; j++){
			for(int k = 0; j+k <= N; k++){
				for(int l = 0; j+k+l <= N; l++){
					if(!D[i][j][k][l]) continue;
					for(int p = 0; j+k+l+p <= N; p++){
						for(int q = 0; j+k+l+p+q <= N; q++){
							add(D[i+1][j+k+l][p][q], (ll)D[i][j][k][l] * H[k][l][p][q] % MM * get_value(k, l, p, q) % MM);
						}
					}
				}
			}
		}
	}
	printf("%lld\n", D[N][N][0][0] * F[N] % MM);
}


Measured memory_bytes: 56832
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let d:i128 = read();
    let mut ans = 0;
    for _ in 0..n {
        let x:i128 = read();
        let y:i128 = read();
        if (x * x + y * y) <= d * d {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll x,y;
    cin>>x>>y;
    if(y%2==0){
        if(y>=x*2&&x*4>=y){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3600