akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

x = I()
ret = 100
for i in range(10000):
    ret = int(ret * 1.01)
    if ret >= x:
        print(i + 1)
        break

Measured memory_bytes: 77120
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n;
  cin >> n;
  int p[n + 5];
  reps(i, n){
    cin >> p[i];
  }
  int ans = 0;
  
  for(int i = 2;i < n;i ++){
    if(p[i - 1] < p[i] && p[i] < p[i + 1]){
      ans ++;
    }
    if(p[i - 1] > p[i] && p[i] > p[i + 1]){
      ans ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;

struct Dice {
  static const int DN = 6;
  vi ds;

  // 0=X+(top), 1=Y+(front), 2=Z+(right), 3=Z-(left), 4=Y-(back), 5=Z-(bottom)
  Dice(vi &_ds): ds(_ds) {}
  Dice(const int _ds[]) { ds.assign(_ds, _ds + DN); }
  Dice() {}

  bool operator==(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return false;
    return true;
  }

  bool operator<(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return (ds[i] < d.ds[i]);
    return false;
  }

  inline int top()    { return ds[0]; }
  inline int front()  { return ds[1]; }
  inline int right()  { return ds[2]; }
  inline int left()   { return ds[3]; }
  inline int back()   { return ds[4]; }
  inline int bottom() { return ds[5]; }
  
  Dice rotx(int n = 1) { // 1, 2, 4, 3
    Dice r(*this);
    while (n--) {
      int t = r.ds[1];
      r.ds[1] = r.ds[3]; r.ds[3] = r.ds[4]; r.ds[4] = r.ds[2];
      r.ds[2] = t;
    }
    return r;
  }

  Dice roty(int n = 1) { // 2, 0, 3, 5
    Dice r(*this);
    while (n--) {
      int t = r.ds[2];
      r.ds[2] = r.ds[5]; r.ds[5] = r.ds[3]; r.ds[3] = r.ds[0];
      r.ds[0] = t;
    }
    return r;
  }

  Dice rotz(int n = 1) { // 0, 1, 5, 4
    Dice r(*this);
    while (n--) {
      int t = r.ds[0];
      r.ds[0] = r.ds[4]; r.ds[4] = r.ds[5]; r.ds[5] = r.ds[1];
      r.ds[1] = t;
    }
    return r;
  }

  void print() {
    for (int i = 0; i < DN; i++) printf("%d", ds[i]); putchar('\n');
  }

  void alldices(set<Dice> &s) {
    for (int z = 0; z < 4; z++) {
      Dice dz = rotz(z);
      for (int y = 0; y < 4; y++) {
	Dice dy = dz.roty(y);
	for (int x = 0; x < 4; x++)
	  s.insert(dy.rotx(x));
      }
    }
  }
};

typedef set<Dice> sd;

/* global variables */

int ids[6];
Dice dcs[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) cin >> ids[j];
    dcs[i] = Dice(ids);
  }

  for (int i = 0; i < n; i++) {
    sd dset;
    dcs[i].alldices(dset);

    for (sd::iterator sit = dset.begin(); sit != dset.end(); sit++)
      for (int j = i + 1; j < n; j++)
	if (*sit == dcs[j]) {
	  puts("No");
	  return 0;
	}
  }

  puts("Yes");
  return 0;
}

Measured memory_bytes: 1176
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
alice,bob=[],[]
for i in range(1,n+1):
    if i%2==1: alice.append(l[i-1])
    elif i%2==0: bob.append(l[i-1])
print(sum(alice)-sum(bob))

Measured memory_bytes: 38384
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        long k = sc.nextLong();

        int ans = 0;
        long l = 1;
        while(l <= n){
            l *= k;
            ans++;
        }

        System.out.println(ans);

    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


Measured memory_bytes: 24532
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, m = Is()
if n == m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 64108
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int a[100002];
    P p[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        p[i] = P(a[i], i);
    }
    sort(p, p + n);
    for(int i = 0; i < n; i++) cout << p[i].second + 1 << " ";
    cout << endl;
}

