akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>

using namespace std;

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

int dp[50][2][3001];

int main(){
	
	while(1){
		int n,m,s;
		scanf("%d%d%d",&n,&m,&s);
		if(n==0)break;
		int t1=0,t2=1;
		n*=n;
		rep(i,50)rep(j,2)rep(k,s+1)dp[i][j][k]=0;
		dp[0][0][0]=1;
		reps(j,m){
			
			dp[0][t2][0]=1;
			
			reps(i,n){
				int nn=i;
				int st=(nn*(nn+1))/2;
				for(int k=st-1;k<s+1;k++){
					dp[i][t2][k]=0;
					if(k-j>=0){
						dp[i][t2][k]+=dp[i-1][t1][k-j];
					}
					dp[i][t2][k]+=dp[i][t1][k];
					if(dp[i][t2][k]<0)puts("AAAAAAA");
					dp[i][t2][k]%=100000;
				}
				/*
				if(i<9&&j<9){
					printf("%d %d\n",i,j);
					for(int k=0;k<50;k++){
						printf("%d ",dp[i][t2][k]);
					}puts("");
				}*/
			}
			swap(t1,t2);
		}
		
		printf("%d\n",dp[n][t1][s]);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define EPS 1e-14
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif*/
    int n, sum=0, m;
    cin>>n;
    m=n;
    while(n>0){
        sum+=(n%10);
        n/=10;
    }
    if(m%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,q; ll a[100005];
priority_queue<pair<ll,ll> >Q;
ll ans[100005];
int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<q;i++) scanf("%lld",&a[i]);
	if(q==0){
	    for(int i=1;i<=n;i++) puts("1"); return 0;
	}
	ll pre = a[q-1]; Q.push(mp(a[q-1],1LL));
	for(int i=q-2;i>=0;i--){
		if(pre <= a[i]) continue;
		ll allcnt = 0;
		while(!Q.empty() && Q.top().fi >= a[i]){
			pair<ll,ll> R = Q.top(); Q.pop();
			allcnt+=R.sc * (R.fi/a[i]);
			ll rem = R.fi%a[i];
			if(rem) Q.push(mp(rem,R.sc));
		}
		Q.push(mp(a[i],allcnt));
		pre = a[i];
	}
	while(!Q.empty()){
		pair<ll,ll> R = Q.top(); Q.pop();
	//	cout<<R.fi<<" " << R.sc<<endl;
		ans[1] += R.sc * (R.fi/(1LL*n));
		ll x = (R.fi%(1LL*n));
		ans[1] += R.sc;
		ans[x+1] -= R.sc;
	}
	for(int i=2;i<=n;i++) ans[i]+=ans[i-1];
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 4976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = 0; k < 10; k++) {
					if ((i >> k & 1) != (j >> k & 1)) {
						System.out.print(k + 1 + " ");
						break;
					}
				}
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 36796
import heapq
N,M = map(int,input().split())
Alist = map(int,input().split())
heapAlist = []

for A in Alist:
    heapq.heappush(heapAlist,-1*A)

for i in range(M):
    A = heapq.heappop(heapAlist)
    #print(A)
    heapq.heappush(heapAlist,((-1)*A//2)*(-1))
    
print((-1)*sum(heapAlist))

Measured memory_bytes: 14180
#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>;
#define PB push_back

const int N = 100005;

int n, u, v;
vector<int> G[N];

bool visited[N], via[N]; // via[i]: v-uの最短ルートでiを経由するか

// uからの帰りならtrueを返す
bool dfs1(int pos) {
  visited[pos] = true;
  bool res = (pos == u);
  rep(i, G[pos].size()) {
    int to = G[pos][i];
    if (visited[to]) continue;
    if (dfs1(to)) res = true;
  }
  return via[pos] = res;
}

int dist[N], jct[N]; // vからの距離, v-uの最短ルートからの分岐点

void dfs2(int pos) {
  rep(i, G[pos].size()) {
    int to = G[pos][i];
    if (dist[to] != -1) continue;
    dist[to] = dist[pos] + 1;
    if (jct[to] == -1) jct[to] = jct[pos];
    dfs2(to);
  }
}

int main() {
  cin >> n >> u >> v; u--; v--;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b; a--; b--;
    G[a].PB(b);
    G[b].PB(a);
  }

  rep(i, n) visited[i] = false;
  rep(i, n) via[i] = false;
  dfs1(v);

  rep(i, n) dist[i] = -1;
  rep(i, n) {
    if (via[i]) jct[i] = i;
    else jct[i] = -1;
  }
  dist[v] = 0;
  dfs2(v);

  int ans = 0;
  rep(i, n) {
    if (2 * dist[jct[i]] < dist[u]) continue;
    ans = max(ans, dist[i] - 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13624
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
while(true){
   var n=Arr.shift();
   if(n==0)break;
   var arr=[];
   for(var i=0;i<n;i++){
      var v=Arr.shift();
      arr.push(v);
   }
   var dp=[];
   for(var i=0;i<arr.length+1;i++)dp.push(-Infinity);
   for(var i=0;i<arr.length;i++){
      dp[i+1]=Math.max(dp[i]+arr[i],arr[i]);
   }
   console.log(Math.max.apply(null,dp));
}

Measured memory_bytes: 8496
import java.util.*;
import java.io.*;

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................

static Long find(int x, int y){
	long xx=(long)(x+y)*(x+y+1);
	return xx/2;
}
   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  int n=int_v(read());
	        		  int[] a=int_arr();
	        		  Map<Integer,Integer> map=new HashMap<>();
	        		  long res=0;
	        		  for(int i=0;i<n;i++){
	        		  	int t2=i+1-a[i],t1=i+1+a[i];
	        		  	res+=map.getOrDefault(t2,0);
	        		  	map.put(t1,map.getOrDefault(t1,0)+1);
	        		  }
	        		  out.write(res+"");
	        	
	        		// if(n[0]>0){out.write("Yes");}
	        		 //else{out.write("No");}
                      out.flush();
	        		 
	}
}
	       
	          



	
  





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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

string g[110];
int cnt[30];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	//	freopen("turtle.in","r",stdin);
	//	freopen("turtle.out","w",stdout);

	int H,W;
	cin>>H>>W;
	for(int i = 0;i < H;i++) {
		cin>>g[i];
		for(int j = 0;j < W;j++) cnt[g[i][j] - 'a']++;
	}
	int num1 = (W%2 == 1) && (H%2 == 1);
	int num2 = (H%2 == 1) * W + (W%2 == 1) * H - 2 * num1;
	num2 /= 2;
	
	int get1 = 0,get2 = 0;
	for(int i = 0;i < 30;i++) {
		get1 += cnt[i]%2 == 1;
		cnt[i] -= cnt[i]%2;
		get2 += cnt[i]%4 == 2;
		cnt[i] -= cnt[i]%4;
	}
	cerr<<num2<<' '<<num1<<' '<<get2<<' '<<get1<<'\n';
	cout<<(num1 == get1 && num2 >= get2?"Yes":"No")<<'\n';
	return 0;
}


Measured memory_bytes: 256
import numpy as np
n,k = map(int, input().split())
mod = 10**9 + 7
_a = [list(map(int, input().split())) for _ in range(n)]
a = np.array(_a, dtype = object)
e = np.eye(n, dtype = object)
while k:
  if k & 1:
    e = np.dot(e, a) % mod
  k >>= 1
  a = np.dot(a, a) % mod
print(e.sum() % mod)

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

# 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 < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}


int main() {
  int(n);
  int(k);
  int num = 0;
  vint(A,n);
  sort(A.begin(),A.end(),greater<int>());

  REP(i,k)
    num += A[i];

  cout << num << endl;
    
  
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
	ll h[303];
	h[0]=0;
	for(int i=1; i<=n; i++){
		cin>>h[i];
	}
	ll dp[303][303][303];
	const ll INF=1e18;
	for(int i=0; i<=n; i++) for(int j=0; j<=k; j++) for(int l=0; l<=i; l++) dp[i][j][l]=INF;
	dp[0][0][0]=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<=k; j++){
			for(int l=0; l<=i; l++){
				dp[i+1][j][i+1]=min(dp[i+1][j][i+1], dp[i][j][l]+max(0ll, h[i+1]-h[l]));
				if(j+1<=k) dp[i+1][j+1][l]=min(dp[i+1][j+1][l], dp[i][j][l]);
			}
		}
	}
	ll ans=INF;
	for(int i=0; i<=k; i++){
		for(int j=0; j<=n; j++){
			ans=min(ans, dp[n][i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 216576
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

struct point{
	double x, y;
};

double th = M_PI * 60.0/180.0;

void koch(int n, point a, point b)
{
	if(n == 0){
		return;
	}
	point s, t, u;

	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	cout << fixed << setprecision(8);
	koch(n - 1, a, s);
	cout << s.x << " " << s.y << endl;
	koch(n - 1, s, u);
	cout << u.x << " " << u.y << endl;
	koch(n - 1, u, t);
	cout << t.x << " " << t.y << endl;
	koch(n - 1, t, b);
}

int main(){
	point a, b;
	int n;
	cin >> n;

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	cout << a.x << " " << a.y << endl;
	koch(n, a, b);
	cout << b.x << " " << b.y << endl;

	return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    map<ll, ll> mp;
    ll N, input;
 
    cin >> N;
 
    for(ll i=1; i<=N; ++i)
    {
        cin >> input;
        mp.insert(make_pair(input, i));
    }
 
    for(ll j=1; j<=N; ++j)
    {
        cout << mp[j] << " ";
    }
 
    return 0;
}

Measured memory_bytes: 7040
def main() :

    N = int(input())
    H_list = [int(i) for i in input().split()]

    # ひっくり返して、単調増加だったらNGと考える
    H_list.reverse()
    c = 0
    for i in range(len(H_list)-1) :
        d = H_list[i+1] - H_list[i]
        if (d >= 2) :
            # 増分2以上はどうしようもない
            print("No")
            return

        if (d == 1) :
            # 増分1なら削ればいい
            c += 1
            H_list[i+1] = H_list[i+1] - 1
    
    print("Yes")

main()

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

void solve()
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int e = 0;
    rep(i, n)
    {
        int t = 1;
        for (int j = 1; t <= d; j++)
        {
            // cout << t << " ";
            t = a[i] * j + 1;
            e++;
        }
        // cout << endl;
    }
    int ans = e + x;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 100000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

string s;
int k,dp[301][301][301];

int calc(int l , int r , int rem){
	if(rem<0)return -oo;
	if(l==r)return 1;
	if(l>r)return 0;
	int &ret = dp[l][r][rem];
	if(ret != -1)return ret;
	ret = max(calc(l+1,r,rem),calc(l,r-1,rem));
	if(s[l]==s[r])
		ret = max(ret,2+calc(l+1,r-1,rem));
	if(s[l]!=s[r])
		ret = max(ret,2+calc(l+1,r-1,rem-1));
	return ret;
}
int main() {
	memset(dp,-1,sizeof dp);
	cin >> s>>k;
	cout << calc(0,s.size()-1,k) << endl;
	return 0;
}


Measured memory_bytes: 106752
import java.util.Scanner;

public class Main {
    static long dp[][] = new long[100005][3]; /// dp[dia][actividad]   para el dia d, actvidad j max abajo
    static int n;
    static int[][] matrix;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        matrix = new int[n][3];

        for(int i=0;i<n;i++) {
            for(int j=0;j<3;j++) {
                int curr = in.nextInt();
                matrix[i][j]=curr;
            }

        }
        solve(0,0); solve(0,1); solve(0,2);
        long max = Long.max(Long.max(dp[0][0],dp[0][1]), dp[0][2]);
        System.out.println(max);

    }

    public static long solve(int dia, int actividad) {
        // caso base
        if(dia == n-1) {dp[dia][actividad]=matrix[dia][actividad]; return matrix[dia][actividad];}
        if(dp[dia][actividad]!=0) return dp[dia][actividad];

        long a=0;long b=0; long c=0;
        if(actividad!=0)a = solve(dia+1,0) + matrix[dia][actividad]; 
        if(actividad!=1)b = solve(dia+1,1)+ matrix[dia][actividad];
        if(actividad!=2)c = solve(dia+1,2)+ matrix[dia][actividad]; 

        long max = Long.max(Long.max(a,b), c);
        dp[dia][actividad]=max;
        return max;
    }

}

Measured memory_bytes: 70276
from itertools import accumulate
N, K = map(int, input().split())
P = [i-1 for i in map(int, input().split())]
C = list(map(int, input().split()))

seen = [0] * N

ans = -10**20

for i in range(N):
    if not seen[i]:
        seen[i] = 1
        loop = [C[i]]
        while True:
            i = P[i]
            if seen[i]:
                break
            seen[i] = 1
            loop.append(C[i])
        L = len(loop)
        loop = loop + loop
        loop = [0] + list(accumulate(loop))
        if loop[L] <= 0:
            move = min(L, K)
            for i in range(L):
                for j in range(1, move + 1):
                    ans = max(ans, loop[i + j] - loop[i])
        else:
            if K > L:
                div, mod = divmod(K, L)
                tmp = div * loop[L]
                move = min(mod, L)
                if move:
                    for i in range(L):
                        for j in range(1, move + 1):
                            ans = max(ans, tmp + loop[i + j] - loop[i])
                else:
                    ans = max(ans, tmp)
                tmp = (div - 1) * loop[L]
                move = L
                for i in range(L):
                    for j in range(1, move + 1):
                        ans = max(ans, tmp + loop[i + j] - loop[i])
            else:
                move = K
                for i in range(L):
                    for j in range(1, move + 1):
                        ans = max(ans, loop[i + j] - loop[i])

print(ans)

Measured memory_bytes: 74564
<?php
fscanf(STDIN, "%d", $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($A);
$ans = 0;
$heap = new SplMaxHeap;
$heap->insert(array_pop($A));
for ($i = 0; $i < $N - 1; $i++) {
    $tmp = array_pop($A);
    $heap->insert($tmp);
    $heap->insert($tmp);
    $ans += $heap->extract();;
}
printf("%d", $ans);


Measured memory_bytes: 38108
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,a,b=LI()

  if abs(a-b)%2==0:
    return abs(a-b)//2

  x=y=1
  x+=a-1
  y+=n-b
  x+=(b-a-1)//2
  y+=(b-a-1)//2
  return min(n-a,b-1,x,y)

# main()
print(main())


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

using namespace std;

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

int main() {
  ll h, w;
  cin >> h >> w;

  ll result = 0;
  if (w == 1 || h == 1) {
    result = 1;
  } else if (w % 2 == 0) {
    result = h * (w / 2);
  } else {
    result = (h * ((w - 1) / 2)) + ((h % 2 == 0) ? h / 2 : h / 2 + 1);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int A[N];
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  
  int count =0;
  
  while (true){
    bool exist_odd= false;
    for(int i=0; i<N; i++){
      if (A[i]%2!=0){
        exist_odd=true;
      }
    }
    
    if (exist_odd){
       break;
    }
      
    for(int i=0; i<N; i++){
       A[i] /=2;
    }
    
    count++;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;

int n, q;
int a[100000];
int SS;
int kisuu[100000], guusuu[100000];
int mix[100001];
signed main() {
	cin >> n >> q;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = n - 1; i >= n / 2; i--)SS += a[i];
	kisuu[1] = a[1]; guusuu[0] = a[0];
	for (int i = 2; i < n; i+=2) {
		guusuu[i] = guusuu[i - 2] + a[i];
	}
	for (int i = 3; i < n; i += 2) {
		kisuu[i] = kisuu[i - 2] + a[i];
	}
	for (int i = 1; i <= n; i++) {
		mix[i] = mix[i - 1] + a[i - 1];
	}
	for (int i = 0; i < q; i++) {
		int k; cin >> k;
		if (k >= a[n - 1]) {
			cout << max(kisuu[n - 1], guusuu[n - 1]) << endl;
			continue;
		}
		if (k <= a[0]) {
			cout << SS << endl;
			continue;
		}
		int L = 0, R = n;
		while (R - L > 1) {
			int T = (L + R) / 2;
			if (a[T-1] <= k) {
				L = T;
				continue;
			}
			// a[T]>k
			int l = -1, r = n-1;
			while (r - l > 1) {
				int t = (l + r) / 2;
				if (a[T-1] - k >= k - a[t]) {
					r = t;
				}
				else {
					l = t;
				}
			}
			if ((T - r) >= (n - T+1)) {
				R = T;
			}
			else {
				L = T;
			}
		}
		int SSS = L * 2 - n;
		int ans = mix[n] - mix[L];
		SSS--;
		if (SSS >= 0) {
			ans += max(guusuu[SSS], kisuu[SSS]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main() {
	// #ifndef ONLINE_JUDGE
	// 	// for getting input from input.txt
	// 	freopen("input.txt", "r", stdin);
	// 	// for writing output to output.txt
	// 	freopen("output.txt", "w", stdout);
	// #endif
	
		int a,b,c;
		cin>>a>>b>>c;
		for (int i = 1; i < 1000000; ++i)
		{	
				int p = a*i;
				if(p%b == c){cout<< "YES"<<"\n"; return 0;}
		}
		cout<<"NO"<<"\n";
		return 0;	
	}	

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
//#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,k; cin>>n>>k;
int a[n]; map<int,int> m;
for(int i=0;i<n;++i){
	cin>>a[i]; 
	m[a[i]]++;
}
int ans=0;
for(int i=0;i<n;++i) for(int j=i+1;j<n;++j) 
	if(a[i]>a[j]) ++ans;
ans=(ans*k)%MOD;
int less=0, two_inv=mexp(2,MOD-2,MOD);
for(auto e: m){
	int cur=(k*(k-1))%MOD;
	cur=(cur*two_inv)%MOD;
	cur=(cur*less)%MOD;
	cur=(cur*e.ss)%MOD;
	ans=(ans+cur)%MOD;
	less+=e.ss;
}
cout<<ans<<el;

return 0;
}


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

int main(){
  int N; string S; cin >>N >>S;
  int ans=0;
  for (int i=1;i<N;i++) {
    int count=0;
    for (char c='a';c<='z';c++) {
      bool left=false,right=false;
      for (int j=0;j<i;j++) {
        if (S[j]==c) left=true;
      }
      for (int j=i;j<N;j++) {
        if (S[j]==c) right=true;
      }
      if (left and right) count++;
    }
    ans=max(ans,count);
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n, x, t;
  cin >> n >> x >> t;

  int ans = ceil(double(n) / x) * t;
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz                size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define deb(x) cout << #x << " " << x << endl
#define inf INT_MAX
const ll N = 100010;
const ll MOD = 1e9+7;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}


void solve(){
    int a[5];
    for(int i=0;i<5;i++){
        cin >> a[i];
        if(a[i] == 0) cout << i+1;
    }
}

int main(){
    fast
    int T=1;
    //cin >> T;
    for(int i=0;i<T;i++) solve();
}

Measured memory_bytes: 3608
S=list(input())

s=0
f=0
g=0
h=0
for i in range(len(S)):
    if S[i]==">":
        g=0
        f+=1
        if h>=f:
            s+=f-1
        else:
            s+=f
        
    else:
        f=0
        g+=1
        s+=g
        h=g

print(s)


Measured memory_bytes: 13232
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let ans = if 1 <= a && a <= 9 && 1 <= b && b <= 9 {
        a * b
    } else {
        -1
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys

n = int(input())
a = list(map(int,input().split()))
wk=1
if a.count(0)>=1:
    print(0)
    sys.exit()
else:
    for i in range(n):
        wk *=a[i]
        if wk>10**18:
            print('-1')
            sys.exit()
print(wk)

Measured memory_bytes: 21476
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main(void){
  int N;
  bool mis=0;

  cin >>N;
  vector<string> W(N);
  map<string,int> M;
  for(int i=0;i<N;i++){
    cin >>W[i];
    if(M[W[i]]!=0){
      mis=1;
    }
    M[W[i]]=1;
  }

  for(int i=0;i<N-1;i++){
    if(W[i][W[i].size()-1]!=W[i+1][0]){
      mis=1;
      break;
    }
  }

  if(mis==0){
    cout <<"Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll ans1 = X /D;
    ll ans2 = (X + D - 1) / D;
    if(ans1 >= K) ans1 = K;
    if(ans2 >= K) ans2 = K;
    cout << min(abs(X - ans1 * D - D * ((K - ans1)%2)), abs(X - ans2 * D + D * ((K - ans2)%2))) << endl;
}


Measured memory_bytes: 3608
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}


int prim(const vector< vector<edge> >& G)
{
  int sum = 0;
  vector<bool> used(G.size(), false);
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, 0));
  while (!que.empty()) {
    int cost = que.top().first;
    int from = que.top().second;
    que.pop();
    if (used[from]) continue;
    used[from] = true;
    sum += cost;
    for (int i = 0; i < G[from].size(); i++) {
      edge e = G[from][i];
      if (!used[e.to]) {
        que.push(P(e.cost, e.to));
      }
    }
  }
  return sum;
}

void add_edge(vector< vector<edge> >& G, int u, int v, int c) {
  G[u].push_back((edge){ v, c });
  G[v].push_back((edge){ u, c });
}


signed main()
{
  int N; cin >> N;
  vec< pair<int,int> > x(N), y(N);
  rep(i, 0, N) {
    int a, b; cin >> a >> b;
    x[i] = MP(a, i);
    y[i] = MP(b, i);
  }
  SORT(x); SORT(y);

  vec< vec<edge> > G(N, vec<edge>());
  rep(i, 0, N-1) {
    int dist = abs(x[i+1].first - x[i].first);
    int u = x[i].second, v = x[i+1].second;
    add_edge(G, u, v, dist);
    add_edge(G, v, u, dist);
  }
  rep(i, 0, N-1) {
    int dist = abs(y[i+1].first - y[i].first);
    int u = y[i].second, v = y[i+1].second;
    add_edge(G, u, v, dist);
    add_edge(G, v, u, dist);
  }

  cout << prim(G) << endl;

  return 0;
}


Measured memory_bytes: 27252
N = int(input())

s = []
n = N
while True:
    mod = n % 26
    s.append(mod)
    if n // 26 == 0:
        break
    n = (n - mod) // 26

for i in range(len(s)):
    if s[i] == 0 and i != len(s)-1:
        s[i] = 26
        s[i+1] = s[i+1] - 1
    if s[i] == -1:
        s[i] = 25
        s[i+1] = s[i+1] - 1

if s[-1] == 0:
    s = s[:-1]

name = ''
for i in range(len(s)):
    name = 'abcdefghijklmnopqrstuvwxyz'[s[i]-1] + name

print(name)

Measured memory_bytes: 9160
import collections

n = int(input())

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

c = collections.Counter(a)
total = 0
for i in c:
    total += c[i]*(c[i]-1)//2


for i in range(n):
    target = c[a[i]]
    print(total - target*(target-1)//2 + (target-1)*(target-2)//2)





Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

ll gozyou(ll n){
  ll a = 1;
  rep1(i,5) a *= n;
  return a;
}

int main() {
  ll x,a,b;
  cin >> x;
  for(ll i=-199;i<200;i++){
    for(ll k=-199;k<200;k++){
      
     if(gozyou(i)-gozyou(k)==x){
      a = i;
      b = k;
      break;
     }
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
long long a[200005];
int main(){
	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	
	long long r=0,ans=0,sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		while(sum1==sum2 && r<=n){
			r++;
			sum1+=a[r];
			sum2^=a[r];
		}
		//cout<<r<<" "<<i<<endl;
		ans+=r-i;
		sum1-=a[i];
		sum2^=a[i];
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 5272
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0;i<N;i++) cin >> A[i];

  sort(A.begin(),A.end(),greater<ll>());

  priority_queue<ll> q;
  q.push(A[1]);
  q.push(A[1]);

  ll ans=A[0];
  for(int i=2;i<N;i++){
    ans+=q.top();
    q.pop();
    q.push(A[i]);
    q.push(A[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6928
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  map<ll, ll> mp;
  vector<ll> v;

  REP(i, N){
    ll A;
    cin >> A;
    mp[A] += 1;
    if(mp[A] == 2){
      v.push_back(A);
      mp[A] = 0;
    }
  }

  v.push_back(0);
  v.push_back(0);
  sort(ALL(v));
  reverse(ALL(v));

  cout << v[0] * v[1] << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int dp[105][105];
int q[105];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>q[i-1]>>q[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i==j)	dp[i][j]=0;
			else dp[i][j]=0x3f3f3f3f;
	for(int l=1;l<=n-1;l++){
		for(int i=1;i<=n-l ;i++){
			int j=i+l;
			for(int k=i;k<=j-1;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+q[i-1]*q[k]*q[j]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(n, a);
    vlint x(n); line(x);
    vector<vector<vlint>> dp(n+1, vector<vlint>(n+1, vlint(50 * n + 1, 0)));
    dp[0][0][0] = 1;
    rep(i, n){
        rep(cnt, n){
            rep(k, 50 * n + 1){
                dp[i+1][cnt+1][k + x[i]] += dp[i][cnt][k];
                dp[i+1][cnt][k] += dp[i][cnt][k];
            }
        }
    }
    lint ans = 0;
    rep1(cnt, n+1){
        ans += dp[n][cnt][cnt * a];
    }
    print(ans);
    
}


Measured memory_bytes: 55224
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

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

    int r = 0;
    for (int i = 0; i < n - 1; i++) {
        if (p[i] == i) {
            swap(p[i], p[i + 1]);
            r++;
        }
    }
    int i = n - 1;
    if (p[i] == i) {
        r++;
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    string s;

	cin >> s;

	stack<char> st;
	string ans = "";

	int i, len = s.size();

	rep(i, len) {
		if (s[i] == '0') st.push('0');
		else if (s[i] == '1') st.push('1');
		else if (!st.empty()) st.pop();
	}

	while (!st.empty()) {
		ans += st.top();

		st.pop();
	}

	std::reverse(All(ans));

	Out(ans);
	
	return 0;
}


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

#define int long long

signed main(){
    string a, b;
    cin >> a >> b ;
    int c, d;
    cin >> c >> d;
    string u;
    cin >> u;
    if(a == u){
        c--;
    }else{
        d--;
    }

    cout << c << " " << d << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  int n;
  cin>>n;
  vector<int> vec(n);
  int a=0,b=0,c=0;
  rep(i,n) cin>>vec[i];
  rep(i,n){
    if(vec[i]%4==0) a++;
    else if(vec[i]%2==0) b++;
    else c++;
  }

  if(c<=a) return true;

  if(c==a+1){
    if(b==0) return true;
    else return false;
  }

  return false;
}

int main(){
  if(solve()) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

string S ;

int funcA(){
	int cnt = 0 , i ;
	for( i=2 ; i<S.size() ; i++ ){
		if( S[i] == '=' ) cnt++ ;
		else if( S[i] == '#' ) break ;
		else return -1 ;
	}
	if( cnt == 0 ) return -1 ;
	for( i++ ; i<S.size() ; i++ ){
		if( S[i] == '=' ) cnt-- ;
		else if( S[i] == '~' ) break ;
		else return -1 ;
	}
	if( cnt == 0 ) return 1 ;
	return -1 ;
}

int funcB(){
	int cnt = 0 ;
	for( int i=2 ; i<S.size() ; i+=2 ){
		if( S[i] == 'Q' && S[i+1] == '=' ) cnt++ ;
		else if( S[i] == '~' && S[i+1] == '~' && cnt ) return 2 ;
		else return -1 ;
	}
	return -1 ;
}

int main(){
	
	int N ;
	
	cin >> N ;
	while( N-- ){
		cin >> S ;
		int ans = -1 ;
		if( S.size() < 6 || S.size()%2 == 1 ){}
		else if( S[0] == '>' && S[1] == '\'' ){ ans = funcA() ; }
		else if( S[0] == '>' && S[1] == '^' ){ ans = funcB() ; }
		
		if( ans == -1 ) cout << "NA" << endl ;
		if( ans == 1 ) cout << "A" << endl ;
		if( ans == 2 ) cout << "B" << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1200
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int L = 1000010;

int N, X;
bool p[L];

void init(){
  REP(i, L) p[i] = 1;
  p[0] = p[1] = 0;
  for(int i = 2; i <= sqrt(L); ++i){
    if(!p[i]) continue;
    for(int j = i + i; j < L; j += i) p[j] = 0;
  }
}

int solve(vector<int> &v){
  for(int i = X; i >= 0; --i) if(p[i] && v[i]) return i;
  return -1;
}

int main() {
  init();
  while(cin >>N >>X && N && X){
    vector<int> num(N), v(L, 0);
    v[0] = 1;
    REP(i, N){
      cin >>num[i];
      for(int j = num[i]; j < L; j++) if(v[j - num[i]]) v[j] = 1;
    }
    int res = solve(v);
    if(res == -1) cout <<"NA" <<endl;
    else cout <<res <<endl;
  }
  return 0;
}

Measured memory_bytes: 6164
#include<stdio.h>
int main(){
  int a,b=0,c=0;
  scanf("%d",&a);
  for(int i=0; i<a; i++){
    int d;
    scanf("%d",&d);
    if(d>=b){b=d;c++;}
  }
  printf("%d",c );
  
  return 0;}


Measured memory_bytes: 128
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]

cnt = 0

def binarysearch(x, l):
	mi = 0
	ma = len(l) - 1
	
	while mi < ma:
		tmp = (mi + ma) // 2
		
		if l[tmp] == x:
			return tmp
		elif l[tmp] < x:
			mi = tmp + 1
		else:
			ma = tmp - 1
	
	else:
		if mi == ma:
			if x == l[mi]:
				return mi
			else:
				return -1
		else:
			if x == l[mi]:
				return mi
			elif x == l[ma]:
				return ma
			else:
				return -1
	
	

for x in t:
	if binarysearch(x, s) != -1:
		cnt += 1

print(cnt)

Measured memory_bytes: 18764
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[100010][3];
int a[100010][3];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n){
        rep(j, 0, 3){
            cin >> a[i][j];
        }
    }
    rep(i, 0, n){
        rep(j, 0, 3){
            rep(k, 0, 3){
                if(j == k) continue;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 0, 3) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

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

int main(void)
{
	int n,i;
	double x[100],y[100],s;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lf",&x[i]);
	for(i=0;i<n;i++)scanf("%lf",&y[i]);
	s=0;
	for(i=0;i<n;i++)s+=fabs(x[i]-y[i]);
	printf("%.6f\n",s);
	s=0;
	for(i=0;i<n;i++)s+=pow(fabs(x[i]-y[i]),2);
	printf("%.6f\n",sqrt(s));
	s=0;
	for(i=0;i<n;i++)s+=pow(fabs(x[i]-y[i]),3);
	printf("%.6f\n",pow(s,1./3));
	s=0;
	for(i=0;i<n;i++)if(fabs(x[i]-y[i])>s)s=fabs(x[i]-y[i]);
	printf("%.6f\n",s);
	return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        int i,x;
        int a;
        str = scan.nextLine();
        a = Integer.valueOf(str);
        str = scan.nextLine();
        String[] nums = str.split(" ", 0);
        int[] b = new int[a];
        i = 0;
        for (String num: nums){
            b[i++] = Integer.valueOf(num);
        }

        for(i = a-1; i > 0; i--){
            System.out.print(b[i]+" ");
        }
         System.out.print(b[0]);
        System.out.println();
        scan.close();
    }
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll N;
  cin>>N;
  ll A[200010]={0};
  ll B[200010]={0};
  rep(i,N){
    cin>>A[i];
    B[A[i]]+=1;
  }
  ll ans=0;
  rep(i,N+1){
    ans+=B[i]*(B[i]-1)/2;
  }
  ll bus;
  rep(i,N){
    bus=A[i];
    cout<<ans-B[bus]*(B[bus]-1)/2+(B[bus]-1)*(B[bus]-2)/2<<endl;
  }
}

Measured memory_bytes: 5760