akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(n, -1);
    queue<int> que;
    int count = 0;
    for (int v = 0; v < n; ++v) {
        if (dist[v] != -1) continue;
        dist[v] = 0, que.push(v);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    que.push(nv);
                }
            }
        }
        ++count;
    }
    --count;
    if(count < 0) count = 0;
    cout << count << endl;
    return 0; 
}
 

Measured memory_bytes: 8800
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=9&&a>=1&&b<=9&&b>=1) printf("%d\n",a*b);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    answer = ""
    for s in S:
        index = alpha.index(s)
        new_index = (index+N)%26
        answer+=alpha[new_index]
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    ll ans = 0;
    for(int d=29;d>=0;d--){
        ll high = 1 << (d+1), low = 1 << d;
        REP(i,N) a[i] %= high, b[i] %= high;
        sort(b.begin(), b.end());
        ll sum = 0;
        REP(i,N){
            int tmp = 0;
            if(low - a[i] >= 0) tmp += lower_bound(b.begin(), b.end(), high-a[i]) - lower_bound(b.begin(), b.end(), low-a[i]);
            else{
                tmp += lower_bound(b.begin(), b.end(), high-a[i]) - b.begin();
                tmp += lower_bound(b.begin(), b.end(), high) - lower_bound(b.begin(), b.end(), high + low-a[i]);
            }
            sum += tmp;
        }
        if(sum & 1) ans += low;
    }
    cout << ans << endl;
}

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

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

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

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

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

template <typename T>
class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ

        // 重み付きUnionFindでのみ利用
        vector<T> diffWeight; // 親ノードとの値の差
    public:
        UnionFind(int n);          // n要素で初期化
        int Find(int x);           // 木の根を返す
        void Unite(int x, int y);  // xとyの属する集合を併合
        bool Same(int x, int y);   // xとyが同じ集合に属するか否か

        // 重み付きUnionFindでのみ利用
        void Unite(int x, int y, T w);
        T Weight(int x);      // xの重みを返す
        T Diff(int x, int y); // xとyの差を返す
};

template <typename T>
UnionFind<T>::UnionFind(int n) : parent(n), rank(n), diffWeight(n, 0) {
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

template <typename T>
int UnionFind<T>::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        int r = Find(parent[x]);
        diffWeight[x] += diffWeight[parent[x]];
        return parent[x] = r;
    }
}

template <typename T>
void UnionFind<T>::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

template <typename T>
bool UnionFind<T>::Same(int x, int y) { return Find(x) == Find(y); }

template <typename T>
void UnionFind<T>::Unite(int x, int y, T w){
    w += Weight(x); w -= Weight(y);
    x = Find(x); y = Find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) swap(x, y), w = -w;

    if(rank[x] == rank[y]) rank[x]++;
    parent[y] = x;

    diffWeight[y] = w;
}

template <typename T>
T UnionFind<T>::Weight(int x){
    Find(x);
    return diffWeight[x];
}

