akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;

    int len = S.size();

    ll ans = 0;
    for (int msk = 0; msk < 1 << (len - 1); msk++) {
        ll num = S[0] - '0';

        for (int i = 0; i < len - 1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }

            num = num * 10 + (S[i + 1] - '0');
        }

        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

bool was[N];

vector<int> g[N];

void dfs(int v) {
	was[v] = 1;
	for (auto u : g[v]) {
		if (!was[u]) dfs(u);
	}
}

void no() {
	puts("No");
	exit(0);
}

void yes() {
	puts("Yes");
	exit(0);
}

int main() {
	FREOPEN();
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		g[x].pb(y);
		g[y].pb(x);
	}
	for (int i = 1; i <= n; i++) {
		if (SZ(g[i]) & 1) no();
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (SZ(g[i]) >= 6) yes();
		if (SZ(g[i]) > 3) cnt++;
	}
	if (cnt > 2) yes();
	if (cnt <= 1) no();
	int v = 0, u = 0;
	for (int i = 1; i <= n; i++) {
		if (SZ(g[i]) == 4) {
			if (!v) v = i;
			else u = i;
		} 
	}
	for (auto go : g[v]) {
		int pred = v;
		int ver = go;
		while (ver != v && ver != u) {
			int nex = g[ver][0];
			if (g[ver][0] == pred) nex = g[ver][1];
			pred = ver;
			ver = nex;
		}
		if (ver == v) yes();
	}
	no(); 
	return 0;
}


Measured memory_bytes: 8064
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	A := make([]float64, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%f", &A[i])
	}
	
	var sum float64
	for _, a := range A {
		sum += 1 / a
	}
	
	fmt.Println(1/sum)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int n,m;
void proc(){
  int d1[100],d2[100];
  int sum1=0,sum2=0;
  rep(i,n){
    cin>>d1[i];
    sum1+=d1[i];
  }
  rep(i,m){
    cin>>d2[i];
    sum2+=d2[i];
  }
  if((sum1+sum2)&1){
    cout<<-1<<endl;
    return;
  }
  int msum=400,m1,m2;
  rep(i,n){
    rep(j,m){
      if(sum1-d1[i]+d2[j]==sum2-d2[j]+d1[i]&&msum>d1[i]+d2[j]){
        msum=d1[i]+d2[j];
        m1=d1[i];m2=d2[j];
      }
    }
  }
  if(msum!=400){
    cout<<m1<<" "<<m2<<endl;
  }else{
    cout<<-1<<endl;
  }
}

int main(){
  while(true){
    cin>>n>>m;
    if(!n&&!m)return 0;
    proc();
  }
}

Measured memory_bytes: 1160
n, t = map(int, input().split())
cost = []
time = []
for i in range(n):
    c, ti = map(int, input().split())
    if ti <= t:
        cost.append(c)
        time.append(ti)
cost = sorted(cost)
if time != []:
    print(cost[0])