Measured memory_bytes: 2048
# ABC072 D - Derangement
N = int(input())
P = list(map(int,input().split()))

ans = 0
is_renzoku = False

for i in range(N):
    if i == N-1:
        if not is_renzoku:
            if P[i] == i+1:
                ans += 1
                continue
        else:
            continue    
    if not is_renzoku:
        if P[i] == i+1:
            ans += 1
            if P[i+1] == i+2:
                is_renzoku = True
    else:
        is_renzoku = False
print(ans)

Measured memory_bytes: 14008
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    A = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    if N==1:
        print(1)
        return

    l=[-A[0]]
    for a in A[1:]:
        ind=bisect_right(l,-a)
        if ind==len(l):
            l.append(-a)
        else:
            l[ind]=-a
    print(len(l))






if __name__ == "__main__":
    main()

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

int main(){
	string str;
	cin >> str;
	
	bool ok = true;
	while(str.length() > 0){
		if(str.length() > 4 && str.substr(str.length() - 5) == "erase"){
			str = str.substr(0, str.length() - 5);
		}else if(str.length() > 4 && str.substr(str.length() - 5) == "dream"){
			str = str.substr(0, str.length() - 5);
		}else if(str.length() > 5 && str.substr(str.length() - 6) == "eraser"){
			str = str.substr(0, str.length() - 6);
		}else if(str.length() > 6 && str.substr(str.length() - 7) == "dreamer"){
			str = str.substr(0, str.length() - 7);
		}else{
			ok = false;
			break;
		}
	}
	if(ok == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long a[n];
    long long sum=0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a+n);
    printf("%ld %ld %ld\n", a[0], a[n-1], sum);
    return 0;
}


Measured memory_bytes: 3268
n = int(input())
l = list(map(int, input().split()))

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort(reverse=True)
  vsu = list(du.values())
  vsu.sort(reverse=True)
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])
  
print(ans)
    
    

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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H * W - (h * W + H * w - h * w) << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      mut n: usize,
      b: [usize; n]
   }
   let mut a = vec![];
   a.push(b[0]);
   for i in 1..n {
      if b[i - 1] != b[i] {
         a.push(b[i]);
      }
   }
   let n = a.len();
   if n == 1 {
      println!("{}", 1000);
      return;
   }
   let mut m: usize = 1000;
   let mut kab: usize = if a[0] < a[1] { 1000 / a[0] } else { 0 };
   m -= kab * a[0];
   for i in 1..n - 1 {
      if a[i - 1] < a[i] && a[i] > a[i + 1] {
         m += kab * a[i];
         kab = 0;
      }
      if a[i - 1] > a[i] && a[i] < a[i + 1] {
         kab += m / a[i];
         m -= a[i] * kab;
      }
   }
   m += a[n - 1] * kab;
   println!("{}", m);
}


Measured memory_bytes: 2168
program logs
  implicit none
  integer :: n, k, a(200000) = 0, x, i
  integer :: l = 0, r = 2e9, m
  read(*,*) n, k
  read(*,*) a(1:n)
  do while (r - l > 1)
    m = (l + r) / 2
    x = 0
    do i = 1, n
      x = x + (a(i) - 1) / m
    end do
    if (x <= k) then
      r = m
    else
      l = m
    end if
  end do
  write(*,'(i0)') r
end program logs

Measured memory_bytes: 3920
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=605,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,cnt,opt[MAXN],F[2][MAXN][MAXN];
inline void Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();Rep(i,1,n){
		int x=read(),y=read();
		if(!(~x)||!(~y))(~x?opt[x]=1:0),(~y?opt[y]=1:0),(!(~x)&&!(~y)?cnt++:0);
		else opt[x]=opt[y]=-1;
	}int now=0,s1=0,s2=0;F[0][0][0]=1;
	Red(i,2*n,1)if(~opt[i]){
		now^=1,memset(F[now],0,sizeof(F[now]));		
		Rep(j,0,min(s1,n))Rep(k,0,min(s2,n))if(F[now^1][j][k]){
			if(opt[i]){
				if(j<n)Add(F[now][j+1][k],F[now^1][j][k]);
				if(k)Add(F[now][j][k-1],F[now^1][j][k]);
			}else{
				if(k<n)Add(F[now][j][k+1],F[now^1][j][k]);
				if(j)Add(F[now][j-1][k],1ll*F[now^1][j][k]*j%Mod);
				if(k)Add(F[now][j][k-1],1ll*F[now^1][j][k]*(cnt-(s2-s1+j-k>>1)+Mod)%Mod);
			}
		}if(opt[i])s1++;else s2++;
	}cout<<F[now][0][0]<<'\n';
	return 0;
}