template <typename T>
T UnionFind<T>::Diff(int x, int y){
    return Weight(y) - Weight(x);
}

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

    int n, m;
    cin >> n >> m;
    UnionFind<int> uf(m+n);
    REP(i, n){
        int k;
        cin >> k;
        REP(j, k){
            int l;
            cin >> l;
            l--;
            uf.Unite(m+i, l);
        }
    }

    FOR(i, 1, n){
        if(!uf.Same(m, m+i)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    string s;
    cin>>s;
    if (s=="SUN") {
        cout<<7<<endl;
    }
    if (s=="MON") {
        cout<<6<<endl;
    }
    if (s=="TUE") {
        cout<<5<<endl;
    }
    if (s=="WED") {
        cout<<4<<endl;
    }
    if (s=="THU") {
        cout<<3<<endl;
    }
    if (s=="FRI") {
        cout<<2<<endl;
    }
    if (s=="SAT") {
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int k[30], a[30][30];
	int suki[31];
	for (int i = 0; i <= 30; i++) {
		suki[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		cin >>k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> a[i][j];
			suki[a[i][j]]++;

		}

	}
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		if (suki[i] == n)ans++;
	}
	cout << ans;
	return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.1416
#define f(i,l,r) for(int i=l;;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    ll int i,j,k,sum=0,x,p=100,r,a,b,c=0;
    long double n,q=100;

    cin>>a;

    f(i,1,)
    {
        if(p>=a)
            break;
        else
        {

            n=p*(1/q);
            p=p+n;
            c++;
        }

    }

    cout<<c<<endl;

    return 0;

}


Measured memory_bytes: 3608
package main

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

var sc = bufio.NewScanner(os.Stdin)

const MAX = 10000

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func CountingSort(A []int) []int {
	C := make([]int, MAX+1)
	for _, value := range A {
		C[value]++
	}
	for i := 1; i < len(C); i++ {
		C[i] = C[i] + C[i-1]
	}
	B := make([]int, len(A))
	for j := 0; j < len(A); j++ {
		B[C[A[j]]-1] = A[j]
		C[A[j]]--
	}
	return B
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n)

	for i := range A {
		A[i] = nextInt()
	}

	result := strings.TrimRight(fmt.Sprintf("%+v", CountingSort(A))[1:], "]")
	fmt.Println(result)

}



Measured memory_bytes: 74148
#pragma GCC optimize ("Ofast")
#pragma GCC target(*sse4.2*)
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define S second
#define debug(x) cout<<("#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define mod 1000000007
#define lg2(x) 63-(__builtin_ctzll(x))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
typedef unsigned long long ull;
typedef long double d64;




int main(){
    fast
   read(a);
   read(b);
   read(c);
   read(k);

   while(k>0){
    if(a>=b){
            b*=2;
            k--;
        }
    if(b>a)break;
   }
   while(k>0){
    if(b>=c){
        c*=2;
        k--;
    }
    if(c>b)break;
   }

    if(b>a&&c>b)cout<<"Yes";
    else cout<<"No";

return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>

int main(){
	int max,min,sa=0,i,n,r[200000]={};
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&r[i]);
	min = r[0];
	max=min;	
	for(i=0;i<n-1;i++){
		if(r[i+1]-min<0) {
			min = r[i+1];
			max = min;
		}
		if(max<r[i+1]) max = r[i+1];
		if(sa<max-min) sa=max-min;
	}

	if(max==min&&sa==0){
		sa = r[1]-r[0];
		for(i=0;i<n-1;i++){
			if(sa<r[i+1]-r[i]) sa = r[i+1]-r[i]; 
		}	
	}

	printf("%d\n",sa);

	return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N);
	long long sum =0;
	for(int i =0; i < N; i++) {
		cin >> A[i];
		sum +=A[i];}
	int steps =0;
	while(sum > 0) {
		sum -=1LL*N*(N+1)/2;
		steps++;}
	if(sum < 0) {
		cout << "NO\n";
		return 0;}

	vector<int> dif(N);
	for(int i =0; i < N; i++) dif[i] =A[i]-A[(i+N-1)%N]-steps;
	for(int i =0; i < N; i++) if(dif[i]%N != 0 || dif[i] > 0) {
		cout << "NO\n";
		return 0;}
	vector<int> apl(N,0);
	for(int i =0; i < N; i++) {
		apl[i] =(-dif[i])/N;
		steps -=apl[i];}
	if(steps != 0) {
		cout << "NO\n";
		return 0;}
	cout << "YES\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

long long N,A,B;
int x[200000];
int main(){
    cin >> N;
    cin >> A;
    cin >> B;

    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    long long int sum = 0;
    for(int i=0;i<N-1;i++){
        if((x[i+1]-x[i])*A>B){
            sum += B;
        }else{
            sum += (x[i+1]-x[i])*A;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

bool f(){
	int t=n-1;
	for(int i=n-2;i>=0;i--){
		if(a[i]+i>=t) t=i;
	}
	reverse(a.begin(),a.end());
	return t==0;
}

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]/=10;
	}
	if(f()&&f()) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}


Measured memory_bytes: 3900
l, n = [int(i) for i in input().split(" ")]
x = []

