akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Runtime.InteropServices.ComTypes;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());
        var B = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

        var ans = new long[N];
        var exi = true;
        for (int i = 1; i <= N; i++)
        {
            var remove = -1;
            for (int j = B.Count - 1; j >= 0; j--)
            {
                if(j+1 == B[j])
                {
                    remove = j + 1;
                    B.RemoveAt(j);
                    ans[N - i] = remove;
                    break;
                }
            }
            if(remove == -1)
            {
                exi = false;
                break;
            }
        }

        if (exi)
        {
            for (int i = (int)N - 1; i >= 0; i--)
            {
               
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
        else
        {
            Console.WriteLine(-1);
        }
        
    }



}


Measured memory_bytes: 27932
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; }


int main() {
    int n;
    cin >> n;
    cout << n/3 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct FOUNTAIN_DATA{
	int area;
	int plane;
	struct FOUNTAIN_DATA *next;
} ST_FOUNTAIN;
 
/* push data */
void push(ST_FOUNTAIN **p, ST_FOUNTAIN *ptPushData)
{
	ptPushData->next = *p;
	*p = ptPushData;
}
 
/* pop data */
ST_FOUNTAIN *pop(ST_FOUNTAIN **ptPopData)
{
	ST_FOUNTAIN *ptTempData = *ptPopData;
	if(ptTempData != NULL)
	{
		*ptPopData = (*ptPopData)->next;
	}
	
	return ptTempData;
}
 
int main()
{
	char ch;
	int area;
	int plane;
	int total;
	int count;
	int loop;
	ST_FOUNTAIN *ptNewData;
	ST_FOUNTAIN *ptOldData;
	ST_FOUNTAIN *ptTempData;
	
	ptNewData = NULL;
	ptOldData = NULL;
	while((ch = getchar()) != '\n')
	{
		if(ch == '\\')
		{
			/* set new fountain point */
			ptTempData = (ST_FOUNTAIN*)malloc(sizeof(ST_FOUNTAIN));
			ptTempData->area = 0;
			ptTempData->plane = 0;
			push(&ptNewData, ptTempData);
		}
		else if(ch == '_')
		{
			/* set plane length */
			ptTempData = pop(&ptNewData);
			if (ptTempData != NULL)
			{
				ptTempData->plane++;
				push(&ptNewData, ptTempData);
			}
			else
			{
				/* error process */
			}
		}
		else if(ch == '/')
		{
			area = 0;
			plane = 0;
			while((ptTempData = pop(&ptNewData)) != NULL)
			{
				/* merge foutain data with more depth point */
				area += ptTempData->area;	
				plane += ptTempData->plane;
				if(ptTempData->area == 0)	/* if merge point */
				{
					break;
				}
				else						/* more depth point */
				{
					push(&ptOldData,ptTempData);
				}
			}
 
			if(ptTempData != NULL)						/* calcrate or merge foutain data with more depth point */
			{
				/* calcrate fountain data */
				ptTempData->area = area + plane + 1;
				ptTempData->plane = plane + 2;
				push(&ptNewData, ptTempData);					/* set fountain data after merge */
				while((ptTempData = pop(&ptOldData)) != NULL)	/*  after merge, free more depth point data  */
				{
					free(ptTempData);
				}
			}
			else if (area > 0)
			{
				while((ptTempData = pop(&ptOldData)) != NULL)
				{
					push(&ptNewData, ptTempData);			/* Re-store pop data */
				}
			}
		}
		else
		{
			/* error input */
		}
	}

	/* calcrate all area sum value and area num */
	total = 0;
	count = 0;
	while((ptTempData = pop(&ptNewData)) != NULL)
	{
		if(ptTempData->area == 0)
		{
			free(ptTempData);
		}
		else
		{
			total += ptTempData->area;
			count++;
			push(&ptOldData, ptTempData);
		}
	}
 	
	/* Output Result */
	printf("%d\n", total);
	printf("%d", count);
	if (count > 0)
	{
		for(loop = 0; loop < count; loop++)
		{
			printf(" ");
			ptTempData = pop(&ptOldData);
			printf("%d", ptTempData->area);
			free(ptTempData);
		}
	}
	printf("\n");
 
	return 0;
}



Measured memory_bytes: 2260
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#include<set>
#define ws " "
#define nl "\n"
#define tc ll test; cin>>test; while(test--)
#define f(i, a, b) for(ll i = a; i<b; i++)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#include<fstream>

using namespace std;

#define pll pair<ll, ll>
bool compare(pll a, pll b)
{
	//for descending order replace with a.roll >b.roll
   if((a.ff < b.ff)||((a.ff==b.ff)&&a.ss<b.ss))
        return 1;
	else
		return 0;
}

ll power(ll x,  ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}

  void solve(){
                    ll n;
                    cin>>n;
                    if(n%2 == 0){
                        cout<<"-1";
                        return ;
                    }
                    ll k = 7;
                    ll cnt = 1;
                    while(true){
                        if(k%n == 0){
                            cout<<cnt;
                            break;
                        }
                        if(cnt > n){
                            cout<<"-1";
                            break;
                        }
                        k = (k%n)*10 +7;
                        // cout<<k<<"\n";
                        ++cnt;
                    }
                }


int main()
{
    fastIO;
    //tc

    //cout<<"Case #"<<i+1<<" :"<<nl;
    solve();


}


Measured memory_bytes: 3604
n=int(input())
l=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    st=str(i)
    start=int(st[0])
    end=int(st[-1])
    l[start][end]+=1
ans=0
for i in range(10):
    for j in range(10):
        ans+=l[i][j]*l[j][i]
print(ans)
            

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < S.length(); i++) {
			sb.append("x");
		}
		System.out.println(sb.toString());
	}

}