Measured memory_bytes: 6444
///created: 29/May/2019 10:30:41

#include <bits/stdc++.h>

using namespace std;

int x[11], c, dp[11][2][1 << 11];
const int S = (1 << 3) | (1 << 5) | (1 << 7);
char t[12] = {0};
void pr(int a) {
	for (int j = 0; j <= 9; ++j)
		printf("%d", a >> j & 1);
	printf("\n");
}

int calc(int i, bool tight, int state) {
	int& res = dp[i][tight][state];
	if (~res) return res;
	res = 0;
	if (i == c + 1) {
		return res = ((state ^ S) == 0);
	}
	for (int j = 0; j <= (tight ? x[i] : 9); ++j) {
		int newstate = 0;
		if (j == 0 && state != 0) newstate = state | 1;
		if (j != 0) newstate = state | (1 << j);
		res += calc(i + 1, tight && (j == x[i]), newstate);
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	c = 0;
	while (n) { x[++c] = n % 10; n /= 10; }
	reverse(x + 1, x + 1 + c);
	memset(dp, -1, sizeof dp);
	for (int i = 1; i <= c; ++i)
		t[i] = '0';
	cout << calc(1, 1, 0);
	return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let h = read_vec::<usize>();
    let mut accum_min = vec![0; n];
    accum_min[n - 1] = h[n - 1];
    for i in (0..n - 1).rev() {
        accum_min[i] = min(accum_min[i + 1], h[i]);
    }
    for i in 0..n {
        if h[i] >= accum_min[i] + 2 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

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

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


Measured memory_bytes: 8444
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Main m = new Main();
		m.solve();
	}

	private void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] mx = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			if (i == 0) {
				mx[i] = a[i];
			} else {
				mx[i] = Math.max(mx[i - 1], a[i]);
			}
		}
		sc.close();

		long[] cnt = new long[N];

		TreeSet<Count> set = new TreeSet<>();
		long upCnt = 0;
		int cur = Integer.MAX_VALUE;
		for (int i = N - 1; i >= 0; i--) {
			int next = 0;
			Count c = set.ceiling(new Count(a[i], 0));
			if (c == null || c.num != a[i]) {
				set.add(new Count(a[i], 1));
			} else {
				set.remove(c);
				c.cnt += 1;
				set.add(c);
			}
			if (i == 0) {
				next = 0;
			} else {
				if (cur == mx[i - 1]) {
					continue;
				}
				next = mx[i - 1];
			}
			cnt[i] = upCnt * (mx[i] - next);
			while ((c = set.lower(new Count(mx[i] + 1, 0))) != null) {
				if (c.num <= next) {
					break;
				}
				cnt[i] += ((long) c.num - next) * c.cnt;
				cur = c.num;
				set.remove(c);
				upCnt += c.cnt;
			}
			cur = next;
		}
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < N; i++) {
			buf.append(Long.toString(cnt[i]));
			buf.append("\n");
		}
		System.out.println(buf.toString());
	}

	class Count implements Comparable<Count> {
		int num = 0;
		int cnt = 0;

		Count(int num, int cnt) {
			this.num = num;
			this.cnt = cnt;
		}

		@Override
		public int compareTo(Count o) {
			if (this.num != o.num) {
				return this.num - o.num;
			} else {
				return this.cnt - o.cnt;
			}
		}

		@Override
		public boolean equals(Object o) {
			if (o instanceof Count) {
				Count c = (Count) o;
				return c.num == this.num && c.cnt == this.cnt;
			} else {
				return false;
			}
		}
	}
}


