akhauriyash/Code-Regression huggingface dataset:
n=int(input())
A=list(map(int,input().split()))

ri=0
co=0
su=0

for le in range(n):
    while ri<n and su+A[ri]==su^A[ri] :
        su+=A[ri]
        ri+=1
    co+=ri-le
    if le==ri :
        ri+=1
    else:
        su-=A[le]

print(co)


Measured memory_bytes: 24840
def solve(l:list):
    cnt = 0
    for i in range(1, len(l)-1):
        if l[i+1]>l[i]>l[i-1] or l[i+1]<l[i]<l[i-1]:
            cnt += 1
    return cnt

def main():
    input()
    l = list(map(int, input().split(" ")))
    print(solve(l))

if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
    double x1, y1, x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    // cout << sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) << endl;
    printf("%lf",sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int N;
    cin >> N;
    vector<vector<int>> h(N, vector<int>(3));
    rep(i, 0, N) cin >> h[i][0] >> h[i][1] >> h[i][2];

    vector<vector<ll>> dp(N, vector<ll>(3, 0));
    rep(i, 0, 3) dp[0][i] = h[0][i];

    rep(i, 1, N)
    {
        dp[i][0] = max(dp[i][0], dp[i - 1][1] + h[i][0]);
        dp[i][0] = max(dp[i][0], dp[i - 1][2] + h[i][0]);
        dp[i][1] = max(dp[i][1], dp[i - 1][0] + h[i][1]);
        dp[i][1] = max(dp[i][1], dp[i - 1][2] + h[i][1]);
        dp[i][2] = max(dp[i][2], dp[i - 1][0] + h[i][2]);
        dp[i][2] = max(dp[i][2], dp[i - 1][1] + h[i][2]);
    }

    ll ans = max(dp[N - 1][0], dp[N - 1][1]);
    ans = max(ans, dp[N - 1][2]);
    cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int K;
    cin >> K;
    if(K==4 || K==6 || K==9 || K==10 || K==14 || K==21 || K==22 || K==25 || K==26) cout << 2;
    else if(K==8 || K==12 || K==18 || K==20 || K==27) cout << 5;
    else if(K==28 || K==30) cout << 4;
    else if(K==16) cout << 14;
    else if(K==24) cout << 15;
    else if(K==32) cout << 51;
    else cout << 1;
    return 0;
}

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
--import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO



getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

mFromInt :: Int -> Mint
mFromInt a = M (mod a modNum)

main :: IO ()
main = do
    [aH, aW] <- getIL
    aS       <- replicateM aH getLine
    let colorArray =
            AU.listArray ((1, 1), (aH, aW))
            $ map (\x -> if x == '#' then 1 else 0)
            $ concat aS :: AU.UArray (Int, Int) Int

    --colorArray     <- AIO.thaw sI :: IO (AIO.IOUArray (Int, Int) Int)
    minArray <-
        AIO.newArray ((1, 1), (aH, aW)) (-1) :: IO (AIO.IOUArray (Int, Int) Int)

    if colorArray AU.! (1, 1) == 1
        then AIO.writeArray minArray (1, 1) 1
        else AIO.writeArray minArray (1, 1) 0

    forM_ [1 .. aH] $ \x -> forM_ [1 .. aW] $ \y -> do
        let backList = filter
                (\f -> fst f >= 1 && fst f <= aH && snd f >= 1 && snd f <= aW)
                [(x - 1, y), (x, y - 1)]

        pList <- forM backList $ \b -> do
            m <- AIO.readArray minArray b
            let bC = colorArray AU.! b
            let pC = colorArray AU.! (x, y)
            if pC == bC
                then return m
                else if pC == 1 then return (m + 1) else return m

        if backList == []
            then return ()
            else AIO.writeArray minArray (x, y) $ minimum $ pList

    AIO.readArray minArray (aH, aW) >>= print





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

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> weight(N);
  vector<int> value(N);
  for (int i = 0; i < N; i++) {
    cin >> weight.at(i) >> value.at(i);
  }
  vector<vector<int64_t>> dp(N + 1, vector<int64_t> (W + 1));
  for (int i = 0; i <= W; i++) {
    dp.at(0).at(i) = 0;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= W; j++) {
      if (weight.at(i - 1) <= j) {
        if (dp.at(i - 1).at(j) <
            dp.at(i - 1).at(j - weight.at(i - 1)) + value.at(i - 1)) {
          dp.at(i).at(j) = dp.at(i - 1).at(j - weight.at(i - 1)) + value.at(i - 1);
        }
        else dp.at(i).at(j) = dp.at(i - 1).at(j);
      }
      else dp.at(i).at(j) = dp.at(i - 1).at(j);
    }
  }
  cout << dp.at(N).at(W) << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	
	int N; cin >> N;
	vector<int> d(N);
	REP(i,N) cin >> d[i];

	SORT(d);

	int l = N/2-1;
	int r = N/2;
	cout << d[r]-d[l] << endl;


	return 0;

}


