akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;

    int[] c, dep;
    int len, pos;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long k = in.nextLong();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = in.nextInt();
        dep = new int[n + 1];
        c = new int[n + 1];
        findCycle(a, 1, 1);
        if (k < pos) {
            out.println(c[(int)k + 1]);
        } else {
            long p = pos + (k + 1 - pos) % (len - pos + 1);
            out.println(c[(int)p]);
        }
   }

    private void findCycle(int[] a, int s, int d) {
        if (dep[s] > 0) {
            pos = dep[s];
            return;
        }
        dep[s] = d;
        c[++len] = s;
        findCycle(a, a[s], d + 1);
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

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

}


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

int main()
{
int N;cin>>N;vector<int> a(N+1);int ans=0;
for(int i=1;i<N+1;i++)
{
  cin>>a[i];
  if(i%2==1&&a[i]%2==1)ans++;
}
cout<<ans;
}

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

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int dp[50][5001];

int main(){
    while(true){
	int n,m,s;
	cin >> n >> m >> s;
	if(n == 0 && m == 0 && s == 0) break;
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	FOR(j,1,m+1){
	    RREP(k,s){
		RREP(i,n*n){
		    dp[i+1][k+j]  = (dp[i+1][k+j] + dp[i][k])%100000 ;
		}
	    }
	}
	int ans =0 ;
	ans += dp[n*n][s];
	cout << ans << endl;
    }
    return 0;
}

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

int main(){
	priority_queue<int> pq;
	string command; cin>>command;
	int key;
	while(command!="end"){
		if(command=="insert"){
			cin>>key;
			pq.push(key);
		}else if(command=="extract"){
			cout<<pq.top()<<endl;
			pq.pop();
		}
		cin>>command;
	}
}

Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int a,b;
  cin >> a >> b;
  if((a*b)%2==0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void marge(vector<int>&a,int left,int mid,int right,int &cnt){
    int nl=mid-left,nr=right-mid;
    vector<int> L(nl+1),R(nr+1);
    for(int i=0;i<nl;i++)L[i]=a[left+i];
    for(int i=0;i<nr;i++)R[i]=a[mid+i];
    L[nl]=2000000000;
    R[nr]=2000000000;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            a[k]=L[i];
            i++;
        }else{
            a[k]=R[j];
            j++;
        }
        cnt++;
    }
    return;
}
void margesort(vector<int>&a,int left,int right,int &cnt){
    if(left+1<right){
        int mid=(left+right)/2;
        margesort(a,left,mid,cnt);
        margesort(a,mid,right,cnt);
        marge(a,left,mid,right,cnt);
    }
    return;
}
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int cnt=0,left=0,right=n;
    margesort(a,left,right,cnt);
    for(int i=0;i<n;i++){
      cout<<a[i];
      if(i<n-1)cout<<' ';
}
    cout<<endl<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 6816
import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    n, x, y = map(int, input().split())
    k_cnt = Counter()
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            if i <= x:
                if j < y:
                    dist = min(j - i, (x - i) + 1 + (y - j))
                elif y <= j:
                    dist = (x - i) + 1 + (j - y)
            elif x < i < y:
                dist = min(j - i, (i - x) + 1 + abs(j - y))
            else:
                dist = j - i
            k_cnt[dist] += 1
    for i in range(1, n):
        print(k_cnt[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9728
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > G(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(make_pair(i, b));
        G[b].push_back(make_pair(i, a));
    }

    queue<int> Q;
    Q.push(0);
    vi kir(n-1, -1);
    int i_ = -1;
    while(!Q.empty()) {
        int now = Q.front();
        Q.pop();
        int x = 0;
        for(auto next:G[now]) {
            if(kir[next.first] != -1) i_ = next.first;
        }
        for(auto next:G[now]) {
            if(i_ != -1 && kir[i_] == x) {
                ++x;
            }
            if(kir[next.first] != -1) continue;
            kir[next.first] = x;
            ++x;
            Q.push(next.second);
        }
    }
    cout << *max_element(kir.begin(), kir.end())+1 << '\n';
    rep(i, n-1) {
        cout << kir[i]+1 << '\n';
    }
}

Measured memory_bytes: 6912
(defun solve ()
  (let* ((n (read))
         (m (read))
         (a (make-array `(,n ,n)))
         (b (make-array `(,m ,m))))
    (dotimes (i n)
      (dotimes (j n)
        (setf (aref a i j) (read-char)))
      (read-char))
    (dotimes (i m)
      (dotimes (j m)
        (setf (aref b i j) (read-char)))
      (read-char))
    (dotimes (i (1+ (- n m)))
      (dotimes (j (1+ (- n m)))
        (unless (loop named check
                      for x below m
                      do (dotimes (y m)
                           (unless (eq (aref b x y) (aref a (+ x i) (+ y j)))
                             (return-from check t))))
          (return-from solve "Yes"))))
    "No"))
(format t "~A~%" (solve))

Measured memory_bytes: 18920
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        System.out.println( solve(S) );
    }

    private static long solve(String S) {
        Result result = solve_rec(S);
        return result.sum;
    }

    private static Result solve_rec(String s) {
        if( s.length() == 1 ) return new Result(1, Long.parseLong(s));

        long times = 1;
        long sum = Long.parseLong(s);
        for (int i = 1; i < s.length(); i++) {
            String head = s.substring(0, i);
            String tail = s.substring(i);
            Result result = solve_rec(tail);

            times += result.times;
            sum += Long.parseLong(head) * result.times + result.sum;
        }
        return new Result(times, sum);
    }

    private static class Result {
        private final long times;
        private final long sum;

        public Result(long times, long sum) {
            this.times = times;
            this.sum = sum;
        }
    }
}

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