Measured memory_bytes: 21584
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::*;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",(a..b+1).filter(|i|i/10000==i%10&&i/1000%10==i/10%10).count());
}


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

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

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

	ll a, b, n;
	cin>>a>>b>>n;
	ll x = min(n, b-1);
	cout<<(a*x)/b - a * (x/b)<<'\n';

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>



#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
const int MAXN=1e5+20;
const char p[2]={'S','W'};

char cmd[MAXN],ans[MAXN];
int N;

int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    scanf("%d",&N);
    scanf("%s",cmd+1);
    cmd[N+1]=cmd[1];
    for(int k=0;k<4;k++){
         ans[N+1]=ans[1]=k%2;
         ans[N+2]=ans[2]=k/2;
         for(int i=1;i<=N;i++){
             if(ans[i+1]==0){
                 if(cmd[i+1]=='o')ans[i+2]=ans[i];
                 else ans[i+2]=1-ans[i];
             }else{
                 if(cmd[i+1]=='o')ans[i+2]=1-ans[i];
                 else ans[i+2]=ans[i];
             }
         }
         if((ans[N+1]==ans[1])&&(ans[N+2]==ans[2])){
             for(int i=1;i<=N;i++){
                 putchar(p[ans[i]]);
             }
             putchar('\n');
             return 0;
         }
    }
    puts("-1");

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_IOSTREAM
#include<bits/stdc++.h>
#define maxn 200100
using namespace std;
typedef long long ll;
char s[maxn];
int fail[maxn],n;
ll L,R,c[50],d[100][50],len[100];
void solve(ll x,int k,int flag){
	if(n%k==0){
		for(int i=1;i<=n&&i<=x;++i)
			c[s[i]-'a']+=flag;
		ll y=(x-n)/k;
		if(y>0){
			for(int i=1;i<=k;++i)c[s[i]-'a']+=flag*y;
			for(int i=1;i<=x-n-k*y;i++)c[s[i]-'a']+=flag;
		}
	} else {
		memset(d,0,sizeof(d)),memset(len,0,sizeof(len));
		for(int i=1;i<=k;++i)d[1][s[i]-'a']+=flag;len[1]=k;
		for(int i=1;i<=n;++i)d[2][s[i]-'a']+=flag;len[2]=n;
		for(int i=3;len[i-1]+len[i-2]<=x;i++){
			for(int j=0;j<26;++j)d[i][j]=d[i-1][j]+d[i-2][j];
			len[i]=len[i-1]+len[i-2];
//			printf("[Len:%lld]\n",len[i]);
		}
		int i=1;
		for(;len[i]<=x&&len[i];i++);i--;
		for(int j=i;j>=2;--j)if(x>=len[j]){
			x-=len[j];
			for(int k=0;k<26;++k)c[k]+=d[j][k];
		}
//		printf("[%lld]",x);
		for(int i=1;i<=x;++i)c[s[i]-'a']+=flag;
	}
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1)/2;
	fail[1]=0;
	for(int i=2;i<=n;++i){
		int j=fail[i-1];
		while(j&&s[j+1]!=s[i])j=fail[j];
		if(s[j+1]==s[i])fail[i]=j+1;
		else fail[i]=j;
	}
	scanf("%lld%lld",&L,&R);
	solve(L-1,n-fail[n],-1);
	solve(R,n-fail[n],1);
	for(int i=0;i<26;++i)printf("%lld ",c[i]);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
