akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


int main(){
int i,N,sum=0;

scanf("%d",&N);
for(i=1;sum<N;i++)
  sum+=i;
i--;

  for(;N>0;i--){
    if(N-i>=0){
    N-=i;
    printf("%d\n",i);
  }
}

  return 0;
}


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



int main()
{
	int r[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	int K;
	std::cin >> K;
	std::cout << r[K-1];
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from math import sqrt, ceil
def inpl(): return list(map(int, input().split()))

N, M = inpl()
ans = 1
for i in range(1, ceil(sqrt(M))+1):
    if M%i != 0:
        continue
    d = M // i
    if M >= N*i:
        ans = max(i, ans)
    if M >= N*d:
        ans = max(d, ans)

print(ans)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var n int
	var x int
	var t int

	fmt.Scan(&n)
	fmt.Scan(&x)
	fmt.Scan(&t)

	var ans int

	if n % x == 0 {
		ans = n / x * t
	} else {
		ans = (n / x + 1) * t
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1768
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define me min_element
#define Me max_element
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
template<class T>void mini(T &a,T b){a=min(a,b);}
template<class T>void maxi(T &a,T b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
void addin(){}template<class Head,class...Tail>void addin(vector<Head>&vechead,Tail&&...tail){in(Head,head);vechead.emb(head);addin(forward<Tail>(tail)...);}
template<class C>void vecout(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}

#define int int64_t
// #define double long double


signed main(){
  IOS;

  in(int,n,m);
  VI x(n),y(n),z(n);fou(i,0,n)cin>>x[i]>>y[i]>>z[i];
  int ans=0;

  fou(p,0,2){
    fou(q,0,2){
      fou(r,0,2){
        VI sum(n);
        fou(i,0,n){
          sum[i]=(2*p-1)*x[i]+(2*q-1)*y[i]+(2*r-1)*z[i];
        }
        sortdown(sum);
        int ans0=0;
        fou(i,0,m){
          ans0+=sum[i];
        }
        maxi(ans,ans0);
      }
    }
  }
  out(ans);

}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import bisect

def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    
    a.sort()
    cum = [0]
    for num in a:
        cum.append(cum[-1]+num)
    
    def power(x):
        count = 0
        for num in a:
            rest = x-num
            index = bisect.bisect_left(a,rest)
            count += N-index
        if count >= M:
            return True
        else:
            return False
    
    l,r = -1,10**10
    while r-l > 1:
        mid = (r+l)//2
        if power(mid):
            l = mid
        else:
            r = mid
            
    border = r
    
    count,ans = 0,0
    for num in a:
        rest = border-num
        index = bisect.bisect_left(a,rest)
        ans += (N-index)*num
        ans += cum[N]-cum[index]
        count += N-index
        
    print(ans+(M-count)*l)
        

if __name__ == "__main__":
    main()


Measured memory_bytes: 53712
#include <iostream>
char S[3][99999];
int main()
{
auto up = [](char c)->char{if('a'<=c&&c<='z'){return c-'a'+'A';}return c;};
std::cin>>S[0]>>S[1]>>S[2];
std::cout << up(S[0][0])<<up(S[1][0])<<up(S[2][0])<<std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>


#define MOD 1000000007

using namespace std;
using ll=long long;
using vll=vector<ll>;
using vi=vector<int>;


void mod_add(ll&d, ll s)
{
	d=(d+s)%MOD;
}


int main(void)
{
	int h, w, k;

	while(scanf("%d%d%d", &h, &w, &k)==3)
	{
		vi p;

		for(int i=0;i<(1<<(w-1));i++)
		{
			int is_ok=1;
			for(int j=0;j<w-1;j++)
			{
				if(((i>>j)&3)==3)
				{
					is_ok=0;
					break;
				}
			}
			if(is_ok) p.push_back(i);
		}

		vll c(w);

		c[0]=1;
		for(int i=0;i<h;i++)
		{
			vll n(w);

			for(int mp:p)
			{
				for(int j=0;j<w;j++)
				{
					if((mp>>j)&1)
					{
						mod_add(n[j], c[j+1]);
						mod_add(n[j+1], c[j]);
						j++;
					}
					else
					{
						mod_add(n[j], c[j]);
					}
				}
			}
			c=n;
		}
		printf("%lld\n", c[k-1]);
	}

	return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22)cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        long[] L = new long[N+1];
        L[0] = 2;
        L[1] = 1;

        for(int i=2; i<=N; i++){
            L[i] = L[i-1] + L[i-2];
        }
        System.out.println(L[N]);
    }
}

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

int main()
{
    char a,b,c;
    scanf("%c%c%c",&a,&b,&c);
    if((a=='A'&&b=='B')||(a=='A'&&c=='B')||(b=='A'&&a=='B')||(b=='A'&&c=='B')||(c=='A'&&a=='B')||(c=='A'&&b=='B'))    printf("Yes");
    else printf("No");
    return 0;

}


Measured memory_bytes: 128
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
NEVER DO 300IQ CONTESTS EVER
300IQ AS WRITER = EXTRA NONO
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class  Main
   {
      static long MOD = 1000000007L;
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Integer>[] edges = new ArrayList[N+1];
         for(int i=1; i <= N; i++)
            edges[i] = new ArrayList<Integer>();
         for(int i=0; i < N-1; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            edges[a].add(b);
            edges[b].add(a);
         }
         long[][] dp = new long[N+1][2];
         dfs(1, 0, dp, edges);
         long res = dp[1][0]+dp[1][1];
         res %= MOD;
         System.out.println(res);
      }
      public static void dfs(int curr, int par, long[][] dp, ArrayList<Integer>[] edges)
      {
         dp[curr][0] = 1L;
         dp[curr][1] = 1L;
         for(int next: edges[curr])
         {
            if(next == par)
               continue;
            dfs(next, curr, dp, edges);
            dp[curr][0] *= (dp[next][0]+dp[next][1])%MOD;
            dp[curr][0] %= MOD;
            dp[curr][1] *= dp[next][0];
            dp[curr][1] %= MOD;
         }
      }
   }

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

using namespace std;

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

int main(){

	string s;
	cin>>s;

	int flag=0;
	string str[]={"dream","dreamer","erase","eraser"};
	int i=0;
	while(i<s.size()){
		if(s[i]=='d'){
			if(str[1]==s.substr(i,7)){
				if(str[3]==s.substr(i+5,6))i+=11;
				else if(str[2]==s.substr(i+5,5))i+=10;
				else i+=7;
			}
			else if(str[0]==s.substr(i,5))i+=5;
			else {
				flag=1;
				break;
			}
		}
		else if(s[i]=='e'){
			if(str[3]==s.substr(i,6))i+=6;
			else if(str[2]==s.substr(i,5))i+=5;
			else {
				flag=1;
				break;
			}
		}
		else {
			flag=1;
			break;
		}
	}

	if(flag==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


Measured memory_bytes: 512
import Control.Applicative
import Data.Function
import Control.Monad

makeEvenLine w =  take w $ concat $ zipWith (\a b -> [a,b]) (repeat '#') (repeat '.')
makeOddLine w =  tail $ makeEvenLine $ w+1
makeSq h w = take h $ concat $ repeat [makeEvenLine w, makeOddLine w]

main :: IO ()
main = fix $ \loop -> do
    [h,w] <- map read . words <$> getLine
    unless (h == 0) $ do
        forM_ (makeSq h w) $ \l -> putStrLn l
        putStrLn ""
        loop


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

int main() {
	int a,b,n,T,cas=0;
	string s0, s1, s2;
	cin>>s0>>s1>>s2;
	reverse(s0.begin(), s0.end());
	reverse(s1.begin(), s1.end());
	reverse(s2.begin(), s2.end());

	int c = 0;
	while(1) {
		if(c==0) {
			if(s0.size()==0) break;
			else {
				c = s0[s0.size()-1] - 'a';
				s0.pop_back();
			}
		}
		else if(c==1) {
			if(s1.size()==0) break;
			else {
				c = s1[s1.size()-1] - 'a';
				s1.pop_back();
			}
		}
		else if(c==2) {
			if(s2.size()==0) break;
			else {
				c = s2[s2.size()-1] - 'a';
				s2.pop_back();
			}
		}
		assert(c<3);
	}
	char ch = c+'A';
	cout<<ch<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, a, b, c, d[1000] = { 0 }, p = 0, ans = 0;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) cin >> d[i];
	sort(d, d + n);
	p = c;
	int w = 1;
	for (int i = n - 1; i >= 0; i--) {
		p += d[i];
		if (ans < p / (a + b*w)) ans = p / (a + b*w);
		w++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A[200000],ans=0,B[3];
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n-2){
        rep(j,3) B[j]=A[i+j];
        sort(B,B+3);
        if(B[1]==A[i+1]) ans++;
    }
    cout<<ans;
}

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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;
      ll arr[n];
      loop(i,0,n){cin>>arr[i];}

      ll cnt=0;
      for(ll i=0; i<n; i++){
            for(ll j=i+1; j<n; j++){
                  for(ll k=j+1; k<n; k++){
                        ll x=arr[i];
                        ll y=arr[j];
                        ll z=arr[k];
                        if((x==y) || (x==z) || (y==z)){continue;}
                        if((x+y)>z && (x+z)>y && (y+z)>x){cnt++;}
                  }
            }
      }
      cout<<cnt<<endl;


      bye;
}


Measured memory_bytes: 3644
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let [a,b]=nrin(2)
  out(a+b>=10?'error':a+b)
}
main()


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
int c[100000] = {};
int main(){
	int n;
	cin>>n;
	int t[n];
	for(int  i= 0;i<n;i++){
		cin>>t[i];
	}
	for(int i = 0;i<n;i++){
		c[t[i]]++;
	}
	int j = 0,p = 0;
	for(int i = 0;i<100000;i++){
		for(int j = c[i];j>0;j--){
			if(p >= n-1){
				cout<<i<<endl;
				break;
			}
			cout<<i<<" ";
			c[i]--;
			p++;
		}
	}
}


Measured memory_bytes: 10960
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))