int main() {
	string S;
	cin >> S;
	vector<int> a(S.size()), ans(S.size());
	for (int i = 0, b = 0; i < S.size(); ++i) {
		if ('L' == S[i]) a[i] = b;
		else b = i;
	}
	for (int i = S.size() - 1, b = S.size() - 1; i >= 0; --i) {
		if ('L' == S[i]) b = i;
		else a[i] = b;
	}
	for (int i = 0; i < S.size(); ++i) {
		if ('L' == S[i]) {
			if ((i - a[i]) % 2) ++ans[1 + a[i]];
			else ++ans[a[i]];
		}
		else {
			if ((a[i] - i) % 2) ++ans[a[i] - 1];
			else ++ans[a[i]];
		}
	}
	cout << ans.front();
	for (int i = 1; i < ans.size(); ++i) cout << ' ' << ans[i];
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
string ch;
int n;
vector<int> arr[15];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin>>n>>ch)
    {
        for(int i=0;i<=9;i++) arr[i].clear();
        for(int i=0;i<n;i++)
        {
            int x=ch[i]-'0';
            arr[x].push_back(i);
        }
        int ans=0;
        for(int i=0;i<=9;i++)
        {
            for(int j=0;j<=9;j++)
            {
                int id=-1;
                if(arr[i].size()>0)
                {
                    id=arr[i][0];
                }
                if(id!=-1)
                {
                    int again=lower_bound(arr[j].begin(),arr[j].end(),id+1)-arr[j].begin();
                    if(again<arr[j].size())
                    {
                        again=arr[j][again];
                        for(int k=0;k<=9;k++)
                        {
                            int ase=upper_bound(arr[k].begin(),arr[k].end(),n)-lower_bound(arr[k].begin(),arr[k].end(),again+1);
                            if(ase>0)
                            {
                                ans++;
                                //cout<<i<<j<<k<<endl;
                            }
                        }
                    }
                    else
                    {

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


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

int main()
{
    int n;
    long long sum=1,sum1=0,m=1000000007;
    vector<long long>v;
    bool t=1;
    cin>>n;
    for(int i=2; i<=n;i++)
    {
        for(int j=i-1;j>1;j--)
        {
            if(i%j==0 && i!=j)
               {t=false;
                 break;}
        }
        if(t==false) {t=true; continue; }
        else         {v.push_back(i);}
        t=true;
    }

    for(int i=0 ; i<v.size() ; i++)
    {
         long long x = v[i] ;
        while(n/x>0)
        {
            sum1+=n/x;
            x*=v[i];
        }
        v[i]=sum1;

        sum1=0;
    }
    for(int i=0;i<v.size();i++)
        {
        sum=(sum*(v[i]+1))%m;

       }

    cout <<sum << endl;
    return 0;
}

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

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

  for (int i = 0; i < N; i++) {
    mp[a[i]]++;
  }
  int ans = 0;
  for (auto p: mp) {
    if (p.second < p.first) ans += p.second;
    else ans += p.second - p.first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

	int cnt = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			if (i % 2 == 0 && j % 2 == 1) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10,X=5e3+10;
int n,p,ans=0,top[N],xx[N],f[2][X],sum[X];
struct lol {int x,y;} e[N];
void freo(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
void ein(int x,int y){
	e[++ans]=(lol){top[x],y};
	top[x]=ans;
}
void init(){
	scanf("%d",&n);
	for(int i=1;++i<=n;scanf("%d",&p),ein(p,i));
	for(int i=0;++i<=n;scanf("%d",&xx[i]));
}
void dfs(int x){
	for(int i=top[x],y;i;y=e[i].y,dfs(y),i=e[i].x);
	int cnt=0;
	memset(f[0],0x3f,sizeof(f[0]));
	f[0][0]=0;
	for(int i=top[x],y;i;i=e[i].x){
		y=e[i].y;
		cnt^=1;
		memset(f[cnt],0x3f,sizeof(f[cnt]));
		for(int j=-1;++j<=xx[x];
			j<xx[y]?:f[cnt][j]=min(f[cnt][j],f[cnt^1][j-xx[y]]+sum[y]),
			j<sum[y]?:f[cnt][j]=min(f[cnt][j],f[cnt^1][j-sum[y]]+xx[y]));
	}
	for(int i=-1;++i<=xx[x];sum[x]=min(sum[x],f[cnt][i]));
}
void work(){
	memset(sum,0x3f,sizeof(sum));
	dfs(1);
}
void prin(){
	printf(sum[1]==0x3f3f3f3f?"IMPOSSIBLE":"POSSIBLE");
}
int main(){
//	freo();
	init();
	work();
	prin();
	return 0;
}


Measured memory_bytes: 384
/*   --------------------
    |       LOSER        |
    |     ~NOOBOSS~      |
     --------------------
*/
#include <bits/stdc++.h>
using namespace std;
#define      mxx                 LLONG_MAX
#define      mnn                 LLONG_MIN
#define      Y()                 cout<< "YES" <<endl
#define      N()                 cout << "NO"<<endl
#define      endl                "\n"
#define      max_3(a,b,c)        max(a, max(b,c))
#define      min_3(a,b,c)        min(a, min(b,c))
#define      gcd(a,b)            __gcd(a,b)
#define      lcm(a,b)           (a*b)/gcd(a,b)
#define      loser               return 0
#define      ll                  long long
#define      PI                  acos(-1)
#define      mem(a,v)            memset(a,v,sizeof(a))
#define      SORT(v)             sort(v.begin(),v.end())
#define      REV(v)              reverse(v.begin(),v.end())
#define      B                   begin()
#define      E                   end()
#define      V                   vector
#define      F                   first
#define      S                   second
#define      PSB                 push_back
#define      MP                  make_pair
#define      flash               cout.flush()
#define      InTheNameOfGod      ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
constexpr ll MOD = 998244353;
constexpr ll mod = 1e9  + 7;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
/*-----*/
#define bug1(a)  cerr<<a<<endl;
#define bug2(a,b)  cerr<<a<<" "<<b<<endl;
#define bug3(a,b,c)  cerr<<a<<" "<<b<<" "<<c<<endl;
/*----*/
const ll N=2e5+5;
vector<ll> adj[N];
ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
ll nsum(ll num){return (num*(num+1))/2;}
void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);}
/*------------------START---------------------*/


/*-----*/
void solve(){
   ll n;
   string s;
   cin>>n;
   if(n) cout<<"0";
   else cout<<"1";



}
/*-----*/
int main(){
   InTheNameOfGod

   ll Test=1;
   //cin>>Test;
   while(Test--){
     solve();
    }
  loser;
}
///////   C O D I N G  I S  L I F E   ///////


Measured memory_bytes: 8340
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

int n; ll a[100100];

ll hoge(ll x) {
    ll sum = x;
    ll res = 0;
    rep(i, n - 1) {
        ll y = a[i + 1];
        if(sum > 0) {
            if(sum + y < 0) sum += y;
            else {
                res +=  sum + y - (-1);
                sum = -1LL;
            }
        } else {
            if(sum + y > 0) sum += y;
            else {
                res += 1LL - (sum + y);
                sum = 1LL;
            }
        }
    }
    return res;
}

void solve() {
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    ll c = max(a[0], 1LL), d = min(a[0], -1LL);
    ll ans = min(hoge(c) + (c == 1LL ? abs(a[0] - 1) : 0), hoge(d) + (d == -1LL ? abs(a[0] + 1) : 0));
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1024
N = (input())
s = N[-1]

if s == str(2) or s == str(4) or s == str(5) or s == str(7) or s == str(9):
   	print("hon")
elif s == str(0) or s== str(1) or s == str(6) or s == str(8):  
	print("pon")
else:
	print("bon")

Measured memory_bytes: 9128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// C - Welcome to AtCoder
// https://atcoder.jp/contests/abc151/tasks/abc151_c
public class Main {

    static class Result {
        boolean isAC;
        int waCount;

        Result(boolean isAC, int waCount) {
            this.isAC = isAC;
            this.waCount = waCount;
        }

        int getPenaltyCount() {
            return isAC ? waCount : 0;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());

        Map<Integer, Result> map = new HashMap<>();

        for (int i = 0; i < M; i++) {
            int number = Integer.parseInt(scanner.next());
            String acOrWa = scanner.next();
            boolean isAc = acOrWa.equals("AC");

            Result result;
            if (map.containsKey(number)) {
                result = map.get(number);
                if (isAc) {
                    result.isAC = true;
                } else {
                    // AC済はWA出してもカウントしない
                    if (!result.isAC) {
                        result.waCount++;
                    }
                }
            } else {
                result = new Result(isAc, isAc ? 0 : 1);
                map.put(number, result);
            }
        }

        scanner.close();

        int acCount = 0;
        int penaltyCount = 0;
        for (Map.Entry<Integer, Result> entry : map.entrySet()) {
            acCount += entry.getValue().isAC ? 1 : 0;
            penaltyCount += entry.getValue().getPenaltyCount();
        }
        System.out.println(acCount + " " + penaltyCount);
    }
}


Measured memory_bytes: 67736
fn main() {
  let stdin = std::io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();

  let line = buf.trim().to_string();

  buf.clear();
  stdin.read_line(&mut buf).unwrap();
  let p = buf.trim();

  let add = line.split_at(p.len() - 1).0.to_string();
  let s = line + &add;

  match s.find(p) {
    Some(_) => { println!("Yes"); }
    None    => { println!("No"); }
  }

}


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

int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
     if (i % 2 == 0)
       A += a.at(i);
    else
      B += a.at(i);
  }
  cout << A - B << endl;
}

Measured memory_bytes: 256
class Heap
  def initialize
    @array = []
  end

  def insert(key)
    @array.push(key)

    # sifting up
    index = @array.size - 1
    until index == 0
      pindex = (index - 1) / 2
      if (@array[index] <=> @array[pindex]) <= 0
        break
      else
        @array[pindex], @array[index] = @array[index], @array[pindex]
        index = pindex
      end
    end
  end

  alias push insert

  def peek
    if @array.empty?
      fail 'empty'
    end

    @array[0]
  end

  def size
    @array.size
  end

  def empty?
    @array.empty?
  end

  def pop
    if @array.empty?
      fail 'empty'
    end

    top = @array[0]
    last = @array.pop
    if @array.empty?
      return top
    end

    @array[0] = last
    i = 0
    # sifting down
    while true
      break unless i*2 + 1 < @array.size

      if i*2 + 2 < @array.size &&
         (@array[i*2 + 1] <=> @array[i*2 + 2]) <= 0
        if (@array[i*2 + 2] <=> @array[i]) <= 0
          break
        else
          @array[i], @array[i*2 + 2] = @array[i*2 + 2], @array[i]
          i = i*2 + 2
        end
      else
        fail "logic error" unless i*2 + 1 < @array.size
        if (@array[i*2 + 1] <=> @array[i]) <= 0
          break
        else
          @array[i], @array[i*2 + 1] = @array[i*2 + 1], @array[i]
          i = i*2 + 1
        end
      end
    end

    return top
  end
end

def degrade(ai, bi, ci)
  res = []
  if ai > 0
    res.push [ai - 1, bi, ci]
  end
  if bi > 0
    res.push [ai, bi - 1, ci]
  end
  if ci > 0
    res.push [ai, bi, ci - 1]
  end
  return res
end

_x, _y, _z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort

with_score = proc do |ai, bi, ci|
  [a[ai] + b[bi] + c[ci], [ai,bi,ci]]
end
queue = Heap.new
queue.push with_score.([a.size-1, b.size-1, c.size-1])
seen = {}

until k == 0
  _score, (ai, bi, ci) = queue.pop

  puts a[ai] + b[bi] + c[ci]
  k -= 1

  paths = degrade(ai,bi,ci).reject { |path| seen[path] }
  paths.each do |path|
    seen[path] = true
  end
  paths.each do |path|
    queue.push(with_score.(path))
  end
end


Measured memory_bytes: 3064
N=int(input())
A=list(map(int, input().split()))
mod=10**9+7
if A[0]!=0:
    print(0)
    exit()
L=[1,0,0]
ans=3
for i in range(1,N):
    a=A[i]
    count=0
    add=True
    for j,l in enumerate(L):
        if a==l:
            count+=1
            if add:
                L[j]+=1
                add=False

    ans*=count
    ans%=mod
print(ans)
#print(L)


Measured memory_bytes: 20708
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n;string s;
  cin>>n>>s;
  int ans=0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        bool one=false;
        bool two=false;
        bool three=false;
        rep(t,n){
          if(two && s[t]-'0'==k)three=true;
          if(one && s[t]-'0'==j)two=true;
          if(s[t]-'0'==i)one=true;
        }
        if(three)ans++;
      }
    }
  }
  cout<<ans<<endl;
}
          