Measured memory_bytes: 640
import numpy as np
import pdb
import copy

def main():
    [A, B, C, D] = map(int, raw_input().split(' '))
    left = A + B
    right = C + D
    if left >  right:
        print 'Left'
    elif right > left:
        print 'Right'
    else:
        print 'Balanced'

if __name__ == '__main__':
    main()


Measured memory_bytes: 10652
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm;

void main() {
    uint c = to!uint(readln().chomp);
    for (uint i = 0; i < c; ++i) {
        double[] dx = map!(to!double)(readln().chomp.split).array;
        double[] ap = dx[0..2];
        double[] bp = dx[3..5];
        double ar = dx[2];
        double br = dx[5];
        double d = dist(ap, bp);
        if (d < (ar-br)^^2) {
            if (br < ar) {
                writeln(2);
            } else {
                writeln(-2);
            }
        } else if (d - (ar+br)^^2 < 1.0e-10) {
            writeln(1);
        } else {
            writeln(0);   
        }
    }
}

double dist(double[] ax, double[] bx) {
    return (ax[0]-bx[0])^^2 + (ax[1]-bx[1])^^2;
}

Measured memory_bytes: 1060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0 ; i < n ; i++) {
			p[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 0 ; i < n ; i++) {
			if(i >= 1 && i < n - 1) {
				if(p[i - 1] < p[i] && p[i] < p[i + 1]) {
					ans++;
				} else if(p[i - 1] > p[i] && p[i] > p[i + 1]) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();

	}

}


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


signed main(void){
    int h,w; cin >> h >> w;
    int n; cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int index = 0,cnt=0;
    string ans="";
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                if(a[index]<=cnt){
                    index++;
                    cnt =0;
                }
                if(ans.length()==0){
                    ans = to_string(index+1);
                }else{
                    ans += ' '+to_string(index+1);
                }
                // cout << index << '-';
                cnt++;
            }
        }else{
            for(int j=w-1;0<=j;j--){
                if(a[index]<=cnt){
                    index++;
                    cnt =0;
                }
                if(ans.length()==0){
                    ans = to_string(index+1);
                }else{
                    ans = to_string(index+1) + ' ' + ans;
                }
                
                cnt++;
            }
        }
        cout << ans << endl;
        ans = "";
    }
    return 0;
}

Measured memory_bytes: 384
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

map<pair<string,string>, int> f(string s) {
	const int n = s.length();
	map<pair<string,string>,int> mapka;
	for(int mask = 0; mask < (1 << n); ++mask) {
		string a, b;
		for(int i = 0; i < n; ++i) {
			if(mask & (1 << i)) a += s[i];
			else b += s[i];
		}
		++mapka[{a,b}];
	}
	return mapka;
}

int main() {
	int n;
	cin >> n;
	n *= 2;
	string s;
	cin >> s;
	auto one = f(s.substr(0, n / 2));
	reverse(s.begin(), s.end());
	auto two = f(s.substr(0, n / 2));
	debug() << imie(one);
	debug() << imie(two);
	long long answer = 0;
	for(auto & pp : one)
		answer += (long long) two[pp.first] * pp.second;
	cout << answer << endl;
}