Measured memory_bytes: 64492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

bool ch[3][3];
int main() {
	ll a[3][3];
	for(ll i=0;i<3;i++){
		for(ll j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		for(ll j=0;j<3;j++){
			for(ll k=0;k<3;k++){
				if(a[j][k]==now){
					ch[j][k]=true;
				}
			}
		}
	}
	for(ll i=0;i<3;i++){
		if(ch[i][0]&&ch[i][1]&&ch[i][2]){
			cout << "Yes";
			return 0;
		}
	}
	for(ll j=0;j<3;j++){
		if(ch[0][j]&&ch[1][j]&&ch[2][j]){
			cout << "Yes";
			return 0;
		}
	}
	if(ch[0][0]&&ch[1][1]&&ch[2][2]){
		cout << "Yes";
		return 0;
	}
	if(ch[2][0]&&ch[1][1]&&ch[0][2]){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	// your code goes here
	return 0;
}

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

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;

vvii g;
int n;

bool hascycle;
vi color;

void cycle(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            cycle(u.second);
        else if(color[u.second] == 1)
            hascycle = true;
    color[v] = 2;
}

vi sorted;

void toposort(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            toposort(u.second);
    sorted.push_back(v);
}

bool posible;
vi dis;

void check(int v, int d)
{ 
    color[v] = 1;
    dis[v] = d;
    for(ii u : g[v])
        if(!color[u.second])
            check(u.second, d + u.first);
        else if(dis[u.second] != d + u.first)
            posible = false; 
    color[v] = 2;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int m,x,y,w;
    while(cin >> n >> m)
    {
        g = vvii(n);
        for(int i = 0; i < m; i++)
        {
            cin >> x >> y >> w; x--; y--;
            g[x].push_back({w, y});
        }
        // Cycle check
        color = vi(n, 0); hascycle = false;
        for(int i = 0; i < n; i++)
            if(!color[i])
                cycle(i);
        if(hascycle)
            cout << "No" << '\n';
        else
        {
            // Toposort
            color = vi(n, 0); sorted.clear(); 
            for(int i = 0; i < n; i++)
                if(!color[i])
                    toposort(i);
            reverse(sorted.begin(), sorted.end());
            // Distance check
            color = vi(n, 0); dis = vi(n, 0); posible = true;
            for(int i = 0; i < n; i++)
                if(!color[sorted[i]])
                    check(sorted[i], 0);
            cout << (posible? "Yes" : "No") << '\n';
        }
    }
    return 0;
} 

Measured memory_bytes: 11632
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
import qualified Data.Array.IArray as A
import qualified Data.IntMap.Strict as M
import Control.Monad

readIntPair :: B.ByteString -> [(Int, Int)]
readIntPair = map (pair . map readInt . B.words) . B.lines

pair :: [t] -> (t, t)
pair [x, y] = (x, y)
pair _ = undefined

main = do
  n <- readLn
  es <- readUndirectedEdge <$> replicateM (n-1) B.getLine
  [q,k] <- map read . words <$> getLine
  xys <- readIntPair <$> B.getContents
  let g = buildG (1,n) es
  let m = dijkstra g k
  putStrLn $ unwords $ map (show . transit m) xys

transit m (x,y) = m M.! x + m M.! y  

type Bound = (Vertex, Vertex)
type Vertex = Int
type Weight = Int
type Edge = ((Vertex, Vertex), Weight)
type Path = [Vertex]
type Graph = A.Array Vertex (S.Set (Vertex, Weight))

buildG :: Bound -> [Edge] -> Graph
buildG b = A.accumArray (flip S.insert) S.empty b . map (\((s, t), w) -> (s, (t, w)))

from :: Graph -> Vertex -> S.Set (Vertex, Weight)
from = (A.!)

size :: Graph -> Int
size g = let (i,j) = A.bounds g in j - i + 1

readUndirectedEdge :: [B.ByteString] -> [Edge]
readUndirectedEdge = concatMap (constructTwoWay . map readInt . B.words)

constructTwoWay :: [Int] -> [Edge]
constructTwoWay [s,t,w] = [((s, t), w), ((t, s), w)]
constructTwoWay _ = undefined

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

type Memo = M.IntMap Weight

-- accumrated weight and lexical order shortest path
dijkstra :: Graph -> Vertex -> Memo
dijkstra g s = _dijkstra g q0 m0
  where
   q0 = singleton (0, s)
   m0 = M.singleton s 0

_dijkstra :: Graph -> PriorityQueue -> Memo -> Memo
_dijkstra g q m
  | isEmpty q = m
  | otherwise = _dijkstra g q2 m1
  where
    ((w0, s), q1) = deleteFindMin q
    m1 = S.foldr (\(t, w) acc -> M.insertWith min t (w0 + w) acc) m vns
    q2 = S.foldr (\(t, w) acc -> insert (w0 + w, t) acc) q1 vns
    vns = S.filter (\(t, w) -> M.notMember t m || w0 + w <= m M.! t) (from g s)

type PriorityQueue = S.Set (Weight, Vertex)

isEmpty :: PriorityQueue -> Bool
isEmpty = S.null

singleton :: (Weight, Vertex) -> PriorityQueue
singleton = S.singleton

insert :: (Weight, Vertex) -> PriorityQueue -> PriorityQueue
insert = S.insert

deleteFindMin :: PriorityQueue -> ((Weight, Vertex), PriorityQueue)
deleteFindMin = S.deleteFindMin


Measured memory_bytes: 86012
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


bool check(int xi, vector<ll> &A){
  ll big = 0;
  for (int i=0; i<=xi; i++) big += A[i];
  for (int i=xi+1; i<A.size(); i++){
    if (A[i]>2*big) return false;
    big += A[i];
  }
  return true;
}

int main() {
  int N; cin >>N;
  vector<ll> A(N); rep(i, N) cin >>A[i];
  sort(all(A));
  int ok = N, ng = -1;
  while (abs(ok - ng) > 1){
    int mid = (ok+ng)/2;
    if (check(mid, A)) ok = mid;
    else ng = mid;
  }
  int res = N-ok;
  cout <<res <<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int Q = scanner.nextInt();

        String S = scanner.next();

        int[] array = new int[S.length()];

        for(int i=1; i<S.length(); i++){
            if(S.charAt(i) == 'C' && S.charAt(i-1) == 'A'){
                array[i] = array[i-1] + 1;
            }else{
                array[i] = array[i-1];
            }
        }

        for(int i=0; i<Q; i++){
            int l = scanner.nextInt();
            l--;
            int r = scanner.nextInt();
            r--;
            System.out.println(array[r] - array[l]);
        }

    }
}


Measured memory_bytes: 64640
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
map <string,int> m;
int main() {
	
	int n;
	cin>>n;
	
	while(n--)
	{
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
//abc058_a.cpp
//Fri Oct 19 23:18:47 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if ((b-a) == (c-b)){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
/*
* @Author: Kabid
* @Date:   {{create_time}}
* @Last Modified by:   Kabid
* @Last Modified time: 2020-09-21 11:25:16
*/
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');

int t;       //test cases
ll i, j;	 //iterators
ll n, k ,  q,  d, m, c, c1, c2, d1, x; //variables;
ll mx1 = LLONG_MIN, mx2 = LLONG_MIN, mx = LLONG_MIN, mn = LLONG_MAX;		// max min
char s[6], s1, s2;		// string
ll a [1000001], b [200001] ;
bool mox [1000001];	// array
map <int, int > mp;
vector <vector<ll>> vc;
vector <ll> v;
set <ll> st;
bool r;
ll p = 1000000007;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cin >> t; q = t;
	t = 1;

	while (t--) {

		cin >> n;
		a[0] = 1; a[1] = 0; a[2] = 0; a[3] = 1;
		for (i = 4; i <= n; i++) {
			c = 0;
			for (j = 3; j <= i; j++) {
				c = (c + a[i - j]) % p;
			}
			a[i] = c;
		}
		cout << a[n] << endl;
	}
	return 0;

}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<numeric>
#include<utility>

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	ll num = 0;

	int N, H;
	cin >> N >> H;

	vector<pii> ab(N);
	int max_a = 0;

	rep(i, N) {
		cin >> ab[i].first >> ab[i].second;
		if (max_a < ab[i].first) max_a = ab[i].first;
	}

	sort(ab.begin(), ab.end(), [](const pii x, const pii y) { if (x.second == y.second) { return x.first < y.first; } else { return x.second > y.second; }});

	rep(i, N) {
		if (max_a < ab[i].second) {
			num++;
			H -= ab[i].second;
			if (H <= 0) break;
		}
		else break;
	}

	if (H <= 0) cout << num << endl;
	else cout << num + (H + max_a - 1) / max_a << endl;

	return 0;
}

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

vector<vector<int>> g, vis;

void dfs(int x, vector<int> &v) {
  v[x] = 1;
  for (auto to : g[x]) {
    if (v[to])  continue;
    dfs(to, v);
  }
}

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, m, p;
  cin >> n >> m >> p;

  g.resize(n);
  vis.resize(n);

  vector<pair<pair<int, int>, int>> edges;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u; 
    --v;

    g[u].push_back(v);
    edges.push_back({{u, v}, c - p});
  }

  for (int i = 0; i < n; ++i) {
    vis[i].resize(n, 0);
    dfs(i, vis[i]);
  }

  vector<long long> dist(n, INT_MIN);
  dist[0] = 0;

  for (int i = 0; i < n-1; ++i) {
    for (int j = 0; j < m; ++j) {
      int u = edges[j].first.first, v = edges[j].first.second, w = edges[j].second;
      if (dist[u] + w > dist[v]) {
        dist[v] = dist[u] + w;
      }
    }
  }

  bool poss = 1;
  for (int i = 0; i < m; ++i) {
    int u = edges[i].first.first, v = edges[i].first.second, w = edges[i].second;
    if (dist[u] + w > dist[v]) {
      if (vis[0][u] && vis[v][n-1])
        poss = 0;
    }
  }
  
  poss &= vis[0][n-1];
  if (!poss) cout << -1 << '\n';
  else cout << max(0ll, dist[n-1]) << '\n';

} 