for i in range(0, n):
    x.append(int(input()))

y = [l - x[n - i - 1] for i in range(0, n)]
m = 0

def cal(x, y):
    global m
    
    sx = [0] * (n + 1)
    sy = [0] * (n + 1)
    for i in range(1, n + 1):
        sx[i] = sx[i - 1] + x[i - 1]
        sy[i] = sy[i - 1] + y[i - 1]
    for i in range(0, n):
        xc = (n - i - 1) // 2
        yc = (n - i - 1) - xc
        last = 0
        if (n - i) % 2 == 0:
            last = y[yc - 1]
        else:
            last = x[i + xc]
        mt = 2 * x[i] + 2 * (sy[yc] + sx[i + xc + 1] - sx[i + 1]) - last
        #print(i, mt, xc, yc, sx[i + xc + 1] - sx[i + 1], sy[yc], last)
        if mt > m:
            m = mt

cal(x, y)
cal(y, x)
print(m)

Measured memory_bytes: 37948
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;
string s[444];
ll dx[]={-1, 0, 1, 0};
ll dy[]={0, -1, 0, 1};

P dfs(ll x, ll y, ll clr, ll** used) {
    used[x][y]=1;
    
    
    P p=mkp(0, 0);
    if(s[x][y]=='#') p.fi++;
    else p.se++;
    
    for(ll i=0; i<4; i++) {
        ll tx=x+dx[i];
        ll ty=y+dy[i];
        
        if(tx<0 || ty<0 || tx>=H || ty>=W) continue;
        if((s[x][y]=='#' && s[tx][ty]=='#') || (s[x][y]=='.' && s[tx][ty]=='.')) continue;
        if(used[tx][ty]!=-1) continue;
        
        P t=dfs(tx, ty, clr, used);
        p.fi+=t.fi;
        p.se+=t.se;
    }
    
    return p;
}

int main(void) {
    ll i, j;
    cin >> H >> W;
    ll clr=0;
    for(i=0; i<H; i++) {
        cin >> s[i];
    }
    ll ans=0;
    ll **used;
    used=(ll**)malloc(H*sizeof(ll*));
    for(i=0; i<H; i++) {
        used[i]=(ll*)malloc(W*sizeof(ll));
    }
    
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            used[i][j]=-1;
        }
    }
    
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            if(s[i][j]=='#') {
                P t=dfs(i, j, clr, used);
                ans+=t.fi*t.se;
            }
        }
    }
    
    pr(ans);
}














Measured memory_bytes: 16768
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] list = new int[N];
        long sum = 0;
        for(int i=0;i<N;i++){
            list[i]=sc.nextInt();
            sum += list[i];
        }
        int cnt = 0;
        for(int i=0;i<N;i++){
            if(list[i]>=sum/4.0/M){
                cnt++;
            }
        }
        System.out.println(cnt>=M?"Yes":"No");
    }

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


Measured memory_bytes: 22996
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll DIV = (ll)8e3+7;
const ll MAXN = (ll)8e3+7;


int main(void) {
   ll X,Y;
   cin>>X>>Y;
   // ll ans = log2((double)Y/X)+1;
   // cout<<ans<<endl;
   ll ans = 0;
   ll y = X;
   while (y <= Y) {
      y*= 2;
      ans++;
   }
   cout<<ans<<endl;


   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=105,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,D;cin>>N>>D;
        if(N+D==0) break;
        
        vector<vector<int>> S(N);
        int T=0;
        
        for(int i=0;i<N;i++){
            int m;cin>>m;
            for(int j=0;j<m;j++){
                int a;cin>>a;
                S[i].push_back(a);
            }
            T+=m;
        }
        
        bool ok=true;
        
        vector<int> sum(N),now(N);
        
        for(int k=0;k<T;k++){
            ok=false;
            for(int i=0;i<N;i++){
                if(now[i]==S[i].size()) continue;
                
                sum[i]+=S[i][now[i]];
                
                int ma=-INF,mi=INF;
                
                for(int j=0;j<N;j++){
                    ma=max(ma,sum[j]);
                    mi=min(mi,sum[j]);
                }
                
                if(ma-mi<=D){
                    now[i]++;
                    ok=true;
                    break;
                }else{
                    sum[i]-=S[i][now[i]];
                }
            }
            if(!ok) break;
        }
        
        if(ok) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int X;

void _main() {
    cin >> X;
    int sum = 0, i = 1;
    while (sum < X) {
        sum += i;
        ++i;
    }
    --i;
    cout << i << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    var l: number = 0;
    var ans: number = 0;
    // init
    l = Number(input.shift());
    // solve
    ans = Math.pow(l/3, 3);
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        var input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            input = lines;
            main(input);
        });
    }
}
entrypoint();


