akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;
int main()
{
	ll n;
	cin >> n;
	ll Min = Max;
	for (int i = 1;i <= sqrt(n);i++) {
		if (n % i == 0) {
			ll a = i + (n / i);
			Min = min(Min, a);
		}
	}
	cout << Min - 2;
}

Measured memory_bytes: 3648
from collections import deque

d = deque(input())
q = int(input())
reverse_flag = False

for i in range(q):
  query = input().split()
  if query[0] == "1":
    reverse_flag = not reverse_flag
  else:
    if (query[1] == "1") ^ reverse_flag:
      d.appendleft(query[2])
    else:
      d.append(query[2])

print("".join(list(d)[::-1]) if reverse_flag else "".join(d))

Measured memory_bytes: 10092
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

LL s;

int n, m;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, x; i <= m; i++) {
		scanf("%d", &x);
		s += x;
	}
	if (s <= n) printf("%lld\n", n - s);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <stack>

using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
    for (int v = nt[u]; v < n; ++v) {
        nt[u] = v + 1;
        if (M[u][v])
            return v;
    }
    return -1;
}

void dfs_visit(int r) {
    for (int i = 0; i < n; ++i) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    // ?????????
    for (int i = 0; i < n; ++i) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    // ????¨??????? u ????§??????¨????????±???????????¢?´¢
    for (int u = 0; u < n; ++u) {
        if (color[u] == WHITE)
            dfs_visit(u);
    }

    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}

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

using namespace std;
typedef long long ll;

const ll INF = 1145141919810364364;

void chmax(ll &x, ll val) {
    x = max(x, val);
}

int main() {
    int n;
    cin >> n;
    int extra = n % 2 + 1;
    vector<vector<ll>> dp(n + 10, vector<ll>(extra + 1, -INF));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j <= extra; j++) {
            dp[i][j] = 0;
        }
    }
    for (int i = 10; i < n + 10; i++) {
        ll a;
        cin >> a;
        for (int j = 0; j <= extra; j++) {
            for (int k = 0; k + j <= extra; k++) {
                chmax(dp[i][k + j], dp[i - (j + 2)][k] + a);
            }
        }
    }

    ll ret = -INF;
    for (int i = 0; i <= extra; i++) {
        for (int j = 0; i + j <= extra; j++) {
            chmax(ret, dp[n + 9 - j][i]);
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
	int i=1, a, b, c, d;
	scanf("%d %d", &a, &b);
	d = b;
	if(d>10){
		do{
			d /= 10;
			i++;
//			printf("d=%d\n", d);
		}while(d>=10);
	}				//bはi桁
	int j, e=1;
	for(j=0; j<i; j++){
		e*=10;
	}
	
	c=a*e+b;
//	printf("%d %d %d\n", a, b, c);	//cが-1されることがあるのはなぜ
	
	
	i=0;
	do{				//Noのときどうしようか
		if(/*pow(i,2)*/i*i==c){
			printf("Yes\n");
			return 0;
		}
		i++;
//		printf("i=%d\n", i);
	}while(pow(i,2)<=c);
	
	printf("No\n");
	
	return 0;
}


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

int main(void){
    int IN;
    cin >> IN;
    int top = IN/100;
    int bot = IN%100;
    bool topM = false;
    bool botM = false;
    if(1 <= top && top <= 12){
        topM = true;
    }
    if(1 <= bot && bot <= 12){
        botM = true;
    }
    if(topM & botM){
        cout<<"AMBIGUOUS"<<endl;
    }else if(topM){
        cout<<"MMYY"<<endl;
    }else if(botM){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
    return 0;
}

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

int main(){
 string s; cin >> s;
 bool used[26] = {0};
 for(char u : s){
  used[u - 'a'] = 1;
 }
 for(int i = 0; i < 26; ++i){
   if(!used[i]){
      cout << (char)(i + 'a') << endl;
      return 0;
    }
 }
 cout << "None\n";
 return 0;
}

Measured memory_bytes: 512
import math
A, B, H, M = map(int, input().split())

a = 30 * H + 30 * (M / 60)
b = 360 * M /60

ans = A**2 + B**2 - 2 * A * B * math.cos((abs(a - b) * math.pi / 180))
ans = math.sqrt(ans)
print(ans)

Measured memory_bytes: 9404
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#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;
const ll mod = 1000000007;
const ll INF = mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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 pair<ll, ll> LP;
typedef vector<LP> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;


void solve() {
	int n; cin >> n;
	vector<int> a(n);
	multiset<int> st;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
	}
	rep(i, n) {
		auto itr = st.end(); itr--;
		if (*itr == a[i])itr--;
		cout << *itr << endl;
	}
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
		return 0;
}



Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;

const ll MOD = 1000000007;
const ld EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }

ll intabs(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

ll intpow(ll a, ll b, ll p = LLONG_MAX)
{
    ll ret = 1;
    while (b != 0)
    {
        if ((b & 1) == 1)
            ret *= a;
        a *= a;
        if (a >= p)
            a %= p;
        if (ret >= p)
            ret %= p;
        b = b >> 1;
    }
    return ret;
}

int digit(ll a, ll b = 10)
{
    int ret = 0;
    while (a != 0)
    {
        a /= b;
        ret++;
    }
    return ret;
}

ll gcd(ll x, ll y)
{
    while (y != 0)
    {
        ll cnt = x % y;
        x = y;
        y = cnt;
    }
    return x;
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

class UnionFind
{
    vector<int> par, sz;

public:
    UnionFind(int n) : par(n), sz(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
        sz[ry] += sz[rx];
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        return sz[root(x)];
    }
};

vector<bool> seen;
void dfs(const graph &g, int v)
{
    seen[v] = true;
    for (auto i : g[v])
    {
        if (seen[i])
            continue;
        dfs(g, i);
    }
}

int main()
{
    int i, j, k, cnt;
    ll n, m;
    cin >> n >> m;
    graph g(n + m);
    for (i = 0; i < n; i++)
    {
        ll k;
        cin >> k;
        for (j = 0; j < k; j++)
        {
            ll l;
            cin >> l;
            g[i].push_back(n + l - 1);
            g[n + l - 1].push_back(i);
        }
    }
    seen.assign(n + m, false);
    dfs(g, 0);
    for (i = 0; i < n; i++)
    {
        if (!seen[i])
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            out.println(s[0] == '9' || s[1] == '9' ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

vector<ll> V[4]; // w = w1+iとなる荷物の価値

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

	ll N, W; cin >> N >> W;

	for (int i = 0; i < 4; i++) V[i].push_back(0);

	ll base; cin >> base;
	ll tmp; cin >> tmp; V[0].push_back(tmp);
	for (int i = 0; i < N-1; i++) {
		ll weight, value; cin >> weight >> value;
		V[weight - base].push_back(value);
	}

	for (int i = 0; i < 4; i++) sort(V[i].begin()+1, V[i].end(), greater<int>());

	//cout << "ok1" << endl;

	// 累積
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < V[i].size(); j++) V[i][j] += V[i][j - 1];
	}

	ll ans = 0;

	for (ll i = 0; i < V[0].size(); i++) {
		for (ll j = 0; j < V[1].size(); j++) {
			for (ll k = 0; k < V[2].size(); k++) {
				for (ll l = 0; l < V[3].size(); l++) {
					
					ll totw = base * i + (base + 1)*j + (base + 2)*k + (base + 3)*l;
					if (totw <= W) {
						ll totv = V[0][i] + V[1][j] + V[2][k] + V[3][l];
						ans = max(ans, totv);
					}

				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement

# import heapq
# from collections import deque

# N, M = map(int, input().split())
# sequence = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N = int(input())
    sequence = list(map(int, input().split()))

    sequence.sort()

    max_v = sequence[-1]

    dp = [True] * (max_v + 1)

    previous = -1
    for v in sequence:
        if v == previous:
            dp[v] = False
            continue

        previous = v

        if not dp[v]:
            continue

        for iv in range(2 * v, max_v+1, v):
            dp[iv] = False

    count = 0
    for v in sequence:
        if dp[v]:
            count += 1

    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 32228
#include <bits/stdc++.h>
using namespace std;
int comp(const void* a, const void* b)
{ return *(int*)a > *(int*)b ; }

int findNumberOfTriangles(int arr[], int n)
{

    qsort(arr, n, sizeof( arr[0] ), comp);

    int count = 0;


    for (int i = 0; i < n - 2; ++i)
    {
        int k = i + 2;


        for (int j = i + 1; j < n; ++j)
        {

            while (k < n && arr[i] + arr[j] > arr[k])
            ++k;

            if(k > j)
            count += k - j - 1;
        }
    }

    return count;
}

int main()
{  int n,i;
    cin>>n;
    int arr[n];
    for (i=0;i<n;i++)cin>>arr[i];
    int size = sizeof( arr ) / sizeof( arr[0] );

    cout<<findNumberOfTriangles( arr, size );

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

bool used[110];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a;
		for(j=0;j<a;j++){
			cin>>b;
			if(!used[b]){
				used[b]=true;
				n--;
			}
		}
	}
	cout<<n<<endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------

const int MAX_N = 1e6 + 1000;

int nth_prime[MAX_N];
int is_prime[MAX_N];
int min_factor[MAX_N];

void sieve() {
  int n = MAX_N;
  int p = 0;
  for (int i = 0; i <= n; ++i) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      nth_prime[p] = i;
      ++p;
      min_factor[i] = i;

      for (int j = 2 * i; j <= n; j += i) {
        if (is_prime[j]) {
          is_prime[j] = false;
          min_factor[j] = i;
        }
      }
    }
  }

  // n以下の素数の個数が必要な場合はpをreturn
  // return p;
}

int main() {
  int X;
  cin >> X;
  sieve();
  repe(i, X, 1e6) {
    if (is_prime[i]) {
      cout << i << endl;
      return 0;
    }
  }
}


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

int main(){
    string s;

    cin >> s;

    if (s == "SUN") cout << 7 << endl;
    else if (s == "MON") cout << 6 << endl;
    else if (s == "TUE") cout << 5 << endl;
    else if (s == "WED") cout << 4 << endl;
    else if (s == "THU") cout << 3 << endl;
    else if (s == "FRI") cout << 2 << endl;
    else if (s == "SAT") cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 888
fun main(args: Array<String>) {
    val (n, a) = readLine()!!.split(" ").map(String::toInt)
    val x = readLine()!!.split(" ").map(String::toInt)
    val an = a * n
    val mm = Array(n + 1) {
        Array(n + 1) { LongArray(an + 1) }
    }
    for (i in 0..n) {
        for (j in 0..n) {
            for (k in 0..an) {
                mm[i][j][k] = when {
                    i == 0 && j == 0 && k == 0 -> 1L
                    1 <= i && k < x[i - 1] -> mm[i - 1][j][k]
                    1 <= i && 1 <= j && x[i - 1] <= k -> mm[i - 1][j][k] + mm[i - 1][j - 1][k - x[i - 1]]
                    else -> 0L
                }
            }
        }
    }
    var result = 0L
    for (i in 1..n) {
        result += mm[n][i][a * i]
    }
    println(result)
}


Measured memory_bytes: 112160
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int a[] = new int[N];
        int b[] = new int[N];
        HashMap<Integer, Integer> trees[] = new HashMap[N];
        int maxSides = 0;
        for (int i = 0; i < N; i++) {
            trees[i] = new HashMap();
        }

        for (int i = 0; i < N-1; i++) {
            a[i] = scan.nextInt() - 1;
            b[i] = scan.nextInt() - 1;
            trees[a[i]].put(b[i], 0);
            trees[b[i]].put(a[i], 0);

            if (maxSides < trees[a[i]].size())
                maxSides = trees[a[i]].size();
            if (maxSides < trees[b[i]].size())
                maxSides = trees[b[i]].size();
        }

        //K
        os.println(maxSides);

        dfs(0, -1, -1, trees);

        for(int i = 0; i < N-1; i++) {
            os.println(trees[a[i]].get(b[i]));
        }
    }


    static void dfs(int to, int root, int rootColor, HashMap<Integer, Integer>[] trees) {
        if(root >= 0) {
            trees[to].put(root, rootColor);
        }
        int color = 1;
        for (Integer child: trees[to].keySet()) {
            if (child == root)
                continue;
            if(color == rootColor)
                color++;
            trees[to].put(child, color);
            dfs(child, to, color++, trees);
        }

    }
}

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

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

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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 (b < a) { a = b; return 1; } return 0; }

map<lli,lli> cnt;
map<lli,lli> minPos;

lli ans[100100];

void func(long long N, std::vector<long long> a){

    REP(i,0,N){
        cnt[a[i]]++;
        if(minPos.count(a[i])==0){
            minPos[a[i]]=i;
        }
        else{
            chmin(minPos[a[i]],(lli)i);
        }
    }

    //q.first num, second.first cnt, second.second minPos
    priority_queue<pair<lli,pair<lli,lli>>> q;
    
    for(auto e:cnt){
        q.push({e.first,{e.second,minPos[e.first]}});
    }

    while(q.size()>1){
        pair<lli,pair<lli,lli>> nowTop = q.top();
        q.pop();
        pair<lli,pair<lli,lli>> nexTop = q.top();
        q.pop();
        lli diffNum = nowTop.first - nexTop.first;
        ans[nowTop.second.second] += diffNum * nowTop.second.first;

        nexTop.second.first += nowTop.second.first;
        chmin(nexTop.second.second,nowTop.second.second);
        q.push(nexTop);
    }

    pair<lli,pair<lli,lli>> lasTop = q.top();

    ans[lasTop.second.second] += lasTop.first * lasTop.second.first;

    REP(i,0,N){
        cout<<ans[i]<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    func(N, std::move(a));
    return 0;
}


Measured memory_bytes: 19660
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] A = new int[N];

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		Arrays.sort(A);

		int ans=Math.abs(A[0]-A[N-1]);
		pln(ans);

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 22868
from sys import stdin

def main():
    n,m = map(int,stdin.readline().split())
    arr= [0 for _ in range(n+1)]
    p=0;a= 0
    for _ in range(m):
        x,y = stdin.readline().split()
        x = int(x)
        if  arr[x] != -1:
            if y == "WA":
                arr[x]+=1
            else:
                a+=1
                p+=arr[x]
                arr[x] = -1
    print(a,p)
main()


Measured memory_bytes: 3888
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct A {
  int a, b;
  bool operator<(A const& r) const { return b < r.b; }
};
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<A> AB(N);
  for(int i = 0; i < N; ++i) std::cin >> AB[i].a;
  for(int i = 0; i < N; ++i) std::cin >> AB[i].b;
  std::sort(AB.begin(), AB.end());
  std::vector<int> ix(N);
  std::iota(ix.begin(), ix.end(), 0);
  std::sort(ix.begin(), ix.end(),
    [&](int l, int r){ return AB[l].a < AB[r].a; });
  for(int i = 0; i < N; ++i) if(AB[ix[i]].a > AB[i].b) fin("No");
  int c = 1;
  for(int p = ix[0]; p!=0; p = ix[p]) ++c;
  if(c < N) fin("Yes");
  for(int i = 0; i < N-1; ++i) if(AB[ix[i+1]].a <= AB[i].b) fin("Yes");
  fin("No");
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int mn=1<<30,mx=0;
		for(int i=0;i<n;i++){
			int a,b,c,d,e;	cin>>a>>b>>c>>d>>e;
			int s=a+b+c+d+e;
			if(s<mn)	mn=s;
			if(s>mx)	mx=s;
		}
		cout<<mx<<' '<<mn<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        wa = a*i + b*j
        if 0 < wa*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    su = c*k + d*l
                    if (su <= wa*e) and wa*100+su <= f:
                        g = su/(wa*100+su)
                        res.append([g,wa*100+su,su])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	rep(i, n - 3 + 1) {
		string t = s.substr(i, 3);
		if (t == "ABC")ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(17);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 16640
program main;
var 
    a, b, c : string;
    i : integer;
begin
    readln(a);
    for i := 1 to length(a) do 
        if a[i] = ' ' then 
            begin 
                b := copy(a,1,i-1);
                c := copy(a,i+1,(length(a)-i));
            end;
    writeln(c,b);
end.

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
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;}


int main()
{
    char a;
    cin >> a;
    if(a>='A'&&'Z'>=a){
        cout << "A" << endl;
    }
    else{
        cout << "a" << endl;
    }
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, n);
    VI cnt(100'001);
    int sm = 0;
    for(int i =0 ; i < n; ++i){
        make(int, q);
        sm += q;
        cnt[q]++;
    }
    make(int, q);
    while(q--){
        make(int, a, b);
        int d = (b - a) * cnt[a];
        sm += d;
        cnt[b] += cnt[a];
        cnt[a] = 0;
        cout << sm << '\n';
    }

    return 0;
}

Measured memory_bytes: 3948
#include <iostream>
using namespace std;
constexpr long long mod = 2019;

int main(){
  long long l, r;
  cin >> l >> r;
  long long ans = 1e9;
  for(long long i = l; i <= min(r,l+mod); ++i){
    for(long long j = i+1; j <= min(r,l+mod); ++j){
      ans = min(ans,i*j%mod);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n;
  scanf("%d",&n);
  int a[n+10];
  double ans=0.0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    ans += 1.0/(double)a[i];
  }
  printf("%f",1/ans);
  return 0;
}

Measured memory_bytes: 128
X = int(input())
for B in range(-10 ** 3, 10 ** 3):
    A_5 = B ** 5 + X
    A = A_5 ** (1 / 5)
    if type(A) is not float:
        continue
    A = int(A)
    if A ** 5 == A_5:
        print(A, B)
        exit()

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec S(N+1, 0), T(M+1, 0);
    REP(i,1,N+1) cin >> S[i];
    REP(i,1,M+1) cin >> T[i];

    mat dp(N+1, vec(M+1, 0));
    REP(i,0,N+1) dp[i][0] = 1;
    REP(i,0,M+1) dp[0][i] = 1;

    REP(i,1,N+1) {
        REP(j,1,M+1) {
            if(S[i] == T[j]) dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MOD) % MOD;
        }
    }
    PR(dp[N][M]);

    return 0;
}

/*



*/

Measured memory_bytes: 34588
n = int(input())
a = [int(i) for i in input().split()]
color = [0, 0, 0]
ans = 1
mod = 10 ** 9 + 7
for i in a:
    cnt = color.count(i)
    ans *= cnt
    ans = ans % mod
    if ans > 0:
        color[color.index(i)] += 1
    else:
        break
print(ans)

Measured memory_bytes: 20548
#include <iostream>
#include <map>

using namespace std;

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

    map<int, int> sequence;

    for (int i = 1; i <= n; ++i){
        int tmp;
        cin >> tmp;
        sequence[tmp] = i;
    }

    for (auto e : sequence)
        cout << e.second << " ";

    return 0;
}

Measured memory_bytes: 5504
#include<iostream>
using namespace std;
int main(){
	char ch;
	int a[100];
	for (int i = 0; i < 100; i++){
		a[i] = 0;
	}
	while (cin >> ch){
	
		if (isupper(ch)){
			ch = tolower(ch);
		}
		int num = ch - 'a';
		
		if (0 <= num && num <= 25)
		{
			a[num]++;

		}
	
	}
	for (int i = 0; i < 26; i++){
		char y = i + 'a';
		cout << y << ' ' << ':' << ' ';
		cout << a[i] << endl;
	}

	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
ll A[MAX_N];
ll B[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = nextInt();

  int ans = 0;
  ll need = 0;
  vector<ll> have;
  REP(i, N) {
    if (A[i] > B[i]) {
      have.push_back(A[i] - B[i]);
    }
    if (A[i] < B[i]) {
      ans++;
      need += (B[i] - A[i]);
    }
  }
  sort(ALL(have));
  reverse(ALL(have));

  int i = 0;
  while (need > 0 && i < (int)have.size()) {
    need -= have[i];
    i++;
    ans++;
  }
  if (need > 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s, t;
int main() {
    cin>>s>>t;

    bool flag=false;
    REP(i, 0, s.size()){
        bool iql=true;
        REP(j, 0, s.size()){
            if(s[(i+j)%s.size()]!=t[j]){
                iql=false;
                break;
            }
        }
        if(iql) flag=true;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    int h[N];
    rep(i, N) cin >> h[i];

    int ans = 0;
    rep(i, N) {
        if (h[i] >= K) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;cin >> N;
  const ll mod = 1000000007;
  vector<vector<ll>> dp(N+1, vector<ll>(4));
  dp[1][0] = 8;
  dp[1][1] = 1;
  dp[1][2] = 1;
  dp[1][3] = 0;
  rep(i, 1, N) {
    dp[i+1][0] = (dp[i][0] * 8 % mod);
    dp[i+1][1] = ((dp[i][0] + dp[i][1] * 9) % mod);
    dp[i+1][2] = ((dp[i][0] + dp[i][2] * 9) % mod);
    dp[i+1][3] = ((dp[i][1] + dp[i][2] + dp[i][3] * 10) % mod);
  }
  cout << (dp[N][3] % mod) << endl;
}

Measured memory_bytes: 73424
n, k = map(int, input().split())
vs = list(map(int,input().split()))
rvs = list(reversed(vs))
def get_cand(vs):
    sums = [0]
    trushes = [[]]
    pre = 0
    trush = []
    for v in vs:
        sums.append(v+pre)
        pre += v
        if v < 0:
            trush.append(-v)
        trushes.append(list(tuple(trush)))
    return sums, trushes
lsums, ltrushes = get_cand(vs)
rsums, rtrushes = get_cand(rvs)

total = []
for i in range(len(lsums)):
    for j in range(len(rsums)):
        if i + j > min(n, k):
            continue
        trushes = sorted(ltrushes[i] + rtrushes[j], reverse = True)
        total.append(lsums[i] + rsums[j] + sum(trushes[:k - i - j]))

print(max(total))


Measured memory_bytes: 3064
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

simulate (sc : scs) table = do
  let i = head sc
  let v = last sc
  p <- VUM.read table (i -1)
  if p == (-1)
    then do
      VUM.write table (i -1) v
      if scs /= []
        then simulate scs table
        else return True
    else do
      if p /= v
        then return False
        else do
          if scs /= []
            then simulate scs table
            else return True

showL table i n f s = do
  v <- VUM.read table (i -1)
  if f == False && (v == 0 || v == (-1))
    then do
      if v == 0
        then do
          if n == 1
            then return "0"
            else return "-1"
        else showL table (i + 1) n True "1"
    else do
      let v'
            | v == (-1) = "0"
            | otherwise = show v
      let s' = v' ++ s
      if i == n
        then return (reverse s')
        else showL table (i + 1) n True s'

main = do
  [n, m] <- getIntList
  if m == 0
    then
      if n == 1
        then print 0
        else putStrLn $ "1" ++ (replicate (n - 1) '0')
    else do
      scs <- getIntNList m
      table <- VUM.replicate n (-1) :: IO (VUM.IOVector Int)
      result <- simulate scs table
      if result == False
        then print (-1)
        else do
          num <- showL table 1 n False ""
          putStrLn num


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int main (){
    int H,W,count;
    cin >> H >> W;
    vector<vector<char>> v(H+2,vector<char>(W+2,'.'));

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> v.at(i+1).at(j+1);
        }
    }

    for(int i=1;i<H+1;i++){
        for(int j=1;j<1+W;j++){
            count = 0;
            if(v.at(i).at(j) == '.'){
                if(v.at(i-1).at(j-1)=='#'){count++;}
                if(v.at(i-1).at(j)=='#'){count++;}
                if(v.at(i-1).at(j+1)=='#'){count++;}
                if(v.at(i).at(j-1)=='#'){count++;}
                if(v.at(i).at(j+1)=='#'){count++;}
                if(v.at(i+1).at(j-1)=='#'){count++;}
                if(v.at(i+1).at(j)=='#'){count++;}
                if(v.at(i+1).at(j+1)=='#'){count++;}
                v.at(i).at(j) = count+48;//0のアスキーコードは４８
            }
            else{
                continue;
            }
        }
    }

    for(int i=1;i<H+1;i++){
        for(int j=1;j<1+W;j++){
            cout << v.at(i).at(j);
            if(j==W){cout << endl;}
        }
    }

}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;typedef long long ll;
int n,i,j,pos,mod=1e9+7;char s[3][107];ll ans;
int main(){
	for(scanf("%d",&n),i=1;i<=2;++i)for(j=1;j<=n;++j)scanf(" %c",&s[i][j]);
	if(s[1][1]!=s[2][1])ans=6,pos=3;
	else ans=3,pos=2;
	for(i=pos;i<=n;)if(s[1][i]==s[2][i]){
		if(s[1][i-1]==s[2][i-1]){
			ans*=2;ans%=mod;
		}
		i++;
	}else{
		if(s[1][i-1]!=s[2][i-1]){
			ans*=3;ans%=mod;
		}else{
			ans*=2;ans%=mod;
		}
		i+=2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
/* B */

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    int tmp;
    for(int i = min(a,b); cnt < k; i--){
    	if(a % i == 0 && b % i == 0){
    		cnt++;
    		tmp = i;
    	}else{

    	}
    }

    cout << tmp << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		
		ArrayList<String> lt = new ArrayList<String>();
		for (int i = 0; i < n; i++) {
			lt.add(sc.next());
		}
		
		Collections.sort(lt);
		String result = "";
		for (String str : lt) {
			result += str;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 14852
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (Math.abs(x-a) < Math.abs(x-b)) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
		
	}
}


Measured memory_bytes: 23764
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  rep(i, N){
    cin >> T.at(i);
  }
  sort(all(T));
  int cus = 1;
  int i = 0;
  int j = 1;
  int bus = 1;
  while(i < N){
    while(i+j < N){
      if(T.at(i+j) - T.at(i) <= K){
        if(cus < C){
          cus++;
        }
        else{
          bus++;
          cus = 1;
          break;
        }
      }
      else{
        bus++;
        cus = 1;
        break;
      }
      if(i+j == N-1){
        cout << bus << endl;
        return 0;
      }
      j++;
    }
    i = i+j;
    j = 1;
  }
  cout << bus << endl;
}

Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll x=6;
   ll a,b;
   cin>>a>>b;
   cout<<6-a-b<<endl;
return 0;
}


Measured memory_bytes: 4992