akhauriyash/Code-Regression huggingface dataset:
#pragma region template 1.0
#pragma region def
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion enddef

vector<vi> dp(20, vi(10, 1));
vector<vi> dp2(20, vi(10, 1));

ll K;
ll f(ll i, ll j, ll s)
{
    // cout << i << ' ' << j << ' ' << s << endl;
    if (i == 1)
    {
        return j;
    }
    for (ll k = max(0LL, j - 1); k <= min(9LL, j + 1); ++k)
    {
        // OUT(s + dp[i - 1][k]);
        if (s + dp[i - 1][k] >= K)
        {
            return j * pow(10, i - 1) + f(i - 1, k, s);
        }
        s += dp[i - 1][k];
    }
    ll k = min(9LL, j + 1);
    return j * pow(10, i - 1) + f(i - 1, k, s);
}

int main()
{
    cin >> K;
    if (K < 10)
    {
        OUT(K);
        return 0;
    }
    ll u, v;
    ll acc = 9;
    for (ll i = 2; i < 20; ++i)
    {
        bool x = false;
        REP(j, 10)
        {
            dp[i][j] = 0;
            if (j > 0)
            {
                dp[i][j] += dp[i - 1][j - 1];
            }
            dp[i][j] += dp[i - 1][j];
            if (j < 9)
            {
                dp[i][j] += dp[i - 1][j + 1];
            }
            if (j > 0)
            {
                acc += dp[i][j];
                dp2[i][j] = acc;
            }
            // cout << i << ' ' << j << ' ' << acc << endl;
            if (acc >= K)
            {
                // if (j == 0)
                // {
                //     u = i - 1;
                //     v = 9;
                // }
                // else
                // {
                //     u = i;
                //     v = j - 1;
                // }
                // acc -= dp[i][j] + dp[u][v];
                u = i;
                v = j;
                acc -= dp[i][j];
                x = true;
                break;
            }
        }
        if (x)
        {
            break;
        }
    }
    ll s = acc;
    // cout << u << ' ' << v << ' ' << s << endl;
    ll ans = f(u, v, s);
    OUT(ans);
}
#pragma endregion template

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int a[100002],b[100002];