Measured memory_bytes: 29516
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int a, b;
  cin >> a >> b;
  if(a < 9 && b < 9) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<bool> flag(55556, true);
    flag[0] = flag[1] = 0;

    vector<int> anslst;
    for (int i = 2; i <= 55555; i++)
    {
        if (flag[i])
        {
            if (i%5 == 3)
            {
                anslst.push_back(i);
                if (anslst.size() == N)
                    break;
            }
            for (int j = i * 2; j <= 55555; j += i)
                flag[j] = false;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << anslst[i] << "\n";
    }
    return 0;
}

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


int main(){
  int N; cin >> N;
  vector<int> p(N);
  vector<int> q(N);
  rep(i,N) cin >> p[i];
  rep(i,N) cin >> q[i];
  vector<int> a(N);
  rep(i,N) a[i]=i+1;
  map<vector<int>,int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(a.begin(),a.end()));
  int ans=abs(mp[p]-mp[q]);
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 5248
#include<iostream>
using namespace std;
int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int a ;
    if(n>k)
    {
        a=x*k + (n-k)*y;
        cout<<a<<endl;
    }
    else
    {
        a=n*x;
        cout<<a<<endl;
    }
}

Measured memory_bytes: 256
n = int( input() )
a = sorted( list( map( int, input().split())))

res = a[0]

while True:
    base = res
    total = 0
    for i in a:
        if  i % base > 0:
            res = min( res, i % base)
        total +=  i % base
    if total == 0:
        break

print(base)



Measured memory_bytes: 14252
S = input()
dir = [0]*4
move = "NWSE"
for i in S:
    dir[move.index(i)] += 1
p1 = (dir[0] > 0 and dir[2] > 0) or (dir[0] == 0 and dir[2] == 0)
p2 = (dir[1] > 0 and dir[3] > 0) or (dir[1] == 0 and dir[3] == 0)
print("Yes" if p1 and p2 else "No")

Measured memory_bytes: 9032
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String str = br.readLine();
        int addon = 0;
        
        for(int i = 0; i < 3; i++) if(str.charAt(i) == 'o') addon += 100;
        
        System.out.println(700 + addon);
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int pow(int a, int b)
{
    int x = 1;
    for (int i = 0; i < b; ++i)
    {
        x *= a;
    }
    return x;
}

