akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
	ll n, m;
	//ll a, b;
	//ll x, y;
	ll k;
	ll l_ans = 0;

	cin >> n;

	map<ll, ll> a;
	ll tmp;
	rep(i, n) {
		cin >> tmp;
		++a[tmp];
	}

	ll q;
	cin >> q;
	ll b, c;
	vector<ull> sum(q, 0);
	ull base = 0;
	for (auto itr = a.begin(); itr != a.end(); itr++) {
		base += itr->first * itr->second;
	}

	rep(i, q) {
		cin >> b >> c;
		base += (c - b) * a[b];
		a[c] += a[b];
		a[b] = 0;
		sum[i] = base;
	}

	rep(i, q) {
		cout << sum[i] << "\n";
	}

	return;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 10036
n = int(input())
a = list(map(int, input().split()))
print(*a, sep=' ')

for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        a[j] = v
        j -= 1
    print(*a, sep=' ')


Measured memory_bytes: 5976
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;

int cnt[100010];

int main() {

  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    cnt[l]++;
    cnt[r + 1]--;
  }
  for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += cnt[i] == m;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0;
  for(c = getchar();c < '0' || c > '9';c = getchar());
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res;
}

int main(){
  int a = getint(), b = getint(), c = getint();
  printf("%d\n",min(b / a,c));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r){
	int x,i,j,t;
	x=A[r];
	i=p-1;
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			t=A[i];A[i]=A[j];A[j]=t;
		}
	}
	t=A[i+1];A[i+1]=A[r];A[r]=t;
	return i+1;
}