Measured memory_bytes: 25088
//Dragon_warrior7(IITK)
#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 ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(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 modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
cin>>m;
ll dif[n+1];
for(int i=0;i<=n;i++)
dif[i]=-1;
for(int i=0;i<m;i++)
{
    cin>>a>>b;
    if(dif[a]!=-1 && dif[a]!=b)
    {
        cout<<-1;
        return ;
    }
    dif[a]=b;
}
if(n>1 && dif[1]==0)
{
   cout<<-1;
   return ;
}
if(n==1)
{
    cout<<((dif[1]==-1)?0:dif[1]);
    return ;
}
string s;
s.resize(n);
if(dif[1]==-1)
dif[1]=1;
for(int i=0;i<n;i++)
{
    s[i]='0';
    if(dif[i+1]!=-1)
    s[i]+=dif[i+1];
}
cout<<s;






return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#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 namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
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;}

// head

int main(){

  ll n = in();
  vector<ll> a(n);
  ll sum = 0;
  REP(i, n){
    a[i] = in();
    sum += a[i];
  }
  ll cur = 0;
  REP(i, n){
    cur += a[i];
    if(cur * 2 >= sum){
      ll ans = cur * 2 - sum;
      cur -= a[i];
      chmin(ans, sum - 2 * cur);
      cout << ans << endl;
      return 0;
    }
  }


  return 0;
}


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