int main()
{
    int N, M, ans = 0, s, c;
    cin >> N >> M;
    map<int, int> sc;
    for (int i = 0; i < M; ++i)
    {
        cin >> s >> c;
        if (sc.count(s))
        {
            if (sc[s] != c)
            {
                ans = -1;
                break;
            }
        }
        sc[s] = c;
    }
    if (!(sc.count(1)))
    {
        if (ans != -1)
            ans += pow(10, N - 1);
    }
    else
    {
        if (N != 1)
        {
            if (sc[1] == 0)
                ans = -1;
        }
    }
    if(N == 1 && M == 0){
        ans = 0;
    }

    if (ans != -1)
    {
        for (auto itr = sc.begin(); itr != sc.end(); ++itr)
        {
            ans += pow(10, N - itr->first) * itr->second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

min = min(A)
sum = sum(A)

def solve(i,m):
  if sum < m:
    return False
  if m == 0:
    return True
  if i >= n:
    return False
  res = solve(i+1,m) or solve(i+1, m - A[i])
  return res
 
for m in M:
    if solve(0, m):
      print 'yes'
    else:
      print 'no'
 

Measured memory_bytes: 6444
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    string o, e;
    cin >> o >> e;
    int n = o.size() + e.size();
    FOR(i, 0, n) {
        int idx = i / 2;
        if (i % 2 == 0) {
            cout << o[idx];
        }
        else
            cout << e[idx];
    }
    cout << endl;
    return 0;
}

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

int main(){ 
  Int N, K, ans = 0;
  cin >> N >> K;
  
  vector<Int> H(N);
  
  rep(i,N) cin >> H[i];
  
  if (N <= K) {
    cout << 0 << endl;
    return 0;
  }
  
  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());
  for (Int i = K; i < N; i++) {
    ans += H[i];
  }
  
  cout << ans << endl;
  

}


Measured memory_bytes: 1792
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}*/ 
int main()
{
	int n;
	cin>>n;
	string str;
	cin>>str;
    int LCSRe[n+1][n+1]; 
  
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res; // To store result 
    int res_length  = 0; // To store length of result 
  
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
    cout<<res.size();
	return 0;
	
}







Measured memory_bytes: 98048
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	llong A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if(V>W){
		if(abs(A-B)%(V-W)==0 && abs(A-B)/(V-W)<=T) cout << "YES" << endl;
		else if(abs(A-B)%(V-W)!=0 && abs(A-B)/(V-W)<T) cout << "YES" << endl;
		else cout << "NO" << endl;
	}else cout << "NO" << endl;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,r_s;
  	cin>>s;
	r_s.resize(s.size());
	reverse_copy(s.begin(),s.end(),r_s.begin());
	bool flag=false;
	if(s==r_s){
		s=s.substr(0,s.size()/2);
		r_s.resize(s.size());
		reverse_copy(s.begin(),s.end(),r_s.begin());
		flag=s==r_s;
	}
	cout<<(flag?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 2000000000
#define MOD 1000000007
#define SIZE 200005
#define FOR(i,a,n) for(i=(a);i<(n);i++)

int *par;
int *rank;
int *v;
void init_union(int size){
	int i;
	par = (int*)calloc(size,sizeof(int));
	rank = (int*)calloc(size,sizeof(int));
	v = (int*)calloc(size,sizeof(int));
	FOR(i,0,size) par[i]=i,v[i]=1;
	return;
}

int root(int a){
 	if(par[a]==a) return a;
 	else{
 		return (par[a]=root(par[a]));
 	}
}
 
int is_same(int a,int b){
 	return root(a)==root(b);
}
 
void unite(int a,int b){
	a=root(a);
	b=root(b);
	if(a==b){
		return;
	}
	if(rank[a]>rank[b]){
		par[b]=a;
		v[a]+=v[b];
	}
	else{
		par[a]=b;
		v[b]+=v[a];
		if(rank[a]==rank[b]) rank[b]++;
	}
	return;
}

ll inv[SIZE],f[SIZE],finv[SIZE];
void make_table(){
	int i;
	f[0]=f[1]=1; finv[0]=finv[1]=1;
	inv[1]=1;
	FOR(i,2,SIZE+1){
		inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
		f[i]=(f[i-1]*(ll)i)%MOD;
		finv[i]=(finv[i-1]*inv[i])%MOD;
	}
	return;
}
ll comb(int n,int k){
	if(n<0||k<0||n<k) return 0;
	return (((f[n]*finv[k])%MOD)*finv[n-k])%MOD;
}

typedef struct{
	int c,w;
}Ball;
int comp1(const void* a,const void* b){
	return ((Ball*)a)->w - ((Ball*)b)->w;
}
int comp2(const void* a,const void* b){
	return *(int*)a - *(int*)b;
}
Ball ball[200000];
int min[200000];
int *ary[200000];
int size[200000];
int main(void)
{
	int n,x,y,id,color,total,cnt,i,j,k;
	ll res;
	scanf("%d%d%d",&n,&x,&y);
	FOR(i,0,n){
		scanf("%d%d",&ball[i].c,&ball[i].w);
		ball[i].c--;
		min[i]=INF;
	}
	
	FOR(i,0,n) min[ball[i].c]=MIN(min[ball[i].c],ball[i].w);
	FOR(i,0,n){
		if(ball[i].w+min[ball[i].c]<=x){
			ball[i].w=min[ball[i].c];
		}
	}
	qsort(ball,n,sizeof(Ball),comp1);
	//FOR(i,0,n) printf("%d %d\n",ball[i].c,ball[i].w);
	
	color=ball[0].c;
	FOR(i,1,n){
		if(color!=ball[i].c){
			id=i;
			color=ball[i].c;
			break;
		}
	}
	if(color==ball[0].c){
		puts("1");
		return 0;
	}
	
	init_union(n);
	FOR(i,0,n){
		if(ball[i].c==ball[0].c&&ball[i].w+ball[id].w<=y){
			unite(id,i);
		}
		if(ball[i].c!=ball[0].c&&ball[i].w+ball[0].w<=y){
			unite(0,i);
		}
	}
	
	FOR(i,0,n) ary[i]=calloc(v[i],sizeof(int));
	FOR(i,0,n){
		id=root(i);
		ary[id][size[id]++]=ball[i].c;
	}
	
	make_table();
	res=1;
	
	FOR(i,0,n){
		qsort(ary[i],size[i],sizeof(int),comp2);
		total=size[i]; cnt=j=k=0;
		while(j<size[i]){
			while(k<size[i]&&ary[i][j]==ary[i][k]) k++;
			res*=comb(total,k-j);
			res%=MOD;
			total-=(k-j);
			j=k;
		}
	}
	printf("%lld\n",res);
	return 0;
}
    

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

using namespace std;

typedef long long ll;

int cnt[2];
int main()
{
    int n;
    cin>>n;
    map<int,int> mp;
    map<int,int>::iterator it;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    for(it=mp.begin();it!=mp.end();it++)
        cnt[(it->second)%2]++;
    cnt[0]-=((cnt[0]%2));
    cout<<cnt[1]+cnt[0]<<endl;
    return 0;
}


Measured memory_bytes: 4992
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " " ;
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
	int ans =-1;
   for(int i = 0, x; i < 5; i++) {
   	cin >> x;
   	if(x == 0) ans = i + 1;
   }
   cout << ans << endl;
}
  