Measured memory_bytes: 384
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		
		solve();flush();
		
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int a = Math.min(one.get(0), one.get(1));
		int b = Math.max(one.get(0), one.get(1));
		String output = "";
		for(int i = 0; i < b; i++){
			output += String.valueOf(a);
		}
		myout(output);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 37160
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		int[] a = new int[n];
		long[] sum = new long[n];
		a[0] = sc.nextInt();
		sum[0] = a[0];
		for (int i = 1; i < n; i++) {
			a[i] = sc.nextInt();
			sum[i] = sum[i - 1] + a[i];
		}
 
		long minDiff = Long.MAX_VALUE;
		int sep1 = 0;
		int sep3 = 2;
		for (int sep2 = 1; sep2 <= n - 3; sep2++) {
			long minOfDiff = Long.MAX_VALUE;
			for (int j = sep1; j <= sep2 - 1; j++) {
				long diff = Math.abs((sum[sep2] - sum[j]) - sum[j]);
				if (diff < minOfDiff) {
					minOfDiff = diff;
					sep1 = j;
				} else {
					break;
				}
			}
			minOfDiff = Long.MAX_VALUE;
			for (int j = sep3; j <= n - 2; j++) {
				long diff = Math.abs((sum[n - 1] - sum[j]) - (sum[j] - sum[sep2]));
				if (diff < minOfDiff) {
					minOfDiff = diff;
					sep3 = j;
				} else {
					break;
				}
			}
			long b = sum[sep1];
			long c = sum[sep2] - sum[sep1];
			long d = sum[sep3] - sum[sep2];
			long e = sum[n - 1] - sum[sep3];
			long max = Math.max(Math.max(b, c), Math.max(d, e));
			long min = Math.min(Math.min(b, c), Math.min(d, e));
			minDiff = max - min < minDiff ? max - min : minDiff;
		}
 
		System.out.println(minDiff);
	}
 
}