int main(){
	int a[4][3][10];
	int n,b,f,r,v;
	cin>>n;
	for(int c=0;c<4;c++){
		for(int d=0;d<3;d++){
			for(int e=0;e<10;e++){
				a[c][d][e]=0;
			}
  		}
	}
	for(int g=0;g<n;g++){
		cin>>b>>f>>r>>v;
		a[b-1][f-1][r-1]+=v;
		}
	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				cout<<" "<<a[i][j][k];
				}
				cout<<endl;
			}
			if(i==0||i==1||i==2){
			for(int h=0;h<20;h++){
				cout<<"#";
				}
				cout<<endl;
			}
		}
	return 0;
	}


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

using namespace std;

int main()
{
    int a[5];
    for (int i = 0; i < 5; ++i) cin >> a[i];
    sort(a,a+5,greater<int>());
    for (int i = 0; i < 5; ++i) printf(i == 4 ? "%d\n" : "%d ", a[i]);
}

Measured memory_bytes: 1160
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cstdlib> 
#include <algorithm>

using namespace std;

int main()
{
 int n;
 cin>> n;
 int height[n];
 
 for(int i=0;i<n;i++){
     cin>> height[i];
 }
 int answer[n];
  for(int i=0;i<n;i++){
     answer[i]=0;
 }
 answer[0]=0; answer[1]=abs(height[1]-height[0]);
 for(int i=2;i<n;i++){
       answer[i]= min(abs(height[i]-height[i-1])+answer[i-1],abs(height[i]-height[i-2])+answer[i-2]); 
      
 }
 
 
 cout<< answer[n-1];
}