cnt = {}
for x in a:
    if x in cnt:
        cnt[x] += 1
    else:
        cnt[x] = 1

ans = 0
for i in range(n - 1, -1, -1):
    for d in range(30, -1, -1):
        k = bisect.bisect_left(a, (1 << d) - a[i])
        if k < n and a[i] + a[k] == (1 << d) and (a[i] == a[k] and cnt[a[i]] >= 2 or a[i] != a[k] and cnt[a[i]] >= 1 and cnt[a[k]] >= 1):
            ans += 1
            cnt[a[i]] -= 1
            cnt[a[k]] -= 1

print(ans)

Measured memory_bytes: 127708
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll A,B;
  cin >> A >> B;
  unordered_set<int> s;
  s.emplace(1);
  s.emplace(2);
  s.emplace(3);
  s.erase(A);
  s.erase(B);
  cout << *s.begin() << endl;
  

}


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

int main(){
  string s;
  bool no=false;
  cin >> s;
  for(int i=1;i<s.size();i+=2){
    if(s[i] == 'R'){
      no=true;
    }
  }
  for(int i=0;i<s.size();i+=2){
    if(s[i] == 'L'){
      no=true;
    }
  }
  if(no) cout << "No" << endl;    
  else cout << "Yes" << endl;    
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
s = xor = 0
right = 0
ans = 0
for left in range(n):
    while right < n and s + a[right] == xor ^ a[right]:
        s += a[right]
        xor ^= a[right]
        right += 1
    ans += right - left
    if left == right: right += 1
    else:
        s -= a[left]
        xor ^= a[left]
print(ans)

Measured memory_bytes: 23560
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		String[] str1 = buf.readLine().split(" ");
		String[] str2 =  buf.readLine().split(" ");
		int[] dice1 = new int[6];
		int[] dice2 = new int[6];
		

		for(int i=0; i<6; i++){
			dice1[i] = Integer.parseInt(str1[i]);
			dice2[i] = Integer.parseInt(str2[i]);
		}
		Saikoro sk = new Saikoro(dice1,dice2);
		if(sk.compare_saikoro())
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}
class Saikoro{
	int[] dice1 = new int[6];
	int[] dice2 = new int[6];
	StringBuilder sb1 = new StringBuilder();
	StringBuilder sb2 = new StringBuilder();
	String str1,str2;