int main(){
	int i,q;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	
	q=partition(0,n-1);
	
	for(i=0;i<n;i++){
		if(i)printf(" ");
		if(i==q)printf("[");
		printf("%d",A[i]);
		if(i==q)printf("]");
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;


int dpt[111][111];
int dpc[111][111];
int n, m, a, b, cost, t, k, p, q, r;

int main(){
	while (cin >> n >> m&&n + m){
		REP(i, 111){
			REP(j, 111){
				dpt[i][j] = INF;
				dpc[i][j] = INF;
			}
		}
		REP(i, n){
			cin >> a >> b >> cost >> t;
			dpt[a][b] = min(dpt[a][b], t);
			dpt[b][a] = min(dpt[a][b], t);
			dpc[a][b] = min(dpc[a][b], cost);
			dpc[b][a] = min(dpc[a][b], cost);
		}
		FOR(l, 1, m + 1){
			FOR(i, 1, m + 1){
				FOR(j, 1, m + 1){
					dpt[i][j] = min(dpt[i][j], dpt[i][l] + dpt[l][j]);
					dpc[i][j] = min(dpc[i][j], dpc[i][l] + dpc[l][j]);
				}
			}
		}
		cin >> k;
		REP(i, k){
			cin >> p >> q >> r;
			if (r == 0)cout << dpc[p][q] << endl;
			else cout << dpt[p][q] << endl;
		}
	}
}

Measured memory_bytes: 1256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    int n;
    scanf("%d", &n);
    vector<ll> ary(n);
    for(int i = 0; i<n;i++) {
        cin >> ary[i];
    }
    sort(ary.begin(), ary.end());
    //for(int i = 0; i<n; i++) {printf("%d ,", ary[i]);}
    //printf("\n");

    int ia, ib, c, ja, jb;
    vector<int> aryb(n);
    
    c = 0; ia = n/2; ib = n/2 - 1; ja = 0; jb = n-1;
    while(ia != n || ib != -1) {
        if(c %2 == 0) {
            if(ia != n) {
                aryb[ia] = ary[ja];
                ja++; ia++;
            }

            if(ib != -1) {
                aryb[ib] = ary[jb];
                jb--; ib--;
            }          
        } else {
            if(ia != n) {
                aryb[ia] = ary[jb];
                ia++; jb--;
            }
            if (ib != -1) {
                aryb[ib] = ary[ja];
                ja++; ib--;
            }
        }
        c++;
    }
    unsigned long long int suma = 0;
    for(int i=0; i < n-1; i++) {
        suma += abs(aryb[i] - aryb[i+1]);
    }
    c = 0; ia = n/2; ib = n/2 - 1; ja = 0; jb = n-1;
    while(ia != n || ib != -1) {
        if(c %2 == 0) {
            if(ia != n) {
                aryb[ia] = ary[jb];
                jb--; ia++;
            }

            if(ib != -1) {
                aryb[ib] = ary[ja];
                ja++; ib--;
            }          
        } else {
            if(ia != n) {
                aryb[ia] = ary[ja];
                ia++; ja++;
            }
            if (ib != -1) {
                aryb[ib] = ary[jb];
                jb--; ib--;
            }
        }
        c++;
    }
    unsigned long long int sumb = 0;
    for(int i=0; i < n-1; i++) {
        sumb += abs(aryb[i] - aryb[i+1]);
    }

    unsigned long long int sum=0;
    if (suma > sumb) {
        sum = suma;
    } else {
        sum = sumb;
    }

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

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy

vector<vi> graph(MX);
int C[MX];
int pre[MX], out[MX], nxt[MX], in[MX], sub[MX]; 
ll adj[MX*2];

ll ans[MX];
int ct = 0;
stack<int> vals[MX];

int dfs(int v, int p) {
    pre[ct] = v;
    in[v] = ct;
    ct++;
    int ss = 1;
    if (p != -1) {
        vals[C[p]].push(v);
    }
    F0R(i, sz(graph[v])) {
        int nv = graph[v][i];
        if (nv == p) continue;
        ss += dfs(nv, v);
    }
    out[v] = ct;
    if (!vals[C[v]].empty()) {
        adj[vals[C[v]].top()] += ss;
    }
    if (p != -1) vals[C[p]].pop();
   return sub[v] = ss;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    F0R(i, N) cin >> C[i];
    F0R(i, N) C[i]--;
    F0R(i, N-1) {
        int A, B; cin >> A >> B; A--; B--; graph[A].pb(B); graph[B].pb(A);
    }
    F0R(i, N) {
        ans[i] = N;
        ans[i] *= ans[i] - 1;
        ans[i] /= 2;
    }
    F0R(i, 2*N) {
        adj[i] = 0;
    }
    F0R(i, N) {
        vals[i].push(i+N);
    }

    dfs(0, -1);

    F0R(i, N) {
        ans[C[i]]++;
    }


    F0R(i, N) {
        F0R(x, sz(graph[i])) {
            int j = graph[i][x];
            if (in[i] > in[j]) continue;
            ll X = sub[j] - adj[j];
            ans[C[i]] -= X * (X-1) / 2;
        }
    }
    F0R(i, N) {
        ll X = N - adj[i+N];
        ans[i] -= X * (X - 1) / 2;
    }
    


    F0R(i, N) {
        cout << ans[i] << nl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 173680
from itertools import combinations_with_replacement

n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]

ans = 0
for seq in combinations_with_replacement(range(1, m + 1), n):
    score = 0
    for a, b, c, d in req:
        if seq[b - 1] - seq[a - 1] == c:
            score += d
    ans = max(ans, score)

print(ans)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, b;
	cin >> a >> b;
	ll n = b-a;
	ll ans = 0;
	zep(i, 1, n){
		ans += i;
	}
	print(ans-a)
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
a = [int(input()) for _ in range(n)]

dp = [a[0]]
for i in range(n):
    if a[i] > dp[-1]:
        dp.append(a[i])
    else:
        dp[bisect_left(dp, a[i])] = a[i]

print(len(dp))



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

int main() {
  string s;
  cin>>s;
  vector<char>a(4);
  for(int i=0;i<4;i++){
    a[i]=s[i];
  }
  for(int i=0;i<8;i++){
    string ans;
    int sum=0;
    ans+=a[0];
    sum+=a[0]-'0';
    for(int j=0;j<3;j++){
      if(i>>j&1){
        sum+=a[j+1]-'0';
        ans+='+';
        ans+=a[j+1];
      }
      else{
        sum-=a[j+1]-'0';
        ans+='-';
        ans+=a[j+1];
      }
    }
    if(sum==7){
      cout<<ans<<"=7"<< endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  int ans = 0;
  string ck[] = {"A","G","C","T"};
  bool flag;
  int cnt = 0;
  rep(i,s.size()){
    for(int j = i; j < s.size(); j++){
      flag = false;
      rep(k,4){
        if(s.substr(j,1) == ck[k]){
          flag = true;
        }
      }
      if(!flag){
        ans = max(ans,cnt);
        break;
      }else{
        cnt++;
      }
    }
    ans = max(ans,cnt);
    cnt = 0;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import Data.Char

main = do
  ss <- lines <$> getContents
  mapM_ putStrLn $ solve ss

solve :: [String] -> [String]
solve = map cipher

cipher :: String -> String
cipher s | (or . map (flip isInfixOf ns)) ["the", "this", "that"] = ns
        | otherwise = cipher ns
  where ns = map (rot 1) s

rot :: Int -> Char -> Char
rot n c | c `elem` tbl = tbl !! (ord c - ord 'a' + n)
        | otherwise = c
  where tbl = ['a'..'z'] ++ ['a'..'z']

Measured memory_bytes: 3972
#include <cstdio>
#include <climits>
#include <vector>

int main(void) {
  int N;
  scanf("%d", &N);

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

  std::vector< std::vector<long long int> > dp(N+1, std::vector<long long int>(2));
  dp[0][0] = 0; dp[0][1] = INT_MIN;
  for (int i = 1; i <= N; ++i) {
    dp[i][0] = std::max(dp[i-1][0] + A[i-1], dp[i-1][1] - A[i-1]);
    dp[i][1] = std::max(dp[i-1][0] - A[i-1], dp[i-1][1] + A[i-1]);
  }

  printf("%lld\n", dp[N][0]);

  return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

set<int> indices[26];

int idxToChar[200005];
int n;

const int BIT_SIZE = 200005;
int bit[BIT_SIZE];
void upd(int idx, int val) {
  idx += 2;
  while(idx < BIT_SIZE) {
    bit[idx] += val;
    idx += idx & -idx;
  }
}
int qry(int idx) {
  idx += 2;
  int ret = 0;
  while(idx) {
    ret += bit[idx];
    idx -= idx & -idx;
  }
  return ret;
}

void clean(set<int>& all, int idx) {
  assert(indices[idx].size());
  int val = *indices[idx].begin();
  upd(val, -1);
  indices[idx].erase(val);
  all.erase(val);
  if(indices[idx].size()) {
    val = *indices[idx].rbegin();
    upd(val, -1);
    indices[idx].erase(val);
    all.erase(val);
  }
}

void init() {
  string s;
  cin >> s;
  n = s.size();
  for(int i = 0; i < s.size(); i++) {
    indices[s[i] - 'a'].insert(i);
    idxToChar[i] = s[i] - 'a';
    upd(i, 1);
  }
  int odd = 0;
  for(int i = 0; i < 26; i++) {
    odd += indices[i].size()%2;
  }
  if(odd > 1) {
    cout << "-1\n";
    exit(0);
  }
}

void solve() {
  init();
  set<int> all;
  for(int i = 0; i < n; i++) all.insert(i);
  ll ret = 0;
  while(all.size()) {
    int lowest = *all.begin();
    int lowestCost = 0;
    {
      if(indices[idxToChar[lowest]].size() == 1) {
        lowestCost = all.size() / 2;
      }
      else {
        lowestCost = all.size() - qry(*indices[idxToChar[lowest]].rbegin());
      }
    }
    ret += lowestCost;
    int desired = idxToChar[lowest];
    clean(all, desired);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 20560
n = gets.to_i
p = gets.split.join('').to_i
q = gets.split.join('').to_i
retu = [*(1..n)].permutation(n).to_a
un =[]
retu.each do |a|
  un << a.join('').to_i
end
a = un.index(p) + 1
b = un.index(q) + 1
puts (a - b).abs

Measured memory_bytes: 9596
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn pow2(n: usize) -> i64 {
    let mut ret = 1;
    for _ in 0..n {
        ret *= 2;
        ret %= 1_000_000_007
    }
    ret
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(usize;;);

    let mut m = HashMap::new();
    for v in vs.iter() {
        let num = m.entry(v).or_insert(0);
        *num += 1;
    }

    let mut ans = pow2(n / 2);
    if n % 2 == 1 {
        if m.get(&0).is_none() {
            ans = 0
        } else {
            let mut nums = vec![];
            for (&&k, &v) in m.iter() {
                if (k == 0 && v != 1) || (k != 0 && v != 2) {
                    ans = 0
                }
                nums.push(k);
            }
            nums.sort();
            for (i, &n) in nums.iter().enumerate() {
                if i * 2 != n {
                    ans = 0
                }
            }
        }
    } else {
        let mut nums = vec![];
        for (&&k, &v) in m.iter() {
            if v != 2 {
                ans = 0
            }
            nums.push(k)
        }
        nums.sort();
        for (i, &n) in nums.iter().enumerate() {
            if 2 * i + 1 != n {
                ans = 0
            }
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int N ;
  cin >> N;
  int p[N],q[N];
  vector<int> m(N);
  for(int i = 0; i<N; i++){
    cin >> p[i];
    m.at(i) = i+1;
  }
  for(int i = 0; i< N;i++){
    cin >> q[i];
  }
  int ans_a;
  int ans_b;
  int count = 0;
  do{
    bool b = true; 
    bool c = true;
    for(int i = 0; i<N; i++){
      if(p[i] != m.at(i)){
        b = false;
        break;
      }
    }
    for(int i = 0; i<N; i++){
      if(q[i] !=m.at(i)) {
        c = false;
        break;
      }
    }
    if(b) ans_a = count;
    if(c) ans_b = count;
    count++;
    }while(next_permutation(m.begin(),m.end()));
  cout << abs(ans_a-ans_b) << endl;
  }



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

using namespace std;

int main() {

    long long N, W, sum = 0;
    cin >> N >> W;
    long long w[N], v[N];

    for(int i = 0 ; i < N; i++) 
        cin >> w[i] >> v[i];

    for(int i = 0 ; i < N; i++)
        sum += v[i];
    
    vector<long long> dystruct(sum + 1, 1e18L + 5);

    dystruct[0] = 0;
    for(int i = 0 ; i < N; i++) {

        for(int j = sum - v[i]; j >= 0; j--) {

            dystruct[j + v[i]] = min(dystruct[j + v[i]], dystruct[j] + w[i]);
        }
    }

    long long ans = 0;
    for (long long i = 0 ; i <= sum; i++) {

        if(dystruct[i] <= W) {

            ans = max(ans, i);
        }
    }

    cout << ans;

    return 0;
}


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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

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

	for( int i=0; i<4; i++ ){
		if( n % 10 == 7 ){
			cout << "Yes" << endl;
			return 0;
		}
		n /= 10;
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



int main() {
	int n;
	cin >> n;
	
	vector<pair<pair<int, int>, int>> inf(n);
	for (int i = 0; i < n; i++) {
		int x, y, h;
	
		cin >> x >> y >> h;

		inf[i] = make_pair(make_pair(x, y), h);

	}

	for (int cx = 0; cx <= 100; cx++) {
		for (int cy = 0; cy <= 100; cy++) {
			bool canConsist = true;
			int h;
			for (int i = 0; i < n; i++) {
				if (inf[i].second > 0) {
					pair<int,int> pos = inf[i].first;
					
					h = abs(pos.first - cx) + abs(pos.second - cy) + inf[i].second;
					break;
				}
			}

			for (int i = 0; i < n;i++) {
				pair<int, int> pos = inf[i].first;
				int h_pos = h - abs(pos.first - cx) - abs(pos.second - cy);
				if (h_pos < 0) {
					h_pos = 0;
				}

				if (h_pos != inf[i].second) {
					canConsist = false;
					break;
				}
				
			}

			if (canConsist) {
				cout << cx << " "<<  cy<< " " << h << endl;
			}
		}
	}
	
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;


public class Main {
	public static void main(String[] args){
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		for (int i = 0; i < A.length-1; i++) {
			int a=sc.nextInt()-1;
			A[a]++;
		}
		for (int i = 0; i < A.length; i++) {
			out.println(A[i]);
		}
		out.flush();
	}
	
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 45372
x,y,a,b,c= list(map(int, input().split()))
p= list(map(int, input().split()))
q= list(map(int, input().split()))
r= list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
np=p[0:x]
nq=q[0:y]
np.extend(nq)
m=min(np)
nr=[i for i in r if i>=m]
np.extend(nr)
np.sort(reverse=True)
print(sum(np[0:x+y]))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    int idx = 0;
    int res[h][w];
    for (int i = 0; i < h; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; j++) {
                while (arr[idx] == 0)
                    idx++;
                res[i][j] = idx + 1;
                arr[idx]--;
            }
        }
        else {
            for (int j = w - 1; j >= 0; j--) {
                while (arr[idx] == 0)
                    idx++;
                res[i][j] = idx + 1;
                arr[idx]--;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << res[i][j] << ' ';
        }
        cout << '\n';
    }
    return  0;
}

Measured memory_bytes: 384
#include <cstdio>

int c[6], total;
int p[] = { 1, 5, 10, 50, 100, 500 };

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

  for (int i = 0; i < 6; ++i) {
    total += c[i] * p[i];
  }

  if (total >= 1000) { printf("1\n"); }
  else { printf("0\n"); }

  return 0;
}

Measured memory_bytes: 1012
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int64_t i = 0;i < n;i++)

template<class T> bool chmin(T& a,T b){
    if(a > b){ a = b; return true; }else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){ a = b; return true; }else return false;
}

class BTripleDots {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int64_t k;cin >> k;
        string s;cin >> s;

        if(s.size() > k){
            cout << s.substr(0,k) + "..." << '\n';
        }else cout << s << '\n';
	}
};


int main() {
	BTripleDots solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = 998244353;//1e9+7

vector<int> cnt[201],sp;

void pre() {

}

void solve() {
  char c; cin>>c;
  if(c>='a')  cout<<'a';
  else  cout<<'A';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3640
s=list(str(input()))
t=list(str(input()))
s=sorted(s)
t=sorted(t,reverse=True)
judge=0

for i,j in zip(s,t):
    if ord(i)>ord(j):
        judge=0
        break
        
    elif ord(i)<ord(j):
        judge=1
        break
        
    else:
        judge=2
        continue
    
if judge==2:
    if len(s)>=len(t):
        judge=0
    else:
        judge=1

if judge==1:print('Yes')
else:print('No')

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cctype>
using namespace std; 
#define Maxn 500009
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
typedef long long LL;
int read() {
	int x = 0;
	char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) {
		x = x * 0xA + ch - 0x30;
		ch = getchar();
	}
	return x;
}

struct node {
	int a, b, c;
	int operator < (const node &x) const {
		return (a - b) < (x.a - x.b);
	}
}f[Maxn];
priority_queue<LL, vector<LL>, greater<LL> >q; 
LL ans, sum, base, lef[Maxn<<2];
int X, Y, Z, n;
int main() {
	X = read(); Y = read(); Z = read(); n = X + Y + Z;
	rep(i, 1, n) {
		f[i].a = read();
		f[i].b = read();
		f[i].c = read();
		base += f[i].c;
	}
	sort(f + 1, f + n + 1); 
	rep(i, 1, Y) {
		sum += f[i].b - f[i].c;
		q.push(f[i].b - f[i].c);
	}
	rep(i, Y + 1, n - X + 1) {
		lef[i] = sum;
		sum += f[i].b - f[i].c;
		q.push(f[i].b - f[i].c);
		sum -= q.top();
		q.pop();
	}

	while(!q.empty()) q.pop(); 
	sum = 0;
	drep(i, n, n - X + 1) {
		sum += f[i].a - f[i].c;
		q.push(f[i].a - f[i].c);
	}
	drep(i, n - X, Y) {
		ans = max(ans, base + lef[i + 1] + sum);
		sum += f[i].a - f[i].c;
		q.push(f[i].a - f[i].c);
		sum-= q.top();
		q.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[n+1];
  cin >> s;
  int c=0;
  for(int i=0;i<n;i++){
    if(s[i]=='B')c--;
    else c++;
  }
  if(c>0)cout << "Yes";
  else cout << "No";
}


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

int main () {
  int n, m;  
  cin >> n >> m;
  int a[m], b[m], c[m];
  int edge[n + 1][n + 1];
  int stand[n + 1][n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      edge[i][j] = 1001;
    }  
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    edge[a[i]][b[i]] = c[i]; 
    edge[b[i]][a[i]] = c[i]; 
  }
  int original[n + 1][n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (edge[i][j] != 1001) {
        original[i][j] = edge[i][j]; 
      }
      else {
        original[i][j] = 0;  
      }
    }  
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (edge[i][j] > edge[i][k] + edge[k][j]) {
          edge[i][j] = edge[i][k] + edge[k][j];  
        }    
      }  
    }    
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (original[i][j] != 0 && original[i][j] != edge[i][j]) {
        ans++;  
      }
    }  
  }
  cout << ans / 2 << endl;

}

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

using namespace std;

int main(void) {
  long long N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }

  long long count = 0;
  for (int i = 0; i < N; i++) {
    string::size_type pos = s[i].find("AB");
    while (pos != string::npos) {
      count++;
      pos = s[i].find("AB", pos + 2);
    }
  }

  long long countB = 0;
  long long countA = 0;
  long long countAB = 0;
  for (int i = 0; i < N; i++) {
    if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') {
      countAB++;
    } else if (s[i][s[i].length() - 1] == 'A') {
      countA++;
    } else if (s[i][0] == 'B') {
      countB++;
    }
  }

  if (countAB == 0) {
    cout << count + min(countA, countB) << endl;
  } else if (countA + countB > 0) {
    cout << count + countAB + min(countA, countB) << endl;
  } else {
    cout << count + countAB - 1 << endl;
  }
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};


template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

int main(){
    int n; cin >> n;
    vector<pair<int,int> > v;
    for(int i = 0; i < n; i++){
        int a,b; cin >> a >> b;
        v.push_back({b,a});
    }
    sort(v.begin(),v.end());
    long long time = 0;
    for(int i = 0; i < n; i++){
        time += v[i].second;
        if (time > v[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double N = double.Parse(Console.ReadLine());
            for(int i = 0; i < 50001; i++)
            {
                double X = Math.Floor(i * 1.08);
                if(N == X)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(":(");

        }
    }
}


Measured memory_bytes: 13140
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        // Alice,Bob got poit.
        int a = 0;
        int b = 0;
        boolean isAlice = true;
        Integer val = null;
        while ((val = list.pollLast()) != null) {
            if (isAlice) {
                a += val;
            } else {
                b += val;
            }
            isAlice = !isAlice;
        }
        // 出力
        System.out.println(a-b);
    }
}


Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
  unsigned long long max,A,B,C; cin>>A>>B>>C;
  if(A>B){max=A;
       if(max<C)max=C;}
  else{max=B;
       if(max<C)max=C;}
  if(A%2==1 && B%2==1 && C%2==1){
    if(max==A)cout<<B*C<<endl;
    else if(max==B)cout<<A*C<<endl;
    else cout<<A*B<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return 0;
 
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Music struct {
	Name string
	Time int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	playlist := make([]*Music, n)
	for i := 0; i < n; i++ {
		var name string
		var time int
		fmt.Scanf("%s %d", &name, &time)
		playlist[i] = &Music{
			Name: name,
			Time: time,
		}
	}

	var x string
	fmt.Scanf("%s", &x)

	total := 0
	start := false
	for _, music := range playlist {
		if start {
			total += music.Time
		}
		if music.Name == x {
			start = true
		}
	}

	fmt.Printf("%d", total)
}


Measured memory_bytes: 640
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

LL dp[1001][1001];

int main()
{
    fast();

    

    LL t,n,i,j,k,x,y,c,m;
    cin >> n >> m;
    LL a[n][m];
    char ch;
    REP(i, n){
        REP(j, m){
            cin >> ch;
            if(ch == '.'){
                a[i][j] = 1;
            }
            else{
                a[i][j] = 0;
            }
        }
    }
    REP(i, n){
        REP(j, m){
            if(i == 0 && j == 0){
                dp[i][j] = 1;
                continue;
            }
            if(i == 0){
                if(a[i][j] == 0){
                    dp[i][j] = 0;
                }
                else{
                    dp[i][j] = dp[i][j - 1];
                }
                continue;
            }
            if(j == 0){
                if(a[i][j] == 0){
                    dp[i][j] = 0;
                }
                else{
                    dp[i][j] = dp[i - 1][j];
                }
                continue;
            }
            if(a[i][j] == 0){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD;
            }
        }
    }

    // REP(i, n){
    //     REP(j, m){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[n - 1][m - 1];

}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){


    int a,b;
    int result;
    while(cin>>a>>b,a||b){
        result = 0;
        FOR(i,1,a-1){
            FOR(j,i+1,a){
                FOR(k,j+1,a+1){
                    if(i+j+k==b){
                        result++;
                    }
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n, d; cin >> n >> d;
    vector<vector<int>> points(n, vector<int>(d));
    for (int i = 0; i < n; i++) for (int j = 0; j < d; j++) cin >> points[i][j];
    
    int ans = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            int dist2 = 0;
            for (int k = 0; k < d; k++) {
                int dif = points[i][k] - points[j][k];
                dist2 += dif * dif;
            }
            int test = (int)sqrt(dist2);
            if (test * test == dist2) ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;
pair < ll , ll > a[100100];

int main()
{
    ll n , m;  cin >> n >> m;
    for(int i = 0;i<n;i++)  cin >> a[i].first >> a[i].second;
    sort(a , a + n);
    ll Ans = 0;
    for(int i = 0;i<n;i++)  {
        if(m >= a[i].second) {
            Ans+=a[i].second * a[i].first;
            m-=a[i].second;
        }
        else {
            Ans+=m * a[i].first;
            m = 0;
        }
    }
    cout << Ans;
    return 0;
}


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

public class Program {
	public static void Main() {
		var opinions = Enumerable.Range(0, int.Parse(Console.ReadLine()))
			.Select(_ => Enumerable.Range(0, int.Parse(Console.ReadLine()))
				.Select(__ => Console.ReadLine().Split(' '))
				.Select(x => new { index = int.Parse(x[0]) - 1, flag = x[1] == "1" })
				.ToArray())
			.ToArray();

		Console.WriteLine(Enumerable.Range(0, (int)Math.Pow(2, opinions.Length))
			.Select(flags => Convert.ToString(flags, 2).PadLeft(opinions.Length, '0')
				.Select((x, i) => new { index = i, flag = x == '1' })
				.Where(x => x.flag)
				.Select(x => x.index)
				.ToArray())
			.Where(honests => honests.All(honest => opinions[honest].All(x => x.flag && honests.Contains(x.index) || !x.flag && !honests.Contains(x.index))))
			.Max(x => x.Length));
	}
}


Measured memory_bytes: 15908
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <cmath>
#include <algorithm>

using namespace std;

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

#define pii pair<int, int>
#define pll pair<long long, long long>
#define mp make_pair
#define fr first
#define sc second
#define tiii tuple<int, int, int>
#define tlll tuple<long long, long long, long long>
#define mt make_tuple
#define ll long long
#define ld long double
#define pb push_back

const int SZ = 3e5;

int nxt['z' + 1][SZ];
int dp[SZ];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;

    for (int i = 'a'; i <= 'z'; i++)
        for (int j = 0; j < SZ; j++)
            nxt[i][j] = (int)s.size();

    for (int i = 0; i < SZ; i++)
        dp[i] = SZ;

    for (int c = 'a'; c <= 'z'; c++)
    {
        int j = 0;
        for (int i = 0; i < s.size(); i++)
            if (s[i] == c)
                for (; j <= i; j++)
                    nxt[c][j] = i;
    }

    for (int i = (int)s.size() - 1; i >= 0; i--)
        for (int c = 'a'; c <= 'z'; c++)
        {
            if (nxt[c][i] >= s.size())
                dp[i] = 1;
            else
                dp[i] = min(dp[i], dp[nxt[c][i] + 1] + 1);
        }

    string ans = "";
    int i = 0;
    while (i < s.size())
    {
        int c = 'a';
        for (; !(nxt[c][i] >= s.size() || dp[i] == dp[nxt[c][i] + 1] + 1) && c <= 'z'; c++) {}
        ans.push_back(c);
        i = nxt[c][i] + 1;
    }

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

Measured memory_bytes: 32404
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #pragma comment(linker, "/STACK:2000000")
  #pragma comment(linker, "/HEAP:2000000")
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  int32_t main()
  {        
    IOS
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
      cout<<"1";
    }
    else if((a+b)%2==0)
    {
      cout<<(a+b)/2;
    }
    else
    {
      cout<<"IMPOSSIBLE";
    }
    return 0;
} 

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut anss = vec![];
    for i in 0..n {
        for j in (0..n - i).rev() {
            if seq[j] == j + 1 {
                anss.push(seq[j]);
                seq.remove(j);
                break;
            }
        }
        if anss.len() != i + 1 {
            println!("-1");
            return;
        }
    }
    anss.reverse();
    for &ans in anss.iter() {
        println!("{}", ans);
    }
}


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

using namespace std;
long long k;
long long odd, even;

string s;
int main() {
	cin >> s >> k;
	bool changed = false;
	for (int i = 1; i < s.size(); i++) {
		if (changed) {
			changed = false;
			continue;
		}
		if (s[i] == s[i-1]) {
			changed = true;
			odd++;
		}
	}
	if (s[s.length()-1] != s[0] || changed) {
		cout << odd * k << '\n';
		return 0;
	}

	changed = true;
	even = 1;
	for (int i = 1; i < s.size(); i++) {
		if (changed) {
			changed = false;
			continue;
		}
		if (s[i] == s[i-1]) {
			changed = true;
			even++;
		}
	}
	if (changed) {
		cout << odd * (k + 1) / 2 + even * (k / 2) << '\n';
	} else {
		cout << odd + even * (k-1) << '\n';
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n, m, cnt, dis[M], last[M], vis[M], head[M];
struct Edge{
    int next, to;
}edge[M * 2];
struct node{
    int u, d;
    node(int U, int D) {
        u = U;
        d = D;
    }
    bool operator < (const node &rhs) const {
        return d > rhs.d;
    }
};
void add_edge(int u, int v) {
    edge[++cnt].next = head[u];
    edge[cnt].to = v;
    head[u] = cnt;
}
void dijkstra(int s) {
    for(int i = 1; i <= n; i++) dis[i] = INF;
    dis[s] = 0;
    priority_queue <node> que;
    que.push(node(s, 0));
    while(!que.empty()) {
        node tmp = que.top();
        que.pop();
        int u = tmp.u, d = tmp.d;
        if(vis[u]) continue;
        vis[u] = 1;
        for(int i = head[u]; i; i = edge[i].next) {
            int v = edge[i].to;
            if(!vis[v] && (d + 1) < dis[v]) {
                dis[v] = d + 1;
                last[v] = u;
                que.push(node(v, dis[v]));
            }
        }
    }
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1, u, v; i <= m; i++) {
        scanf("%d%d", &u, &v);
        add_edge(u, v);
        add_edge(v, u);
    }
    dijkstra(1);
    for(int i = 1; i <= n; i++) {
        if(dis[i] == INF) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    for(int i = 2; i <= n; i++) printf("%d\n", last[i]);
    return 0;
}


Measured memory_bytes: 8652
h=int(input())
w=int(input())
n=int(input())
if h>=w:
  if n%h==0:
    ans=n//h
  else:
    ans=n//h+1
else:
  if n%w==0:
    ans=n//w
  else:
    ans=n//w+1
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	static String str;
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		str = sc.next();
		
		return true;
	}
	
	public static void solve(){
		
		for(int i = str.length() - 1; i >= 0; i--){
			System.out.print(str.charAt(i));
		}
		System.out.println();
	}

}

Measured memory_bytes: 11000