Measured memory_bytes: 1024
// B - Traveling AtCoDeer Problem
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i, N) cin>>A[i];
	sort(all(A));
	cout<< A[N-1] - A[0] <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
  int n,i,*l,sum = 0;
  scanf("%d", &n);
  l = (int *)malloc(sizeof(int)*2*n);
  for(i = 0; i < 2*n; ++i){
    scanf("%d", &l[i]);
  }
  qsort(l,2*n,sizeof(int),compare_int);
  for(i = 0; i < 2*n; i += 2){
    sum += l[i];
  }
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())
s=list(map(int,input().split()))
s.sort()
dp=[0]*(m-1)
if n>=m:
    print(0)
else:
    for i in range(m-1):
        dp[i]=s[i+1]-s[i]
    dp.sort(reverse=True)
    print(sum(dp[n-1:]))


Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi  acos(-1)
const int w=5e5+5;
const ll mod=998244353;
vector<int> ve[w];
int dis[w];
queue<pair<int,int> > qu;
int ans[w];
int main()
{
    int i,j;
    int n,x,y;
    cin>>n>>x>>y;
    for(i=1;i<n;i++)
    {
        ve[i].push_back(i+1);
        ve[i+1].push_back(i);
    }
    ve[x].push_back(y);
    ve[y].push_back(x);
    qu.push({1,1});
    dis[1]=1;
    while(!qu.empty())
    {
        int x=qu.front().first,z=qu.front().second;
        qu.pop();
        for(i=0;i<ve[x].size();i++)
        {
            int y=ve[x][i];
            if(dis[y])
                continue;
            else
                dis[y]=z+1,qu.push({y,z+1});
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            int u=j-i;
            int v=abs(dis[i]-dis[x])+abs(dis[j]-dis[x]);
            //cout<<i<<" "<<j<<" "<<min(u,v)<<endl;
            ans[min(u,v)]++;
        }
    }
    for(i=1;i<n;i++)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll calc(ll k,ll d) {
  return k*(k+1)/2*d;
}

const ll n=26;
ll c[n],q[444];
ll a[444][n];
set<ll> s[n];

ll solve(ll x,ll y,ll t) {
  ll ans=0,e=q[x];
  {
    ans-=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans+=calc(*it2-*it1-1,c[q[x]]);
    ans+=calc(*it3-*it2-1,c[q[x]]);
    ans-=calc(*it3-*it1-1,c[q[x]]);
    s[q[x]].erase(it2);
  }
  {
    q[x]=y;
    s[q[x]].in(x);
    ans+=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans-=calc(*it2-*it1-1,c[q[x]]);
    ans-=calc(*it3-*it2-1,c[q[x]]);
    ans+=calc(*it3-*it1-1,c[q[x]]);
  }
  if(!t) {
    s[q[x]].erase(x);
    q[x]=e;
    s[q[x]].in(x);
  }
  return ans;
}

         
void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  rep(i,n) R c[i];
  rep(i,T)rep(j,n) R a[i][j];
  rep(i,n) s[i].in(-1),s[i].in(T);
  rep(k,T) {
    q[k]=0;
    s[0].in(k);
  }
  ll ans[T];
  mem(ans);
  clock_t t2=clock();
  for(int tt=0;;tt++) {
    ll x=rand()%T,y=rand()%n;
    if(solve(x,y,0)>0) {
      solve(x,y,1);
      ans[x]=y;
    }
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if(tt>=2&&(double)t3/CLOCKS_PER_SEC+t4*2>1.500) break;
    t2=t3;
  }
  rep(i,T) pr(ans[i]+1);
}

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