Measured memory_bytes: 85180
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
char s[200005];
main(){
	while(~scanf("%s",s)){
		int l=strlen(s);
		F(i,0,l) printf("%c",s[i]=='?'?'D':s[i]);
		puts("");
	}
}

Measured memory_bytes: 3852
// abc138_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    double ans = 0;
    REP(i, N) {
        double a;
        cin >> a;
        ans += 1.0 / a;
    }

    print(1 / ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int a[3];
	int ans=0;
	
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]<a[1])
	{
		ans=a[0];
	}else{
		ans=a[2];
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

    ll n,k; cin >>n>>k;
    vector<ll> a(n); vector<ll> b(n);
    REP(i,n) cin >> a[i] >> b[i];

    ll max_n = 100100;
    vector<ll> counts(max_n, 0);
    vector<ll> cumcounts(max_n+1, 0);
    for (ll i = 0; i < (ll)a.size(); i++) {
        counts[--a[i]] += b[i];
    }
    for (ll i = 0; i < max_n; i++) {
        cumcounts[i+1] = cumcounts[i] + counts[i];
    }

    for (ll i = 0; i < max_n; i++) {
        if (cumcounts[i] < k && cumcounts[i+1] >= k) {
            cout << i+1 << endl;
            break;
        } 
    }
    
    return 0;
}


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

