akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long

class UnionFind {
public:
    vector<int> Parent;
    vector<int> Size;

    UnionFind(int N) : Parent(N), Size(N,1){
        for(int i = 0; i < N; i++) Parent[i] = i;
    }

    int root(int A) {
        if (Parent[A] == A) return A;
        return Parent[A] = root(Parent[A]);
    }

    bool merge(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) return false;

        if (Size[A] < Size[B]) swap(A, B);

        Size[A] += Size[B];
        Parent[B] = A;
        return true;
    }

    bool issame(int A, int B) { //
        return root(A) == root(B);
    }

    int findsize(int A) {
        return Size[root(A)];
    }
};
signed main() {
    int n,m;
    cin >> n >> m;

    UnionFind Tree(n);
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    vector<int> ans(m + 1);
    ans[m] = n * (n - 1) / 2;

    for(int i = m - 1; i >= 0; i--){
        if(Tree.issame(a[i],b[i])) {
            ans[i] = ans[i + 1];
            Tree.merge(a[i],b[i]);
        } else {
            ans[i] = ans[i + 1] - (Tree.findsize(a[i]) * Tree.findsize(b[i]));
            Tree.merge(a[i],b[i]);
        }
    }

    for(int i = 1; i <= m; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define bit(n) (1LL<<(n))

typedef pair<i64,i64> P;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;

void Main()
{
  i64 N,K;
  cin >> N >> K;

  vi h(N);
  rep(i,N) cin >> h[i];

  vi dp(N,INF);
  dp[0] = 0;

  rep(i,N) rep(ii,1,K+1){
    if(i+ii>N-1) continue;
    mins(dp[i+ii],dp[i]+abs(h[i]-h[i+ii]));
  }

  cout << dp[N-1] << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
#define MAX 200000
#define NIL -1

struct Node {int parent, left, right;};
Node T[MAX];
int n, Depth[MAX];

// 再帰的に深さを求める
void rec(int node,int parent){
    Depth[node] = parent;
    if(T[node].right != NIL){
        // 右の兄弟に同じ深さを設定
        rec(T[node].right,parent);
    }
    if(T[node].left != NIL){
        // 最も左の子に自分の深さ+1を設定
        rec(T[node].left,parent + 1);
    }
}

void Print(int node){
    cout << "node " << node << ": ";
    cout << "parent = " << T[node].parent << ", ";
    cout << "depth = " << Depth[node] << ", ";
    
    if(T[node].parent == NIL) cout << "root, ";
    else if(T[node].left == NIL)cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for(int i = 0,left = T[node].left;left != NIL;++i,left = T[left].right){
        if(i) cout << ", ";
        cout << left;
    }
    cout << "]" << endl;
}

int main() {
    // 節点の個数
    int n = 0;
    // 次数
    int iDeg = 0;
    int iNodeIdx = 0;
    int left, node, root;

    cin >> n;
    // 初期化
    for (int i = 0; i < n; ++i)
    {
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    // 各ノードに対して、
    // その節点番号、子の情報を、
    // 記憶していく
    for (int i = 0; i < n; i++)
    {
        // 節点番号、次数(子の数)を取得
        cin >> iNodeIdx >> iDeg;
        // 全ての子の情報を記憶する
        for (int k = 0; k < iDeg; k++)
        {
            cin >> node;
            if (k == 0)
            {
                // 一番左の子を取得
                T[iNodeIdx].left = node;
            }
            else
            {
                // 子の兄弟を記憶していく
                T[left].right = node;
            }
            left = node;
            // 子の親を記憶する
            T[node].parent = iNodeIdx;
        }
    }
    // rootを探す
    for (int i = 0; i < n; ++i)
    {
        if (T[i].parent == NIL)
        {
            root = i;
        }
    }

    // 根からはじめて深さを代入する
    rec(root, 0);

    // Nodeのindexごとに出力する
    for (int i = 0; i < n; ++i)
    {
        Print(i);
    }
    return 0;
}


Measured memory_bytes: 7688
N = input()
ans = 0
if len(N) % 2 == 1:
  ans += int(N) - (10 ** (len(N) - 1)) + 1
for i in range(1,len(N)):
  if i % 2 == 0:
    continue
  ans += 9 * (10 ** (i - 1))
print(ans)

Measured memory_bytes: 3060
# 橋検出
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)


def input(): return sys.stdin.readline().rstrip()


# 二つの配列ord,miniを持つ。
V, E = map(int, input().split())
edge = []
graph = [[] for i in range(V)]
for i in range(E):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
    edge.append((min(x, y), max(x, y)))

order = [i for i in range(V)]
mini = [V+1 for i in range(V)]
visited = [False for i in range(V)]

used = defaultdict(bool)
for node in range(V):
    for point in graph[node]:
        used[(node, point)] = False
cnt = 0


def dfs(node):
    global cnt
    visited[node] = True
    cnt += 1
    order[node] = cnt
    mini[node] = cnt
    for point in graph[node]:
        if visited[point] == False:
            used[(node, point)] = True
            dfs(point)
            mini[node] = min(mini[node], mini[point])
        elif not used[(point, node)]:
            mini[node] = min(mini[node], order[point])
    return


dfs(0)

answer = []

for x, y in edge:
    if order[x] < order[y]:
        if order[x] < mini[y]:
            answer.append((x, y))
    elif order[x] > order[y]:
        if order[y] < mini[x]:
            answer.append((x, y))
answer.sort()
for x, y in answer:
    print(x, y)


Measured memory_bytes: 35132
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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



int main(){
    int X; std::cin >> X;
    for(long long A(-1000); A <= 1000; ++A){
        for(long long B(-1000); B <= 1000; ++B){
            if(A*A*A*A*A - B*B*B*B*B == X){
                std::cout << A << " " << B << std::endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	int x;cin>>x;
	int ans=0;
	rep(i,n-1){
		int y;cin>>y;
		ans+=(y>x);
		x=y;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
const ll N=1e5+5;
ll bexpo(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==0)return bexpo(x*x,n/2);
    else return x*bexpo(x*x,(n-1)/2);
}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);} 
int Arr[N];
void initialize()
{
    for(int i = 0;i<N;i++)
    Arr[ i ] = i ;
}
int root(int i)
{
    while(Arr[ i ] != i)       
    {
     i = Arr[ i ];
    }
    return i;
}

void unio(int A ,int B)
{
    int root_A = root(A);       
    int root_B = root(B);  
    if(root_A<root_B)
        Arr[ root_A ] = root_B ;    
    else
        Arr[root_B]=root_A;
}
bool find(int A,int B)
{
    if( root(A)==root(B) )    
    return true;
    else
    return false;
} 
int main() {
FIO;
  ll n,j,k;
  cin>>n>>k;
  ll a[n+1];
  ll i;
  for(i=1;i<=n;i++)
      cin>>a[i];
    ll dp[n+1];
   dp[1]=0;
  dp[2]=abs(a[2]-a[1]);
  for(i=3;i<=n;i++)
  {
     ll temp=max(1LL,i-k);
     dp[i]=INT_MAX;
     for(j=i-1;j>=temp;j--)
        dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
  }
  cout<<dp[n];

}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// const double EPS = 1e-8;
using vec = vector<int>;
using mat = vector<vec>;

// 行列の階数を求める
// 係数行列と拡大係数行列の階数が異なるときは不能
// 係数行列と拡大係数行列の階数が等しく、係数行列の階数と変数の個数が異なるときは不定
// 係数行列と拡大係数行列の階数と変数の個数がすべて等しいときは一意解が存在
int mat_rank(mat A){
    const int R = A.size(), C = A[0].size();
    int ret = 0;
    for(int i=0; ret<R&&i<C; ++i){
        // dbg(i);
        // rep(rr,R){
        //     rep(cc,C) printf("%2d", A[rr][cc]);
        //     puts("");
        // }

        int pivot = ret;
        for(int j=ret+1; j<R; ++j){
            if(abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
        }
        swap(A[pivot], A[ret]);

        if(A[ret][i]==0) continue;

        // for(int k=C-1; k>=i; --k) A[ret][k] /= A[ret][i];
        for(int j=ret+1; j<R; ++j){
            for(int k=C-1; k>=i; --k) A[j][k] ^= A[ret][k]*A[j][i];
        }
        ++ret;
    }
    return ret;
}

// 連立方程式Ax=bを解く
// Aは正方行列を仮定
// 解無し、一意に定まらない : 長さ0のvector
vec gauss_jordan(const mat &A, const vec &b){
    int d = A.size();
    mat B(d, vec(d+1));
    rep(i,d){
        rep(j,d) B[i][j] = A[i][j];
        B[i][d] = b[i];
    }

    rep(i,d){
        int pivot = i;
        for(int j=i; j<d; ++j){
            if( abs(B[j][i]) > abs(B[pivot][i]) ) pivot = j;
        }
        swap(B[i], B[pivot]);

        // 解無し、一意に定まらない : 長さ0のvector
        if(B[i][i] == 0) return vec();

        // 注目する変数の係数を1にする
        // for(int j=i+1; j<=d; ++j) B[i][j] /= B[i][i];
        rep(j,d){
            if(i==j) continue;
            // j番目の式からi番目の変数を除去
            for(int k=i+1; k<=d; ++k) B[j][k] ^= B[j][i]*B[i][k];
        }
    }

    vec ret(d);
    rep(i,d) ret[i] = B[i][d];
    return ret;
}

mat mul(const mat &A, const mat &B){
    int n = A.size();
    mat ret(n,vec(n));
    rep(i,n)rep(j,n){
        rep(k,n) ret[i][j] ^= A[i][k]*B[k][j];
    }
    return ret;
}

mat mat_pow(const mat &A, int T){
    int n = A.size();
    mat ret(n,vec(n)),aa(A);
    rep(i,n) ret[i][i]=1;
    while(T){
        if(T&1) ret = mul(ret,aa);
        aa = mul(aa,aa);
        T>>=1;
    }
    return ret;
}

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

    mat A(n, vec(n));
    rep(i,n)rep(j,n) scanf(" %d", &A[i][j]);

    vec v(n);
    rep(i,n) scanf(" %d", &v[i]);

    int T;
    scanf(" %d", &T);

    mat P = mat_pow(A,T);

    mat Pv(n, vec(n+1));
    rep(i,n){
        rep(j,n) Pv[i][j] = P[i][j];
        Pv[i][n] = v[i];
    }

    int rp = mat_rank(P), rpv = mat_rank(Pv);
    if(rp != rpv) printf("none\n");
    else{
        if(rp != n) printf("ambiguous\n");
        else{
            vec res = gauss_jordan(P,v);
            rep(i,n) printf("%d%c", res[i], " \n"[i==n-1]);
        }
    }
    return 0;
}



Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


ll fun(ve <ll> v,ll k){
ll ans=0;
ll sum=0;
ll n=v.size();
for(auto i:v)sum+=i;
if(sum>0){
	ll z=k/n;
	k=k%n;
	if(z!=0){
	ans+=(z-1)*sum;
	k+=n;
}
}
ll take=-M;
FOR(i,0,n){
	ll lans=0;
	for(ll j=i;j<min(2*n+i,i+k);j++){
		ll po=j%n;
		lans+=v[po];
		take=max(take,lans);
	}
}

if(take!=-M)
	ans+=take;
return ans;

}



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE



ll n,k;
cin>>n>>k;
ve <ll> p(n);
ve <ll> c(n);
FOR(i,0,n)cin>>p[i],p[i]--;
FOR(j,0,n)cin>>c[j];
ll ans=-M;
ve <ll> used(n);
FOR(i,0,n)
{
	if(!used[i]){
		ve <ll> cr;
		ll j=i;
		while(!used[j]){
			used[j]=1;
			cr.pb(c[j]);
			j=p[j];
		}
		ans=max(ans,fun(cr,k));
	}
}
cout<<ans;



return 0;
 }
 

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int a,b;
int sum[1024];
int main()
{
    for(int i=1;i<=999;i++)
    {sum[i]=sum[i-1]+i;
     //cout<<sum[i]<<endl;
     }
    while(cin>>a>>b)
    {
        int t=b-a;
        int ans=sum[t]-b;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;


#[derive(Copy, Clone)]
struct Edge{
    from: usize,
    to: usize,
    weight: i64,
}

fn is_partite (graph: Vec<Vec<Edge>>) -> (bool,usize,usize) {
    let nodes = graph.len();
    let mut stack: Vec<Edge> = Vec::new();
    let mut visited: Vec<bool> = vec![false; nodes];
    let mut color: Vec<i32> = vec![-1; nodes];

    stack.push(Edge{from:0, to:0, weight:0});
    color[0] = 2;
    let mut is_partite : bool = true;
    
    // dfs
    while let Some(e) = stack.pop()  {
        if visited[e.to] {
            continue;
        }
        visited[e.to] = true;
        color[e.to] = 3 - color[e.from];
        for i in graph[e.to].iter() {
            if ! visited[i.to] {
                stack.push(*i);
            } else if color[i.from] == color[i.to] {
                is_partite = false; // if adjacent node's color is different, given graph is not bipartite.
            }
        }
    }
    let whites = color.iter().filter(|&x| *x == 1).collect::<Vec<&i32>>().len();

    (is_partite, whites, graph.len() - whites)
}


fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    // get stdio    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    
    let edges: Vec<(usize, usize)> = (0..m)
        .map(|_| {
            (
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            )
        })
        .collect();


    // construct graph
    let mut graph: Vec<Vec<Edge>> = (0..n)
        .map(|_| {
            Vec::new()
        }).collect();

    for e in edges.iter() {
        graph[e.0].push( Edge{from:e.0, to:e.1, weight:1});
        graph[e.1].push( Edge{from:e.1, to:e.0, weight:1})
    }

    let re = is_partite(graph);

    if re.0 {
        println!("{}",  re.1 * re.2 - m);
    } else {
        println!("{}", n * ( n - 1 ) / 2 - m);
    }

}


Measured memory_bytes: 26876
#include <stdio.h>
#define ll long long
ll gcd(ll p,ll q){while(q){ll t=p%q;p=q;q=t;}return p;}
int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll d=gcd(a,b);
	int ans=1;
	for(ll i=2;i*i<=d;i++)if(d%i==0){
		ans++;
		while(d%i==0)d/=i;
	}
	printf("%d",ans+(d!=1));
}

Measured memory_bytes: 128
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
P A[100],j=sqrt(-1),p,p0;
double a,b,d;
int n;
int f(int m){
	int i,s1=2,s2=2;
	d=acos(a/2);
	P p3=polar(1.0,b+d)+p,p4=polar(1.0,b-d)+p;
	for(i=0;i<n;i++){
		P q=A[i];
		if(q==p||q==p0)continue;
		if(abs(q-p3)-1<1e-6)s1++;
		if(abs(q-p4)-1<1e-6)s2++;
	}
	if(m<s1)m=s1;
	if(m<s2)m=s2;
	return m;
}
int main(){
	int m,i,i1;
	char c;
	while(cin>>n,n!=0){
		for(i=0;i<n;i++){
			cin>>a>>c>>b;A[i]=P(a,b);
		}
		m=1;
		for(i=0;i<n;i++){
			p=A[i];
			for(i1=i+1;i1<n;i1++){
				p0=A[i1];a=abs(p0-p);b=arg(p0-p);
				if(a<=2)m=f(m);
			}
		}
		cout<<m<<endl;
	}
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string x,y;
    cin>>x>>y;
    if(x==y)
    {
        cout<<"="<<endl;
    }
    else if(x>y)
    {
        cout<<">"<<endl;
    }
    else

    {
        cout<<"<"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())

A = list(map(int,input().split()))

num = 0

for i in range(N):

    minj = i

    for j in range(N-i):

        j += i

        if A[j] < A[minj]:

            minj = j

    if minj != i:
        num += 1

    oai = A[i]
    A[i] = A[minj]
    A[minj] = oai

print (" ".join(map(str,A)))
print (num)        



Measured memory_bytes: 5596
//AGC 020
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;

int main(){
	
	std::ios::sync_with_stdio(false);
	lld t=1;
	//cin>>t;
	while(t--){
		lld n,a,b;
		cin>>n>>a>>b;
		lld rem=b-a;
		if(rem%2){
			cout<<"Borys\n";
		}
		else{
			cout<<"Alice\n";
		}
		
	}
}

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

using namespace std;

vector<int> lg;

template <typename T>
struct RMQ {
    int n;
    vector<vector<T>> table;
    RMQ(vector<int>& xs): n(xs.size()) {
        int K = lg[n] + 2;
        table = vector<vector<T>>(K, vector<T>(n, 0));
        for (int i = 0; i < n; ++i) {
            table[0][i] = xs[i];
        }
        for (int k = 1; k < K; ++k) {
            for (int i = 0; i < n; ++i) {
                int j = min(i + (1 << (k-1)), n-1);
                table[k][i] = max(table[k-1][i], table[k-1][j]);
            }
        }
    }
    T get_max(int i, int j) {
        int k = lg[j-i];
        return max(table[k][i], table[k][j - (1 << k)]);
    }
};

long long second_sum(vector<int>& ps) {
    int n = (int)ps.size();
    vector<int> inv_p(n+1);
    for (int i = 0; i < n; ++i) {
        inv_p[ps[i]] = i;
    }
    RMQ<int> rmq(ps);
    function<long long (int, int)> calc_sum = [&](int l, int r) {
        if (r - l < 2) return 0LL;
        int m = inv_p[rmq.get_max(l, r)];
        deque<int> lefts, rights;
        int i = l-1;
        lefts.push_back(l-1);
        while (i < m-1) {
            i = inv_p[rmq.get_max(i+1, m)];
            lefts.push_back(i);
        }
        i = r;
        rights.push_back(r);
        while (m+1 < i) {
            i = inv_p[rmq.get_max(m+1, i)];
            rights.push_back(i);
        }
        int current_left = m, current_right = m;
        int current = 0;
        long long sum = 0;
        while (lefts.size() > 1 || rights.size() > 1) {
            if (lefts.size() == 1 || (rights.size() > 1 && ps[rights.back()] < ps[lefts.back()])) {
                current = ps[rights.back()];
                rights.pop_back();
                int new_right = rights.back() - 1;
                sum += ((long long) current) * ((long long) m - current_left + 1) * (new_right - current_right);
                current_right = new_right;
            } else {
                current = ps[lefts.back()];
                lefts.pop_back();
                int new_left = lefts.back() + 1;
                sum += ((long long) current) * ((long long) current_right - m + 1) * (current_left - new_left);
                current_left = new_left;
            }
        }
        return sum + calc_sum(l, m) + calc_sum(m+1, r);
    };
    return calc_sum(0, n);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    lg = vector<int>(n+1, 0);
    for (int i = 2; i <= n; ++i) {
        lg[i] = 1 + lg[i/2];
    }
    vector<int> ps(n);
    for (int& p : ps) {
        cin >> p;
    }
    cout << second_sum(ps) << endl;
    return 0;
}


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

class dice {
    int dice[6];
public:
    void input() {
        for(int i=0; i<6; ++i) cin >> dice[i];
    }
    void output() {
        cout << dice[0];
        for(int i=1; i<6; ++i) cout << ' ' << dice[i];
        cout << endl;
    }
    void move(string state) {
        for(int i=0; i<state.length(); ++i) {
            switch(state[i]) {
                case 'N':
                    swap(dice[0], dice[1]);
                    swap(dice[1], dice[5]);
                    swap(dice[5], dice[4]);
                    break;
                case 'S':
                    swap(dice[0], dice[4]);
                    swap(dice[4], dice[5]);
                    swap(dice[5], dice[1]);
                    break;
                case 'E':
                    swap(dice[0], dice[3]);
                    swap(dice[3], dice[5]);
                    swap(dice[5], dice[2]);
                    break;
                case 'W':
                    swap(dice[0], dice[2]);
                    swap(dice[2], dice[5]);
                    swap(dice[5], dice[3]);
                    break;
                default:
                    break;
            }
        }
    }
    int index_of(int x) {
        for(int i=0; i<6; ++i) {
            if(dice[i] == x) return i;
        }
        return -1;
    }
    int getRightside(int top, int front) {
        int ind;
        ind = index_of(top);
        switch(ind) {
            case 0:
                break;
            case 1:
                move("N");
                break;
            case 2:
                move("W");
                break;
            case 3:
                move("E");
                break;
            case 4:
                move("S");
                break;
            case 5:
                move("NN");
                break;
            default:
                break;
        }
        ind = index_of(front);
        switch(ind) {
            case 0:
                break;
            case 1:
                break;
            case 2:
                move("NWS");
                break;
            case 3:
                move("NES");
                break;
            case 4:
                move("NWWS");
                break;
            case 5:
                break;
            default:
                break;
        }
        return dice[2];
    }
};

int main() {
    dice d;
    d.input();
    int i, n;
    cin >> n;
    int t[n], f[n];

    for(i=0; i<n; ++i) {
        cin >> t[i] >> f[i];
    }
    for(i=0; i<n; ++i) {
        cout << d.getRightside(t[i], f[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 3196
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

ll n,a,csum[200010],cxor[200010];

ll bs(ll x){
	ll lw=x,hi=n,ans=x;
	while(lw<=hi){
		ll mid=(lw+hi)>>1;
		if(csum[mid]-csum[x-1]==(cxor[mid]^cxor[x-1])){
			ans=mid;
			lw=mid+1;
		}
		else{
			hi=mid-1;
		}
	}

	return ans;
}
int main(){
	sfl(n);
	csum[0]=cxor[0]=0;
	FOR(i,n){
		sfl(a);
		csum[i]=csum[i-1]+a;
		cxor[i]=cxor[i-1]^a;
	}

	ll ans=0;

	for(ll i=1;i<=n;i++){
		ans += bs(i)-i+1;
	}

	pfl(ans);
}



Measured memory_bytes: 3328
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    string N;
    cin >> N;
    //cout << (N[0] -'0' + N[1]-'0') << endl;
    //cout << (N[0] -'0' + N[1]-'0' - 1) << endl;

    for (ll i = N.length() - 1; i > 0; --i) {
        if ( ((N[i] -'0') + (N[i-1]-'0')) > (9 + (N[i-1] - '0') - 1)) {
        } else {
            N.replace(i,1,"9");
            if (N[i-1] - '0' == 0) {

            } else {
                string s = to_string((N[i-1] - '0' - 1));
                N.replace(i-1,1,s);
            }
        }
    }
        int ans = 0;
        rep(i, 0, N.length()) {
            ans += N[i] - '0';
        }
        cout << ans << endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    set<int> s;
    rep(i,n){
        int a; cin >> a;
        if(s.count(a)){
            s.erase(a);
        }else{
            s.insert(a);
        }
    }
    int ans = s.size();
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector <int> a(2 * n);
  for (int i = 0; i < 2 * n; ++i)
    scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ret += a[i];
  printf("%d", ret);
  return 0;
}


Measured memory_bytes: 256
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; lint C; std::cin >> n >> C;
  std::vector<lint> pos(n), val(n);
  rep(i,0,n) {
    lint x, y; std::cin >> x >> y;
    pos.at(i) = x;
    val.at(i) = y;
  }

  auto rev = [&] (auto pos, auto val) {
    std::reverse(all(pos));
    for (lint & x : pos) {
      x = C - x;
    }
    std::reverse(all(val));
    return std::tie(pos,val);
  };

  auto make_v = [&] (auto pos, auto val, lint coeff) {
    std::partial_sum(all(val),val.begin());
    std::vector<lint> v(n);
    rep(i,0,n) {
      v.at(i) = val.at(i) - coeff * pos.at(i);
    }
    return v;
  };

  auto cal = [&] (auto pos, auto val) {
    debug("cal", pos,val);
    auto cal = [&] (auto&& v) {
      debug(v);
      std::vector<lint> ans = {0};
      lint max = 0;
      for (lint x : v) {
        cmx(max, x);
        ans.emplace_back(max);
      }
      return ans;
    };
    auto left = cal(make_v(pos,val,1));
    std::tie(pos,val) = rev(pos,val);
    auto right = cal(make_v(pos,val,2));
    debug(left, right);

    lint ans = 0;
    rep(i,0,n+1) {
      lint x = left.at(i);
      lint y = right.at(n-i);
      lint now = x + y;
      debug(now);
      cmx(ans,now);
    }
    return ans;
  };

  lint x = cal(pos,val);
  std::tie(pos,val) = rev(pos,val);
  lint y = cal(pos,val);
  lint ans = std::max(x,y);
  std::cout << ans << std::endl;
  return 0;
}

/*
負方向に行って戻って正方向に行くか、その逆が最適です。
境目を全探索です。
戻る方は coeff = 2, 行きっぱなしの方は coeff = 1 として、v - coeff * pos の累積和を考えます。
各場所について、そこまでしか行けないときの累積和の最大値を DP です。
*/

Measured memory_bytes: 8384
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

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

int main(){

	int N, M;
	cin >> N >> M;
	vector<bool> FLAG(N + 1, true);
	int a;
	for(int i = 0; i < M; i ++){
		cin >> a;
		FLAG[a] = false;
	}
	vector<ll> ANS(N + 1);
	ANS[0] = 1;
	if(FLAG[1]){
		ANS[1] = 1;
	}
	else{
		ANS[1] = 0;
	}
	for(int i = 2; i <= N; i ++){
		if(FLAG[i]){
			ANS[i] = ANS[i - 1] + ANS[i - 2];
		}
		else{
			ANS[i] = 0;
		}
		ANS[i] %= 1000000007;
	}
	cout << ANS[N] << endl;

//"Hiroakimm0415"

	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

#define MAXN 200000

ll bit[MAXN+1], n;

ll dp_max(ll i){
  ll s = 0;
  while(i>0){
    s = max(s,bit[i]);
    i -= i&-i;
  }
  return s;
}

void update(ll i, ll x){
  while(i<=n){
    bit[i] = max(bit[i],x);
    i += i&-i;
  }
}

int main(){
  cin >> n;
  fill(bit,bit+n+1,0);
  ll h[n], a[n];
  REP(i,n) cin >> h[i];
  REP(i,n) cin >> a[i];
  REP(i,n){
    update(h[i],dp_max(h[i]-1)+a[i]);
  }
  cout << dp_max(n) << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;

// AC
public class Main{
	Scanner sc=new Scanner(System.in);
	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	HashMap<Integer, Integer>[] w, cs;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			if((n|m)==0){
				break;
			}
			w=new HashMap[n];
			cs=new HashMap[n];
			for(int i=0; i<n; i++){
				w[i]=new HashMap<Integer, Integer>();
				cs[i]=new HashMap<Integer, Integer>();
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt()-1;
				int v=sc.nextInt()-1;
				int d=sc.nextInt();
				int c=sc.nextInt();
				w[u].put(v, d);
				w[v].put(u, d);
				cs[u].put(v, c);
				cs[v].put(u, c);
			}
			solve();
		}
	}

	void solve(){
		boolean[] used=new boolean[n];
		int[] road=new int[n];
		int[] d=new int[n];

		Arrays.fill(d, INF);
		d[0]=0;

		for(;;){
			int u=-1;
			for(int v=0; v<n; v++){
				if(!used[v]&&(u==-1||d[v]<d[u])){
					u=v;
				}
			}
			if(u==-1){
				break;
			}
			used[u]=true;
			for(Entry<Integer, Integer> entry : w[u].entrySet()){
				int v=entry.getKey();
				int w=entry.getValue();
				int c1=cs[road[v]].containsKey(v)?cs[road[v]].get(v):INF;
				int c2=cs[u].get(v);
				if(d[v]>d[u]+w){
					d[v]=d[u]+w;
					road[v]=u;
				}else if(d[v]==d[u]+w&&c1>c2){
					road[v]=u;
				}
			}
		}
		int ans=0;
		for(int i=1; i<n; i++){
			ans+=cs[i].get(road[i]);
		}
		println(""+ans);
	}

	void debug(Object... os){
	// System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 20000
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll sq[maxn];
int main()
{
	ll n,k,q,m;
	cin>>n>>k>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>m;
		sq[m]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(k-q+sq[i]>0) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 2010
#define maxm 100010
#define inf 9999999999999999
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn];
char s[maxn];
int head[maxn],nxt[maxn*2],to[maxn*2],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
ll mn[maxn],mx[maxn];
int g[maxn];
int solve(int x,int las)
{
    mx[x]=mn[x]=0;g[x]=a[x];
    int p=0;
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        solve(to[i],x);
        g[x]+=g[to[i]];
        mx[x]+=mx[to[i]];
        if(mx[to[i]]>mx[p])  p=to[i];
    }
    if(mn[p]>mx[x]-mx[p])  mn[x]=mn[p]+mx[p]-mx[x]+g[x];
    else                   mn[x]=(mx[x]&1)+g[x];
    mx[x]+=g[x];
    if(!las)  mn[x]-=g[x],mx[x]-=g[x];
}
ll ans=inf;
int main()
{
    n=read();
    scanf("%s",s+1);for(int i=1;i<=n;i++)  a[i]=s[i]-'0';
    for(int i=1;i<n;i++)
    {
        int q=read(),w=read();
        add(q,w);add(w,q);
    }
    for(int i=1;i<=n;i++)
    {
        solve(i,0);
        if(!mn[i])  ans=min(ans,mx[i]/2);
    }
    if(ans==inf)  puts("-1");
    else          cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let MOD = 998244353L

let pow x y =
    let rec aux k x y =
        if y = 0L then
            k
        else
            aux ((k * x) % MOD) x (y - 1L)
    aux 1L x y

[<EntryPoint>]
let main _ =
    let N = read int64
    let DS = reads int64

    let bs =
        List.groupBy id DS
        |> List.map (fun (x, y) -> (x, int64 <| List.length y))
        |> List.sortBy fst

    let cs = List.pairwise (List.tail bs)

    // eprintfn "*%A" bs
    // eprintfn "*%A" cs

    let rec solve acc = function
        | [] -> acc
        | ((x, xlen), (y, ylen)) :: xs ->
            if y - x <> 1L then
                0L
            else
                let d = pow xlen ylen
                solve ((acc * d) % MOD) xs

    if List.head DS = 0L && List.head bs = (0L, 1L) then
        solve 1L cs
    else
        0L
    |> printfn "%i"

    0

Measured memory_bytes: 59644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool F = false;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    string A;
    cin >> A;
    
    if (A == "Y") {
      F = true;
      cout << "Four" << endl;
      break;
    }
    }
  
  if (F == false) {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

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

int min=a;
int max=a;
long sum=a;


for(int i=1; i<n; i++){
scanf("%d",&a);
if(min>a){
min=a;
}else if(max<a){
max=a;
}
sum=sum+a;
}
printf("%d %d %ld\n",min,max,sum);

return 0;
}



Measured memory_bytes: 2148
from collections import deque
sa = input()
sb = input()
sc = input()

q = deque(sa[0])
sa = sa[1:]
while q:
  t = q.pop()
  if t == "a":
    if not sa:
      ans = "A"
      break
    q.append(sa[0])
    sa = sa[1:]
  elif t == "b":
    if not sb:
      ans = "B"
      break
    q.append(sb[0])
    sb = sb[1:]
  elif t == "c":
    if not sc:
      ans = "C"
      break
    q.append(sc[0])
    sc = sc[1:]
print(ans)

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;
int n;
vector<int> v;

const int M = 200000 / 26 + 1;
int L;
string ans;
bool tr[M][26][26];
bool vis[M][26];
bool dfs(int i, int c) {
	if(i == L) { return true; }
	if(exchange(vis[i][c], true)) { return false; }
	inc(d, 26) {
		if(tr[i][c][d] && dfs(i + 1, d)) {
			ans += ('a' + d);
			return true;
		}
	}
	return false;
}

int main() {
	cin >> s;
	n = s.size();
	
	int b[26], c = 0;
	inc(j, 26) { b[j] = 0; }
	v.PB(0);
	inc(i, n) {
		if(setmax(b[s[i] - 'a'], 1)) { c++; }
		if(c == 26) {
			v.PB(i + 1);
			inc(j, 26) { b[j] = 0; }
			c = 0;
		}
	}
	v.PB(n);
	
	L = v.size() - 1;
	inc(i,  L) {
	inc(j, 26) {
	inc(k, 26) {
		tr[i][j][k] = true;
	}
	}
	}
	
	inc(i, L) {
		bool b[26];
		inc(j, 26) { b[j] = true; }
		if(i != L - 1) {
			incID(j, v[i], v[i + 1]) {
				inc(k, 26) { tr[i + 1][k][s[j] - 'a'] &= b[k]; }
				b[s[j] - 'a'] = false;
			}
		} else {
			incID(j, v[i], v[i + 1]) {
				inc(k, 26) { tr[i + 0][k][s[j] - 'a'] = false; }
			}
		}
	}
	
	dfs(0, 0);
	reverse(ALL(ans));
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6148
#include "bits/stdc++.h"
#define ll long long
using namespace std;
#define INF (1<<30)

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N;
	while (cin >> N, N) {
		vector<vector<int>> t(N, vector<int>(N + 1));
		for (int i = 0;i < N;i++) {
			for (int j = 0; j < N+1;j++) {
				cin >> t[i][j];
			}
		}
		vector<int> bitdp(1 << N, INF);

		bitdp[0] = 0;

		for (int i = 0; i < (1<<N);i++) {
			for (int j = 0;j < N;j++) {
				if (i&(1 << j)) continue;
				int Min = t[j][0];
				for (int k = 0; k < N;k++) {
					if (!(i&(1 << k))) continue;
					Min = min(t[j][k+1], Min);
				}
				int at = (i | (1 << j));
				bitdp[at] = min(bitdp[at], bitdp[i] + Min);
			}
		}
		cout << bitdp[(1 << N) - 1] << endl;
	}
}

Measured memory_bytes: 3396
makeSum :: Int ->  (Int, Int) -> Int 
makeSum n (p, q)
  | n < 1     = 0
  | n == 1    = if q - p == 0 then 1 else 0
  | otherwise = if (q - p) >= 0 then (n - 2) * (q - p) + 1 else 0

main = do
  [n, minVal, maxVal] <- map read . words <$> getLine
  putStrLn $ show $ makeSum n (minVal, maxVal)
  


Measured memory_bytes: 508
//#include"bits/stdc++.h"
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
using namespace std;

int main()
{
	long long  a,b,c,x,y,ans,ans1,ans2,ans3;
	cin>>a>>b>>c>>x>>y;
	ans1=max(x,y)*2*c;
	ans2=a*x+b*y;
	if(y>x)ans3=min(x,y)*2*c+(y-x)*b;
	else ans3=min(x,y)*2*c+(x-y)*a;
	if(ans1>ans2)ans=ans2;
	else ans=ans1;
	if(ans>ans3)ans=ans3;
    cout<<ans;
    return 0;
	
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a, b = map(int,input().split()) 

ans1 = 0
for i in range(b):
    ans1 += a * 10 ** i
ans2 = 0
for i in range(a):
    ans2 += b * 10 ** i
tmp = [str(ans1), str(ans2)]
tmp.sort()
print(tmp[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,ans=0;
vl v;
float ff;
string s;
ll solve(){
    for(ll i=1;i<n-1;i++){
    	if(v[i-1]<v[i]&&v[i]<v[i+1])ans++;
    	if(v[i-1]>v[i]&&v[i]>v[i+1])ans++;
    }
    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
    	cin>>a;
    	v.push_back(a);
    }
 
    cout<<solve()<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
#include <string.h> 
#include <stdint.h>
 
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
 
#define ll long long
#define ld long double
#define ull unsigned long long
#define ut uint64_t
 
#define pb push_back
#define ins insert
#define er erase
 
#define fi(i, b) for (int i=0;i<b;i++)
#define fll(i, b) for (ll i=0;i<b;i++)
#define fla(i,a,b) for (ll i=a;i<b;i++)
 
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define vv(n,m) vector<vector<ll> > vec( n , vector<ll> (m, 0))
 
 
#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element
 
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
 
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
 
#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
 
#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>
 
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
 
 #define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
 
#define nl "\n"
using namespace std;
 
 
ll md = 1000000007;
ll ma = 998244353;
 
ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b){
        if (b & 1)c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}
 
ll pwmd(ll a, ll b){
    ll c = 1, m = a;
    while (b){
        if (b & 1)
            c = ((c * m)) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}
 
ll modinv(ll n)
{
    return pwmd(n, md - 2);
}
ll min(ll a,ll b){
    if(a>=b)return b;
    return a;
}
int binomialCoeff(ll n, ll k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (ll i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
}  

 
// Here we go...

void solve(){
  
  
  
      ll n,x;
      cin>>n>>x;
      cout<<n*x;
}


int main(){
    
    fast;
    ll t=1;
    //cin>>t;
    
    while(t--){
        solve();
    }
    return 0;
    }
    
// KHATAM HO GAYA:)...







Measured memory_bytes: 3676
n = int(input())
shop_list = []
for i in range(n):
    temp_list = list(input().split())
    temp_list[1] = int(temp_list[1])
    temp_list.append(i+1)
    shop_list.append(temp_list)

shop_list_sorted = sorted(shop_list,key=lambda x:(x[0],-x[1]))
for k in range(n):
    print(shop_list_sorted[k][2])


Measured memory_bytes: 9064