akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
template<typename K, typename V> using umap = unordered_map<K, V>;
template<typename K, typename V> using uset = unordered_set<K, V>;

//func
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

template<typename V, typename H> void resize(vector<V>& v, const H h) { v.resize(h); }
template<typename V, typename H, typename ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
template<typename V, typename T> void fill(V& x, const T& val) { x = val; }
template<typename V, typename T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }


int main(void) {
	vi X(3);
	REP(i, 3)X[i] = IN();
	int oddnum = 0;
	REP(i, 3) {
		if (X[i] % 2 != 0)oddnum++;
	}

	if (oddnum == 0 || oddnum == 3) {
		int mx = *max_element(ALL(X));
		int ans = 0;
		REP(i, 3) {
			if (X[i] == mx)continue;
			ans += (mx - X[i]) / 2;
		}
		OUT(ans);
		return 0;
	}

	ll ans = 1;
	if (oddnum == 1) {
		REP(i, 3) {
			if (X[i] % 2 == 0)X[i]++;
		}
	}
	else if (oddnum == 2) {
		REP(i, 3) {
			if (X[i] % 2 != 0)X[i]++;
		}
	}
	int mx = *max_element(ALL(X));
	REP(i, 3) {
		if (X[i] == mx)continue;
		ans += (mx - X[i]) / 2;
	}
	OUT(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	//cout << K * pow(K - 1, N - 1);

	int result = K;
	for (int i = 1; i <= N - 1; i++)
	{
		result *= (K - 1);
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int> > AB(N,vector<int>(2,0));
    for(int i=0; i<N; i++){
        int a,b;
        cin >> AB[i][0] >> AB[i][1];
    }
    sort(AB.begin(),AB.end());
    long long ans=0;
    for(int i=0; i<N; i++){
        ans+=(long long) AB[i][0] * min(M,AB[i][1]);
        M-=min(M,AB[i][1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	s,t = split(chomp(readline()))
	for i in 1:n
		print(s[i],t[i])
	end
	println("")
end

main()

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

int main(){
  int a, b;
  cin >> a >> b;
  int ans=0;
  if(a==1 && b==1) ans+=400000;
  if(a==1) ans+=300000;
  if(b==1) ans+=300000;
  if(a==2) ans+=200000;
  if(b==2) ans+=200000;
  if(a==3) ans+=100000;
  if(b==3) ans+=100000;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int H=sc.nextInt();
            int W=sc.nextInt();
            if(H==0 && W==0)break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++)System.out.printf("#");
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 56296
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;
#define int long long
const int N = (int) 1e6 + 6, mod = (int) 0;
int d[N], res[N], best[N];
int32_t main() {
	int n, init_dis;
	cin >> n >> init_dis;
	for (int j = 0; j < n; ++j) {
		cin >> d[j];
	}
	best[n] = 1;
	for (int j = n - 1; j >= 0; --j) {
		int nxtd = best[j + 1];
		best[j] = nxtd;
		if (abs(nxtd - d[j]) < nxtd) {
			best[j] = d[j] + nxtd;
		}
//		cout << " hi " << j << ' ' << best[j] << ' ' << nxtd << ' ' << d[j] << endl;
	}
	int curd = init_dis;
	for (int j = 0; j < n; ++j) {
		res[j] = curd < best[j + 1];
		if (abs(d[j] - curd) < curd) {
			curd = abs(d[j] - curd);
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x;
		cin >> x;
		--x;
		if (!res[x]) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
	}
}






Measured memory_bytes: 18304
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int x = 0;
		for (int i = 1; i < n + 1; i++) {

			x = x + i;
		}
		System.out.println(x);
	}
}


Measured memory_bytes: 21076
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,C,D;
int main(){
    cin>>A>>B>>C>>D;
    if((C-1)/B+1 <=(A-1)/D+1){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> prev(n);
    for (int i = 0; i < n; ++i) {
        cin >> prev[i];
    }
    for (int i = 0; i < d - 1; ++i) {
        vector<int> p(n);
        for (int j = 0; j < n; ++j) {
            cin >> p[j];
        }
        vector<int> ma(100100);
        for (int j = 0; j < 100100; ++j) {
            ma[j] = j;
        }
        for (int j = 0; j < n; ++j) {
            if (p[j] > prev[j]) {
                for (int k = prev[j]; k < 100100; ++k) {
                    ma[k] = max(ma[k], ma[k - prev[j]] + p[j]);
                }
            }
        }
        x = ma[x];
        prev = p;
    }
    cout << x << "\n";
    return 0;
}

Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {
	
	public static int[] print_num = 
		{0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			int from = sc.nextInt();
			int to = sc.nextInt();
			
			if(from > to){
				if(from <= 5){
					from = 15 - from;
					to = 15 - to;
				}else if(to <= 5){
					to = 15 - to;
				}else{
					to += 15;
				}
			}
			
			boolean first = true;
			for(int j = from; j <= to; j++){
				
				System.out.print((first ? "" : " ") + print_num[j >= 15 ? j - 15 : j]);
				
				if(first){
					first = false;
				}
			}
			System.out.println();
		}
		
	}
	
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll s,w;
	cin>>s>>w;
	if(w>=s)cout<<"un";
	puta("safe");
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,max = 0,min = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
			
				
				
			if(i == 1 || max < b[i] - min) max = b[i] - min;
			if(i == 0 || b[i] < min) min = b[i];
			
			
		}
		System.out.println(max);
	}
}



Measured memory_bytes: 98912
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;
void lots(int len,int a,int b,int array[]){
    int buffer[len];
    for(int i = 0;i < len; i++){
        if(i == a-1){
            buffer[i] = array[b-1];
        }
        else if(i == b-1){
            buffer[i] = array[a-1];
        }
        else{
            buffer[i] = array[i];
        }
    }
    for(int i = 0; i < len; i++){
        array[i] = buffer[i];
    }

}

int main(){
    int len,duration,a,b;
    cin >> len;
    cin >> duration;
    int array[len];
    for(int i = 0; i < len; i++){
        array[i] = i+1;
    }
    for(int i = 0; i < duration; i++){
        scanf("%d,%d",&a,&b);
        lots(len,a,b,array);
    }
    for(int i = 0; i < len; i++){
        cout << array[i] << endl;
    }
}

Measured memory_bytes: 3240
N=int(input())
F,P,F0=[],[],[]
ans=-10**9
for b in range(1,2**10):
    F0.append(format(b,'010b'))
for _ in range(N):
    F.append(list(input().split()))
for _ in range(N):
    P.append(list(map(int,input().split())))

for c in F0:
    benefit=0
    for i in range(N):
        counter=0
        for j in range(10):
            if c[j]=="1" and F[i][j]=="1":counter+=1
        benefit+=P[i][counter]
    ans=max(ans,benefit)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N,X,Y; cin>>N>>X>>Y;
	int edged=Y-X;

	int dist[N];
	dist[0]=0;
	for(int i=1; i<N; i++) dist[i]=N-i;

	int outL=X-1, outR=N-Y;

	for(int i=0; i<=outL; i++) {
		for(int j=0; j<=outR; j++) {
			dist[edged+i+j]--;
			dist[i+j+1]++;
		}
	}

	int inhalf=edged/2-1;

	for(int i=1; i<=outL; i++) {
		for(int j=1; j<=inhalf; j++) {
			dist[i+edged-j]--;
			dist[i+j+1]++;
		}
	}

	for(int i=1; i<=outR; i++) {
		for(int j=1; j<=inhalf; j++) {
			dist[i+edged-j]--;
			dist[i+j+1]++;
		}
	}

	for(int i=0; i<=inhalf; i++) {
		for(int j=0; j<=inhalf; j++) {
			if(i+j==0) continue;
			if(edged-j-i>i+j+1) {
				dist[edged-j-i]--;
				dist[i+j+1]++;
			}
		}
	}

	for(int i=1; i<N; i++) cout<<dist[i]<<endl;
}


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

int main()
{
    stack <char> P[4];
    string t[4];
    for(int i = 0 ; i < 3 ; i++)
    {
        cin >> t[i];
        for(int j = t[i].length() ; j >= 0 ; j--)
        {
            P[i].push(t[i][j]);
        }
    }
    int now = 0;
    while(!P[now].empty())
    {
        char next = P[now].top();
        P[now].pop();
        if(P[now].empty())
        {
            break;
        }
        now = next-'a';
    }
    char ans = now+'A';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#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         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#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")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;


int main(){
    ll tc,ans=INF,n,p,q;
    sfl(n);
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            p=i;
            q=n/i;
            ans = min(ans,p+q-2);
        }
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

/// AOJの疑似コートで指定されていたもの
fn partition(vec: &mut Vec<(char,u32)>, st: usize, end: usize) -> usize {
    let num = vec[end].1;
    let mut i: i32 = st as i32 - 1;

    // st..i+1にnum未満、
    // i+1..endにnum以上の数が入るように操作する
    for j in st..end {
        if vec[j].1 <= num {
            i += 1;
            vec.swap(i as usize, j);
        }
    }
    vec.swap(end, i as usize +1);
    i as usize + 1
}

fn quicksort(vec: &mut Vec<(char,u32)>, st: usize, end: usize) {
    if st < end {
        let q = partition(vec, st, end);
        quicksort(vec, st, q-1);
        quicksort(vec, q+1, end);
    }
}

/// 安定ソートとの結果を比較して安定かどうかを判別
fn is_stable(src: &Vec<(char,u32)>, vec: &Vec<(char,u32)>) -> bool {
    let mut t = src.clone();
    t.sort_by_key( |d| d.1 );
    for (i, j) in t.iter().zip(vec.iter()) {
        if i.0 != j.0 {
            return false;
        }
    }
    return true;
}

fn main() {
    let sin = io::stdin();
    let mut l_iter = sin.lock().lines();
    let l = l_iter.next().unwrap().unwrap();
    let n: usize = l.trim().parse().unwrap();
    let mut vec: Vec<(char, u32)> = vec![('0',0);n];

    for i in 0..n {
        let l = l_iter.next().unwrap().unwrap();
        let mut ws = l.split_whitespace();
        let c: char = ws.next().unwrap().chars().next().unwrap();
        let d: u32 = ws.next().unwrap().parse().unwrap();
        vec[i] = (c, d);
    }
    let src = vec.clone();

    // println!("{:?}", vec);
    let end = vec.len() - 1;
    quicksort(&mut vec, 0, end);
    
    if is_stable(&src, &vec) {
        println!("Stable");
    } else {
        println!("Not stable");
    }
    // println!("{:?}", vec);
    // println!("{:?}", src);
    for &(c, i) in vec.iter(){
        println!("{} {}", c, i);
    }
}



Measured memory_bytes: 6972
def calc():
  n=int(input())
  arr=[list(map(int,input().split())) for _ in range(2)]
  move1=[]
  move2=[]
  ans=n
  for i in range(3):
    if arr[0][i]-arr[1][i]>0:
      move2+=[i]
    if arr[1][i]-arr[0][i]>0:
      move1+=[i]
  if len(move1)==1:
    idx=move1[0]
    ans=arr[1][idx]*(ans//arr[0][idx])+ans%arr[0][idx]
  elif len(move1)==2:
    idx1=move1[0]
    idx2=move1[1]
    s1=arr[0][idx1]
    s2=arr[0][idx2]
    g1=arr[1][idx1]
    g2=arr[1][idx2]
    d1=g1-s1
    d2=g2-s2
    ta=max(ans+i*d1+((ans-i*s1)//s2)*d2 for i in range(ans//s1+1))
    ans=ta
  elif len(move1)==3:
    idx1=move1[0]
    idx2=move1[1]
    idx3=move1[2]
    s1=arr[0][idx1]
    s2=arr[0][idx2]
    s3=arr[0][idx3]
    g1=arr[1][idx1]
    g2=arr[1][idx2]
    g3=arr[1][idx3]
    if g1/s1<g2/s2:
      g1,g2=g2,g1
      s1,s2=s2,s1
    if g1/s1<g3/s3:
      g1,g3=g3,g1
      s1,s3=s3,s1
    if g2/s2<g3/s3:
      g2,g3=g3,g2
      s2,s3=s3,s2
    d1=g1-s1
    d2=g2-s2
    d3=g3-s3
    if ans//s1<=1000:
      pos=0
    else:
      pos=(ans//s1)//2
    ta=max(ans+i*d1+j*d2+((ans-i*s1-j*s2)//s3)*d3 for i in range(pos,ans//s1+1) for j in range((ans-i*s1)//s2+1))
    ans=ta
  if len(move2)==1:
    idx=move2[0]
    ans=arr[0][idx]*(ans//arr[1][idx])+ans%arr[1][idx]
  elif len(move2)==2:
    idx1=move2[0]
    idx2=move2[1]
    s1=arr[1][idx1]
    s2=arr[1][idx2]
    g1=arr[0][idx1]
    g2=arr[0][idx2]
    if g1/s1<g2/s2:
      g1,g2=g2,g1
      s1,s2=s2,s1
    d1=g1-s1
    d2=g2-s2
    if ans//s1<=1000:
      pos=0
    else:
      pos=(ans//s1)//2
    ta=max(ans+i*d1+((ans-i*s1)//s2)*d2 for i in range(pos,ans//s1+1))
    ans=ta
  elif len(move2)==3:
    idx1=move2[0]
    idx2=move2[1]
    idx3=move2[2]
    s1=arr[1][idx1]
    s2=arr[1][idx2]
    s3=arr[1][idx3]
    g1=arr[0][idx1]
    g2=arr[0][idx2]
    g3=arr[0][idx3]
    if g1/s1<g2/s2:
      g1,g2=g2,g1
      s1,s2=s2,s1
    if g1/s1<g3/s3:
      g1,g3=g3,g1
      s1,s3=s3,s1
    if g2/s2<g3/s3:
      g2,g3=g3,g2
      s2,s3=s3,s2
    d1=g1-s1
    d2=g2-s2
    d3=g3-s3
    if ans//s1<=1000:
      pos=0
    else:
      pos=(ans//s1)//2
    ta=max(ans+i*d1+j*d2+((ans-i*s1-j*s2)//s3)*d3 for i in range(pos,ans//s1+1) for j in range((ans-i*s1)//s2+1))
    ans=ta
  print(ans)
calc()

Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;
int INF = 100000;

int main() {
    int H,W;cin >> H >> W;
    char s[H][W] = {};
    int d[H][W] = {};
    queue<P> que;
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cin >> s[i][j];
            if(s[i][j] == '#') {
                d[i][j] = 1;
                que.push(P(i,j));
            }
            else d[i][j] = 0;
        }
    }
    int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
    int ans = 0;
    while(que.size()){
        P p = que.front();que.pop();
        for (int i = 0;i < 4;i++){
            int nx = p.second + dx[i];int ny = p.first + dy[i];
            if (nx >= 0 && nx < W && ny >= 0 && ny < H && d[ny][nx] == 0){
                d[ny][nx] = d[p.first][p.second] + 1;
                que.push(P(ny,nx));
            }
        }
    }
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            ans = max(ans,d[i][j]);
        }
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 13328
N = int(input())
T,A = map(int,input().split())
L = list(map(int,input().split()))
ans = 0
tem = abs((T-L[0]*0.006)-A)
for i in range(N):
  if (abs((T-L[i]*0.006)-A) <= tem):
    ans = i+1
    tem = abs((T-L[i]*0.006)-A)
  else:
    None
print(ans)

Measured memory_bytes: 3064
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end
N = inputs[0].to_i
H = inputs[1].split(" ").map(&:to_i)

max = nil
ans = true

i = 0;
while i < N && ans
  h = H[i]
  if max.nil? || max < h
    max = h
  elsif max - h >= 2
    ans = false
  end
  i += 1
end

puts ans ? "Yes" : "No"

Measured memory_bytes: 8656
#include "cstring"
#include "iostream"

using namespace std;

int main()
{
	int A, B, C, K, Y,a,b,max,t,result=0;
	cin >> A >> B >> C ;
	cin >> K;
	if (A > B) {
		if (A > C){
			max = A;
			result = B + C;
		}
		else {
			max = C;
			result = A + B;
		}
	}
	else {
		if (B > C){
			max = B;
			result = A + C;
		}
		else{
			max = C;
			result = A + B;
		}
	}

	for (t = 0; t < K; t++)
		max += max;

	cout << (max + result);
		
	


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <set>
#include <map>
#define F first
#define S second
#define pb push_back
#define sz(c) (LL) c.size()
#define len(c) (LL) c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
#define vpint vector<pair<int, int>>
#define vpLL vector<pair<LL, LL>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(n) \
    for (int i = 0; i < n; i++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long LU;
const LL mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL r, g, x, y, z, ans = 0;
    cin >> r >> g >> x >> y >> z;
    priority_queue<pair<LL, LL>, vector<pair<LL, LL>>> pq, dp;
    fr(x)
    {
        LL u;
        cin >> u;
        pq.push(make_pair(u, 1));
    }
    fr(y)
    {
        LL u;
        cin >> u;
        pq.push(make_pair(u, 2));
    }
    fr(z)
    {
        LL u;
        cin >> u;
        pq.push(make_pair(u, 0));
    }
    while ((r + g) > sz(dp))
    {
        if (pq.top().S == 0)
        {
            dp.push(pq.top());
        }
        else if (pq.top().S == 1 && r > 0)
        {
            ans += pq.top().F;
            r--;
        }
        else if (pq.top().S == 2 && g > 0)
        {
            ans += pq.top().F;
            g--;
        }
        pq.pop();
    }
    while (!dp.empty())
    {
        ans += dp.top().F;
        dp.pop();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 10604
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <limits.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int P[3];
int ten_two (int x) {
  int sub = 4;
  for (int i = 0; i < 3; i++) {
    if (x >= sub) {
      if (sub != 0) {
        P[i] = 1;  
      }  
      x = x - sub;
    }    
    else {
      P[i] = 0;  
    }
    sub = sub / 2;
  }
    
}
int main () {
  string h;
  cin >> h; 
  int ans[4];
  for (int i = 0; i < 4; i++) {
    ans[i] = stoi(h.substr(i, 1));  
  }
  for (int i = 0; i < 8; i++) {
    ten_two(i);
    int sub = ans[0];
    for (int i = 0; i < 3; i++) {
      if (P[i] == 1) {
        sub = sub + ans[i + 1];  
      } 
      else {
        sub = sub - ans[i + 1];  
      }
    }  
    if (sub == 7) {
      cout << ans[0];
      for (int i = 0; i < 3; i++) {
        if (P[i] == 1) {
          cout << "+";  
        }  
        else {
          cout << "-";  
        }
        cout << ans[i + 1];
      }  
      cout << "=7" << endl;
      return 0;
    }
  }
}

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

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	
	int L[M], R[M];
	for(int i = 0; i < M; i++) scanf("%d %d", &L[i], &R[i]);
	
	int L_max = *max_element(L, L+M);
	int R_min = *min_element(R, R+M);
	if(L_max > R_min) printf("0");
	else printf("%d", R_min - L_max + 1);
	
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String[] mar;
		int[] num;
		num = new int[54];
		int n = scan.nextInt();
		int i,q;
		for(i = 1; i <= n; ++i){
			String m = scan.next();
			int x = scan.nextInt();
			if(m.equals("S")){
				num[x] = x;				
			}
			else if(m.equals("H")){
				q = x + 13;
				num[q] = q;
			}
			else if(m.equals("C")){
				q = x + 26;
				num[q] = q;
			}
			else if(m.equals("D")){
				q = x + 39;
				num[q] = q;
			}	
		}
		int s;
		s = 0;
		for(i = 1; i <= 52; ++i){
			if(num[i] == 0){
				if(i <= 13){
					s = i;
					System.out.println("S "+s);
				}
				else if(i > 13 && i <= 26){
					s = i - 13;
					System.out.println("H "+s);
				}
				else if(i > 26 && i <= 39){
					s = i - 26;
					System.out.println("C "+s);
				}
				else if(i > 39){
					s = i - 39;
					System.out.println("D "+s);
				}
			}
		}
	}
}

		
				

Measured memory_bytes: 26292
n = int(raw_input())
A = [0]
NY = range(1, n)
a = [[0 for i in xrange(n)] for j in xrange(n)]
for i in xrange(n):
	a[i] = map(int,raw_input().split())
long = 0
while NY != []:
	amin = 2001
	for i in A:
		for j in NY:
			if 0 <= a[i][j] < amin:
				amin = a[i][j]
				addA = j
	A.append(addA)
	NY.remove(addA)
	long += amin
print long

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

int main() {
  int N;
  int sum =0;
  cin >>N;
  
  for (int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum <<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long N,i,j,m=1e9+7,r,c;
int main(){
  cin>>N;
  vector<long>A(N);
  for(auto& a:A)cin>>a;
  for(i=0;i<60;i++){
    c=0;
    for(auto& a:A)c+=a>>i&1;
    c=c*(N-c)%m;
    for(j=0;j<i;j++)c=c*2%m;
    r+=c;
  }
  cout<<r%m<<endl;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int N;
  cin >> N;

  vector<int> negative, positive;
  int a;
  rep(i, N) {
    cin >> a;
    if (a < 0)
      negative.push_back(a);
    else
      positive.push_back(a);
  }

  int x, y;
  vector<P> p;
  if (negative.empty()) {  // all positive
    sort(all(positive));
    y = positive.back();
    positive.pop_back();
    reverse(all(positive));
    x = positive.back();
    positive.pop_back();
    p.push_back(P(x, y));
    if (x - y < 0) {
      negative.push_back(x - y);

    } else {
      positive.push_back(x - y);
      if (1 < positive.size()) {
        sort(all(positive));
        x = positive.back();
        positive.pop_back();
        reverse(all(positive));
        y = positive.back();
        positive.pop_back();

        if (positive.empty()) {
          positive.push_back(x - y);
          p.push_back(P(x, y));
        } else {
          negative.push_back(y - x);
          p.push_back(P(y, x));
        }
      }
    }

  } else if (positive.empty()) {  // all negative
    sort(all(negative));
    x = negative.back();
    negative.pop_back();
    reverse(all(negative));
    y = negative.back();
    negative.pop_back();
    positive.push_back(x - y);
    p.push_back(P(x, y));
  }

  while (!negative.empty()) {
    x = positive.back();
    y = negative.back();
    positive.pop_back();
    negative.pop_back();

    if (positive.size() <= negative.size()) {
      positive.push_back(x - y);
      p.push_back(P(x, y));
    } else {
      negative.push_back(y - x);
      p.push_back(P(y, x));
    }
  }

  cout << positive[0] << endl;
  for (auto x : p) {
    cout << x.first << " " << x.second << endl;
  }

  return 0;
}

Measured memory_bytes: 3444
n = int(input())
a = list(map(int, input().split()))
# 1がマックス連続するところ+1の数が出せるサイコロが必要
mx = 0
cnt = 0
for i in a:
    if i == 1:
        cnt += 1
        if mx <= cnt:
            mx = cnt
    else:
        cnt = 0
print(mx+1)


Measured memory_bytes: 5588
s = gets.chomp
n = s.size

val = {}
factor = 1
current_num = 0
val[0] = 1
n.times do |i|
  add_num = s[n-1-i].to_i
  current_num = (current_num + factor * add_num) % 2019
  factor = (factor * 10) % 2019
  val[current_num] ||= 0
  val[current_num] += 1
end

sum = 0
val.values.each do |v|
  sum += (v * (v - 1) / 2)
end

puts sum


Measured memory_bytes: 14844
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int dp[100010];

int main() {
  int n;
  cin >> n;
  vector<int> h(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < 100010; i++) {
    dp[i] = 1000000000;
  }
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);
  for (int i = 3; i <= n; i++) {
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n] << endl;
  return 0;
}

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

signed main(){
    int n,a=1e9,c[2][20];
    cin>>n;
    R(i,n)cin>>c[0][i];
    R(i,n)cin>>c[1][i];
    vector<vector<int>> p(1<<n,vector<int>(51,1e9));
    p[0][0]=0;
    R(B,1<<n){
        int o=0,d[n];
        R(i,n)if(!(B&1<<i))d[i]=o++;
        R(i,n){
            int k=abs(i-n+o);
            R(j,c[k%2][i]+1)p[B|1<<i][c[k%2][i]]=min(p[B|1<<i][c[k%2][i]],p[B][j]+d[i]);
        }
    }
    R(i,51)a=min(a,p[(1<<n)-1][i]);
    cout<<(a==1e9?-1:a);
}

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

int n, m, q, a[55], b[55], c[55], d[55];

long long mx = 0;

void dfs(vector<int> v)
{
	if (v.size() == n + 1)
	{
		long long cnt = 0;
		for (int i = 0; i < q; i++)
		{
			if (v[b[i]] - v[a[i]] == c[i]) cnt += d[i];
		}
		mx = max(mx, cnt);
		return ;
	}
	for (int i = v[v.size() - 1]; i <= m; i++)
	{
		v.push_back(i);
		dfs(v);
		v.erase(v.begin() + v.size() - 1);
	}
	return ;
}

int main()
{
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	vector<int> vv;
	vv.push_back(1);
	dfs(vv);
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()   {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll available = 1000;
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i < n-1; i++){
        ll s = 0;
        s = available/a[i];
        if(a[i] < a[i+1])  available+=(a[i + 1] - a[i])*s;


    }
    cout << available  << "\n";
    return 0;
}


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

using namespace std;

vector < int > adj[100007];

int used[100007], dp[100007], mx;

void dfs( int v ) {
	if ( used[v] ) return;
	used[v] = 1;
	for ( auto u: adj[v] ) {
		dfs(u);
		dp[v] = max( dp[v], dp[u] + 1 );
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	for ( int i = 0; i < m; i++ ) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
	}
	for ( int i = 1; i <= n; i++ ) {
		dfs(i);
		mx = max( mx, dp[i] );
	}
	cout << mx << endl;
}

Measured memory_bytes: 8576
import java.util.*;

public class Main {
    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      double str = Double.parseDouble((String)scan.next());
      int count=0;
      double total=100;
      
      while(true){
          total *= 1.01;
          total = Math.floor(total);
          count++;
          if(str <= total){
              break;
          }
      }
      
      System.out.println(count);
      scan.close();
    }
}

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

int main() {
    int n,ans=100000000,res;
    string s;
    cin>>n>>s;
    vector<int> e(n+1,0),w(n+1,0);
    rep(i,n) {
        if (s[i]=='E') {
            e[i+1]=e[i]+1;
            w[i+1]=w[i];
        } else {
            e[i+1]=e[i];
            w[i+1]=w[i]+1;
        }   
    }
    rep(i,n) {
        res=e[n]-e[i+1];
        ans=min(ans,res+w[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3076
#include<iostream>
#include<cstdio>
using namespace std;
int a,b;
int max(int a,int b)
{
    return a>b?a:b;
}
int main(){
    scanf("%d %d",&a,&b);
    printf("%d\n",max(max(a+b,a-b),a*b));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{


    long long int i,a,c;
    char op;


    for(i=1;i<=i;i++){
        cin>>a>>op>>c;
        if(op=='+'){
            cout<<a+c;
        }
        else if(op=='-'){
            cout<<a-c;
        }

        else if(op=='*'){
            cout<<a*c;
        }

        else if(op=='/'){
            cout<<a/c;
        }

        else if(op=='?'){
            break;
        }


        cout<<endl;
    }
    return 0;
}



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

using namespace std;

using ll = long long;

void Dfs(int cur, int p, int len, auto &d, auto &adj) {
    d[cur] = len;
    for (auto u : adj[cur])
        if (u != p && d[u] == -1)
            Dfs(u, cur, len + 1, d, adj);
}

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
    }

    vector<int> d_b(n, -1), d_w(n, -1);
    Dfs(0, -1, 0, d_b, adj);
    Dfs(n - 1, -1, 0, d_w, adj);

    int black = 0, white = 0;
    for (int v = 0; v < n; ++v) {
        if (d_b[v] <= d_w[v]) ++black;
        else ++white;
    }

    if (white < black) cout << "Fennec\n";
    else cout << "Snuke\n";

    return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    string s; cin >> s;
    
    int cnt1 = 0;
    for (int i = 0; i < s.size(); i++) if (s[i] != '0' + (i%2)) cnt1++;
    int cnt2 = 0;
    for (int i = 0; i < s.size(); i++) if (s[i] != '0' + ((i+1)%2)) cnt2++;
    cout << min(cnt1, cnt2) << endl;
    return 0;
}

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

int main() {
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if (x>=r && y>=r && H-y>=r && W-x>=r){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
    
  
  
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
	int n;
	int i,j,k;
	int a,b,c;
	int s=0;
	cin>>n;
	while(n--){
		cin>>a>>b>>c;
		s=(10-b)*20+20-c+1;
		if(a%3!=0)s-=(10-b)/2+1;
		for(i=a+1;i<1000;i++){
			s+=200;
			if(i%3!=0)s-=5;
		}
		cout<<s<<endl;
	}
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
const int MAX = 1e6 + 10;
typedef long long i64;
using namespace std;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;


int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    //freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'

    string a;
    cin >> a;
    bool mask[26];
    for(int i = 0; i < 26; i++){
    	mask[i] = false;
    }
    vector<int> cuts;
    int cc = 0;
    for(int i = a.size() - 1; i >= 0; i--){
    	if(mask[a[i] - 'a'] == false){
    		mask[a[i] - 'a'] = true;
    		cc++;
    	}
    	if(cc == 26){
    		cuts.push_back(i);
    		cc = 0;
    		memset(mask, 0, sizeof(mask));
    	}
    }
    reverse(cuts.begin(), cuts.end());
    vector<char> ss;

    cuts.push_back(a.size());
    if(cuts[0] != 0){
    	memset(mask, 0, sizeof(mask));
    	for(int i = 0; i < cuts[0]; i++){
    		mask[a[i] - 'a'] = true;
    	}
    	int b = -1;
    	for(int i = 0; i < 26; i++)
    		if(!mask[i]){
    			b = i; break;
    		}
    	ss.push_back(b + 'a');

    	for(int j = 0; j < (int)cuts.size() - 1; j++){
    		memset(mask, 0, sizeof(mask));
    		int last = -1;
    		for(int i = cuts[j + 1] - 1; i >= cuts[j]; i--){
    			if(ss.back() == a[i])last = i;
    		}
    		for(int i = cuts[j + 1] - 1; i > last; i--){
    			mask[a[i] - 'a'] = true;
			}
    		for(int i = 0; i < 26; i++)
				if(!mask[i]){
					b = i; break;
				}
			ss.push_back(b + 'a');
    	}
    }
    else{
    	ss.push_back('a');
    	int b = 0;
    	// wrong
    	for(int j = 0; j < (int)cuts.size() - 1; j++){
			memset(mask, 0, sizeof(mask));
			int last = -1;
			for(int i = cuts[j + 1] - 1; i >= cuts[j]; i--){
				if(ss.back() == a[i])last = i;
			}
			for(int i = cuts[j + 1] - 1; i > last; i--){
				mask[a[i] - 'a'] = true;
			}
			for(int i = 0; i < 26; i++)
				if(!mask[i]){
					b = i; break;
				}
			ss.push_back(b + 'a');
		}
    }
    
    for(auto i:ss)cout<<i;



}



Measured memory_bytes: 720
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int n;
	
	while(scanf("%d", &n), n != 0){
		int guest[10001] = {0};
		long time_sum = 0,i;
						
		for(i = 0; i < n; i++) scanf("%d", &guest[i]);
		
		sort(guest, guest+i);
		
		for (i = 1; i < n; i++){
            for (int j = 0; j < i; j++){
                time_sum += guest[j];
            }
        }
		
		printf("%ld\n", time_sum);
	}
	return(0);
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ' ');
  }
  // os << '}';
  return os;
}

int main()
{
  int r;
  cin >> r;
  double ans = 3.141592648777698869248;
  printf("%.10lf\n", r * 2 * ans);
}


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

int main() {
  int A, B, C, D, L, R;
  
  cin >> A >> B >> C >> D;

  L = A + B;
  R = C + D;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
9592
)");
#define cin input
#endif

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

    int count = 0;
    for (int i=0; i<4; i++)
    {
        if (s[i]=='2')
            count++;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// ABC 109 C

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int gcd(int u, int v)
{
  return (v != 0) ? gcd(v, u % v) : u;
}

int main(int argc, char** argv) {
  int n, x;
  cin >> n >> x;
  vector<int> points(n+1);
  rep(i, n) {
    cin >> points[i];
  }
  points[n] = x;

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

  int ans = INF;
  rep(i, n) {
    chmin(ans, abs(points[i] - points[i+1]));
  }
  // 答えは ans 以下
  rep(i, n) {
    if (abs(points[i] - points[i+1]) % ans != 0) {
      ans = gcd(ans, abs(points[i] - points[i+1]));
    }
  }

  cout << ans << endl;

  return 0;
}


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


int main(){
    int N;
    cin >> N;
    int p[N], q[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    for(int i = 0; i < N; i++){
        cin >> q[i];
    }
    vector<int> a(N, 1);
    vector<int> b(N, 1);
    long long count1 = 0, count2 = 0;
    for(int i = 0; i < N; i++){
        a[p[i] - 1] = 0;
        long long t = 1;
        int c1 = 0;
        for(int j = 0; j < p[i] - 1; j++){
            if(a[j] != 0) c1++;
        }
        for(int j = 1; j < N - i; j++) t *= j;
        count1 += t * c1;
    }
    for(int i = 0; i < N; i++){
        b[q[i] - 1] = 0;
        long long t1 = 1;
        int c = 0;
        for(int j = 0; j < q[i] - 1; j++){
            if(b[j] != 0) c++;
        }
        for(int j = 1; j < N - i; j++) t1 *= j;
        count2 += t1*c;
    }
    printf("%ld\n", abs(count1 - count2));
}

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


int main() {

  int m=0, f=0, r=0;
  int sum=0;

  while(1) {

    cin >> m >> f >> r;

    sum = m+f;

    if(m==-1 && f==-1 && r==-1){

      break;
      
    } else {

      if(m==-1 || f==-1) {

        cout << "F" << endl;
        
      } else if(80<=sum) {

        cout << "A" << endl;
        
      } else if(65<=sum && sum<80) {

        cout << "B" << endl;
        
      } else if(50<=sum && sum<65) {

        cout << "C" << endl;
        
      } else if(30<=sum && sum<50 && (r==-1 || r<50)) {

        cout << "D" << endl;
        
      } else if(30<=sum && sum<50 && 50<=r) {

        cout << "C" << endl;
        
      } else if(sum<30) {

        cout << "F" << endl;
        
      }
      
    }
    
  }

}


Measured memory_bytes: 3132