Measured memory_bytes: 3732
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    int a_idx = 0;
    vector<vector<int>> hw(h, vector<int>(w));
    rep(i, h) rep(j, w) {
        int idx;
        if (i&1) idx = w - j - 1;
        else     idx = j;
        hw[i][idx] = a_idx + 1;
        //cout << a_idx << endl;
        ++cnt;
        if (cnt == a[a_idx]) {
            cnt = 0;
            ++a_idx;
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (j != 0) cout << " ";
            cout << hw[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
 
// int main(void) 
// {
//     int n, count = 0, max = 0;
//     scanf("%d", &n);
//     int h[n];
//     for(int i = 0; i < n; i++) {
//         scanf("%d", &h[i]);
//         if(i > 0) {
//             if(h[i-1] >= h[i]) {
//                 count++;
//             } else {
//                 if(max < count) {
//                     max = count;
//                 }
//                 count = 0;
//             }
//         }
//     }
//     if(max < count) max = count;
//     printf("%d\n", max);
//     return 0;
// }


// りゅうせいの解答1 
void hikaku(int *h, int *a, int N)
{
	int count = 0;
	for (int i = N-1; i > 0; --i)
	{
		if (h[i] <= h[i-1])
		{
			count++;
			if ((i == 1) && (*a < count))
			{
				*a = count;
			}
		}

		else
		{
			if (*a < count)
			{
				*a = count;
			}

			count = 0;
		}

	}
}

int main(int argc, char const *argv[])
{
	int N;
	scanf("%d", &N);
	int H[N];

	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &H[i]);
	}

	int ans = 0;

	hikaku(H, &ans, N);

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


	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main() {int n,r,i;while(1){cin>>n;if(!n)break;n=1000-n,r=0;for(i=0;i<6;i++)r+=n/coin[i],n%=coin[i];cout<<r<<endl;}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
char s1[100005];
int main()
{
	scanf("%s",s1);
	int len=strlen(s1);
//	puts(s1);
	int flag=0;
	if(len%2)
	{
		flag=1;
	}
	for(int i=0;i<len;i++)
	{
		if(flag)
		{
			break;
		}
		if(i%2)
		{
			if(s1[i]!='i')
			{
				flag=1;
			}
		}
		else
		{
			if(s1[i]!='h')
			{
				flag=1;
			}
		}
	}
	if(flag)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
using namespace std;
#define INF 1000000005
int main()
{
int n;
std::cin >> n;
std::vector<std::string> stvec;
std::string firstr;
std::cin >> firstr;
stvec.push_back(firstr);
int yflag = 0;

for(int i = 1; i < n; i++){
    std::string temp;
    std::cin >> temp;
    stvec.push_back(temp);
}
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
    if(stvec[j] == stvec[i]){
         yflag = 1;
         break;
        }
    }
    if(yflag == 0 && stvec[i - 1].back() == stvec[i].front()){
      ;  
    } else {
        yflag = 1;
    }
    if(yflag == 1){
        break;
    }
}
if(yflag == 0){
    std::cout << "Yes" << std::endl;
} else {
    std::cout << "No" << std::endl;
}
return 0;
}

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

int CalculateSum(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for(int i=1;i<=N;++i){
    int sum = CalculateSum(i);
    if(sum >= A and sum <= B) total += i;
  }
  cout << total << endl;
  
  return 0;
}
  
  

Measured memory_bytes: 256