int cmp(int a,int b)
{
    return a > b;
}
int main()
{
    int n,m;
    while(cin >> m >> n)
    {
        ll sum = 0;
        for(int i = 0;i < n;i++)
        cin >> a[i];
        sort(a,a + n);
        if(m >= n)
        {
            cout << 0 << endl;
            continue;
        }
        b[0] = 0;
        for(int i = 1;i < n;i++)
        {
            b[i] = a[i] - a[i - 1];
        }
        sort(b,b + n,cmp);
        for(int i = m - 1;i < n;i++)
        {
            sum += b[i];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int H,W,i,j;
	while(1)
	{
		scanf("%d %d",&H,&W);

		if(H==0 && W==0)
		{
			break;
		}
		for(i=0;i<H;i++)
		{
			if(i%2 == 0)
			{
				for(j=0;j<W;j++)
				{
					if(j%2 == 0)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
			}
			else
			{
				for(j=0;j<W;j++)
				{
					if(j%2 == 0)
					{
						printf(".");
					}
					else
					{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> y(100001),p(100001);
    vector<int> id[100001];
    for(int i=0;i<M;i++){
        cin >> p[i] >> y[i];
    }
    for(int i=0;i<M;i++){
        id[p[i]].pb(y[i]);
    }
    for(int i=0;i<N;i++){
        sort(id[i+1].begin(),id[i+1].end());
    }
    for(int i=0;i<M;i++){
        printf("%012lld\n",ll(p[i])*1000000+int(lower_bound(id[p[i]].begin(),id[p[i]].end(),y[i])-id[p[i]].begin())+1);
    }
    return 0;
}


Measured memory_bytes: 7808
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def is_biparty(g):
    u = list(g.keys())[0]
    s = [u]
    c = {}
    c[u] = True
    while s:
        u = s.pop()
        for v in g[u]:
            if v not in c:
                c[v] = not c[u]
                s.append(v)
            else:
                if c[v] == c[u]:
                    return False, None

    return True, c

@mt
def slv(N, M, AB):
    g = defaultdict(set)
    for a, b in AB:
        g[a].add(b)
        g[b].add(a)

    b, c = is_biparty(g)
    if b:
        d = Counter(c.values())
        return d[True] * d[False] - M
    else:
        return N * (N-1) // 2 - M


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 117336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  string s; cin >> s;
  int count = s.size()-2;
  cout << s[0] << count << s[s.size()-1] << endl;
}

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

int length(int a, int b) {
	if (b == 0) return 0;
	return b * (a / b) + length(b, a % b);
}

signed main() {
	int n, x;
	cin >> n >> x;
	cout << 3 * length(n - x, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	int a[5];
	for(int i=0;i<5;i++) cin>>a[i];
	sort(a,a+5,[](int a,int b){return ((a+9)%10)<((b+9)%10); });
	int ans = 0;
	for(int i=1;i<5;i++){
		ans += a[i]+(!!(a[i]%10))*(10-a[i]%10);
	}
	ans += a[0];
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

signed main() {
  INIT;
	VAR(int, n, k, l);
	UnionFind road(n + 1);
	REP(i, k) {
		VAR(int, p, q);
		road.merge(--p, --q);
	}
	UnionFind train(n + 1);
	REP(i, l) {
		VAR(int, s, t);
		train.merge(--s, --t);
	}

	map< PAIR, int > mp;
	REP(i, n) {
		mp[make_pair(road.root(i), train.root(i))]++;
	}

	REP(i, n) {
		OUT(mp[make_pair(road.root(i), train.root(i))]);
		if (i < n - 1) SP
		else BR
	}
  
  return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, K;
    cin >> N >> K;
    vl A(N);
    rep(i, N) cin >> A[i];
    ll sum = accumulate(all(A), 0ll);

    vl divl;
    repe(i,1,sqrt(sum)){
        if(sum%i==0){
            divl.eb(i);
            divl.eb(sum / i);
        }    
    }
    if (sum % (ll)sqrt(sum) == 0) divl.eb(sum / (ll)sqrt(sum));
    sort(all(divl));

    ll ans = INF;
    for(auto d: divl){
        vl R(N);
        rep(i, N) R[i] = A[i] % d;
        sort(all(R));
        ll DRsum = d*R.size()-accumulate(all(R), 0ll);

        ll m = 0;
        rep(i,N){
            m += R[i];
            DRsum += R[i] - d;
            // cout << d << " " << m << " " << DRsum << endl;
            if(max(m,DRsum)<=K){
                ans = d;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Match struct {
	P1 int
	P2 int
}

func makeMatch(p1, p2 int) Match {
	if p1 > p2 {
		p1, p2 = p2, p1
	}
	return Match{
		P1: p1,
		P2: p2,
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	fc := make(map[Match]int)
	to := make(map[Match][]Match)
	for i := 0; i < n; i++ {
		pa := -1
		for j := 0; j < n-1; j++ {
			sc.Scan()
			a, _ := strconv.Atoi(sc.Text())
			a--
			if pa >= 0 {
				// i-1:pa => i-1:a
				pm := makeMatch(i, pa)
				cm := makeMatch(i, a)
				if _, ok := to[pm]; !ok {
					to[pm] = make([]Match, 0)
				}
				to[pm] = append(to[pm], cm)
				fc[cm]++
			}
			pa = a
		}
	}

	queue := make([]Match, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < i; j++ {
			m := makeMatch(i, j)
			if _, ok := fc[m]; !ok {
				queue = append(queue, m)
			}
		}
	}

	// proc
	var day int
	var cnt int
	for len(queue) > 0 {
		day++
		nq := make([]Match, 0)
		for _, m := range queue {
			for _, cm := range to[m] {
				fc[cm]--
				if fc[cm] == 0 {
					nq = append(nq, cm)
				}
			}
			cnt++
		}
		queue = nq
	}

	var ok = cnt == n*(n-1)/2
	if ok {
		fmt.Println(day)
	} else {
		fmt.Println(-1)
	}
}


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

int main() {
  int N,D,X; cin >>N >>D >>X;
  vector<int> A(N);
  rep(i,0,N) cin >>A[i];
  int ans=X;
  rep(i,0,N) ans+=1+(D-1)/A[i];
  cout <<ans <<endl;
}


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

typedef long long ll;
const int inf = 1e9;

long long n, b, c, q, x, sum;

int main(){
	cin>>n;
	vector<long long> vec(n, 0);
	map<long long, int> m;
	sum = 0;
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
		m[vec[i]]++;
		sum += vec[i];
	}
	cin>>q;
	while(q){
		cin>>b>>c;
		if(m.count(b)){
			int x = m[b];
			m[c] += x;
			m[b] = 0;
			sum += (c - b) * x;
		}
		cout<<sum<<endl;
		q--;
	}
	return 0;
}


Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

struct Student{
   ll val;
   ll pos;
};
bool cmp(Student a,Student b){
    return a.val<b.val;
}
int main(){
    ll A,N,T,K;
    Student arr[100005];
    while(cin>>N){
        ll cnt=0;
        for(ll i=0;i<N;i++){
            ll x;
            cin>>x;
            arr[i].val=x;
            arr[i].pos=i+1;

        }
        sort(arr,arr+N,cmp);
        for(ll i=0;i<N;i++){
            cout<<arr[i].pos<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    for (auto i = 0; i < (int)s.size(); i++) {
        s[i] = s[i] + n;
        if(s[i] > 'Z') s[i] = 'A' + (s[i] - 'Z' - 1);
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll res = 0;
vector<ll> A(13);
ll p = 0;
ll q, ans;
struct item {
	ll a, b, c, d;
} st[55];


int main() {
	ll k;
	cin >> n >> k;
	vector<double> p(n);
	vector<double> sum(n + 1, 0);
	rep(i, n) {
		cin >> p[i];
		p[i] = (1 + p[i]) / 2;
	}
	sum[0] = p[0];
	for (ll i = 0; i < n ; i++) {
		sum[i+1] += sum[i] + p[i];
	}
	double res = 0;
	rep(i, n - k + 1) {
		res = max(sum[i + k] - sum[i], res);
	}
	cout << setprecision(8) << res << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

    int y;
    for(y=0; ; ++y)
    {
        int yp=y*y*y*y*y;
        int ne=(y+1)*(y+1)*(y+1)*(y+1)*(y+1);

        if(ne-yp>x) break;

        for(int z=y+1; ; ++z)
        {
            ne=z*z*z*z*z;
            if(ne-yp>x) break;
            if(ne-yp==x)
            {
                cout << z << " " << y << "\n";
                return 0;
            }
        }
    }

    for(y=0; ; ++y)
    {
        int yp=y*y*y*y*y;
        if(yp>x) break;
    }
    for(int a=0; a<y; ++a)
    {
        for(int b=0; b<y; ++b)
        {
            int aa=a*a*a*a*a;
            int bb=b*b*b*b*b;
            if(aa+bb==x)
            {
                cout << a << " " << -b << endl;
                return 0;
            }
        }
    }


}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 50;
int N, K;
int V[MAX_N];

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

  cin >> N >> K;
  rep(i, N) cin >> V[i];

  ll ans = 0;
  for (int pop = 0; pop <= K; ++pop) {
    int insert = K - pop;
    vector<int> v;
    for (int r = min(pop, N); r >= 0; --r) {
      v.clear();
      int l = min(pop-r, N-r);
      for (int i = 0; i < r; ++i) {
        v.push_back(V[i]);
      }
      for (int i = N-1; i >= N-l; --i) {
        v.push_back(V[i]);
      }
      sort(all(v));

      int idx = 0;
      for (int i = 0; i < min(insert, len(v)); ++i) {
        if (v[i] < 0) {
          ++idx;
        }
      }
      
      ll tmp = 0;
      for (int i = idx; i < len(v); ++i) {
        tmp += v[i];
      }
      ans = max(ans, tmp);
    }
  }

  cout << ans << endl;

  return 0;
}




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

int main() {
	int a, b, tmp = 0;
	double x, y;

	while (scanf("%d,%d", &a, &b) != EOF) {
		if (a == 0 && b == 0) break;
		x += a*sin(tmp*M_PI/180);
		y += a*cos(tmp*M_PI/180);
		tmp += b;
	}
	printf("%d\n%d\n", (int)x, (int)y);
	return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
vector<int> v;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void dfs(ll s, ll n) {
  if (s > n) return;
  string t = to_string(s);
  if (t.find("3") != -1 && t.find("5") != -1 && t.find("7") != -1) {
    v.push_back(s);
  }
  dfs(10 * s + 3, n);
  dfs(10 * s + 5, n);
  dfs(10 * s + 7, n);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;  cin >> n;
    dfs(0, n);
    cout << v.size() << '\n';

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ;
long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
int main (){

    ll N,ans=10e9;
    string S;
    cin >> N >> S;
    ll e[300000]={},w[300000]={};

    for(ll i = 0; i < N; i++) {
        if(i) {
            e[i] = e[i-1];
            w[i] = w[i-1];
        }
        if(S[i] == 'E') {
            e[i]++;
        }else {
            w[i]++;
        }
    }

    for(ll i = 0; i < N; i++) {
        if(i) {
            ans = min(ans,e[N-1]-e[i]+w[i-1]);
        } else {
            ans = min(ans,e[N-1]-e[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5380
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int a; cin >> a;
    string s; cin >> s;
    if(a < 3200) cout << "red";
    else cout << s;
    
    }




Measured memory_bytes: 256
using System;
using System.Linq;

namespace _067
{
    class Program
    {
        static void Main(string[] args)
        {
            // C - Splitting Pile
            var n = long.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(w=>long.Parse(w)).ToArray();

            long x = 0;
            long y = a.Sum();
            long min = 9999999999;
            for (long i = 0; i < n - 1; i++)
            {
                x += a[i];
                y -= a[i];
                var abs = Math.Abs(x - y);
                min = Math.Min(abs,min);
            }

            Console.WriteLine(min);

        }
    }
}


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

typedef struct node{
  int left;
  int right;
  int parent;
}node;

void Preorder(int);
void Inorder(int);
void Postorder(int);

node* tree;
int n;

int main(){
  
  int i,n,id,left,right,root;

  scanf("%d",&n);
  tree = (node *)malloc(sizeof(node)*n);

  for(i=0;i<n;i++) tree[i].parent = -1;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    tree[id].left=left;
    tree[id].right=right;
    if(left!=-1) tree[left].parent=id;
    if(right!=-1) tree[right].parent=id;
  }

  for(i=0;i<n;i++){
    if(tree[i].parent==-1) break;
  }
  
  root=i;

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}

void Preorder(int c){
  printf(" %d",c);
  if(tree[c].left != -1) Preorder(tree[c].left);
  if(tree[c].right != -1) Preorder(tree[c].right);
  
  return;
}

void Inorder(int c){
  if(tree[c].left != -1) Inorder(tree[c].left);
  printf(" %d",c);
  if(tree[c].right != -1) Inorder(tree[c].right);
  
  return;
}

void Postorder(int c){
  if(tree[c].left != -1) Postorder(tree[c].left);
  if(tree[c].right != -1) Postorder(tree[c].right);
  printf(" %d",c);
  
  return;
}

Measured memory_bytes: 616
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
inline int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G

int n,nn,Mod;
int a[200010];
bool check(int x){
	for (int l=x+x+1,r=nn;l<r;l++,r--) if (a[l]+a[r]<Mod) return 0;
	return 1;
}
int work(int x){
	int res=0;
	for (int l=x+x+1,r=nn;l<r;l++,r--) res=max(res,a[l]+a[r]-Mod);
	for (int l=1,r=x+x;l<r;l++,r--) res=max(res,a[l]+a[r]);
	return res;
}
int main()
{
	n=read(),Mod=read(); nn=n<<1;
	for (int i=1;i<=nn;i++) a[i]=read();
	sort(a+1,a+nn+1);
	int l=0,r=n,mid;
	while (l<r){
		mid=l+r>>1;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",work(l));
	return 0;
}

Measured memory_bytes: 2388
#include <iostream>
#include <map>
#include <string>

using namespace std;

map<string, char> mpp1;
map<string, bool> mpp2;
map<char, string> conv;

void makeMap()
{
  conv['A'] = "00000";
  conv['B'] = "00001";
  conv['C'] = "00010";
  conv['D'] = "00011";
  conv['E'] = "00100";
  conv['F'] = "00101";
  conv['G'] = "00110";
  conv['H'] = "00111";
  conv['I'] = "01000";
  conv['J'] = "01001";
  conv['K'] = "01010";
  conv['L'] = "01011";
  conv['M'] = "01100";
  conv['N'] = "01101";
  conv['O'] = "01110";
  conv['P'] = "01111";
  conv['Q'] = "10000";
  conv['R'] = "10001";
  conv['S'] = "10010";
  conv['T'] = "10011";
  conv['U'] = "10100";
  conv['V'] = "10101";
  conv['W'] = "10110";
  conv['X'] = "10111";
  conv['Y'] = "11000";
  conv['Z'] = "11001";
  conv[' '] = "11010";
  conv['.'] = "11011";
  conv[','] = "11100";
  conv['-'] = "11101";
  conv['\''] = "11110";
  conv['?'] = "11111";

  mpp1["101"] = ' ';
  mpp2["101"] = true;
  mpp1["000000"] = '\'';
  mpp2["000000"] = true;
  mpp1["000011"] = ',';
  mpp2["000011"] = true;
  mpp1["10010001"] = '-';
  mpp2["10010001"] = true;
  mpp1["010001"] = '.';
  mpp2["010001"] = true;
  mpp1["000001"] = '?';
  mpp2["000001"] = true;
  mpp1["100101"] = 'A';
  mpp2["100101"] = true;
  mpp1["10011010"] = 'B';
  mpp2["10011010"] = true;
  mpp1["0101"] = 'C';
  mpp2["0101"] = true;
  mpp1["0001"] = 'D';
  mpp2["0001"] = true;
  mpp1["110"] = 'E';
  mpp2["110"] = true;
  mpp1["01001"] = 'F';
  mpp2["01001"] = true;
  mpp1["10011011"] = 'G';
  mpp2["10011011"] = true;
  mpp1["010000"] = 'H';
  mpp2["010000"] = true;
  mpp1["0111"] = 'I';
  mpp2["0111"] = true;
  mpp1["10011000"] = 'J';
  mpp2["10011000"] = true;
  mpp1["0110"] = 'K';
  mpp2["0110"] = true;
  mpp1["00100"] = 'L';
  mpp2["00100"] = true;
  mpp1["10011001"] = 'M';
  mpp2["10011001"] = true;
  mpp1["10011110"] = 'N';
  mpp2["10011110"] = true;
  mpp1["00101"] = 'O';
  mpp2["00101"] = true;
  mpp1["111"] = 'P';
  mpp2["111"] = true;
  mpp1["10011111"] = 'Q';
  mpp2["10011111"] = true;
  mpp1["1000"] = 'R';
  mpp2["1000"] = true;
  mpp1["00110"] = 'S';
  mpp2["00110"] = true;
  mpp1["00111"] = 'T';
  mpp2["00111"] = true;
  mpp1["10011100"] = 'U';
  mpp2["10011100"] = true;
  mpp1["10011101"] = 'V';
  mpp2["10011101"] = true;
  mpp1["000010"] = 'W';
  mpp2["000010"] = true;
  mpp1["10010010"] = 'X';
  mpp2["10010010"] = true;
  mpp1["10010011"] = 'Y';
  mpp2["10010011"] = true;
  mpp1["10010000"] = 'Z';
  mpp2["10010000"] = true;

  return ;
}

int main()
{
  string str, str2, str3, str4;

  makeMap();
  while(!cin.eof() && getline(cin, str)){
    str2 = str3 = str4 = "";
    for(int i = 0; i < str.size(); i++){
      str2 += conv[str[i]];
    }

    for(int i = 0; i < str2.size(); i++){
      str4 += str2[i];
      if(mpp2[str4]){
	str3 += mpp1[str4];
	str4 = "";
      }
    }

    cout << str3 << endl;
  }

  return 0;
}

Measured memory_bytes: 0
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

A,B = inpl()
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B//2)
else:
    print(0)


Measured memory_bytes: 4464
inf = 10**15
mod = 10**9+7
n,k = map(int, input().split())
judge = [1 for i in range(n)]
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for num in a:
        judge[num-1] = 0
print(sum(judge))

Measured memory_bytes: 67832
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

s = gs
ans = []
s.each do |i|
  i = i.split("").first
ans << i
end
puts ans.join.upcase


Measured memory_bytes: 2044
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[] input=sc.nextLine().split(" ");
		long[] num = new long[input.length];
		for(int i=0;i<input.length;i++){
			num[i]=Integer.parseInt(input[i]);
		}
		
		long min = num[0];
		long max = num[0];
		long sum = num[0];
		
		for(int i=1;i<input.length;i++){
			if(max<num[i]){
				max=num[i];
			}
			if(min>num[i]){
				min=num[i];
			}
			sum=sum+num[i];
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

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

int main() {
    int X, N;
    cin >> X >> N;
    map<int, bool> P;
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        P[p] = true;
    }
    for (int i = 0; i <= 100; i++) {
        if (!P.count(X - i)) {
            cout << X - i << endl;
            return 0;
        }
        if (!P.count(X + i)) {
            cout << X + i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>

char s[100010];
void boom()
{
	printf("-1");
	exit(0);
}

int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[1]=='0'||s[n]=='1')boom();
	for(int i=1;i<=n/2;i++)
	if(s[i]!=s[n-i])boom();
	int now=2;
	printf("1 2\n");
	for(int i=2;i<n;i++)
	if(s[i]=='1')printf("%d %d\n",now,i+1),now=i+1;
	else printf("%d %d\n",now,i+1);
}

Measured memory_bytes: 1408
#include <stdio.h>

int get_min(int data[], int n);

int main(int argc, const char * argv[]) {
    
    int N;
    scanf("%d", &N);
    int length[2 * N];
    for(int i = 0; i < 2 * N; i++) {
        scanf("%d", &length[i]);
    }
    
    int forSum[N];
    for(int j = 0; j < N; j++) {
        int kushi1 = get_min(length, 2 * N);
        int kushi2 = get_min(length, 2 * N);
        if(kushi1 > kushi2) {
            forSum[j] = kushi2;
        } else {
            forSum[j] = kushi1;
        }
    }
    
    int sum = 0;
    for(int k = 0; k < N; k++) {
        sum += forSum[k];
    }
    
    printf("%d\n", sum);
    
    return 0;
}

int get_min(int data[], int n) {
    int min = data[0], mindex = 0;
    for(int i = 0; i < n; i++) {
        if(min > data[i]) {
            min = data[i];
            mindex = i;
        }
    }
    data[mindex] = 101;
    return min;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int output;

		Scanner scanner = new Scanner(System.in);

		int a = scanner.nextInt();
		int b = scanner.nextInt();


		if(	(a+b)%2 == 0)
			output = (a+b)/2;
		else output = (a+b)/2 + 1;

		System.out.println(output);

	}

}


Measured memory_bytes: 21588
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>

using namespace std;
typedef long long int lint;

#define SIZE 100

int mat[SIZE + 1][SIZE + 1] = { 0 };
int sum[SIZE + 1] = { 0 };

void print(int n) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			printf("%4d", mat[i][j]);
		}
		cout << endl;
	}
}

//Kadane's algorithm
int max_subarray(int n) {
	int max_ending_here, max_so_far;
	max_ending_here = max_so_far = sum[1];
	for (int i = 2; i <= n; i++) {
		max_ending_here = max(sum[i], max_ending_here + sum[i]);
		max_so_far = max(max_so_far, max_ending_here);
	}
	return max_so_far;
}

void AOJ0098() {
	int n;
	cin >> n;

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

	//print(n);

	//?????????????´???????????¨????
	for (int j = 1; j <= n; j++) {
		for (int i = 1; i <= n; i++) {
			mat[i][j] += mat[i - 1][j];
		}
	}

	//print(n);

	//i1 ?????¨ i2 ????????????????????????
	//	1	3	-9	2
	//	3	10	-10	7	i1
	//	-------------
	//	-5	13	-8	6
	//	0	13	-11	7	i2
	//	-------------

	int max_sub_matrix = -1e9;
	for (int i1 = 0; i1 < n; i1++) {
		for (int i2 = i1 + 1; i2 <= n; i2++) {
			for (int j = 1; j <= n; j++) {
				sum[j] = mat[i2][j] - mat[i1][j];
			}
			//maximum sum sequence ?????????
			int max_sum_sequence = max_subarray(n);
			if (max_sub_matrix < max_sum_sequence) max_sub_matrix = max_sum_sequence;
		}
	}
	cout << max_sub_matrix << endl;
	return;
}

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

Measured memory_bytes: 3140
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

using i64 = long long;
using P = pair<i64, i64>;

int main(){
    string s, t;
    cin >> s >> t;
    vector<vector<i64>> table(26, vector<i64>(s.length() + 1, -1));
    for(int i = s.length() - 1; i >= 0; --i){
        for(int j = 0; j < 26; ++j){
            if(s[i] == 'a' + j) table[j][i] = i;
            else table[j][i] = table[j][i + 1];
        }
    }
    i64 tidx = 0, idx = 0, cnt = 0;
    while(tidx != t.length()){
        i64 c = t[tidx] - 'a';
        if(idx >= s.length()){
            idx = 0;
            ++cnt;
            continue;
        }
        if(s[idx] == t[tidx]){
            ++tidx;
            ++idx;
            continue;
        }
        if(table[c][idx] == -1){
            if(idx == 0){
                cout << -1 << endl;
                return 0;
            }else{
                idx = 0;
                ++cnt;
                continue;
            }
        }else{
            idx = table[c][idx];
        }
    }
    cout << cnt * (i64)s.length() + idx << endl;
}


Measured memory_bytes: 21760
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
list($N)=sscanf(trim(fgets(STDIN)),"%d");
$sc = new Scanner();
$n = array();
for($i=0;$i<$N;$i++){
    $n[$i] = $sc->nextInt();
}
$sum = 0;
for($i=0;$i<$N-1;$i++){
    for($j=$i+1;$j<$N;$j++){
        if($i != $j){
            $sum = $sum + ($n[$i] * $n[$j]);
        }
    }
}
printf($sum);
//

Measured memory_bytes: 4728
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;
  cin >> n;

  if(n % 1000 == 0){
    cout << 0 << endl;
  }
  else{
    cout << (1000 - n % 1000) << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main
{	
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
	
		long a , b , c , d;
		a = scan.nextLong();
		b = scan.nextLong();
		c = scan.nextLong();
		d = scan.nextLong();
		
		long area1 = a * b , area2 = c * d;
		System.out.println(Math.max(area1 , area2));
	}
    
}










Measured memory_bytes: 9044
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    Move = 10**20
    for i in range(1, N + 1):
        if i ** 2 > N: break
        if N % i == 0:
            Move = min((i - 1) + (N // i - 1), Move)
    print(Move)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int n, f[10], num[10], len[12], s[12][8], w[10], allen, c0;
char al[11];

int dfs(int c){
	int i, j, k, ret = 0, t;
	if(c == c0 + 1){
		k = 1;
		for(j = 1;j < len[n - 1];j++) k *= 10;
		t = k * (num[s[n - 1][0]] + 1);
		for(i = 0;i < n - 1;i++){
			k = 1;
			for(j = 1;j < len[i];j++) k *= 10;
			t -= k * num[s[i][0]];
			if(t < 0)
				return 0;
			
		}
	}
	if(c == allen){
		int r;
		t = 0;
		for(k = 0;k < len[n - 1];k++)
			t = t * 10 + num[s[n - 1][k]];
		r = t;
		for(j = 0;j < n - 1;j++){
			t = 0;
			for(k = 0;k < len[j];k++)
				t = t * 10 + num[s[j][k]];
			r -= t;
			if(r < 0) break;
		}
		return r==0?1:0;
	}
	for(i = 0;i < 10;i++){
		if(!(w[c] && i == 0) && !f[i]){
			f[i] = 1;
			num[c] = i;
			ret += dfs(c + 1);
			f[i] = 0;
		}
	}
	return ret;
}

int main(void){
	int i, j, k, cnt, m;
	char c, str[12][9];
	while(1){
		scanf("%d%*c",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			j = 0;
			while((c = getchar()) != '\n')
				str[i][j++] = c;
			str[i][j] = '\0';
		}
		for(i = 0;i < n;i++)
			len[i] = strlen(str[i]);
		allen = 0;
		m = 0;
		do{
			for(j = 0;j < n;j++){
				if(len[j] > m){
					for(k = 0;k < allen;k++)
						if(str[j][m] == al[k]) break;
					if(k == allen){
						al[k] = str[j][m], al[k + 1] = '\0';
						allen++;
					}
					s[j][m] = k;
				}
			}
			cnt = 0;
			for(i = 0;i < n;i++)
				if(len[i] > m) cnt++;
			m++;
		}while(cnt);
		memset(w,0,sizeof(w));
		for(i = 0;i < n;i++)
			if(len[i] > 1) w[s[i][0]] = 1;
		c0 = 0;
		for(i = 0;i < n;i++)
			if(s[i][0] > c0) c0 = s[i][0];
		memset(f,0,sizeof(f));
		printf("%d\n",dfs(0));
	}
	return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;


signed main(){
    cin >> n;
    vector<int> a;
    REP(i,n){
        a.push_back(i+1);
    }
    vec(b,n);
    vec(c,n);
    input(b,n);
    input(c,n);
    int cntb,cntc,cnt=0;
    do{
        if(a==b){cntb = cnt;}
        if(a==c){cntc = cnt;}
        cnt++;
    }while(next_permutation(a.begin(),a.end()));
    print(abs(cntb-cntc));
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
n = int(input())
H = list(map(int,input().split()))
 
flag = 0
tmp = H[0]
d = len(H) - 1
if d == 0:
    print("Yes")
    exit()
 
if d == 1:
    if H[0] - 1 <= H[1]:
        print("Yes")
        exit()
    print("No")    
    exit()
 
H[0] -= 1
for i in range(1, len(H)):
    if  not(H[i - 1] > H[i] - 1):
        H[i] -= 1
    if H[i] > H[i + 1]:
        print("No")
        exit()

    if i + 1 == d:
        break    
print("Yes")

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


using namespace std;

int main(){
    int N,L,sum = 0,min = 99999;
    int ans,taste,sub;

    cin>>N>>L;

    for(int i = 1;i <= N; i++){
        taste = L+i-1;
        sum+=taste;
        if(min > abs(taste)){
            min = abs(taste);
            sub = taste;
        }
    }
    
    ans = sum - sub;

    
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  int N,M,X;
  cin>>N>>M>>X;
  int A[N];
  for(int i=0;i<N;i++){
    A[i]=0;
  }
  for(int i=0;i<M;i++){
    int x;
    cin>>x;
    A[x]++;
    
  }
  int sum=0;
  for(int i=X;i<N;i++){
    if(A[i]>0){
      sum++;
    }
  }
  cout<<min(sum,M-sum)<<endl;





}


  
  


Measured memory_bytes: 256
n, m = map(int, input().split())
src = set()
dst = set()
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        dst.add(b)
    if b == 1:
        dst.add(a)
    if a == n:
        src.add(b)
    if b == n:
        src.add(a)
print('POSSIBLE' if len(src & dst) > 0 else 'IMPOSSIBLE')

Measured memory_bytes: 18892
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

void print_arr(vector<int> A)
{
    rep (i, 0, A.size())
        if (i != A.size()-1)
            printf("%d ", A[i]);
        else
            printf("%d\n", A[i]);
}

int bubble_sort(int N, vector<int> &A)
{
    int cnt = 0;
    bool flg = true;
    while (flg) {
        flg = false;
        for (int i = A.size()-1; i >= 0; i--) {
            if (A[i] < A[i-1]) {
                swap(A[i], A[i-1]);
//                int tmp = A[i];
//                A[i] = A[i-1];
//                A[i-1] = tmp;
                ++cnt;
                flg = true;
            }
        }
    }
    return cnt;
}

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    rep (i, 0, N) cin >> A[i];

    int cnt = bubble_sort(N, A);
    print_arr(A);
    cout << cnt << endl;
}


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

using namespace std;

const int N = 1024;

char ans[N][N];


string s4[4] = {
  "abcc",
  "abdd",
  "ccab",
  "ddab"
};

string s5[5] = {
  "aabcc",
  "b.bdd",
  "baaee",
  "cde..",
  "cde.."
};

string s6[6] = {
  "aabb.c",
  "b..aac",
  "bcd...",
  ".cd.ee",
  "ffg..h",
  "..giih"
};

string s7[7] = {
  ".aaccdd",
  "b..eeff",
  "b..gghh",
  "ceg....",
  "ceg....",
  "dfh....",
  "dfh...."
};
int main() {
  int n;
  scanf("%d", &n);
  if (n <= 2) {
    puts("-1");
    return 0;
  }
  if (n == 3) {
    puts("aa.");
    puts("..b");
    puts("..b");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ans[i][j] = '.';
    }
    ans[i][n] = 0;
  }
  int r = n % 4;
  if (r)
    r += 4;
  assert(r <= n);
  if (r == 5) {
    for (int i = 0; i < r; ++i) {
      for (int j = 0; j < r; ++j) {
        ans[i][j] = s5[i][j];
      }
    }
  }
  else if (r == 6) {
    for (int i = 0; i < r; ++i) {
      for (int j = 0; j < r; ++j) {
        ans[i][j] = s6[i][j];
      }
    }
  }
  else if (r == 7) {
    for (int i = 0; i < r; ++i) {
      for (int j = 0; j < r; ++j) {
        ans[i][j] = s7[i][j];
      }
    }
  }
  else
    assert(r == 0);
  while (r < n) {
    assert(r + 4 <= n);
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
        ans[r+i][r+j] = s4[i][j];
      }
    }
    r += 4;
  }
  for (int i = 0; i < n; ++i) {
    printf("%s\n", ans[i]);
  }
  return 0;
}

Measured memory_bytes: 2176