long long op[100005];
int n;
long long sum = 0;
int main()
{
    scanf("%d", &n);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        op[x] += x;
        sum += x;
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int a, b;
        scanf("%d%d", &a, &b);
        long long tmp = op[a] / a * b;
        sum += tmp - op[a];
        op[b] += op[a] / a * b;
        op[a] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}

Measured memory_bytes: 4504
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Ans = 0;
        String S = sc.next();
        char[] C = S.toCharArray();
        for (int i=0;i<4;i++){
            Ans += (C[i]=='+')? 1:-1;
        }
        System.out.println(Ans);
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,k,a[N];
VI ans,seq;
int main() {
	scanf("%d%d",&n,&k);
	rep(i,0,n) scanf("%d",a+i);
	rep(i,0,n) a[i]-=k+1;
	int pre=-1;
	rep(i,0,k) {
		int minv=1e9,pos=-1;
		rep(j,0,n) if (a[j]<minv&&j!=pre) {
			minv=a[j];
			pos=j;
		}
		if (pos==-1) {
			puts("-1");
			return 0;
		}
		++a[pos];
		ans.pb(pos);
		pre=pos;
	}
	rep(i,0,n) if (a[i]<0) {
		puts("-1");
		return 0;
	}
	rep(i,0,k+1) {
		set<int> st;
		rep(j,0,n) st.insert(j);
		if (i==0) st.erase(ans[i]);
		else if (i==k) st.erase(ans[i-1]);
		else {
			st.erase(ans[i]); st.erase(ans[i-1]);
		}
		for (auto p:st) seq.pb(p);
		if (i!=k) seq.pb(ans[i]);
	}
	printf("%d\n",SZ(seq));
	for (auto p:seq) printf("%d ",p+1); puts("");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int v[100000];

int main() {
    int n, k, i, maxim, a, b;
    scanf( "%d%d%d", &n, &k, &v[0] );
    maxim = 0;
    for( i = 1; i < n; i++ ) {
        scanf( "%d", &v[i] );
        if( v[i - 1] + v[i] > maxim ) {
            maxim = v[i - 1] + v[i];
            a = i - 1;
            b = i;
        }
    }
    if( maxim >= k ) {
        printf( "Possible\n" );
        for( i = 1; i <= a; i++ ) {
            printf( "%d\n", i );
        }
        for( i = n - 1; i > b; i-- ) {
            printf( "%d\n", i );
        }
        printf( "%d", b );
    }
    else {
        printf( "Impossible" );
    }
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    int n;
    cin>>n;
    ll a[n],b[n],cnt=0;
    for (int i = 1; i <=n; ++i) cin>>a[i]>>b[i];
    
    for (int i = n; i>=1; i--)
    {
    a[i] += cnt;
    if(a[i] % b[i] == 0) 
        continue;
        cnt += b[i] - (a[i] % b[i]);
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
string s;
cin >> s;
if (s == "000") cout << 0 << endl;
if (s == "100") cout << 1 << endl;
if (s == "010") cout << 1 << endl;
if (s == "001") cout << 1 << endl;
if (s == "110") cout << 2 << endl;
if (s == "101") cout << 2 << endl;
if (s == "011") cout << 2 << endl;
if (s == "111") cout << 3 << endl;
  
  return 0;
}

Measured memory_bytes: 3624
n = int(input())
x = [list(input().split()) for _ in range(n)]
BTC = 380000.0
YEN = 1
ans = 0
for i in x:
    if i[1] =='BTC':
        ans += float(i[0]) * BTC
    else:
        ans += float(i[0]) * YEN
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
int x[8], y[8];

int main() {
	cin >> N;
	REP(i, N) scanf("%d %d", x + i, y + i);
	
	vector<int> ord(N);
	REP(i, N) ord[i] = i;
	
	double sum = 0;
	do {
		double cur = 0;
		FOR(i, 1, N) {
			ll difx = x[ord[i]] - x[ord[i - 1]];
			ll dify = y[ord[i]] - y[ord[i - 1]];
			cur += sqrt(difx*difx + dify*dify);
		}
		sum += cur;
	} while (next_permutation(ALL(ord)));
	
	ll d = 1;
	FOR(i, 1, N + 1) d *= i;
	printf("%.10f\n", sum / d);
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
M = [0 for i in range(N)]

M[0] = 0
for j in range(N-1):
    M[j+1] = (A[j] - int(M[j]//2)) * 2

n = int((A[N-1] - M[0]//2 - M[N-1]//2)//2)

for i in range(N):
    if i%2 == 0:
        print(M[i] + 2*n, end=" ")
    else:
        print(M[i] - 2*n, end=" ")

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b/__gcd(a,b)<<endl;
    
    return 0;
}

Measured memory_bytes: 384
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n, a, b;

int main() {
    cin >> n >> a >> b;
    int min;
    if (n * a < b) {
        min = n * a;
    } else {
        min = b;
    }

    cout << min << endl;

    return 0;
}


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

using namespace std;

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int f(int len)
{
    return len / 2;
}

int n, a[202];

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

    cin >> n;

    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    int l = 1, ans = 0;

    while(l <= n)
    {
        int r = l + 1;
        while(r <= n && a[l] == a[r])
            ++r;
        ans += f(r - l);
        l = r;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    double r;
    cin >> r;
    cout << r * 2.0 * 3.14 << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  rep(i, s.size()) {
    if(s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    char c = s.back();
    s.pop_back();
    s = c + s;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
cnt = 0

def merge(A, left, mid, right):
    global cnt

    L = A[left:mid]
    R = A[mid:right]
    L.append(10000000000)
    R.append(10000000000)

    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1

def mergesort(A, left, right):
    if left + 1 < right: #if block size >= 2
        mid = int((left + right)/2)
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, mid, right)
        

n = int(input())
S = list(map(int,input().split()))
mergesort(S, 0, n)
print(*S)
print(str(cnt))


Measured memory_bytes: 63164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool can = false;
  for (int i = 1; i < 10; i++) if (N % i == 0 && N / i < 10) can = true;
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    int x;
    cin >> x;
    int ans=0;
    while(x>=500){
        ans += 1000;
        x -= 500;
    }
    while(x>=5){
        ans += 5;
        x -= 5;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

	int a[10][1000], sum[10];
	int sum1[5];
	for(int j=0;j<5;j++){
		cin>>sum[j];
		sum1[j] = 0;
		if(sum == 0) break;
		for(int i=0;i<9;i++){
			cin>>a[j][i];
			sum1[j] += a[j][i];
		}
		cout<<sum[j] - sum1[j]<<endl;
	}
	return 0;
}
		



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
 
 
int main(){
  int N;
  cin >> N;
 
  std::vector<long> a(N);
  std::copy_n(std::istream_iterator<long>{std::cin}, a.size(), a.begin());
    
  long long sum1=a[0];
  long long sum2=0;
  for(int i=1;i<N;i++){
	sum2+=a[i];
  }
  
  long long min=sum2-sum1;
  if(min<0){
	min=-min;
  }
  for(int i=1;i<N-1;i++){
	sum2-=a[i];
	sum1+=a[i];
	long long tmp=sum2-sum1;
	if(tmp<0){
	  tmp=-tmp;
	}
	if(min>tmp){
	  min=tmp;
	}
  }
  cout << min<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <array>
#include <vector>

using namespace std;

struct Cell {
  int val;
  bool checked;
  Cell() : checked(false), val(0) {};
};


bool checkDiagonally(array<array<Cell, 3>, 3> tbl, int dir) {
  bool matched = true;
  int yi = 0, xi = dir == 1 ? 0 : 2; 
  while (yi < 3 && xi < 3 && xi >= 0) {
    if (!tbl[yi][xi].checked) {
      matched = false;
      break;
    }
    yi++;
    xi += dir;
  }

  return matched;
}

// 横にチェック
bool checkHorizontally(array<array<Cell, 3>, 3> tbl, int x, int y) {
  bool matched = true;
  for (int xi = 0; xi < 3; xi++) {
    if (!tbl[y][xi].checked) {
      matched = false;
      break;
    }
  }

  return matched;
}

// 縦にチェック
bool checkVertically(array<array<Cell, 3>, 3> tbl, int x, int y) {
  bool matched = true;
  for (int yi = 0; yi < 3; yi++) {
    if (!tbl[yi][x].checked) {
      matched = false;
      break;
    }
  }

  return matched;
}

int main(int argc, const char *argv[])
{
  array<array<Cell, 3>, 3> tbl;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> tbl[i][j].val;
    }
  }

  int n;
  cin >> n;
  bool matched = false;
  for (int i = 0; i < n; i++) {
    int num, x = -1, y = -1;
    cin >> num;

    // 指定された数字を探す
    for (int xi = 0; xi < 3; xi ++) {
      for (int yi = 0; yi < 3; yi++) {
        if (tbl[yi][xi].val == num && !tbl[yi][xi].checked) {
          tbl[yi][xi].checked = true;
          x = xi;
          y = yi;
          break;
        }
      }
    }

    if (x == -1 || y == -1) {
      continue;
    }

    // 指定された数字があった
    // 同じ行，列の検査
    bool hmatch = checkHorizontally(tbl, x, y);
    if (checkHorizontally(tbl, x, y) || checkVertically(tbl, x, y)) {
      matched = true;
      break;
    }

    // 対角線上にある場合，斜めに検査
    // y = x
    // y = 3 - x + 1
    if (checkDiagonally(tbl, 1) || checkDiagonally(tbl, -1)) {
      matched = true;
      break;
    }
  }

  cout << (matched ? "Yes" : "No") << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second
using ll = long long;
using P = pair<ll ,ll>;
//using Tu = tuple<ll, ll, ll>;
const ll INF = 1LL<<61LL;
const ll MOD = 1e9+7;



using ld = long double;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}


vector<ll> fact;
vector<ll> ifact;

ll modpow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k & 1){
      res = (res * x) % MOD;
    }
    x = (x * x) % MOD;
    k >>= 1;
  }
  return res;
}

ll comb(ll n, ll r){
  if(r < 0 || r > n)
    return 0;
  return fact[n] * ifact[n-r] % MOD * ifact[r] % MOD;
}

int main(){
  ll N;
  cin >> N;
  fact.assign(N + 10, 1);
  ifact.assign(N + 10, 1);
  for(ll i=1;i<fact.size();i++){
    fact[i] = fact[i-1] * i % MOD;
    ll x, y;
    ifact[i] = modpow(fact[i], MOD-2);
  }
  vector<ll> iti(N, -1);
  ll left, right;
  for(int i=0;i<=N;i++){
    ll a;
    cin >> a; a--;
    if(iti[a] != -1){
      left = iti[a];
      right = i;
    }
    iti[a] = i;
  }
  
  ll rest = left + N - right;
  //cout << rest << "rest" << endl;
  for(ll i=1;i<=N+1;i++){
    ll ans = (comb(N+1, i) - comb(rest, i-1) + MOD) % MOD;
    cout << ans << endl;
  }
  /*cout << endl;
  for(int i=0;i<10;i++)
    cout << fact[i] << " " << ifact[i] << " " << fact[i] * ifact[i] % MOD << endl;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
    cout << i << "C" << j << " " << comb(i, j) << endl;*/
}


Measured memory_bytes: 3584
#include<stdio.h>
int a[1000000];
int main()
{
    int n,i,max,t,l;
    scanf("%d",&n);
    t=n;
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    max=a[0];
    for(i=1; i<n; i++)
    {
        if(a[i]>a[i-1])
        {
            l=a[i];
            a[i]=a[i-1];
            a[i-1]=l;
            t--;
        }
    }
 printf("%d\n",t);
 return 0;

}


Measured memory_bytes: 896
#include<iostream>

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;

	int a[4] = { -1,-1,-1,-1 };
	int c, s;
	int tmp = 1;

	for (int i = 0; i < m; i++) {
		cin >> s >> c;

		if (a[s] == -1) {
			a[s] = c;
		}
		else if (a[s] != c)tmp = 0;

	}
	if (n == 1 && a[1] == -1)cout << 0;
	else if (n == 1 && a[1] == 0) cout << 0;
	else {
		if (a[1] == -1) a[1] = 1;
		for (int i = 2; i <= n; i++) {
			if (a[i] == -1) a[i] = 0;
		}
		if (tmp == 0) cout << -1;
		else if (a[1] == 0) cout << -1;
		else for (int i = 1; i <= n; i++) {
			cout << a[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans=min(n%k,abs((n%k)-k));
    cout<<ans<<"\n";



    return 0;
}


Measured memory_bytes: 384
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = (1..2).map { sc.nextLong() }.sorted()
    val a = t[0]
    val b = t[1]
    println(when {
        a == 1L && b == 1L -> 1L
        a == 1L -> b - 2
        a == 2L -> 0
        else -> a * b - (a + b - 2) * 2
    })
}

Measured memory_bytes: 35788
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int dp[1000001][2];
const int INF = 1e+9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string N;
    cin >> N;
    dp[0][0] = 0;
    dp[0][1] = 1;
    for(int i = 0; i < N.size(); i++){
        dp[i+1][0] = INF;
        dp[i+1][1] = INF;
    }
    for(int i = 0; i < N.size(); i++){
        int n = N[i]-'0';
        dp[i+1][0] = min(dp[i+1][0], dp[i][0]+n);
        dp[i+1][1] = min(dp[i+1][1], dp[i][0]+n+1);
        dp[i+1][0] = min(dp[i+1][0], dp[i][1]+10-n);
        dp[i+1][1] = min(dp[i+1][1], dp[i][1]+10-n-1);
    }
    cout << dp[N.size()][0] << endl;
}

Measured memory_bytes: 9116
#include<stdio.h>
int main(){
    int n,ans;
    scanf("%d",&n);
    if(n<105) ans=0;
    else if(n<135) ans=1;
    else if(n<165) ans=2;
    else if(n<189) ans=3;
    else if(n<195) ans=4;
    else ans=5;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b = li()

if a <= 0 and b >= 0:
    print('Zero')
    
elif a > 0:
    print('Positive')
    
elif b > 0:
    if (-a)%2 == 0:
        print('Positive')
    else:
        print('Negative')
        
else:
    if (a-b)%2 == 0:
        print('Negative')
    else:
        print('Positive')

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

int main() {
  int64_t N, X;
  cin >> N >> X;
    
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x.at(i);
  
  if ( N == 1 ){
    cout << abs(x.at(0) - X);
    return 0;
  }
  
  x.push_back(X);
  sort(x.begin(), x.end());
  
  vector<int> xi(N);
  for (int i = 0; i < N; i++){
    xi.at(i) = x.at(i+1) - x.at(i);
  }
  
  int64_t minv = 1001001001;
  for (int i = 0; i < N-1; i++){
    int64_t num = __gcd(xi.at(i), xi.at(i+1));
    minv = min(num, minv);
  }
  
  cout << minv << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;

int t[1000000] = {0};

int main(){
    int n,m;
    cin>>n>>m;
    int pinv=1;
    for(int i=0;i<m;i++)pinv*=2;
    cout << pinv * (100*(n-m)+1900*m) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   std::string S;
   std::cin >> S;

   std::string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
   for(int i=0; i<7; ++i){
      if(week[i]==S){
	 std::cout << 7 - i << std::endl;
	 return 0;
      }
   }
   return -1;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long    ←保留
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
//C++(GCC9.2.1)

/*signed*/int main() {
    //宣言
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> vec(n);
    for (int i = 0; i < n; ++i) {
        long long a, b;
        cin >> a >> b;
        vec[i] = make_pair(a, b);
    }
    sort(vec.begin(), vec.end());
    long long ans = 0;
    long long i = 0;
    while (m > 0) {
        long long buy = min(m, vec[i].second);
        ans += vec[i].first * buy;
        m -= buy;
        ++i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4840
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int n;
    scan(n);
    auto p = readln.split.to!(int[]);

    int ans;

    foreach (i ; 1 .. n - 1) {
        int mx = max(p[i - 1], p[i], p[i + 1]);
        int mn = min(p[i - 1], p[i], p[i + 1]);
        ans += mx != p[i] && mn != p[i];
    }

    writeln(ans);
}

















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#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) {

using namespace std;

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 
{
	~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 << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int h1,m1,h2,m2,k;
		cin>>h1>>m1>>h2>>m2>>k;
		ll int l=h1*60+m1;
		ll int r=h2*60+m2;
		ll int d=r-l;
		ll int ans=max(0ll,d-k);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int N, Q;
    cin >> N;
    ll sum = 0;

    map<ll, int> mp;
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        mp[a]++;
        sum += a;
    }

    cin >> Q;

    vector<ll> ans;

    for(int q = 0; q < Q; q++) {
        ll b, c;
        cin >> b >> c;

        sum += mp[b] * (c - b);
        mp[c] += mp[b];
        mp[b] = 0;

        ans.push_back(sum);
    }

    for(auto val : ans) {
        cout << val << endl;
    }

    return 0;
}


Measured memory_bytes: 9972
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};
int n,m;
vector<int> v[100005];
int main() {
	int n,h,w;
	cin>>n>>h>>w;

	cout<<(n-h+1)*(n-w+1)<<endl;
	return 0;
}


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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3,greater<int>());
  cout << a[0] * 10 + a[1] + a[2] << '\n';
  return 0;
}

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

const int MAXN = 100005;

struct node {
	int to, next;
} edge[MAXN*2];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top; }

int n, a[MAXN], u, v, d[MAXN];

int flag = 1;

long long dfs(int nd, int f)
{
	if (d[nd] == 1) return a[nd];
	long long pre = 0, tot = 0, sub = 0, maxp = 0;
	for (int i = head[nd]; i; i = edge[i].next) {
		int to = edge[i].to;
		if (to == f) continue;
		long long tar = dfs(to, nd);
		maxp = max(maxp, tar);
		tot += tar;
	}
	if (maxp*2 > tot) sub = tot-maxp;
	else sub = tot/2;
	if (tot < a[nd] || tot-sub > a[nd]) 
		flag = 0;
	// cerr << flag << " " << nd << " " << tot << " " << sub << " " << a[nd] << " " << tot-2*(tot-a[nd]) << endl;
	return tot-2*(tot-a[nd]);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	if (n == 2) {
		if (a[1] == a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &u, &v);
		push(u, v), push(v, u), d[u]++, d[v]++;
	}
	int rt = 0;
	for (int i = 1; i <= n; i++)
		if (d[i] > 1) {
			rt = i;
			break;
		}
	long long t = dfs(rt, 0);
	if (t == 0 && flag) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    long n; cin>>n;
    if(n%2==0){
        p("%d\n",n);
    }else{
        p("%d\n",n*2);
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h == 0 && w == 0){
                break;
            }else{
                for(int i = 0; i < h; i++){
                    for(int j = 0; j < w; j++){
                        if(i % 2 == 0 && j % 2 == 0|| i % 2 == 1 && j % 2 == 1){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 33692
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int n,m,p;
    cin>>n>>m>>p;
    if(n==0){
      break;
    }
    m--;
    vector<int> x(n);
    int sum=0;
    for(int i=0;i<n;i++){
      cin>>x[i];
      sum+=x[i];
    }
    sum*=100;
    double temp=(double)sum;
    temp-=temp*((double)p/100.0);
    if(x[m]==0){
      cout<<0<<endl;
      continue;
    }
    cout<<(int)temp/x[m]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3048
from bisect import bisect_left

n = int(input())
l = sorted(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = l[i-1], l[j-1]
        ab = a + b
        c = bisect_left(l, ab)
        ans += c - j - 1

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  bool isOdd = n%2 == 1;
  vector<ll> dp[3];
  rep(i,3) dp[i] = vector<ll>(n+1,0);
  rep(i,n){
    ll a;
    cin >> a;

    dp[0][i+1] = dp[0][i];
    if(i%2==0 && i <= n-2){
      dp[0][i+1] += a;
    }
    int ii = max(0,i-1);
    dp[1][i+1] = max(dp[1][i],dp[0][ii]);
    if(i%2==1){
      dp[1][i+1] += a;
    }
    if(isOdd){
      dp[2][i+1] = max(dp[2][i],dp[1][ii]);
      if(i%2==0){
        dp[2][i+1] += a;
      }
    }
  }
  ll ans = max(dp[0][n],dp[1][n]);
  if(isOdd) ans = max(ans,dp[2][n]);
  cout << ans << endl;
}


Measured memory_bytes: 7580
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int l,a,b,c,d;
  cin>>l>>a>>b>>c>>d;
  cout<<l-max((a+c-1)/c,(b+d-1)/d)<<endl;


}

Measured memory_bytes: 1160
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

void solve(int test_case) {//210
	int n;
	cin>>n;
	ull ans = 1;
	vector<ull> arr(n,0);
	int mx = INT_MIN;
	REP(i,1,n){
		int val;
		cin>>val;
		if(i==1&&val!=0) {
			cout<<0;
			return;
		}
		if(i!=1&&val==0){
			cout<<0;
			return;
		}
		mx=max(mx,val);
		arr[val]++;
	}
	REP(i,0,mx) {
		if(arr[i]==0){
			cout<<0;
			return;
		}
	}
	REP(i,1,mx) {
		ull mp = modpow(arr[i-1], arr[i], 998244353ull);
		ans = (ans * mp)%998244353ull;
	}
	cout<<ans;
}//no. current ^ no. child

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

using namespace std;

const int N = 1e5 + 5;

int a[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int m = n / 2;
  if (a[m - 1] == a[m]) {
    puts("0");
  } else {
    int d = a[m] - a[m - 1];
    printf("%d", d);
  }
  return 0;
}


Measured memory_bytes: 640
//from PKU1125
main(){
	int i,j,n,k,K,a,b,d,dist[10][10];
	for(;scanf("%d",&k),k;){
		/*initialize*/
		memset(dist,11,sizeof(dist));
		for(i=0;i<=9;i++)dist[i][i]=0;
		for(n=0;k;k--){
			scanf("%d%d%d",&a,&b,&d);
			if(n<b)n=b;
			dist[a][b]=d,dist[b][a]=d;
		}

		{/*warshall-floyd*/
			int k,i,j;
			for(k=0;k<=n;k++)
				for(i=0;i<=n;i++)
					for(j=0;j<=n;j++)
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j];
		}

		for(k=99999999,i=0;i<=n;i++){
			for(d=j=0;j<=n;j++)d+=dist[i][j];
			if(k>d)k=d,K=i;
		}
		printf("%d %d\n",K,k);
	}
	exit(0);
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

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

/**
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int main(){
    int a,b,ans=0;
    sc2(a,b);
    ans=max(a*2-1,max(b*2-1,a+b));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3776
package main

import (
	"fmt"
)

func main() {
	var A, B, X int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&X)

	if A <= X && X <= A + B {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

void solve() {
    lli n;
    cin >> n;
    if (n == 3) {
        cout << "2 5 63" << endl;
        return;
    }
    if (n == 4) {
        cout << "2 3 4 9" << endl;
        return;
    }

    lli beg = 3;
    vector<lli> v;
    cout << "2 4 ";
    n -= 2;

    while (n > 0 && beg <= 30000) {
        v.pb(beg);
        beg += 6;
        n--;
    }

    if (v.size() % 2 == 1) {
        v.pop_back();
        n++;
    }

    beg = 8;
    while (n >= 2 && beg + 2 <= 30000) {
        cout << beg << " " << beg + 2 << " ";
        n -= 2;
        beg += 6;
    }

    beg = 6;
    while (n > 0) {
        cout << beg << " ";
        n--;
        beg += 6;
    }

    for (lli i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }

    cout << endl;
}

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

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

using namespace std; 

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    
    for(int i=0;i<m;i++)
        cin>>a[i];
    
    int sum=accumulate(a.begin(),a.end(),0);
    
    if(n>=sum)
        cout<<n-sum<<endl;
    else
        cout<<-1<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  ll n;
  cin >> n;

  ll m = n;
  int k = 0;
  while(m != 0){
    m /= 10;
    ++k;
  }

  int b[k];
  for(int i = 0; i < k; i++){
    for(int j = 9; j >= 0; j--){
      b[i] = j;
      ll sum = 0;
      for(int l = i; l >= 0; l--){
        sum = sum * 10 + b[l];
      }
      if(sum <= n) break;
    }
  }

  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += b[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ns "-1"
#define fs(i,x,y,z) for(ll i=x;i<=y;i+=z)
#define ft(i,x,y,z) for(ll i=x;i>=y;i+=z)
#define ll long long
#define ull unsigned long long
#define db double
#define ms(a,b) memset(a,b,sizeof(a))
#define sz(a) sizeof(a)
using namespace std;
const int rw[]={-1,0,1,0,-1,1,-1,1},cl[]={0,1,0,-1,-1,1,1,-1};
const int N=100001,inf=0x3f3f3f3f;
const int daynum[]={114514,31,28,31,30,31,30,31,31,30,31,30,31};
const db E=2.718281828459,pi=acos(-1.0),eps=0.0000000001;
inline int read(){
	int date=0,w=1;char c=0;
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
	return date*w;
}
ull ksm(ull a,ull b){
    ull ans=1,base=a;
    while(b){
        if(b&1){
            ans*=base;
	    }
	    base*=base;
	    b>>=1;
	}
    return ans;
}
ll gcd(ll a,ll b){
    if(b) return gcd(b,a%b);
    return a;
}
bool prm(int k){
	if(k<2) return 0;
	if(k==2||k==3) return 1;
	if(k%6!=1&&k%6!=5) return 0;
	for(int i=5;i<=sqrt(k);i+=6)
		if(k%i==0||k%(i+2)==0) return 0;
	return 1;
}
int r,a[N];
db q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>r;
	cout<<fixed<<setprecision(8)<<(db)r*pi*2;
	return 0;
}


Measured memory_bytes: 3828