int32_t main() {
 
    FAST;

   
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll N;
ll A[100100];
ll B[100100];
int main(){
	cin >> N;
	ll sum = 0ll;
	for(int i=0;i<N;i++){
		cin >> A[i];
		sum += A[i];
	}
	if(sum%(N*(N+1ll)/2ll)!=0ll){
		cout << "NO" << endl;
		return 0;
	}
	ll K = sum/(N*(N+1ll)/2ll);
	ll M = -LLINF;
	for(int i=0;i<N-1;i++){
		B[i] = A[i+1]-A[i];
		chmax(M,B[i]);
	}
	/*if(M<0ll){
		cout << "NO" << endl;
		return 0;
	}*/
	for(int i=0;i<N-1;i++){
		if((M-B[i])%N!=0ll){
			cout << "NO" << endl;
			return 0;
		}
	}
	if(M>=0ll){
		if(K-M<0ll || (K-M)%N!=0ll){
			cout << "NO" << endl;
			return 0;
		}
	}else{
		if(K-4ll*M<0ll || (K-4ll*M)%N!=0ll){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

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

int main(void) {
	int d[10][10];
	int h, w;
	int a[201][201];
	long long int count = 0;

	cin >> h >> w;
	FOR(i, 0, 9) {
		FOR(t, 0, 9) {
			cin >> d[i][t];
		}
	}
	FOR(i, 1, h) {
		FOR(t, 1, w) {
			cin >> a[i][t];
		}
	}

	FOR(k, 0, 9) {
		FOR(i, 0, 9) {
			FOR(t, 0, 9) {
				d[i][t] = min(d[i][t], d[i][k] + d[k][t]);
			}
		}
	}

	FOR(i, 1, h) {
		FOR(t, 1, w) {
			if (a[i][t] != -1) {
				count += d[a[i][t]][1];
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100005];
inline bool cmp(int a,int b){
    return a>b;
}
int main(){
    int dis1=0,dis2=0;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n,cmp);
    for (int i=1;i<=n;i++){
        if(a[i+1]<i+1){
            dis1=a[i]-i;
            for (int j=i+1;j<=n;j++){
                if(a[j]==i){
                    dis2++;
                }else{
                    break;
                }
            }
            break;
        }
    }
    dis1&=1,dis2&=1;
    printf("%s\n",!(dis1+dis2)?"Second":"First");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    string S;
    cin >> S;
    const string alpha("abcdefghijklmnopqrstuvwxyz");
    if(!cin) return;
    if(S.size() < 26){
        set<char> alp;
        for (int i = 0; i < alpha.size(); ++i) {
            alp.insert(alpha[i]);
        } // end i
        for (auto &&cc : S) {
            alp.erase(cc);
        } // end cc
        S.push_back(*alp.begin());
    }
    else{
        int p = -1;
        char bc = S.back();
        set<char> alp; alp.insert(bc);
        for (int i = S.size() - 2; i >= 0; --i) {
            if(bc > S[i]){
                p = i;
                break;
            }
            bc = S[i];
            alp.insert(S[i]);
        } // end i
        if(p < 0){
            cout << -1 << endl;
            return ;
        }
        S = S.substr(0, p+1);
        S[p] = (*alp.upper_bound(S[p]));
    }
    cout << S << endl;
    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	long long t,s,a,b,c,d;
	cin >> t >> s >> a >> b >> c >> d;
	a=a-c; // 区間tにおける増加分
	b=b-d; // 区間sにおける増加分
	if((a>0 and b>0) or (a<0 and b<0))
	{
		cout << 0 << endl;
		return 0;
	}
	a=abs(a);
	b=(-1)*abs(b);
	a*=t; // 10^15
	b*=s; // 10^15
	
//	cout << a << endl;
//	cout << b << endl;

	long long x=a+b;

	if(x>0)
	{
		cout << 0 << endl;
	}
	else if(x==0)
	{
		cout << "infinity" << endl;
	}
	else
	{
		cout << ((a+abs(x)-1)/abs(x))*2+(a%abs(x)==0 ? 1:0)-1 << endl;
	}





}

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

const ll INF = 1e9;
int N, M, now = 0, newLeft, Next, Left, timer;
string S;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N >> M >> S;
    
    vector<ll> dist(N + 1, INF), MostLeft(N + 1, INF), ans;
    dist[N] = 0;
    MostLeft[0] = N;
    
    Next = N-1;
    Left = N;
    timer = 0;
    
    while(Next >= 0) {	
    	++timer;
        newLeft = Left;
        while(Next >= Left - M && Next >= 0) {
            if(S[Next] == '0') {
                dist[Next] = timer;
                newLeft = Next;
            }
            --Next;
        }
        if(newLeft == Left) {
            cout << -1 << "\n";
            return 0;
        }
        Left = newLeft;
        MostLeft[timer] = Left;
    }
    
    timer = dist[0];
    while(timer--) {
        ans.emplace_back(MostLeft[timer] - now);
        now = MostLeft[timer];
    }
    
    for(int i = 0; i < ans.size(); ++i) {
        cout << ans[i];
        if(i + 1 != ans.size()){
        	cout << " ";
		}
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3144
n = int(input())

if n >= 100:
    n = n%100
    if n >= 10:
        n = n%10
    if n == 3:
        print("bon")
    elif n == 0 or n == 1 or n == 6 or n == 8:
        print("pon")
    else:
        print("hon")
elif n <= 99 and n >= 10:
    n = n%10
    if n == 3:
        print("bon")
    elif n == 0 or n == 1 or n == 6 or n == 8:
        print("pon")
    else:
        print("hon")
else:
    if n == 3:
        print("bon")
    elif n == 0 or n == 1 or n == 6 or n == 8:
        print("pon")
    else:
        print("hon")




Measured memory_bytes: 9212
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

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

using namespace std;

const int INF=1<<29;

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

	bool leaf[300];
	rep(u,n){ int a; scanf("%d",&a); leaf[u]=a; }

	vector<int> from[1000];
	int to[1000];
	rep(i,m){
		int a,b; scanf("%d%d",&a,&b);
		to[i]=a-1;
		rep(j,b) scanf("%d",&a), from[i].push_back(a-1);
	}

	int dp[300];
	rep(u,n) dp[u]=(leaf[u]?1:INF);
	rep(i,n) rep(j,m) {
		int cost[10];
		rep(k,from[j].size()) cost[k]=dp[from[j][k]];
		sort(cost,cost+from[j].size(),greater<int>());

		int nextcost=0;
		rep(k,from[j].size()) nextcost=max(nextcost,k+cost[k]);
		dp[to[j]]=min(dp[to[j]],nextcost);
	}

	printf("%d\n",dp[g]<INF?dp[g]:-1);

	return 0;
}

Measured memory_bytes: 828
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <complex>
#define ll long long
using namespace std;

int main() {
	ll n, ba = 0, b = 0, a = 0, ans = 0;
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'B' && s[s.size() - 1] == 'A')ba++;
		else if (s[0] == 'B')b++;
		else if (s[s.size() - 1] == 'A')a++;
		for (int j = 0; j < s.size() - 1; j++) {
			if (s[j] == 'A' && s[j + 1] == 'B')ans++;
		}
	}
	if(ba>1)ans += ba - 1;
	
	if (ba == 0) {
		ans += min(a, b);
	}
	else {
		if (a > 0) {
			ans++;
			a--;
		}
		if (b > 0) {
			ans++;
			b--;
		}
		ans += min(a,b);
	}

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


Measured memory_bytes: 256
#include <stdio.h>

int cnt;

void insertionSort(int A[], int n, int g);
void shellSort(int A[], int n);

int n;
int A[1000000];

int main() {
  int i;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) scanf("%d", A+i);
  shellSort(A, n);
  printf("%d\n", cnt);
  for(i = 0; i < n; ++i) printf("%d\n", A[i]);
  return 0;
}

void insertionSort(int A[], int n, int g) {
  int tmp;
  int i, j;
  for(i = g; i < n; ++i) {
    tmp = A[i];
    j = i-g;
    while(j >= 0 && A[j] > tmp) {
      A[j+g] = A[j];
      j -= g;
      ++cnt;
    }
    A[j+g] = tmp;
  }
}

void shellSort(int A[], int n) {
  int m = 0;
  int G[100];
  int i;
  G[0] = 1;
  for(m = 1; 3*G[m-1]+1 <= n; ++m) G[m] = 3*G[m-1]+1;
  printf("%d\n", m);
  cnt = 0;
  for(i = m-1; i >= 0; --i) {
    printf("%d%c", G[i], " \n"[i==0]);
    insertionSort(A, n, G[i]);
  }
}



Measured memory_bytes: 5656
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) ((a).begin(), (a).end())
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EP emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

string s;
int K;

int main(void) {
    cin >> s >> K;
    REP(i, s.size()) {
        if (s[i] !='a' && (int)(s[i] + K) > 'z') {
            K -= 'z' - s[i] + 1;// DEBUG(K)
            s[i] = 'a';
        }
        if (K == 0) {
            cout << s << endl;
            return 0;
        }
    }
    if (K > 0) {
        RREP(i, s.size()) {
            if (s[i] != 'a') {
                K %= 26;
                s[i] += K;
                if (s[i] > 'z') {
                    s[i] = s[i] - 'z' + 'a';
                } K = 0;
                break;
            }
        }
    }
    if (K > 0) {
        K %= 26;
        int i = s.size() - 1;
        s[i] += K;
        if (s[i] > 'z') {
            s[i] = s[i] - 'z' + 'a';
        } K = 0;

    }
    cout << s << endl;
}


Measured memory_bytes: 512