Measured memory_bytes: 109824
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    map<string, int> anagrams;
    lint ret = 0;
    FOR(i, 0, N) {
        string S;
        cin >> S;
        sort(ALL(S));
        ret += anagrams[S];
        anagrams[S]++;
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
int main(){
    int n,p;
    string s;
    cin>>n;
    vector<tuple<string,int,int>>r(n);
    for(int i=1;i<=n;i++){
        cin>>s>>p;
        r[i-1]=make_tuple(s,p,i);
    }
    sort(r.begin(),r.end(),
    [](const auto &x,const auto &y){return (get<0>(x)!=get<0>(y)) ? (get<0>(x)<get<0>(y)) : (get<1>(x)>get<1>(y));}
    );
    for(auto x:r)cout<<get<2>(x)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100];
int l;
int main()
{
	gets(s);
	l=strlen(s);
	for(int i=0;i<l;i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<l;j++)
			{
				if(s[j]=='F')
				{
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import math

def print_circle(r):
    """
    r: float
    outputs area and circumfence of a circle(radius r)
    
    >>> print_circle(2)
    12.566371 12.566371
    """

    print("{0:.6f} {1:.6f}".format(math.pi * r**2, 2 * math.pi * r))

if __name__ == '__main__':
    r = float(input())
    print_circle(r)

Measured memory_bytes: 7608
#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>

using namespace std;

using ll = long long;

const int MM = 102;

vector<int> s[MM];
int p[MM];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0; i<m; ++i){
		int k;
		cin>>k;
		//s[i].resize(k);
		for(int j=0; j<k; ++j){
			int tmp;
			cin>>tmp;
			s[i].push_back(tmp-1);
		}
	}
	for(int i=0; i<m; ++i){
		cin>>p[i];
	}
	int res=0;
	for(int bs=0; bs<(1<<n); ++bs){
		bool good=1;
		for(int i=0; i<m; ++i){
			bool on=!p[i];
			for(auto j:s[i]){
				on^=((1<<j)&bs?1:0);
			}
			//cerr<<bs<<' '<<on<<endl;
			good&=on;
		}
		res+=good;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

nn = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    while c[ali[ii]] == 0:
        ii += 1
    m = ali[ii]
    n = pow2(m) - m
    c[m] -= 1
    if c[m] <= 0:
        del c[m]
    if n in c:
        c[n] -= 1
        if c[n] <= 0:
            del c[n]
        ans += 1

print(ans)








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

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX=2e5+5;
const int MAX2=2e5+4;
const int MAAX=2e18;
const int MOD=1e9+7;

in main()
{
int l,r;
int n,m;
cin>>n>>m;
int x,y;
r=n;
l=0;
for(int i=0;i<m;i++)
{
	cin>>x>>y;
	l=max(l,x);
	r=min(r,y);
}
cout<<max(0ll,r-l+1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define pb push_back
#define inf 1e9
#define maxn 500001
#define VI vector<ll>
#define ll long long
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
bool vis[501];
int n,m,a[401][401],tong[401],to[401],ans=1e9;
int main()
{
	n=read();m=read();
	For(i,1,n)
		For(j,1,m)	a[i][j]=read();
	For(i,1,n)	to[i]=1,tong[a[i][1]]++;
	For(T,1,m-1)
	{
		int mx=-1,k=0;
		For(i,1,m)	if(tong[i]>mx)	mx=tong[i],k=i;
		ans=min(ans,mx);
		vis[k]=1;
		For(i,1,n)
		{
			bool flag=0;
			while(vis[a[i][to[i]]])	to[i]++,flag=1;
			if(flag)	tong[a[i][to[i]]]++;
		}
//		For(i,1,n)	cout<<i<<"->"<<a[i][to[i]]<<endl;cout<<endl;
		tong[k]=0;
	}
	int mx=-1,k=0;
		For(i,1,m)	if(tong[i]>mx)	mx=tong[i],k=i;
	ans=min(ans,mx);
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
data=sorted([[i for i in input().split()]+[_] for _ in range(n)],key=lambda x:x[0])
for i in range(n):
    data[i][1]=int(data[i][1])
l=[]
tmp=[(data[0][1],data[0][2])]
for i in range(1,n):
    if data[i][0]!=data[i-1][0]:
        l.append(tmp)
        tmp=[]
    tmp.append((data[i][1],data[i][2]))
l.append(tmp)

for i in range(len(l)):
    l[i]=sorted(l[i],key=lambda x:x[0])[::-1]
ans=[0]*n
count=0
for i in l:
    for j in i:
        ans[count]=j[1]+1
        count+=1
print(*ans,sep='\n')

Measured memory_bytes: 3064
import sys

def reverse(str, a, b):
	head = str[0:a]
	tail = str[b + 1:]
	mid = str[a:b + 1]
	reversed_str = head + mid[::-1] + tail
	return reversed_str

def replace(str, a, b, rstr):
	head = str[0:a]
	tail = str[b + 1:]
	replaced_str = head + rstr + tail
	return replaced_str


#fin = open("test.txt", "r")
fin = sys.stdin

str = fin.readline()
q = int(fin.readline())

for i in range(q):
	query_list = fin.readline().split()
	op = query_list[0]
	a = int(query_list[1])
	b = int(query_list[2])

	if op == "print":
		print(str[a:b + 1])
	elif op == "reverse":
		str = reverse(str, a, b)
	else:
		str = replace(str, a, b, query_list[3])

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

int main(){
  int N,K,beg=0;
  cin >> N >> K;
  int num0=N-1;
  long long x[N],ans=100000000001;
  for(int i=0; i<N; i++) cin >> x[i];
  for(int i=0; i<N; i++) if(x[i]>0){
     num0 = i-1;
     break;
   }
  for(int i=max(num0-K+1,0); i<min(N-K+1,num0+2); i++){
    ans = min(ans, 2*llabs(x[i])+llabs(x[i+K-1]));
    ans = min(ans, 2*llabs(x[i+K-1])+llabs(x[i]));
    if(x[i]*x[i+K-1]>=0) ans = min(ans, max(llabs(x[i]),llabs(x[i+K-1])));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
from math import gcd
a, b, c, d = map(int, input().split())
whole = b - a + 1
sum_c = b//c - (a-1)//c
sum_d = b//d - (a-1)//d
div = (c*d)//gcd(c, d)
sum_c_d = b//div - (a-1)//div
print(whole - ((sum_c + sum_d) - sum_c_d))

Measured memory_bytes: 9188
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	int u[4];
	int v[4];
	int h, b;
	int i, j;

	while (scanf("%d %d %d %d", &u[0], &u[1], &u[2], &u[3]) != EOF)
	{
		scanf("%d %d %d %d", &v[0], &v[1], &v[2], &v[3]);
		h = 0, b = 0;
		for (i = 0; i < 4; ++i)
		{
			if (u[i] == v[i])
				h++;

			for (j = 0; j < 4; ++j)
			{
				if (i != j && u[i] == v[j])
					b++;
			}
		}

		printf("%d %d\n", h, b);
	}

	return 0;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    if(t.length()==s.length()+1){
        ll i,count=0;
        for(i=0;i<s.length();i++){
            if(t[i]==s[i])
            count++;
        }
        if(count==s.length())
        cout << "Yes" << endl;
        else
        cout << "No" << endl;
    }
    else
    cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int []candyBox  = new int[N];

        for(int i= 0 ; i< N ; i++){
            candyBox[i] = sc.nextInt();
        }
        long cnt =0;
        if(N==1) {
            cnt = X-candyBox[0];
        }
        for(int i= 1 ; i< N ; i++){
            if (candyBox[i] + candyBox[i-1] > X){
                cnt += candyBox[i] + candyBox[i-1] - X;
                if(candyBox[i-1]>=X) {
                    candyBox[i]=0;
                }
                else{
                    candyBox[i]=X-candyBox[i-1];
                }
            }
            //System.out.println(i+";"+ cnt);
        }

        if(cnt<0) cnt =0;

        System.out.println(cnt);

        sc.close();

    }

}


Measured memory_bytes: 33096
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string o,e;
    cin >> o >> e;
    string ans;
    rep(i,min(o.size(),e.size())){
        ans += o[i];
        ans += e[i];
    }
    if (o.size()>e.size()){
        ans += o[o.size()  -1];
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 256
/*input
test
est
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_.pop();
    return_
}

fn main() {
    let string: Vec<u8> = read_line().as_bytes().to_vec();
    let pattern: Vec<u8> = read_line().as_bytes().to_vec();
    //let start = std::time::Instant::now();
    kmp(&string, &pattern);
    //println!("{:?}", start.elapsed());
}

fn kmp_table(pattern: &Vec<u8>, m: usize, mut kmp: Vec<usize>) -> Vec<usize> {
    let mut len: usize = 0;
    kmp[0] = 0;
    let mut i: usize = 1;
    while i < m {
        if pattern[i] == pattern[len] {
            len = len + 1;
            kmp[i] = len;
            i = i + 1;
        } else {
            if len != 0 {
                len = kmp[len - 1];
            } else {
                kmp[i] = 0;
                i = i + 1;
            }
        }
    }
    kmp
}

fn kmp(string: &Vec<u8>, pattern: &Vec<u8>) -> () {
    let mut out: String = String::new();
    let n = string.len();
    let m = pattern.len();
    let kmp = kmp_table(&pattern, m, vec![0usize; m]);
    let mut i: usize = 0;
    let mut j: usize = 0;
    while i < n {
        if pattern[j] == string[i] {
            i = i + 1;
            j = j + 1;
        }
        if j == m {
            out.push_str(&(i - j).to_string());
            out.push('\n');
            j = kmp[j - 1];
        } else if i < n && pattern[j] != string[i] {
            if j != 0 {
                j = kmp[j - 1];
            } else {
                i = i + 1;
            }
        }
    }
    print!("{}", out);
}



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

int main(){
	int a, b, c, d;
  	cin >> a >> b >> c>> d;
  	bool e = true;
  	while(e == true){
    	c -= b;
      	
      	if(c <= 0) break;
      	a -= d;
      	if(a <= 0) e = false; 
    }
  	if(e == true) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 3604
import sys

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret


import math

def get_primenumber(number):#エラトステネスの篩
    prime_list = []
    search_list = list(range(2,number+1))
    #search_listの先頭の値が√nの値を超えたら終了
    while search_list[0] <= math.sqrt(number):
      #search_listの先頭の値が√nの値を超えたら終了
      #search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        #head_numの倍数を除去
        search_list = [num for num in search_list if num % head_num != 0]
    #prime_listにsearch_listを結合
    prime_list.extend(search_list)
    return prime_list

#p=get_primenumber(79000)

n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)
amax=max(ap)

if amax==1:
    print("pairwise coprime")
    sys.exit()

if amin!=1:
    bp=enum_div(amin)+[amin]
    bp=bp[1:]
    for bpi in bp:
        yn=""
        for ai in ap:
            if ai%bpi!=0:
                yn="coprime"
                break
        if yn=="":
            print("not coprime")
            sys.exit()

if n>=78500 :
    print("setwise coprime")
    sys.exit()

p=get_primenumber(amax)

aa=[0]*(amax+1)
for ai in ap:
    aa[ai]+=1
    
for pp in range(2,amax+1):
#for pp in p:
    psum=0
    for pi in range(pp,amax+1,pp):
        psum+=aa[pi]
#    psum=sum(aa[pp: :pp])
#    print("pp:",pp,psum)
    if psum>=2:
            print("setwise coprime")
            sys.exit()
## max_13.txt ... max_16.txt : "setwise coprime"
print("pairwise coprime")
   


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

using namespace std;

int main()
{
    long long n,k,i;
    long long sum1=0;
    cin>>n>>k;
    vector<long long>arr(n);
    vector<long long>sum(n);
    vector<long long>rsum(n);
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    for(i=0;i<k;i++){
        sum1+=arr[i];
    }
    if(arr[0]>=0)
        sum[0]=arr[0];
    else
        sum[0]=0;
    for(i=1;i<n;i++){
        if(arr[i]>=0)
            sum[i]=sum[i-1]+arr[i];
        else
            sum[i]=sum[i-1];
    }
    if(arr[n-1]>=0)
        rsum[n-1]=arr[n-1];
    else
        rsum[n-1]=0;
    for(i=n-2;i>=0;i--){
        if(arr[i]>=0)
            rsum[i]=rsum[i+1]+arr[i];
        else
            rsum[i]=rsum[i+1];
    }
    long long start=0,end=k;
    long long temp1=0;
    long long ans=0;
    for(i=0;i<=(n-k);i++){
        if(i!=n-k)
            ans=max(max(ans,(sum1+temp1+rsum[end])),temp1+rsum[end]);
        else
             ans=max(max(ans,(sum1+temp1)),temp1);
        if(i<(n-k)){
            sum1-=arr[start];
            sum1+=arr[end];
            temp1=sum[start];
            start++;
            end++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC104D()
{
	const int MOD = 1000000007;
	string S;
	cin >> S;
	int N = S.size();
	vl dpQ(N + 1);
	dpQ[0] = 1;
	for (int i = 1; i <= N; ++i)
	{
		dpQ[i] = dpQ[i - 1];
		if (S[i - 1] == '?')
		{
			dpQ[i] *= 3;
			dpQ[i] %= MOD;
		}
	}
	vl dpA(N + 1);
	for (int i = 1; i <= N; ++i)
	{
		dpA[i] = dpA[i - 1];
		if (S[i - 1] == 'A')
		{
			dpA[i] += dpQ[i - 1];
			dpA[i] %= MOD;
		}
		else if (S[i - 1] == '?')
		{
			dpA[i] *= 3;
			dpA[i] += dpQ[i - 1];
			dpA[i] %= MOD;
		}
	}
	vl dpB(N + 1);
	for (int i = 1; i <= N; ++i)
	{
		dpB[i] = dpB[i - 1];
		if (S[i - 1] == 'B')
		{
			dpB[i] += dpA[i - 1];
			dpB[i] %= MOD;
		}
		else if (S[i - 1] == '?')
		{
			dpB[i] *= 3;
			dpB[i] += dpA[i - 1];
			dpB[i] %= MOD;
		}
	}
	vl dpC(N + 1);
	for (int i = 1; i <= N; ++i)
	{
		dpC[i] = dpC[i - 1];
		if (S[i - 1] == 'C')
		{
			dpC[i] += dpB[i - 1];
			dpC[i] %= MOD;
		}
		else if (S[i - 1] == '?')
		{
			dpC[i] *= 3;
			dpC[i] += dpB[i - 1];
			dpC[i] %= MOD;
		}
	}
	cout << dpC[N] << endl;
}
int main()
{
	ABC104D();
	return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int x,y,z;
    cin >> x >> y >> z;
    int ans;
    ans = (x-z)/(y+z);
    cout <<ans;

    return 0;
}

Measured memory_bytes: 256
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;
str a[N];
vector<pll> B;
vector<pll> BAGH;
ll ans[N];

ll CHECK(str s){
	ll ans = 0;
	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == 'A' && s[i + 1] == 'B') ans++;
	}
	return ans;
}


int main(){
//	IOS;
	ll n;
	cin >> n;
	ll Cnt = 0, Cnt1 = 0, Cnt2 = 0;
	ll an = 0;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		an += CHECK(a[i]);
		if (a[i][0] != 'B' && a[i][a[i].size() - 1] == 'A') Cnt++;
		if (a[i][0] == 'B' && a[i][a[i].size() - 1] != 'A') Cnt1++;
		if (a[i][0] == 'B' && a[i][a[i].size() - 1] == 'A') Cnt2 ++;
	}
	//cout << an << '\n';
	an += max((ll)0, Cnt2 - 1);
	//cout << an << '\n';
	if (Cnt2 != 0){
		if (Cnt != 0) an++;
		if (Cnt1 != 0) an++;
		Cnt --;
		Cnt1 --;
		an += min(max(Cnt1, (ll)0), max(Cnt, (ll)0));
	}else{
		an += min(Cnt1, Cnt);
	}
	cout << an;
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 2304
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(A: Long, B: Long, C: Long){
    println(if(A+B >= C) YES else NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val C = sc.next().toLong()
    solve(A, B, C)
}



Measured memory_bytes: 31520
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e-a > k ? ":(" : "Yay!") << endl;
    
    return 0;
}



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  cin >> n;
  int d[100000];
  REP(i, n)
  {
    cin >> d[i];
  }
  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1] << endl;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;
ll n;
ll dp[maxn], ans[maxn];
ll dp1[maxn];

vector<ll>g[maxn];
bool used[maxn];

void dfs(ll u){
	used[u] = 1;
	dp[u] = 1;
	for (ll v : g[u]) {
		if (used[v]) continue;
		dfs(v);
		dp[u] = mul(dp[u], 1 + dp[v]);
	}
}


void dfs1(ll u) {
	used[u] = 1;
	vector<ll>vec;
	for (ll v : g[u]) {
		if (used[v]) continue;
		vec.push_back(v);
	}
	if (vec.size() == 0) return;
	vector<ll>pref(vec.size()), suf(vec.size());
	for (ll i = 0; i < pref.size(); i++) {
		pref[i] = mul((i ? pref[i - 1] : 1LL), (1 + dp[vec[i]]) % mod);
	}
	suf.back() = (dp[vec.back()] + 1) % mod;
	for (ll i = (ll)vec.size() - 2; i >= 0; i--) {
		suf[i] = mul(suf[i + 1], (1 + dp[vec[i]]) % mod);
	}
	vector<ll>kek(vec.size());
	for (ll i = 0; i < kek.size(); i++) {
		kek[i] = mul((i ? pref[i - 1] : 1LL), ((ll)kek.size() - i - 1 ? suf[i + 1] : 1LL));
	}
	
	for (ll i = 0; i < vec.size(); i++) {
		ll v = vec[i];
		dp1[v] = (1 + mul(kek[i], dp1[u])) % mod;
		dfs1(v);
	}
}


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> mod;
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1);
	fill_n(used, maxn, 0);
	dp1[1] = 1;
	dfs1(1);
	for (ll i = 1; i <= n; i++) {
		cout << mul(dp[i], dp1[i]) << '\n';
	}

	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

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

public class hello
{
    public static void Main()
    {
        var a53 = new List<int>() { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
        var a = new List<int>();
        var n = int.Parse(Console.ReadLine().Trim());
        Console.Write("{0}:", n);
        if (IsPrime(n) && n > 100000) { Console.Write(" {0}", n); goto end; }
        var ans1 = GetAns(a53, n);
        if (ans1< n)
        {
            n /= ans1;
            GeneratePrime(a, n);
            GetAns(a, n);
        }
        end:;
        Console.WriteLine();
    }
    public static int GetAns (List<int> p ,int n  )
    {
        var on = n;
        var te = 1;
        foreach (var x in p)
        {
            while (true)
            {
                if (n % x == 0)
                {
                    Console.Write(" {0}", x);
                    n /= x;
                    te *= x;
                    if (te == on) goto end;
                }
                else break;
            }
        }
        end:;
        return te;
    }
    public static void GeneratePrime(List<int> primeList, int m)
    {
        int prime;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            primeList.Add(prime);
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        primeList.AddRange(searchList);
    }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; 
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 10524
package main

import (
	"fmt"
	"sort"
)

type fact struct {
	a, b int
}

type facts []fact

func (f facts) Len() int {
	return len(f)
}

func (f facts) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func (f facts) Less(i, j int) bool {
	return f[i].a > f[j].a
}

func main() {
	var n int
	fmt.Scan(&n)
	s := make(facts, n)
	for key := range s {
		fmt.Scan(&s[key].a, &s[key].b)
	}
	sort.Sort(s)
	fmt.Print(s[0].a+s[0].b)
}

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

int main(){
    std::vector<int> map1 = {};
    std::vector<int> map2 = {};
    std::vector<int> answers = {};
    int length = 0;
    
    std::cin >> length;
    
    for (int i = 0; i < length; i++) {
        int d = 0;
        std::cin >> d;
        map1.push_back(d);
    }
    
    for (int i = 0; i < length; i++) {
        int d = 0;
        std::cin >> d;
        map2.push_back(d);
    }
   
    
    for (int j = 0; j < length; j++) {
        bool flag = false;
        int sum = 0; 
        for(int i = 0; i < length; i++) {
                
            if(flag){
                sum += map2[i];
                // std::cout << map2[i];
            }else{ 
                sum += map1[i];
                // std::cout << map1[i];
            }
            
            if(i == j){
                flag = true;
                sum += map2[i];
                // std::cout << map2[i];
            }
        }
        
        if(!flag){
            sum += map2[length - 1];
        }
        answers.push_back(sum);
    }
    std::cout << *std::max_element(answers.begin(), answers.end()) << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
def solve(n, a_list):
    s = 0
    for i in range(n):
        a = a_list[i]
        s = s ^ a
    res_list = []
    for i in range(n):
        a = a_list[i]
        res_list.append(str(s ^ a))
    # print(res_list)
    return " ".join(res_list)


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(4, [20, 11, 9, 24]) == "26 5 7 22"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 33440
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int x[n],y[n],h[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int hh=-1;
            bool ok=true;
            vector<int>s;
            for(int k=0;k<n;k++){
                if(h[k]==0){s.push_back(abs(x[k]-i)+abs(y[k]-j));continue;}
                if(hh==-1)hh=abs(x[k]-i)+abs(y[k]-j)+h[k];
                else{
                    if(hh!=abs(x[k]-i)+abs(y[k]-j)+h[k]){ok=false;break;}
                }
            }
            for(int v=0;v<s.size();v++){
                    if(s[v]<hh)ok=false;
                }
                if(ok==true){cout<<i<<" "<<j<<" "<<hh<<endl;return 0;}
        }
    }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);

            str = Console.ReadLine ().Split (' ');

            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse (str[i]);
            }

            Array.Sort (a);
            Array.Reverse (a);

            int A = 0;
            int B = 0;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) A += a[i];
                else B += a[i];
            }

            Console.WriteLine (A - B);

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

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

int main() {
  int ans=0, n=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n-2; i++){
    if(s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C'){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 764
N, K = map(int, input().split())
H = list(map(int, input().split()))

# 各足場までのコストの最小値のリスト
dp = [float('inf')] * N
dp[0] = 0
for i in range(N):
    for j in range(K+1):
        if i-j >= 0:
            dp[i] = min(dp[i], dp[i-j]+abs(H[i]-H[i-j]))
print(dp[-1])

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

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

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

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

    vector<vector<int>> a(N, vector<int>(3));
    rep(i, N) cin >> a.at(i).at(0) >> a.at(i).at(1) >> a.at(i).at(2);

    vector<vector<int>> dp(N + 1, vector<int>(3));
    rep(i, N) rep(j, 3) dp.at(i).at(j) == 0;

    rep(i, N)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (j != k)
                {
                    chmax(dp.at(i + 1).at(k), dp.at(i).at(j) + a.at(i).at(k));
                }
            }
        }
    }

    int ans = 0;
    for (int j = 0; j < 3; ++j)
        chmax(ans, dp.at(N).at(j));

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

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

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

    int ans = 0;
    for(int i=1; i<s.size(); i++){
        if(s[i-1] != s[i]) ans++;
    }

    cout << ans << endl;
}

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

int main() {
  int n,a,x,y,hu,te,on,none;
  hu = 100;
  te = 100;
  on = 100;
  none=0;
  
  cin >>n >>a; //n keta a siteisu
  for (int i=0 ;i<a; i++){
  cin >>x >>y;
  if ( n-x==2 ) {
    if (hu != y && hu !=100) {
      none=1;
    break;
    }
    hu =y;
  }
      if ( n-x==1 ) {
    if (te != y && te !=100) {
      none=1;
    break;
    }
    te =y;;
      }
  if ( n-x==0 ) {
    if (on != y && on !=100) {
      none=1;
    break;
    }
    on =y;
  }
  }
  if (n==3) {
    if (hu==100 ) 
      hu = 1;
    if (hu==0) {
      none=1;
      
    }
    if (te==100)
      te=0;
    if (on==100) 
      on=0;
      
  }
  if (n==2) {
    if (te==100 ) 
      te = 1;
    if (te==0) {
      none=1;
      
    }
    if (on==100) 
      on=0;
      
  }
  if (n==1) {
    if (on==100)
      on=0;
      
  }
  if (none==1)
    cout <<-1 <<endl;
  else if (n==3) 
    cout <<hu<<te<<on<<endl;
  else if (n==2) 
    cout <<te<<on<<endl;
  else if (n==1)
    cout<<on<<endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, Y;
	scanf("%d %d", &N, &Y);
	Y /= 1000;
	
	int i, j, k, x = -1, y = -1, z = -1;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N - i; j++) {
			k = N - i - j;
			if (i * 10 + j * 5 + k == Y) {
				x = i;
				y = j;
				z = k;
				i = N;
				j = N;
			}
		}
	}
	
	printf("%d %d %d\n", x, y, z);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<ll> a(n), b(n);
  ll su = 0;
  ll mi = INF;
  for(int i=0;i<n;++i) {
    cin >> a[i] >> b[i];
    su += a[i];
    if(a[i] > b[i]) mi = min(mi, b[i]);
  }
  cout << (a == b ? 0 : su - mi) << endl;
}


Measured memory_bytes: 512
// Iroha's Obasession

import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int K=sc.nextInt();
    int N=sc.nextInt();

    int  array[]=new int[N];

    for(int i=0;i<N;i++){
      array[i]=sc.nextInt();
    }

    boolean flag=true;
    int ans=0;
    int i=1;
    int count=0;


    while(flag){
        ans=K++;
        String str=(Integer.toString(ans));
        String[] str2=str.split("");
        count=0;

        for(int x=0;x<str.length();x++){
          for(int y=0;y<N;y++){
            //System.out.println(str2[x]+" "+array[y]);
            if(Integer.parseInt(str2[x])==array[y]){
              x=str.length()-1;
              break;
            }
            count++;
          }
        }
        //System.out.println(count);
        //System.out.println(str.length()*N);
        if(count==N*str.length()) flag=false;
        i++;

    }



    System.out.println(ans);


  }
}


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

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }

    return 0;
}

Measured memory_bytes: 256