	public Saikoro(int[] dice1, int[] dice2){
		for(int i=0; i<6; i++){
			this.dice1[i] = dice1[i];
			this.dice2[i] = dice2[i];

		}
		sb1.append(dice1[1]);
		sb1.append(dice1[2]);
		sb1.append(dice1[4]);
		sb1.append(dice1[3]);
		str1 = sb1.toString();
	}
	public boolean compare_saikoro(){
		if(dice2[0] == dice1[0] && dice2[5] == dice1[5]){
				sb2.append(dice2[1]);
				sb2.append(dice2[2]);
				sb2.append(dice2[4]);
				sb2.append(dice2[3]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[1] == dice1[0] && dice2[4] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[3]);
				sb2.append(dice2[5]);
				sb2.append(dice2[2]);
				str2 = sb2.toString();	
				return (str1+str1).contains(str2);	
		}
		else if(dice2[2] == dice1[0] && dice2[3] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[1]);
				sb2.append(dice2[5]);
				sb2.append(dice2[4]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[3] == dice1[0] && dice2[2] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[4]);
				sb2.append(dice2[5]);
				sb2.append(dice2[1]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[4] == dice1[0] && dice2[1] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[2]);
				sb2.append(dice2[5]);
				sb2.append(dice2[3]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[5] == dice1[0] && dice2[0] == dice1[5]){
				sb2.append(dice2[1]);
				sb2.append(dice2[3]);
				sb2.append(dice2[4]);
				sb2.append(dice2[2]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 24496
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

int main()
{
	int n;
	scanf("%d", &n);
	map<int, int> M[2];

	REP(i, n)
	{
		int v;
		scanf("%d", &v);
		M[i & 1][v]++;
	}

	PII mx[2], mx2[2];
	REP(sel, 2)
	{
		mx[sel] = mx2[sel] = MP(0, 0);
		for (const auto & p : M[sel])
			if (p.second > mx[sel].second)
			{
				mx2[sel] = mx[sel];
				mx[sel] = p;
			}
			else if (p.second > mx2[sel].second)
				mx2[sel] = p;
	}

	int res = n;

	if (mx[0].first == mx[1].first)
		res = n - max(mx[0].second + mx2[1].second, mx2[0].second + mx[1].second);
	else
		res = n - mx[0].second - mx[1].second;

	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0; i<N; i++)
#define lint long long
#define square_vector(name,N,M) vector<vector<lint>>name(N,vector<lint>(M,0))
#define sort(V) sort(V.begin(),V.end())

/*vector<lint> depth(lint N,lint root,vector<lint> l1,vector<lint> l2) {
  vector<lint> res(N);
  res[root] = 0;
  rep(i,N-1) {
    can[l1[i]].push(l2[i]);
    can[B].push(A);
  }
}*/

int main() {
  lint N,u,v;
  cin >> N >> u >> v;
  u--;
  v--;
  
  vector<lint> u_depth(N,-1),v_depth(N,-1);
  u_depth[u] = 0;
  v_depth[v] = 0;
  
  vector<queue<lint>> can(N);
  vector<queue<lint>> can2(N);
  
  lint A,B;
  rep(i,N-1) {
    cin >> A >> B;
    A--;
    B--;
    can[A].push(B);
    can[B].push(A);
    can2[A].push(B);
    can2[B].push(A);
  }
  
  
  queue<lint> que;
  que.push(u);
  
  lint pla = u;
  
  while (!que.empty()) {
    pla = que.front();
    while (!can[pla].empty()) {
      if (u_depth[can[pla].front()] == -1) {
        u_depth[can[pla].front()] = u_depth[pla] + 1;
        que.push(can[pla].front());
      }
      can[pla].pop();
    }
    que.pop();
  }
    
  queue<lint> que2;
  que2.push(v);
  
  pla = v;
  
  while (!que2.empty()) {
    pla = que2.front();
    while (!can2[pla].empty()) {
      if (v_depth[can2[pla].front()] == -1) {
        v_depth[can2[pla].front()] = v_depth[pla] + 1;
        que2.push(can2[pla].front());
      }
      can2[pla].pop();
    }
    que2.pop();
  }
  
  lint ans = 0;
  
  rep (i,N) {
    if (u_depth[i] < v_depth[i]) {
      ans = max(ans,(v_depth[i] - 1));
    }
    
  }
  
  rep (i,N) {
    cerr << u_depth[i] << " " << v_depth[i] << endl;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 136320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  string ans="No";
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))ans="Yes";
  cout << ans <<endl;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n : i32 = read();
    let an : Vec<i32> = read_vec();
    let count_an = an.iter().fold((0,0,0), |(a,b,c),d| {
        if d % 4 == 0 {
            (a+1,b,c)
        } else if d % 2 == 0 {
            (a,b + 1,c)
        }else {
            (a,b,c+1)
        }
    });
    let (a,b) = (count_an.0,count_an.2 + if count_an.1 == 0 { 0 } else {1});
    let  ans = if a  + 1>= b { "Yes" } else { "No" };
    println!("{}",ans);
}

Measured memory_bytes: 6396
N = int(input())
S = input()
num_E = []
num_W = []
num_All = []
count_W = 0
count_E = 0

for i in range(N):
  if S[i] == 'W':
    count_W += 1
  if S[N-i-1] =='E':
    count_E += 1
  num_W.append(count_W)
  num_E.append(count_E)

num_E.reverse()
num_All = [x + y for (x, y) in zip(num_W, num_E)]

print(min(num_All)-1)


Measured memory_bytes: 30684
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	while(n){
		if(n%10==2) ans++;
		n/=10;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if((i + 1) % 2 == 1 && a % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(void) {
  int n, m;
  int x, y;
  cin >> n >> m >> x >> y;
  
  int maxx = -101, miny = 101;
  for (int i = 0; i < n; i++){
    int t; cin >> t;
    maxx = max(t, maxx); 
  }
  for(int i = 0; i < m; i++)
  {
    int t; cin >> t;
    miny = min(t, miny);
  }
  
  bool flag = true;
  flag &= maxx < miny;
  flag &= x < maxx && miny <= y;
  if (flag) cout << "No War" << endl;
  else cout << "War" << endl;

  return 0;
}

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

#define LEN 100005
/*プロセスを表す構造体*/
typedef struct pp{
    char name[100];
    int t;
} P;
P Q[LEN];
int head,tail,n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail+1)%LEN;
}
P dequeue(){
    P x = Q[head];
    head = (head + 1) %LEN;
    return x;
}

int min(int a, int b){return a<b ? a:b;}


int main(){
    int elaps = 0,c;
    int i,q;
    P u;
    cin >> n >> q;
    for(i = 1;i <=n;i++){
        cin >> Q[i].name;
        cin >> Q[i].t;
    }
    head =1;tail = n+1;
    while(head!=tail){
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t >0){
            enqueue(u);
        }else{
            cout << u.name << " " << elaps << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 13248
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool used[1<<17];
vector<int> ans;

int main(void){
	int n,m,k,i,a[4],j,p[8]={0,1,3,0,2,3,1,2};
	bool flag = false;
	cin >> m >> k; n = (1<<m);
	if(k>=n || (m==1 && k==1)){
		cout << "-1" << endl;
		return 0;
	}
	if(!k){
		for(i=0; i<n; ++i){
			cout << (i?" ":"") << i << " " << i;
		}
		cout << endl;
		return 0;
	}
	for(i=0; i<n; ++i){
		if(used[i]){
			continue;
		}
		if(flag){
			a[1] = i;
			a[3] = a[1]^k;
			used[a[1]] = true;
			used[a[3]] = true;
			for(j=0; j<8; ++j){
				ans.push_back(a[p[j]]);
			}
			flag = false;
		}else{
			a[0] = i;
			a[2] = a[0]^k;
			used[a[0]] = true;
			used[a[2]] = true;
			flag = true;
		}
	}
	n *= 2;
	for(i=0; i<n; ++i){
		cout << ((i)?" ":"") << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3060
from time import time
from random import randrange
from bisect import bisect_left
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
start = time()
d = int(input())
c = list(map(int, input().split()))
C = sum(c)
s = [list(map(int, input().split())) for _ in range(d)]
#t = [int(input()) for _ in range(d)]
t = []
day = [[0] for _ in range(26)]
order = []

def score(t):
	res = 0
	minus = 0
	last = [0 for _ in range(26)]
	for i, x in enumerate(t):
		minus += C - c[x-1] * (i - last[x-1] + 1)
		res -= minus
		res += s[i][x-1]
		last[x-1] = i+1
		#print(res)
	return res

def tri(n):
	return n * (n-1) // 2

def change(i, to):
	diff = 0
	fr = t[i]-1
	#print(day[fr])
	#print(day[to])
	if fr == to:
		return None
	fr_ind = bisect_left(day[fr], i+1)
	diff += (tri(day[fr][fr_ind] - day[fr][fr_ind-1]) + tri(day[fr][fr_ind+1] - day[fr][fr_ind])) * c[fr]
	diff -= (tri(day[fr][fr_ind+1] - day[fr][fr_ind-1])) * c[fr]
	diff -= s[i][fr]
	
	to_ind = bisect_left(day[to], i+1)
	diff += (tri(day[to][to_ind] - day[to][to_ind-1])) * c[to]
	diff -= (tri(day[to][to_ind] - (i+1)) + tri(i+1 - day[to][to_ind-1])) * c[to]
	diff += s[i][to]

	if diff > -1000:
		day[fr].pop(fr_ind)
		after = day[to][:to_ind] + [i+1] + day[to][to_ind:]
		day[to] = after
		t[i] = to+1
		#print("↓")
		#print(day[fr])
		#print(day[to])
		return diff
	else:
		return None

#score(t)
res = 0
minus = 0
last = [0 for _ in range(26)]
for i in range(d):
	minus += C
	li = sorted(list(range(26)), key=lambda x: - c[x] * (i - last[x] + 1) - s[i][x])
	order.append(li)
	M_ind = li[0]
	minus -= c[M_ind] * (i - last[M_ind] + 1)
	last[M_ind] = i+1
	res -= minus - s[i][M_ind]
	t.append(M_ind+1)
	day[M_ind].append(i+1)

for i in range(26):
	day[i].append(d+1)

#print(*t, sep="\n")
#print(score(t))
#print("↓")

priority = [0 for _ in range(d)]
while time() - start < 1.8:
	i = randrange(d)
	pr = randrange(max(0, priority[i]-4), min(26, priority[i]+3))
	diff = change(i, order[i][pr])
	if diff is not None:
		res += diff
		priority[i] = pr

print(*t, sep="\n")

Measured memory_bytes: 97420
#include <bits/stdc++.h>
using namespace std;
int f(int x){
 if (x%2 == 0){
  x /= 2;
  return x;
 }
 else{
  x = 3*x + 1;
  return x;
 }
}

int main(){
  int s;
  cin >> s;
  if(s == 1 || s == 2 || s == 4)
    cout << 4 << endl;
  else{
  int count = 1;
  while (s != 4){
   s = f(s);
   count++;
  }
 
  cout << count + 3 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int ans;
int N;

int solve() {
	if (N < 105) return 0;

	for (int i = 105; i <= N; i += 2) {
		int c = 2;
		REP(j, 2, i) {
			if (i % j == 0) c++;
		}
		if (c == 8) ans++;
	}
	return ans;
}

int main(void) {
    scanf("%d", &N);
    
    printf("%d\n", solve());

	return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())
mod = 10 ** 9 + 7


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


if (X + Y) % 3 != 0:
    print(0)
    exit()

# 移動1, 2を使う回数
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3

if n < 0 or m < 0:
    print(0)
    exit()

print(mod_cmb(n + m, n, mod))

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();

            out.println(x + y / 2);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 22868
#binary_search
def isOK(lis, index, key):
    if lis[index] > key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
COUNT = []
total = 0
for b in B[::-1]:
    index = binary_search(C, b)
    if index == N:
        total += 0
    else:
        total += (N - index)
    COUNT.append(total)
COUNT = COUNT[::-1]
counter = 0
for a in A:
    index = binary_search(B, a)
    if index != N:
        counter += COUNT[index]
print(counter)

Measured memory_bytes: 112612
#include <iostream>
using namespace std;
int main() {
  int n, d, a = 0, b=0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d;
    a += d;
    b += d * d;
  }
  cout << ((a * a) - b) /2;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
ll h[100010];
ll dp[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",h+i+1);
	dp[2]=llabs(h[2]-h[1]);
	rep(i,3,n+1){
		dp[i]=min(dp[i-2]+llabs(h[i]-h[i-2]),dp[i-1]+llabs(h[i-1]-h[i]));
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define Maxn 200007
char s[Maxn];
bool f[Maxn],g[Maxn];
int s1[Maxn],s2[Maxn];
#define modp 998244353
int len,a,b,c,d;
int main()
{
    scanf("%d%d%d%d%d",&len,&a,&b,&c,&d);
    scanf("%s",s+1);
    if (c<d)
    {
        bool check=true;
        memset(f,false,sizeof(f));
        f[b]=true;
        for (int i=b+1;i<=d;i++)
            if (s[i]=='.')
            {
                if (i>1&&f[i-1]) f[i]=true;
                if (i>2&&f[i-2]) f[i]=true;
            }
        if (!f[d]) check=false;
        memset(f,false,sizeof(f));
        f[a]=true;
        for (int i=a+1;i<=c;i++)
            if (s[i]=='.')
            {
                if (i>1&&f[i-1]) f[i]=true;
                if (i>2&&f[i-2]) f[i]=true;
            }
        if (!f[c]) check=false;
        if (check) printf("Yes\n"); else printf("No\n");
    } else
    {
        memset(f,false,sizeof(f));
        f[b]=true;
        for (int i=b+1;i<=d;i++)
            if (s[i]=='.')
            {
                if (i>1&&f[i-1]) f[i]=true;
                if (i>2&&f[i-2]) f[i]=true;
            }
        memset(g,false,sizeof(g));
        g[d]=true;
        for (int i=d-1;i>=b;i--)
            if (s[i]=='.')
            {
                if (g[i+1]) g[i]=true;
                if (g[i+2]) g[i]=true;
            }
        memset(s1,0,sizeof(s1));
        s1[a]=1;
        for (int i=a+1;i<=c;i++)
            if (s[i]=='.')
            {
                if (i>1) s1[i]=(s1[i]+s1[i-1])%modp;
                if (i>2) s1[i]=(s1[i]+s1[i-2])%modp;
            }
        memset(s2,0,sizeof(s2));
        s2[c]=1;
        for (int i=c-1;i>=a;i--)
            if (s[i]=='.')
            {
                s2[i]=(s2[i]+s2[i+1])%modp;
                s2[i]=(s2[i]+s2[i+2])%modp;
            }
        bool check=false;
        for (int i=b;i<=d;i++)
            if (f[i]&&g[i]&&((1LL*s1[i]*s2[i])%modp!=s1[c])) check=true;
        if (check) printf("Yes\n"); else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 5796
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

ll INF=10000000000000;

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

  int A,B,Q;
  cin >> A >> B >> Q;
  ll s[A];
  for(int i=0;i<A;i++) cin >> s[i];
  ll t[B];
  for(int i=0;i<B;i++) cin >> t[i];
  ll x[Q];
  for(int i=0;i<Q;i++) cin >> x[i];

  for(int i=0;i<Q;i++){
    ll s_left;
    ll s_right;
    ll t_left;
    ll t_right;

    ll* ps = lower_bound(s,s+A,x[i]);
    ll* pt = lower_bound(t,t+B,x[i]);
    if(ps==s){
      s_left=-INF;
      s_right=s[0];
    }else if(ps==s+A){
      s_left=s[A-1];
      s_right=INF;
    }else{
      s_left=*(ps-1);
      s_right=*ps;
    }

    if(pt==t){
      t_left=-INF;
      t_right=t[0];
    }else if(pt==t+B){
      t_left=t[B-1];
      t_right=INF;
    }else{
      t_left=*(pt-1);
      t_right=*pt;
    }

    //cout << endl;
    //cout << s_left << endl;
    //cout << s_right << endl;
    //cout << t_left << endl;
    //cout << t_right << endl;

    ll ans=INF;
    ans=min(ans,x[i]-min(s_left,t_left));
    ans=min(ans,max(s_right,t_right)-x[i]);
    ans=min(ans,2*s_right-t_left-x[i]);
    ans=min(ans,2*t_right-s_left-x[i]);
    ans=min(ans,x[i]+s_right-2*t_left);
    ans=min(ans,x[i]+t_right-2*s_left);
    cout << ans << endl;
  }
  return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> alt(N + 1);
    alt[0] = 0;
    REP(i, N) {
        if (i % 2 == 0) {
            alt[i + 1] = alt[i] + A[i];
        } else {
            alt[i + 1] = alt[i] - A[i];
        }
    }

    REP(i, N) {
        ll ans;
        if (i % 2 == 0) {
            ans = (alt[N] - alt[i]) - (alt[i]);
        } else {
            ans = -(alt[N] - alt[i]) + (alt[i]);
        }
        cout << ans << (i == N - 1 ? '\n' : ' ');
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 2432
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (K, N) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<int>().ToList();
            A = A.OrderBy(x => x).ToList();
            A.Add(K);
            var answer = A[N - 1] - A[0];
            for (var i = 0; i < N; i++)
            {
                var tmp = A[i];
                tmp += K - A[i + 1];
                answer = Math.Min(answer, tmp);
            }
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 52672
#include<bits/stdc++.h>
using namespace std;  
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl  
#define DIV 1000000007

int main(){
	ll ans = 0,now = 0;
	ll N,T,input;
	
	cin >> N >> T;
	
	REP(i,N){
		cin >> input;
		ll tt = input - now;
		ans += min(tt,T);
		now = input;
	}
	cout << ans + T << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int k;
    cin >> k;
    string S;
    cin >> S;
    if(S.size()<=k){
        pr(S);
    }else{
        pr(S.substr(0,k)+"...");
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define N 100
const ll INF=1e15+7;


int main(){
	ll n,y;
	cin>>n>>y;
	y/=1000;
	FOR(i,0,n+1){
		FOR(j,0,n+1-i){
			ll m=i*10+5*j+(n-i-j);
			if(i+j<=n&&m==y){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int n, W;
    cin >> n >> W;
    ll dp[n+1][W+1];
    int w[W+1], v[n+1];
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    memset(dp, 0, sizeof dp);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= W; j++){
            dp[i][j] = dp[i-1][j];
            if(w[i] <= j)
                dp[i][j] = max(dp[i][j], v[i] + dp[i-1][j-w[i]]);

        }
    }

    cout << dp[n][W] << "\n";
    return 0;
}


Measured memory_bytes: 79488
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int A[][] = new int[3][3];
        final int C[][] = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                A[i][j] = Integer.parseInt(sc.next());
                C[i][j] = 0;
            }
        }
        final int N = Integer.parseInt(sc.next());
        final int B[] = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < N; k++) {
                    if (B[k] == A[i][j]) {
                        C[i][j] = 1;
                    }
                }
            }
        }
        if (C[0][0] == 1 && C[0][1] == 1 && C[0][2] == 1) {
            System.out.println("Yes");
        } else if (C[1][0] == 1 && C[1][1] == 1 && C[1][2] == 1) {
            System.out.println("Yes");
        } else if (C[2][0] == 1 && C[2][1] == 1 && C[2][2] == 1) {
            System.out.println("Yes");
        } else if (C[0][0] == 1 && C[1][0] == 1 && C[2][0] == 1) {
            System.out.println("Yes");
        } else if (C[0][1] == 1 && C[1][1] == 1 && C[2][1] == 1) {
            System.out.println("Yes");
        } else if (C[0][2] == 1 && C[1][2] == 1 && C[2][2] == 1) {
            System.out.println("Yes");
        } else if (C[0][0] == 1 && C[1][1] == 1 && C[2][2] == 1) {
            System.out.println("Yes");
        } else if (C[0][2] == 1 && C[1][1] == 1 && C[2][0] == 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

int main()
{
    int a,b;
    for(int i=0; i<3000; i++){
        cin >> a >> b;
        if(a == 0 && b == 0)
            break;
        if (a>b){
            int tmp = a;
            a = b;
            b = tmp;
            cout << a << ' ' << b << endl;
        }
        else
            cout << a << ' ' << b << endl;
    }
    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    int fi, se, th;
    if(a > b){
        if(b > c){
            fi = a;
            se = b;
            th = c;
        }
        else{
            if(c > a){
                fi = c;
                se = a;
                th = b;
            }
            else{
                fi = a;
                se = c;
                th = b;
            }
        }
    }
    else{
        if(a > c){
            fi = b;
            se = a;
            th = c;
        }
        else{
            if(c > b){
                fi = c;
                se = b;
                th = a;
            }
            else{
                fi = b;
                se = c;
                th = a;
            }
        }
    }

    cout << fi*10 + se + th << endl;
    return 0;
}

Measured memory_bytes: 256