int main()
{
	string weeks[] = { "NON","SAT","FRI","THU","WED","TUE","MON", "SUN" };

	string s;
	cin >> s;

	for( int i = 0; i < 8; i++ ){
		if( weeks[i] == s ){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 5;

int n, m;
vector <int> adj[N];
int col[N];
ll cnt[3];
bool val;

void dfs(int v) {
	for (auto u : adj[v]) {
		if(!col[u]) {
			col[u] = 3 - col[v];
			dfs(u);
		}
		else if(col[u] == col[v])
			val = 0;
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	for (int i = 0; i < n; i++) {
		if(!col[i]) {
			if(adj[i].size() == 0)
				cnt[0]++;
			else {
				col[i] = val = 1;
				dfs(i);
				if(val)
					cnt[1]++;
				else
					cnt[2]++;
			}
		}
	}
//	cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << "\n";
	cout << 1LL * (2 * n - cnt[0]) * cnt[0] + 1LL * (cnt[1] + cnt[2]) * (cnt[1] + cnt[2]) + (cnt[1] * cnt[1]) << "\n";
}


Measured memory_bytes: 9984
/*
[arc101] D - Median of Medians
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;
const int MAX_A = 1e9;
const int MAX_BIT_IDX = 2 * MAX_N + 2;

template <typename T>
class BIT {
public:
    T b[MAX_BIT_IDX + 1];
    int n;
    void init(int num);
    T sum(int i);          // i : [0, n), returns sum of [0, i)
    void add(int i, T x);  // i : [0, n)
};

template <typename T>
void BIT<T>::init(int num) {
    n = num;
    for (int i = 0; i <= n; i++) {
        b[i] = 0;
    }
    return;
}

template <typename T>
T BIT<T>::sum(int i) {
    T s = 0;

    for (; i > 0; i -= i & -i) {
        s += b[i];
    }
    return s;
}

template <typename T>
void BIT<T>::add(int i, T x) {
    for (i += 1; i <= n; i += i & -i) {
        b[i] += x;
    }
    return;
}

int N;
int a[MAX_N];

bool has_enough(int x) {
    int s[MAX_N + 1];
    s[0] = 0;
    for (int i = 1; i <= N; i++) {
        s[i] = (a[i - 1] >= x) ? 1 : -1;
    }
    for (int i = 1; i <= N; i++) {
        s[i] += s[i - 1];
    }

    BIT<int> bit;
    bit.init(2 * N + 2);
    ll inversion = 0;
    for (int i = 0; i <= N; i++) {
        inversion += i - bit.sum(s[i] + 1 + N);
        bit.add(s[i] + N, 1);
    }

    ll len = (N + 1LL) * N / 2LL;
    return len - inversion >= (len + 1) / 2;
}

ll solve() {
    int l = 0;
    int r = MAX_A + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (has_enough(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    int ans = (r + l) / 2;
    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1792
h, w = map(int, input().split())
arr = [input() for j in range(h)]
tarr = []
counter = 0
for i in range(h):
    if arr[i].count("#") != 0:
        counter += 1
        tarr.append(arr[i])
tans = [["" for i in range(counter)] for j in range(w)]
for i in range(counter):
    for j in range(w):
        tans[j][i] = tarr[i][j]
counter2 = 0
ttans = []
for i in range(w):
    if tans[i].count("#") != 0:
        counter2 += 1
        ttans.append(tans[i])
for i in range(counter):
    for j in range(counter2):
        print(ttans[j][i], end="")
        if j == counter2-1:
            print("")

Measured memory_bytes: 4596
#include <stdio.h>

int main(){
    int apple = 0, kakera = 0, pi = 0;
    scanf("%d %d", &apple, &kakera);
    // printf("apple data:%d\nkakera data:%d\n", apple, kakera);

    kakera += apple * 3;
    pi = kakera / 2;

    // printf("max apple pi count:%d\n", pi);
    printf("%d", pi);

}

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

//#define int ll

typedef int64_t ll;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,0,1,-1}, dy4[4] = {1,-1,0,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    int A = a%2;
    int B = b%2;
    int C = c%2;
    
    if(A==C&&A!=B) swap(b,c);
    else if(B==C&&A!=C) swap(a,c);
    
    int ans = 0;
    if(a%2!=c%2){
        ans++;
        a++;
        b++;
    }
    int m = max(a,max(b,c));

    printf("%d\n",ans+(m-a)/2+(m-b)/2+(m-c)/2);

}












Measured memory_bytes: 256
N = int(input())
print(((N + 1)//2)/N)
  		
#int(input()) で入力された数値をint型で受け取る
#(N+1)//:N+1を2で割ったものが
#切り捨て除算
#(8+1)//2=4,(9+1)//2=5:これが正整数Nに含まれる奇数の数になる

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int minv = Integer.parseInt(br.readLine());
      int n1   = Integer.parseInt(br.readLine());
      int maxv = n1- minv;
      if ( n1 < minv ) minv = n1;

      for( int i=2,r,mv; i<n; i++ ) {
        r = Integer.parseInt(br.readLine());
        if ( (mv = r-minv) > maxv ) maxv = mv;
        else if ( r < minv ) minv = r; 
      }

      System.out.println(maxv);
    }
  }
}


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

int main(){
  int N, A, n = 100;
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> A;
    bool j = true;
    int k = 0;
    while (j){
      j = (A + 1) % 2;
      if(j){
        A /= 2;
        k++;
      }
      else{}
    }
    if(n > k)
      n = k;
    else{}
  }
  cout << n << endl;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(1,n-1):
    if (p[i-1]>p[i] and p[i]>p[i+1]) or (p[i-1]<p[i] and p[i]<p[i+1]):
        c += 1
print(c)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
using namespace std;
int main()
{
    char c;
    cin>>c;
    int a=c;
    if(a>=65&&a<=90)
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"a"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3000
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        boolean result = false;
        if (n <= 81) {
            for (int i = 1; i <= 9 && !result; i++) {
                for (int j = 1; j <= 9 && !result; j++) {
                    if (n == i * j) {
                        result = true;
                    }
                }
            }
        }

        System.out.println(result ? "Yes" : "No");
    }
}


Measured memory_bytes: 22996
#include<stdio.h>
int main(){
  int A[3][10],B[3][10],C[3][10],D[3][10],i,j,n,b,f,r,v;

  for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      A[i][j] = 0;
      B[i][j] = 0;
      C[i][j] = 0;
      D[i][j] = 0;
    }
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    if(b == 1) A[f-1][r-1] += v;
    else if(b == 2) B[f-1][r-1] += v;
    else if(b == 3) C[f-1][r-1] += v;
    else D[f-1][r-1] += v;
  }

  for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      printf(" %d",A[i][j]);
    }
    printf("\n");
  }
  printf("####################\n");
  
   for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      printf(" %d",B[i][j]);
    }
    printf("\n");
  }
  printf("####################\n");

  for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      printf(" %d",C[i][j]);
    }
    printf("\n");
  }
  printf("####################\n");
   for(i=0;i<3;i++){
    for(j=0;j<10;j++){
      printf(" %d",D[i][j]);
    }
    printf("\n");
   }

}




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

int ketanowa (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=0;i<=N;i++){
    int sum = ketanowa(i);
    if(sum >= A && sum <= B){
      total += i;
    }
  }
  cout << total << endl;
 
}

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

int main() {
	int N;
	cin >> N;
	int A[N], B[N];
	B[0] = 0;
	for(int k = 1; k < N; k++){
		cin >> A[k];
		B[k] = 0;
	}

	for(int j = (N - 1); j > 0; j--){
		B[A[j]-1]++;
	}

	for(int i = 0; i < N; i++){
		cout << B[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  vector<ll> R(N+1, 0);
  rep(i, N){
    cin>>A[i];
    R[i+1]=R[i]+A[i];
  }
  ll Ans=INF;
  ll Left, Right;
  Left=1;Right=3;
  vector<ll> M(4, 0);
  vector<ll> L(4, 0);
  M[0]=A[0];M[1]=A[1];M[2]=A[2];M[3]=R[N]-R[3];
  while(M[2]<M[3]&&Right<N){
    Right++;
    M[2]+=A[Right-1];
    M[3]-=A[Right-1];
  }
  ll Rdif,Ldif;
  Rdif=M[3]-M[2];
  Ldif=Rdif+2*A[Right-1];
  if(abs(Rdif)>abs(Ldif)){
    Right--;
    M[2]-=A[Right];
    M[3]+=A[Right];
  }
  rep(i,4){
    L[i]=M[i];
    //cout<<L[i]<<" ";
  }
  //cout<<endl;
  sort(ALL(L));
  Ans=L[3]-L[0];
  for(ll i=3; i<=N-2; i++){
    M[1]+=A[i-1];
    M[2]-=A[i-1];
    if(M[0]<M[1]){
      while(M[0]<M[1]&&i-Left>1){
        Left++;
        M[0]+=A[Left-1];
        M[1]-=A[Left-1];
      }
      if(abs(M[1]-M[0])>abs(M[1]-M[0]+2*A[Left-1])){
          Left--;
          M[0]-=A[Left];
          M[1]+=A[Left];
      }
    }else{
      while(M[0]>M[1]&&Left>0){
        Left--;
        //cout<<A[Left]<<endl;
        M[0]-=A[Left];
        M[1]+=A[Left];
      }
      Rdif=M[1]-M[0];
      Ldif=Rdif-2*A[Left];
        if(abs(Rdif)>abs(Ldif)){
          Left++;
          M[0]+=A[Left-1];
          M[1]-=A[Left-1];
        }
    }
    if(M[2]<M[3]){
      while(M[2]<M[3]&&Right<N){
        Right++;
        M[2]+=A[Right-1];
        M[3]-=A[Right-1];
      }
      Rdif=M[3]-M[2];
      Ldif=Rdif+2*A[Right-1];
        if(abs(Rdif)>abs(Ldif)){
          Right--;
          M[2]-=A[Right];
          M[3]+=A[Right];
  }
    }else{
      while(M[2]>M[3]&&Right-1>i){
        Right--;
        M[2]-=A[Right];
        M[3]+=A[Right];
      }
      Rdif=M[3]-M[2];
      Ldif=Rdif-2*A[Right];
        if(abs(Rdif)>abs(Ldif)){
          Right++;
          M[2]+=A[Right-1];
          M[3]-=A[Right-1];
        }
    }
  rep(j,4){
    L[j]=M[j];
    //cout<<L[j]<<" ";
  }
    //cout<<"i="<<i<<", Left="<<Left<<", Right="<<Right;
    //cout<<endl;
  sort(ALL(L));
  Ans=min(Ans,L[3]-L[0]);
  }
  cout<<Ans<<endl;
} 

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using v = vector<T>;
using P = pair<int, int>;

/*
 *  */

class UnionFind
{
public:
  int n;
  vector<int> par, rnk;

  UnionFind(int n_)
  {
    n = n_;
    par.resize(n);
    rnk.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      rnk[i] = 0;
    }
  }

  int find(int x)
  {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rnk[x] < rnk[y]){
      par[x] = y;
    }else{
      par[y] = x; 
      if(rnk[x] == rnk[y]) rnk[x]++;
    }
  }

  bool same(int x, int y)
  {
    return find(x) == find(y);
  }
};

signed main() {
  int n, m;
  cin >> n >> m;

  v<int> a(n);
  rep(i, 0, n) cin >> a[i];

  v<int> x(n), y(n);
  UnionFind uf(n);
  v<int> b = a;
  rep(i, 0, m){
    cin >> x[i] >> y[i];
    uf.unite(x[i], y[i]);
  }

  priority_queue<int> que[n];
  rep(i, 0, n) que[uf.find(i)].push(-a[i]);

  int cnt = 0, ans = 0;
  rep(i, 0, n){
    if(uf.find(i) == i){
      ans += -que[i].top();
      que[i].pop();
      cnt++;
    }
  }

  v<int> c;
  rep(i, 0, n){
    while(!que[i].empty()){
      c.emplace_back(-que[i].top());
      que[i].pop();
    }
  }

  sort(all(c));
  
  if(cnt == 1){
    cout << 0 << endl;
  }else if(sz(c) < cnt-2){
    cout << "Impossible" << endl;
  }else{
    rep(i, 0, cnt-2) ans += c[i];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 11264
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

  vector<P> lst;
  for (int i = 0; i < M; i++) {
    P tmp;
    cin >> tmp.second >> tmp.first;
    tmp.first--;
    lst.emplace_back(tmp);
  }
  sort(lst.begin(), lst.end());

  ll ans = 1;
  ll cur = lst[0].first;
  for (int i = 1; i < M; i++) {
    if(lst[i].second > cur){
      ans++;
      cur = lst[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2420