else:
    print('TLE')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for (i = 0; i < n; i++) {
        cin >> v >> d;
        for (j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    
    rec(r, 0);
    
    for (i = 0; i < n; i++) print(i);
    
    return 0;
}


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

#define L 10
#define MAX 100000000
#define D 8

int main() {
  string s[2];
  int n, num[2][L], sum[L], dig[D+1];
  for(int i=0; i<=D; ++i) dig[i] = i ? 10*dig[i-1] : 1;
  cin >> n;
  while(n--) {
    cin >> s[0] >> s[1];
    if(s[0].length() > 80 || s[1].length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    for(int i=0; i<2; ++i) {
      for(int j=0; j<L; ++j) num[i][j] = 0;
      int len = s[i].length();
      for(int j=0; j<len; ++j) {
        num[i][j/D] += dig[j%D]*(s[i][len-1-j] - '0');
        //cout << i << ", " << j << " "<< num[i][j/D] << endl;
      }
    }
    int carry = 0;
    for(int i=0; i<L; ++i) {
      sum[i] = num[0][i] + num[1][i] + carry;
      carry = sum[i] / MAX;
      sum[i] %= MAX;
    }
    if(carry > 0) {
      cout << "overflow" << endl;
    }else {
      string ans;
      bool st = false;
      for(int i=L-1; i>=0; --i) {
        if(sum[i] == 0 && st) {
          ans += "00000000";
        }else if(sum[i] > 0) {
          for(int j=D-1; j>=0; --j) {
            int d = (sum[i]%dig[j+1])/dig[j];
            if(d > 0 || st) {
              ans += (char)(d + '0');
              st = true;
            }
          }
        }
      }
      cout << (ans.length() ? ans : "0") << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n;
  cin >> n;
  ll dp[n];
  dp[0] = 1;
  dp[1] = 1;
  FOR(i, 2, n+1) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[n] << endl;

  
  return 0;
}



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

int main(){
	string s;
	int a,b,c;
	int ch=0,hi=0;
	while(cin >> s){
		sscanf(s.c_str(),"%d,%d,%d",&a,&b,&c);
		if(a*a+b*b==c*c){
			ch++;
		}else if(a==b){
			hi++;
		}
	}
	cout << ch << endl << hi << endl;
}

Measured memory_bytes: 0
import numpy as np
N = int(input())
T,A = input().split()

Ave = [0]*N
gosa = [0]*N

H = input().split()

for i in range(N):
    H[i] = int(H[i])
    gosa[i] = abs(float(A) - float(T) + 0.006*H[i])

print(str(int(np.argmin(np.array(gosa)))+1))

Measured memory_bytes: 16032
from math import gcd


N, *A = map(int, open(0).read().split())

acc_l = [0] * (N + 1)
acc_r = [0] * (N + 1)
for i in range(1, N + 1):
    acc_l[i] = gcd(acc_l[i - 1], A[i - 1])
    acc_r[i] = gcd(acc_r[i - 1], A[-i])
ans = 0
for i in range(N + 1):
    ans = max(ans, gcd(acc_l[i], acc_r[N - i - 1]))
print(ans)


Measured memory_bytes: 20684
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N = 2e3+20;
const int INF = 1e9;

vector<int> adj[N];

int main(){

	fastio;
	int n,x,y;
	cin >> n >> x >> y;
	for(int i = 1; i < n; ++i){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[x].pb(y);
	adj[y].pb(x);

	vector<int> ans(n+1,0);
	for(int i = 1; i <= n; ++i){
		queue<int> q;
		vector<int> dist(n+1,INF);
		q.push(i); dist[i] = 0;
		while(sz(q)){
			int u = q.front(); q.pop();
			for(int v : adj[u]){
				if(dist[v] == INF){
					dist[v] = dist[u] + 1;
					ans[dist[v]]++;
					q.push(v);
				}
			}
		}
	}

	for(int i = 1; i < n; ++i){
		cout << ans[i]/2 << '\n';
	}

	return 0;
}
//

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

lint n;
vector<int> u, v;

lint vertice_count() {
    lint res = 0;
    for (lint i = 0; i < n; i++) {
        res += (i + 1 - 0) * (n - i);
    }
    return res;
}

lint edge_count(int l, int r) {
    if (l > r) {
        swap(l, r);
    }
    return 1LL * (l + 1 - 0) * (n - r);
}

lint edges_count() {
    lint res = 0;
    for (int i = 0; i < n - 1; i++) {
        res += edge_count(u[i], v[i]);
    }
    return res;
}

lint solve() {
    return vertice_count() - edges_count();
}

int main() {
    cin >> n;
    u.resize(n - 1);
    v.resize(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    cout << solve() << endl;
}

Measured memory_bytes: 4760
fun Boolean.toInt(): Int = if (this) 1 else 0
fun main(args: Array<String>?): Unit {
    val n = readLine()!!.trim().toLong()
    val s = readLine()!!.trim()
    val memo = Array(s.length){i -> Array(2){Array(11){LongArray(s.length - i){-1L}}}}
    val digit: LongArray = LongArray(10){(0 until it).fold(1L){a, _ -> a * 10}}
    fun sub(i: Int, zeroAllow: Boolean, d: Int, c: Int): Long {
        if (c < 0) return n + 1L
        if (i == s.length) return if (d == 10) 0L else n + 1L
        if (c >= s.length - i) {
            return when(d) {
                10 -> if (s.length - i == 1) n + 1L else if ((s.length - i) % 2 == 0) 0L else 10L
                0 -> sub(i + 1, zeroAllow, 10, c - 1)
                else -> if (zeroAllow) sub(i + 1, true, d - 1, c - 1) else sub(i + 1, true, d - 1, c - 1) + digit[d]
            }
        }
        if (memo[i][zeroAllow.toInt()][d][c] >= 0) return memo[i][zeroAllow.toInt()][d][c]
        memo[i][zeroAllow.toInt()][d][c] = when(d) {
            10 -> when(s[i]){
                '+' -> (0..9).map{j -> sub(i + 1, false, j, c)}.min()!!
                else -> (0..9).map{j -> sub(i + 1, false, j, c - 1)}.min()!!
            }
            0 -> when(s[i]) {
                '+' -> sub(i + 1, false,10, c - 1)
                '0' -> sub(i + 1, false, 10, c)
                else -> Math.min(sub(i + 1, false, 10, c - 1), sub(i + 1, false, 10, c) + (s[i] - '0'))
            }
            else -> when(s[i]) {
                '+' -> if (zeroAllow) sub(i + 1, true, d - 1, c - 1) else (sub(i + 1, true, d - 1, c - 1) + digit[d])
                '0' -> if (zeroAllow) sub(i + 1, true, d - 1, c) else (sub(i + 1, true, d - 1, c - 1) + digit[d])
                else -> if (zeroAllow) Math.min(sub(i + 1, true, d - 1, c - 1), sub(i + 1, true, d - 1, c) + (s[i] - '0') * digit[d]) else Math.min(sub(i + 1, true, d - 1, c - 1) + digit[d], sub(i + 1, true, d - 1, c) + (s[i] - '0') * digit[d])
            }
        }
        if (memo[i][zeroAllow.toInt()][d][c] > n) {
            memo[i][zeroAllow.toInt()][d][c] = n + 1L
        }
        return memo[i][zeroAllow.toInt()][d][c]
    }
    println((0 .. s.length).filter{c -> (0 .. 9).map{d -> sub(0, false, d, c)}.any{it <= n}}.min() ?: -1)
}




Measured memory_bytes: 207744
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define int long long
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N=1e5+5, MOD=1e9+7, B=12;
const lint INF=1e18;
lint _add(lint x, lint y) {
    lint ret=x+y;
    while(ret<0LL) ret+=MOD;
    return ret;
}
lint _mult(lint x, lint y) {
    x%=MOD; y%=MOD;
    lint ret=x*y;
    ret%=MOD;
    while(ret<0LL) ret+=MOD;
    return ret;
}
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo; exp >>= 1;
  }
  return result;
}
int x, dp[B][10], pw[B], dig[B];
int solve(int k)
{
    int ans = 0, curr=0, prv, itr=-1;
    for(int i = B-1; i >= 1; i--)
    {
        if(dig[i-1] >= k)
        {
            continue;
        }
        curr += dig[i-1];
        bool flag=false;
        for(int j = 1; j < 10; j++)
        {
            if(curr + dp[i][j] >= k)
            {
                prv = j;
                itr = i-1;
                ans += pw[i]*j;
                flag=true;
                break;
            }
            else
            {
                //cout << i << " " << j << " " << curr << " " << dp[i][j] << endl;
                curr += dp[i][j];
            }
        }
        if(flag) break;
    }
    //cout << itr << " " << prv << " - " << ans << endl;
    if(itr==-1)
    {
        return k;
    }
    int i = itr;
    while(i>=0)
    {
        for(int j = max(0LL, prv-1); j <= min(prv+1, (int) 9); j++)
        {
            if(curr + dp[i][j] >= k)
            {
                prv = j;
                itr = i-1;
                ans += pw[i]*j;
                break;
            }
            else
            {
                curr += dp[i][j];
            }
        }
        i--;
    }
    return ans;
}
signed main()
{
    pw[0]=1;
    for(int i = 1; i < B; i++)
    {
        pw[i] = pw[i-1]*10;
    }
    for(int i = 0; i < 10; i++)
    {
        dp[0][i]=1;
    }
    dig[0] = 9;
    for(int i = 1; i < B; i++)
    {
        dp[i][0] = dp[i-1][1] + dp[i-1][0];
        dp[i][9] = dp[i-1][8] + dp[i-1][9];
        dig[i] = dp[i][9] + dig[i-1];
        for(int j = 1; j < 9; j++)
        {
            dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j+1];
            dig[i] += dp[i][j];
        }
    }
    cin >> x;
    cout << solve(x);
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
grid = [input() for _ in range(h)]

INF = 10**10
dist = [[INF for _ in range(w)] for _ in range(h)]
dist[0][0] = 0

DX = [0, 0, 1, -1]
DY = [1, -1, 0, 0]

def bfs(sx, sy):
    d = deque([[sx, sy]])
    while len(d) > 0:
        x, y = d.popleft()
        for dx, dy in zip(DX, DY):
            nx = x+dx; ny = y+dy
            if 0 <= nx < h and 0 <= ny < w:
                if grid[nx][ny] == "." and dist[nx][ny] > dist[x][y]+1:
                    dist[nx][ny] = dist[x][y]+1
                    d.append([nx, ny])

bfs(0, 0)

if dist[h-1][w-1] == INF:
    print(-1)
else:
    ans = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == ".":
                ans += 1
    print(ans-dist[h-1][w-1]-1)




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

uint64_t su(uint64_t s,uint64_t n,vector<uint64_t> arr)
{
    uint64_t r=0;
    rep2(i,s,n)
    {
      r+=arr[i];
    }
    return r;
}
uint64_t ki(uint64_t n)
{
    uint64_t t=0;
    rep2(j,1,n+1)t+=j;
    return 10000000*t/n;
}

int main()
{
    cout<<fixed<<setprecision(10);
    uint64_t n,k;
    cin >> n >> k;
    vector<uint64_t> inp(n);
    vector<uint64_t> arr(n);
    rep(i,n){
    cin >> inp[i];
      arr[i]=ki(inp[i]);
    }
  
  uint64_t t=su(0,k,arr);
  uint64_t m=t;
  uint64_t b=t;
    rep2(i,1,n-k+1){
        t=b-arr[i-1]+arr[i+k-1];
        if(m < t){
            m=t;
        }
      b=t;
    }
    cout << (m/10000000.0) << endl;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


int main(){
    string S;
    cin >> S;
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    map<char, int> mp;
    for(char c: S){
        mp[c]++;
    }
    if(mp.size() != 26){
        for(char c = 'a'; c <= 'z'; c++){
            if(!mp.count(c)){
                cout << S << c << endl;
                return 0;
            }
        }
    }

    string t = S;
    next_permutation(S.begin(), S.end());

//    cout << S << endl;

    string ans = "";
    for(int i = 0; i < S.size(); i++){
        ans += S[i];
        if(S[i] > t[i]) {
            break;
        }
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> c(n, vector<int>(m + 1));
    ll min_cost = LONG_LONG_MAX;
    for (int i = 0; i < n; i++) {
        cin >> c[i][0];
        for (int j = 1; j <= m; j++)
            cin >> c[i][j];
    }
    for (int bit = 1; bit < (1 << n); bit++) {
        ll cost = 0;
        vector<int> level(m + 1, 0);
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                cost += c[i][0];
                for (int j = 1; j <= m; j++)
                    level[j] += c[i][j];
            }
        }
        bool ok = true;
        for (int j = 1; j <= m; j++) {
            // cout << level[j] << " ";
            if (level[j] < x) {
                ok = false;
                break;
            }
        }
        // cout << endl;
        if (ok)
            min_cost = min(min_cost, cost);
    }
    if (min_cost == LONG_LONG_MAX)
        cout << "-1";
    else
        cout << min_cost;
}


Measured memory_bytes: 3652
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    my_putchar_unlocked(x[i]);
  }
}
int K;
string S;
int main(){
  wmem = memarr;
  rd(K);
  rd(S);
  if(S.size() > K){
    S = S.substr(0, K) + "...";
  }
  wt_L(S);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int K;
// string S;
// {
//   rd(K,S);
//   if(S.size() > K){
//     S = S.substr(0, K) + "...";
//   }
//   wt(S);
// }


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MAXN = (int)1e5 + 10;
string s;
int DP[MAXN];

bool isPossible()
{
	CLEAR(DP, 0);
	
	DP[0] = 1;	
	int n = sz(s);
	for(int i = 0; i < n; ++i)
	{
		if(DP[i] == 0) continue;
		if(i + 5 <= n && s.substr(i, 5) == "dream") DP[i + 5] = 1;
		if(i + 7 <= n && s.substr(i, 7) == "dreamer") DP[i + 7] = 1;
		if(i + 5 <= n && s.substr(i, 5) == "erase") DP[i + 5] = 1;
		if(i + 6 <= n && s.substr(i, 6) == "eraser") DP[i + 6] = 1;
	}
	return DP[n] == 1;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> s;

	cout << (isPossible() == true ? "YES" : "NO") << endl;

	return 0;
}

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

#define     ll      long long int

ll n, k;
const ll mod = 1000000007;

int main( )
{
    ll i, j, s, p;
    ll ans = 0;
    cin >> n >> k;
    p = ((k * (k - 1)) / 2) % mod;
    for (i = k; i <= n + 1; i++) {
        //cout << p << '\n';
        ans = (ans + (i * n - 2 * p + 1)) % mod;
        p = (p + i) % mod;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <limits>
#include <math.h>
#define ll long long
using namespace std;
int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int e_mx,e_mx_index,e_mx2,o_mx,o_mx_index,o_mx2;
vector<int> ecnt(100010),ocnt(100010);
int main() {
    double n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    cout << ceil((n-1)/(k-1)) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
	char al[6] = { "ABCDE" };
	while (true){
		int p, a, b, max = 0;
		for (int i = 0; i < 5; i++){
			cin >> a >> b;
			if (a == 0 && b == 0)return 0;
			if (max < a + b){
				max = a + b;
				p = i;
			}
		}
		cout << al[p] << " " << max << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
long long n, x, k, c, m, mm, i, j, b[100005], f[100005], g[100005];
int main(){
	scanf("%lld%lld", &m, &k);
	printf("%lld\n", m*k);
	return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

int n;

int main(){
  cin >> n;
  n -= (n/10)*10;
  if(n == 3){
    cout << "bon" << endl;
  }else if(n == 0 || n==1 || n==6 || n==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
int dp[13][203];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int A,B,C;cin>>A>>B>>C;
        //if(A+B+C==0) break;
        
        int now=0;
        int ans=INF;
        
        while(now<=7200){
            if(now%60<=C%60){
                if(now%60+A>=C%60){
                    ans=min(ans,now/60*60+C);
                }
            }else{
                if((now+A)%60>=C%60&&now%60+A>=60){
                    ans=min(ans,(now+A)/60*60+C);
                }
            }
            
            now+=A+B;
        }
        
        if(ans==INF) cout<<-1<<endl;
        else cout<<ans<<endl;
        
        break;
    }
}



Measured memory_bytes: 3216
a,b,k = map(int,input().split())
ans = set()
for i in range(a,a+k):
    if i <= b:
        ans.add(i)
for i in range(b-k+1,b+1):
    if i >= a:
        ans.add(i)
ans = sorted(list(ans))
for i in ans:
    print(i)

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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			StringBuilder sb = new StringBuilder ();
			for(int i = 0; i < str.length();i++) {
				sb.append(str.charAt(i));
				if(i == 3) sb.append(" ");
			}

			System.out.println(sb);
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}

}


Measured memory_bytes: 21076
m = 100010
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
a = primes(m * 2+ 100)
n = int(input())

from bisect import bisect_left
def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def do(x):
    if x in a and (x+1)//2 in a:
        return True
dat = [-1] * m
count = 0
for i in range(len(a)):
    if a[i] > m:
        break
    if do(a[i]):
        count += 1
    dat[a[i]] = count
c = -1
for i in range(m):
    if dat[i] != -1:
        c = dat[i]
    else:
        dat[i] = c
dat[0] = dat[1] = 0

for _ in range(n):
    l, r = map(int, input().split())
    print(dat[r] - dat[l-1])


Measured memory_bytes: 53720
H,W = map(int,input().split())
S = []
for i in range(H):
    s = input()
    S.append(s)

ans = []


def calc(S,i,j):
    n=0
    if (i-1)>=0:
        if S[i-1][j]=="#":
            n += 1
        if (j-1)>=0:
            if S[i-1][j-1]=="#":
                n += 1
        if (j+1)<W:
            if S[i-1][j+1]=="#":
                n += 1
    if (j-1)>=0:
        if S[i][j-1]=="#":
            n += 1
        if (i+1)<H:
            if S[i+1][j-1]=="#":
                n += 1
    if (i+1)<H:
        if S[i+1][j] == "#":
            n += 1
        if (j+1)<W:
            if S[i+1][j+1]=="#":
                n += 1
    if (j+1)<W:
        if S[i][j+1]=="#":
            n += 1
    return n

for i in range(H):
    s = ""
    c = [-1]*W
    for j in range(W):
        if S[i][j]==".":
            n = calc(S,i,j)
            c[j]=n
    for k in range(W):
        if c[k]==-1:
            s = s+"#"
        else:
            s = s+str(c[k])
    ans.append(s)

for i in range(H):
    print(ans[i])

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18

using Field = vector<vector<char>>;
Field F;
int H,W;
int num = 0;

void bfs(int y, int x){
    vector<vector<int>> d(H,vector<int>(W,-1));
    d[0][0] = 1;
    queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    vector<int> k = {-1,0,1,0};

    while(!q.empty()){
        pair<int,int> u = q.front();
        q.pop();
        rep(i,4){
            if(u.first+k[i] >= 0 && u.first+k[i] < H && u.second+k[3-i] >= 0 && u.second+k[3-i] < W){
                if(F[u.first+k[i]][u.second+k[3-i]] == '.'){
                    if(d[u.first+k[i]][u.second+k[3-i]] == -1){
                        d[u.first+k[i]][u.second+k[3-i]] = d[u.first][u.second] + 1;
                        q.push(make_pair(u.first+k[i],u.second+k[3-i]));
                    }
                }
            }
        }
    }
    num = d[H-1][W-1];
}



int main(){
    cin >> H >> W;
    F = vector<vector<char>>(H,vector<char>(W));
    rep(i,H)rep(j,W){
        cin >> F[i][j];
    }
    bfs(0,0);
    if(num == -1) cout << -1 << endl;
    else{
        int sum = 0;
        rep(i,H)rep(j,W){
            if(F[i][j] == '#') sum++;
        }
        int ans = H * W - num - sum;
        cout << ans << endl;
    }
    

}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL X,Y,Z;

void solve(){
	swap(X,Y);
	swap(X,Z);
}

int main(){
    cin >> X >> Y >> Z;
 
    solve();

    cout << X << " " << Y << " " << Z << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll inf=1e9;

int main() {
  vector<ll> dpe(1e6+1,inf);
  vector<ll> dpo(1e6+1,inf);
  dpe[0]=0;
  dpo[0]=0;
  vector<ll> a;
  for(ll i=1;i*(i+1)*(i+2)/6<dpe.size();i++) {
    a.push_back(i*(i+1)*(i+2)/6);
  } 
  for(ll i=0;i<a.size();i++) {
    if(a[i]%2) {
      for(ll j=0;j<dpe.size();j++) {
        if(a[i]+j>dpe.size()-1) break;
        dpe[j+a[i]]=min(dpe[j+a[i]],dpe[j]+1);
        dpo[j+a[i]]=min(dpo[j+a[i]],dpo[j]+1);
      }
    }
    else {
      for(ll j=0;j<dpe.size();j++) {
        if(a[i]+j>dpe.size()-1) break;
        dpe[j+a[i]]=min(dpe[j+a[i]],dpe[j]+1);
      }
    }
  }
  while(1) {
    ll n;
    cin >> n;
    if(n==0) break;
    cout << dpe[n] << " " << dpo[n] << endl;
  }
}


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

int progressDif(long* n){
  int progress = 0;
  if(*n % 2 == 1)
    (*n)--;
  progress += (*n) / 2;
  return progress;
}

signed main() {
  long a,b;
  int k;
  cin >> a >> b >> k;
  for(int i = 0; i < k / 2; i++){
    int difA = progressDif(&a);
    a -= difA;
    b += difA;
    int difB = progressDif(&b);
    a += difB;
    b -= difB;
  }

  if(k % 2 == 1){
    int dif = progressDif(&a);
    a -= dif;
    b += dif;
  }


  cout << a << " " << b << endl;

}

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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a;
  ll sum[200000];

  sum[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a;
    sum[i] = sum[i - 1] + a;
  }

  ll minv = LLONG_MAX;
  for (ll i = 1; i < n; i++) {
    minv = min(minv, llabs(sum[n] - sum[i] - sum[i]));
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      while ((a % 2) == 0) {
        cnt++;
        a /= 2;
      }
    }

    System.out.println(cnt);

  }
}

Measured memory_bytes: 48200
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;

int main()
{
    while (true) {
        int n, a, b, c, x;
        cin >> n >> a >> b >> c >> x;
        if (n == 0 and a == 0 and b == 0 and c == 0 and x == 0) {
            break;
        }
        vector<int> val(n);
        for (int i = 0; i < n; i++) {
            cin >> val[i];
        }
        int j = 0;
        bool flag = true;
        int turn = 0;
        for (int i = 0; i <= 10000; i++) {
            if (val[j] == x) {
                j++;
                if (j == n) {
                    flag = false;
                    turn = i;
                    break;
                }
            }
            x = (a * x + b) % c;
        }
        if (flag) {
            cout << -1 << endl;
        } else {
            cout << turn << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int n;
    cin>>n;
    int a[n];
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
        sum%=MOD;
    }
    int ans=0;
    rep(i,n){
        sum-=a[i];
        while(sum<0)sum+=MOD;
        ans+=a[i]*(sum);
        ans%=MOD;
        while(ans<0)ans+=MOD;
    }
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;




    



}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;


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

	vector<int> p(N);
	vector<int> sorted(N);
	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
		sorted[i] = p[i];
	}
	sort(sorted.begin(), sorted.end());

	//for (int i = 0; i < N; i++)
	//{
	//	cout << p[i] << ", " << sorted[i] << endl;
	//}


	vector<int> indexes;
	for (int i = 0; i < N; i++)
	{
		if (p[i] != sorted[i]) {
			indexes.push_back(i);
		}
	}

	//for (int i = 0; i < indexes.size(); i++)
	//{
	//	cout << indexes[i] << endl;
	//}
	

	if (indexes.size() == 0) {
		cout << "YES" << endl;
		return 0;
	}

	if (indexes.size() > 2) {
		cout << "NO" << endl;
		return 0;
	}


	int i = indexes[0];
	int j = indexes[1];
	if (p[i] == sorted[j] && p[j] == sorted[i]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  vi a(2);
  rep(i,0,2) cin>>a[i];
  rep(i,1,4) {
    int f = 0;
    rep(j,0,2) if(a[j] == i) f = 1;
    if(!f) {
    cout<<i<<endl;
    return 0;
    }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    string s;
    cin >> s;
    int gnum = 0, pnum = 0;
    REP(i, s.size()){
        if(s[i] == 'g') gnum++;
        else pnum++;
    }
    
    cout << ((s.size() / 2) - pnum) << endl;
}


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

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int total = 0;
    for(int i = 1; i <= n; i++){
        int sum = findSumOfDigits(i);
        if(sum >= a && sum <= b){
            total += i;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Nmax 100005
#include <cmath>
#define INF 0x3f3f3f3f

using namespace std;

ifstream f("1.in");
ofstream g("1.out");

long long n, k, dp[105][Nmax];
long long w, v, W, ans;

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

    for (int i = 1; i <= n; i++)
    {
        cin >> w >> v;
        for (int j = 0; j <= W; j++)
            if(j>=w) dp[i][j]=max(dp[i-1][j], dp[i-1][j-w]+v);
            else dp[i][j]=dp[i-1][j];
    }
   /* for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= W; j++)
            cout << dp[i][j] << " ";
        cout << '\n';
    }*/

    for (int i = 1; i <= W; i++)
        ans=max(ans, dp[n][i]);
    cout << ans;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  int n,cnt=0;
  cin >> n;

  vt<int> L(n);
  rep(i,n) cin >> L[i];

  sort(L.begin(), L.end());

  rep(i,n){
    rep(j,n){
      rep(k,n){
        if(L[i]<L[j] && L[j]<L[k]){
          int m = max({L[i],L[j],L[k]});
          if(L[i]+L[j]+L[k]-m > m){
            cnt++;
          }
        }
      }
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	char s[100001]; cin >> s;

	int i = 0;
	while (s[i]) {
		if (i % 2 == 0) {
			cout << s[i];
		}
		i++;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
stack<int>ans;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int>b(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
        b[i]--;
    }
    for(int i=0;i<n;i++)
    {
        int id=-1;
        for(int j=0;j<b.size();j++)
        {
            if(b[j]==j)id=j;
        }
        if(id==-1)
        {
            printf("-1\n");return 0;
        }
         b.erase(b.begin()+id);
        ans.push(id+1);
    }
    while(ans.size())
    {
        printf("%d\n",ans.top());
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    ll a;
    map<ll, ll> mp;
    REP(i, n){
        cin >> a;
        mp[a]++;
    }
    if(mp.size() >= 4){
        cout << "No" << endl;
        return 0;
    }
    if(mp.size() == 1){
        if(mp[0] == n) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if(n % 3){
        cout << "No" << endl;
        return 0;
    }
    vll num;
    for(auto v : mp) num.push_back(v.first);
    if(mp.size() == 2){
        if(mp[num[1]] == 2 * n / 3) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if(mp.size() == 3){
        ll x = 0;
        REP(i, 3) x ^= num[i];
        if(mp[num[0]] == mp[num[1]] && mp[num[1]] == mp[num[2]] && x == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>

#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
 
  if(c-(a-b)>0){
  printf("%d",c-(a-b));
  }else{
  printf("%d",0);
  }
    return 0;
}


Measured memory_bytes: 128
"""
AtCoder Beginner Contest 163  E

・大きいものほど移動距離を増やしたいので、端にもっていく
を真っ先に思いつくので、大きいものから移動距離が大きくなるように配置すると、例２が答えと一致しない。
手を動かしてみると、
・大きいものから端にもっていく
は正しいそうだが、
・移動距離が最も大きくなるように
が当てはまらないことが見えてくる。

大きいものからi人目まで並べるときに、左側にx人配置されているなら、残りのi-x人が右側に配置されている。
・一人目は左右の端のいずれかに配置されうる
・二人目は、左端、その右隣、右端、その左隣、に配置されうる
・n人目は、左端からn番目まで、右端からn番目までの場所に配置されうる
このような感じで、左にx人、右にy人配置されている場合のうれしさの最大値を求めていって、最終的にx+y=Nになるようなdp[x][y]の最大値を求めるとよい

# ~~ 以下考察時 ~~
・大きいものから
・左右の端のどっちかに持っていく

のがいいっぽい


556111の例について、

大きい順から6を左右に振った場合
次に大きい5について、↑でできた2パターンかにおいて左右のどっちかに振った場合、
次に大きい5について、↑でできた4パターンかにおいて左右のどっちかに振った場合、
・・・

みたいな形でやるのがいいか？
2*2*2*2*... みたいな形で増えていかないか？
→NO。最初の6は左右の端のどちらか。次の5が左右から二つ分のいずれか。...。最後の1が左端〜右端で全ての場所に当てうるので、計算量的にはN**2ですむ
 N <= 2000 なので、十分間に合う

 ・例えば上の例で6について左右の端のいずれかにせず、全ての場所を試してもいいのでは？
 →恥に持っていくのが一番点が増えるので意味なし。のちの操作も煩雑になる＆分岐がややこしいのよろしくない。
"""



N = int(input())
A = list(map(int, input().split()))
infants = []
for i,a in enumerate(A):
    infants.append((a, i))

infants.sort(reverse=True)
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]


# i番目の幼児まで見るとき
for i in range(N):
    """
    i番目の幼児を配置する方法として、
    ・左側の１～i番目として配置
    ・右側の１～i番目として配置
    の方法がある
    
    左のj人目として配置した場合、右にはi-j人配置されていることになる（右も同じ）
    例：５番目を左の二人目として配置したら、右には残りの３人がいる計算になる

    """
    for j in range(i+1):

        # 左側に配置したとき
        dp[j+1][i-j] =    max(dp[j+1][i-j], dp[j][i-j] + infants[i][0] * abs(infants[i][1] - j))
            
        # 右側に配置したとき
        dp[i-j][j+1] = max(dp[i-j][j+1], dp[i-j][j] + infants[i][0] * abs(infants[i][1] - (N-1 - j)))


ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])

print(ans)


Measured memory_bytes: 107468
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n,a,b,f=1,s=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		int c=ceil((long double)f/a),d=ceil((long double)s/b);
		f=max(c,d)*a;
		s=max(c,d)*b;
	}
	cout<<s+f<<endl;
	getchar(); getchar();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int p, q, r;
    scanf("%d%d%d", &p, &q, &r);
    printf("%d\n", p+q+r - max({p, q, r}));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;

    if(abs(a-b) <= v*t - w*t)cout << "YES\n";
    else cout << "NO\n";

    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n, money=1000;
  cin>>n;
  vector<ll> a(n+1,0);
  for (ll i = 0;i<n;i++){
    cin >> a[i];
  }
  ll kabu=0;
  for (ll i = 0; i < n;i++){
    if(a[i]<a[i+1]){
      kabu = money / a[i];
      money -= kabu * a[i];
      money += kabu * a[i + 1];
      kabu = 0;
    }
  }
  cout << money << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int q1, zidori, hutuu, q2, yosan;
	int ans;
	
	while (1){
		scanf("%d", &q1);
		if (q1 == 0){
			break;
		}
		scanf("%d%d%d%d",  &yosan, &zidori, &hutuu, &q2);
		
		ans = -1;
		for (int i = q2; i >= 1; i--){
			int mon = yosan;
			mon -= zidori * i;
			if (mon >= 0 && (i + mon / hutuu) >= q1){
				ans = i;
				break;
			}
		}
		
		if (ans == -1){
			printf("NA\n");
		}
		else {
			printf("%d %d\n", ans, (yosan - ans * zidori) / hutuu);
		}
	}
	return (0);
}

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

#define    ll     long long int

int main()
{
    ll n, m;
    vector< pair<int, int> > v;
    ll i, j, k;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
        cin >> j >> k;
        v.push_back(make_pair(j, k));
    }
    sort(v.begin(), v.end());
    ll s = 0;
    for (i = 0; i < n; i++) {
        j = v[i].first;
        k = v[i].second;
        if (k <= m) {
            s += (k * j);
            m -= k;
        }
        else {
            s += m * j;
            break;
        }
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 1400