akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 3e3+7;
double dp[N], p[N];
int n;

int32_t main()
{
	fast;

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	dp[0] = 1 - p[1], dp[1] = p[1];
	for(int i = 2; i <= n; i++)
	{
		for(int j = i; j >= 0; j--)
		{
			if(j == 0)
				dp[j] = dp[j] * (1 - p[i]);
			else if(j == i)
				dp[j] = dp[j-1] * p[i];
			else
				dp[j] = dp[j] * (1-p[i]) + dp[j-1] * p[i];
		}
	}

	double ans = 0;
	for(int i = n/2 + 1; i <= n; i++)
		ans += dp[i];
	cout << setprecision(10) << ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
T = []
for i in range(N):
    s,t = map(str,input().split())
    t = int(t)
    S.append(s)
    T.append(t)
X = str(input())

index = None
for i in range(N):
    if S[i] == X:
        index = i+1

ans = sum(T[index:])
print(ans)


Measured memory_bytes: 3316
import java.util.*;

class Main {
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int a = Integer.parseInt(sc.next());
  sc.close();

  int h = a/3600;
  int m = (a%3600)/60;
  int s = a%60;

  System.out.println(h + ":" + m + ":" + s);
 }
}


Measured memory_bytes: 26180
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200005
using namespace std;
typedef long long ll;
typedef double db;
int n,A[N],B[N],Maxa,Maxb,ans,a[N],b[N];
int Find(int l,int r)
{
	int L=0,R=n,s1;
	while(L<R)
	{
		int mid=(L+R+1)>>1;
		if(b[mid]<=r) L=mid;
		else R=mid-1;
	}
	s1=L;
	L=1,R=n;
	while(L<R)
	{
		int mid=(L+R)>>1;
		if(b[mid]<l) L=mid+1;
		else R=mid;
	}
	if(b[R]<l) R++;
	return s1-R+1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&A[i]),Maxa=max(Maxa,A[i]);
	for(int i=1;i<=n;++i) scanf("%d",&B[i]),Maxb=max(Maxb,B[i]);
	for(int i=1;(1<<i-1)<=Maxa+Maxb;++i)
	{
		int tot=0,num=(1<<i);
		for(int j=1;j<=n;++j) a[j]=A[j]%num,b[j]=B[j]%num;
		sort(b+1,b+n+1);
		for(int j=1;j<=n;++j)
		{
			int L=num/2,R=num-1;
			if(a[j]<L) tot+=Find(L-a[j],R-a[j]);
			else if(a[j]==L) tot+=Find(0,R-a[j]);
			else tot+=Find(0,R-a[j])+Find(L-a[j]+num,R);
		}
		if(tot&1) ans+=num/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
/***************************************** START OF TEMPLATE *********************************************/
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  newl           cout<<"\n";
#define  f              first
#define  s              second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)         s="#"+s+"#";   
#define  all(x)         (x).begin(),(x).end()
#define  alll(x, n)     x+1, x+n+1
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  mset1d(a,n,v)  foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v)foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  INP(a,n)       foo(i,1,n) cin>>a[i];
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    
#define  debm(a)        for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  debp(a,n)      foo(i,1,n)cout<<"{"<<a[i].f<<","<<a[i].s<<"}, ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, q, a[N], f[N],b,c;


/***************************************** FUNCTION IMPLEMENTATIONS **************************************/



/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    ll tot=0;
    cin>>n;
    foo(i,1,n){
        cin>>a[i];
        tot^=a[i];
    }
    foo(i,1,n)cout<<(tot^a[i])<<" ";
    
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
    MAIN(i);
    }
}

Measured memory_bytes: 9816
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) {
    vector<vector<LL>> d(N, vector<LL>(N, INF));
    vector<vector<LL>> edges(N, vector<LL>(N, 0));

    for (int i = 0; i < M; i++) {
        auto u = a[i] - 1, v = b[i] - 1, l = c[i];
        auto src = min(u, v), dst = max(u, v);
        d[src][dst] = l;
        d[dst][src] = l;
        edges[src][dst] = l;
        edges[dst][src] = l;
    }

    for(int k=0; k<N; k++)
        for(auto i=0; i<N; i++)
            for(auto j=0; j<N; j++)
                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);

    LL ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if(d[i][j] < edges[i][j])ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, M, std::move(a), std::move(b), std::move(c));
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int fa[MAXN];
int cnt[MAXN];
void init(){
    for(int u=0;u<MAXN;u++){
        fa[u]=u;
        cnt[u]=1;
    }
}
int rfind(int r){
    if(fa[r]==r)return r;
    int x=rfind(fa[r]);
    fa[r]=x;
    return x;
}
void runion(int a,int b){
    int ta=rfind(a),
    tb=rfind(b);
    if(ta!=tb){
        fa[tb]=ta;
        cnt[ta]+=cnt[tb];
    }
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    init();
    int n,m;
    cin>>n>>m;
    set<pair<int,int>>ex;
    for(int u=0;u<m;u++){
        int a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        if(ex.count({a,b}))continue;
        ex.insert({a,b});
        runion(a,b);
    }
    vector<int>sz;
    int verify=0;
    for(int u=1;u<=n;u++){
        if(fa[u]==u){
            sz.push_back(cnt[u]);
            verify+=cnt[u];
        }
    }
    // assert(verify==n);
    sort(sz.begin(),sz.end());
    int nsz=sz.size();
    int delta=0;
    int grs=0;
    for(int u=0;u<nsz;u++){
        if(delta+sz[u]<=0)continue;
        int t=sz[u]+delta;
        grs+=t;
        delta-=t;
    }
    cout<<grs;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];
  
  vector<vector<P>> dist(n, vector<P>(m));
  rep(i, n) rep(j, m) dist[i][j] = make_pair(abs(a[i] - c[j]) + abs(b[i] - d[j]), j+1);
  rep(i, n) sort(dist[i].begin(), dist[i].end());
  rep(i, n) cout << dist[i][0].second << endl;
  return 0;
}

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

using namespace std;

const int maxn = 2e5+9;
int A[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) scanf("%d",&A[i]);
    while(k--)
    {
        int B[maxn];
        memset(B,0,sizeof(B));
        for(int i=1;i<=n;i++)
        {
            int l = max(1,i-A[i]);
            int r = min(n,i+A[i]);
            //差分
            B[l]++;
            B[r+1]--;
        }
        //差分应用
        for(int i=1;i<=n;i++)
        {
            A[i] = A[i-1] + B[i];
        }
        if(A[n]==n) break;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",A[i]);
    }
    return 0;
}


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

using namespace std;

int conv[128];

bool stronger(char *t1, char *t2, char p1, char p2)
{
    if (t1[1] != t2[1] && (t1[1] == p1 || t1[1] == p2 || t2[1] == p2 || t2[2] == p2)){
        if (t1[1] == p1) return (0);
        if (t2[1] == p1) return (1);
        if (t1[1] == p2) return (0);
        return (1);
    }
    else {
        return (conv[t1[0]] < conv[t2[0]]);
    }
}

int main()
{
    for (int i = 2; i <= 9; i++) conv[i + '0'] = i;
    conv['T'] = 10, conv['J'] = 11, conv['Q'] = 12, conv['K'] = 13, conv['A'] = 14;
    
    char c[2];
    
    while (scanf("%s", c) && c[0] != '#'){
        char mp[4][13][3];
        
        for (int i = 0; i < 4; i++){
            for (int j = 0; j < 13; j++){
                scanf("%s", mp[i][j]);
            }
        }
        
        int whom = 0;
        int won[2] = {0};
        for (int i = 0; i < 13; i++){
            int next = whom;
            for (int j = whom, ctr = 1; ctr < 4; ctr++){
                int player = (j + ctr) % 4;
                if (stronger(mp[next][i], mp[player][i], c[0], mp[whom][i][1])){
                    next = player;
                }
            }
            whom = next;
            won[next & 1]++;
        }
        
        printf("%s %d\n", (won[0] > won[1] ? "NS" : "EW"), max(won[0], won[1]) - 6);
    }
    
    return (0);
}

Measured memory_bytes: 1132
S = input()
N = int(len(S))
i = 0
j = 0
K = []
I = []
while (2*i+1) < N:
    if S[(2*i+1)] == "L":
        K.extend([S[(2*i+1)]])
    elif S[(2*i+1)] == "U":
        K.extend([S[(2*i+1)]])
    elif S[(2*i+1)] == "D":
        K.extend([S[(2*i+1)]])
    i += 1
while (2*j) < N:
    if S[(2*j)] == "R":
        I.extend([S[(2*j)]])
    elif S[(2*j)] == "U":
        I.extend([S[(2*j)]])
    elif S[(2*j)] == "D":
        I.extend([S[(2*j)]])
    j += 1
if int(len(K)) + int(len(I)) == N:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <functional>
#include <algorithm>

using namespace std;

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

int main() {
    int n; // 2 or 3
    scanf("%d", &n);

    int a[n];
    REP(0, i, n) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n, greater<int>());

    REP(1, i, a[0] / 2) {
        bool f = true;
        REP(0, j, n) {
            if (a[j] % i != 0) {
                f = false;
                break;
            }
        }
        if (f) printf("%d\n", i);
    }



    return 0;
}



Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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 n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;


void solve()
{
	ll n,s;
	cin>>n>>s;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	const ll m=998244353;
	vector<vector<Modint<m>>>dp(n+5,vector<Modint<m>>(3005));
	dp[0][0]=1;
	rep(i,n){
		rep(j,s+1){
			if(a[i]+j<=s){
				dp[i+1][j+a[i]]+=dp[i][j];
			}
			dp[i+1][j]+=dp[i][j]*2;
		}
	}
	cout<<dp[n][s];
}

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


Measured memory_bytes: 38572
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n, m;
    cin >> n >> m;
    if(n == m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define INF 1001001001

char s[30];

main(){
    scanf("%s", s);
    if(strlen(s) < 26){
        int x[30] = {};
        for(int i=0; i<strlen(s); i++){
            x[s[i] - 'a']++;
        }
        printf("%s", s);
        int i=0;
        while(x[i])i++;
        putchar(i + 'a');
        putchar(10);
        return 0;
    }
    if(strcmp(s, "zyxwvutsrqponmlkjihgfedcba") == 0){
        puts("-1");
        return 0;
    }
    int i = 25;
    for(; s[i]<s[i-1]; i--);--i;
    for(int j = 25; j > i; j--){
        if(s[j] > s[i]){
            s[i]=s[j];
            s[i+1] = 0;
            printf("%s\n", s);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n; cin >> n;
        int an = 0;
        lp(i, n) {
                int x; cin>> x;
                if ((i+ 1)& 1) {
                        if (x& 1) an++;
                }
        }
        cout << an<< "\n";
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fly ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

using namespace std;

int main(){
    fly;
	int n, w;
	cin >> n >>w;
	int weight[n+1];
	int val[n+1];
	weight[0] = 0;
	val[0] = 0;

	for(int i=1;i<=n;i++){
		cin >> weight[i] >> val[i];
	}

    vector<vector<long long> > dp(n+1, vector<long long>(w+1,0));

	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){

			long long int op1 = dp[i-1][j];
			long long int op2 = (j < weight[i]) ? 0 : val[i] + dp[i-1][j-weight[i]];

			dp[i][j] = max(op1, op2);
		}
	}

	cout << dp[n][w];
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  int ans = 0;
  rep(i,n)
    if (i%2==0 && a[i]%2==1) ans++;
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
N = int(input())
mnstr = list(map(int, input().split()))
yusha = list(map(int, input().split()))
sum = 0
killed = 0

for i in range(N):
  killedtemp1 = min(mnstr[i], yusha[i])#iの勇者が倒したモンスターiの数
  yusha[i] = max(0, yusha[i]-mnstr[i])
  killedtemp2 = min(mnstr[i+1], yusha[i])#iの勇者が倒したモンスターi+1の数
  mnstr[i+1] = mnstr[i+1] - killedtemp2
  killed += killedtemp1 + killedtemp2
  
print(killed)
  

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    vector<int> x(5);rep(i,5)cin >> x[i];
    rep(i,5){
        if(x[i] == 0)cout << i+1 << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  if(a>b)
    swap(a,b);
  ll x=b-a;
  if(x%2==0)
    cout<<x/2<<"\n";
  else
  {
    ll y=min(b-1,n-a);
    ll z=n-b+1;
    ll p=a+z;
    ll q=n-p;
    q/=2;
    q+=z;
    ll r=b-a;
    r-=1;
    r/=2;
    r+=a;
    ll ans=min(y,min(q,r));
    cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	string t; cin >> t;
	vector<int> hash(26,0);
	for(int i = 0 ; i < (int) t.size() ; i++){
		hash[t[i]-'a']++;
	}
	bool k = true;
	for(int i = 0 ; i < (int)hash.size() ; i++)
		if(hash[i] > 1)
			k = false;
	if(k){
		cout<<"-1 -1";
		return;
	}
	else{
		k = true;
		for(int i = 0 ; i < (int) t.size()-1 ; i++){
			if(t[i] == t[i+1]){
				cout<<i+1<<" "<<i+2;
				k = false;
				return;
			}
		}
		if(k){
			for(int i = 0 ; i < (int)t.size()-2 ; i++){
				if(t[i] == t[i+2]){
					cout<<i+1<<" "<<i+3;
					return;
				}
			}
		}
	}
	cout<<"-1 -1";
		
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	while(T--){
		test_case();
	}
	return 0;
}


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

int main() {
  string s;
  getline(cin, s);
  for (auto &c : s) {
    if (islower(c))
      c = toupper(c);
    else if (isupper(c))
      c = tolower(c);
  }
  cout << s << endl;

  return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    string n;
    cin >> n;
    if((n[0] == n[1] && n[1] == n[2] && n[0] == n[2])|| (n[2] == n[1] && n[1] == n[3] && n[2] == n[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    string s[3];
    rep(i, 3) cin>>s[i];
    string pa="";
    rep(i,3) pa+=s[i][i];
    cout<<pa<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a==b){
		cout<<"Draw";
	}else if(a>b){
		cout<<"Alice";
	}else{
		cout<<"Bob";
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  int l = S.length();
  vector<int> dir;
  char now = 'R'; int count = 0;
  rep(i,l) {
    if (S[i]==now) { count++; continue; }
    if (S[i]=='R') { now = 'R'; dir.push_back(count); count = 1; }
    else { now = 'L'; dir.push_back(count); count = 1; }
  }
  dir.push_back(count);
  rep(i,dir.size()/2) {
    int d1 = dir[i*2], d2 = dir[i*2+1]; 
    rep(j,d1-1) cout << 0 << " ";
    if ((d1+d2)%2==0) cout << (d1+d2+1)/2 << " " << (d1+d2)/2 << " ";
    else if (d1%2==1) cout << (d1+d2+1)/2 << " " << (d1+d2)/2 << " ";
    else cout << (d1+d2)/2 << " " << (d1+d2+1)/2 << " ";
    rep(j,d2-1) cout << 0 << " ";
  }
  cout << endl;
  // for (auto x: dir) cout << x << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main() {
	Fast_IO

	int n, m, x;
	cin >> n >> m >> x;
	int a[n][m + 1];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m + 1; j++) {
			cin >> a[i][j];
		}
	}
	int minans = 2e9;
	for (int i = 1; i < pow(2, n); i++) {
		vector<int> skills(m, 0);
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (1 & (i >> j)) {
				//buy j;
				ans += a[j][0];
				for (int k = 1; k <= m; k++) {
					skills[k - 1] += a[j][k];
				}
			}
		}
		bool ok = true;
		for (auto it : skills) {
			if (it < x) {
				ok = false;
			}
		}
		if (ok) {
			minans = min(minans, ans);
		}
	}
	if (minans == 2e9) {
		cout << "-1";
		return 0;
	}
	cout << minans;
}

Measured memory_bytes: 4092
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int main()
{
    int n,m;cin>>n>>m;
    vector<long long> a(n);
    vector<int> b(n);
    int i;
    for(i=0;i<n;i++)cin>>a.at(i)>>b.at(i);
    vector<pair<long long,long long>> p(n);
    for(i=0;i<n;i++)p.at(i)=make_pair(a.at(i),b.at(i));
    sort(p.begin(),p.end());
    long long ans=0;
    int left=m;
    for(i=0;i<n;i++)
    {
        if(p.at(i).second<left)
        {
            ans += p.at(i).first*p.at(i).second;
            left-=p.at(i).second;
        }
        else
        {
            ans += p.at(i).first*left;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2944
import sys
sys.setrecursionlimit(1000000)

MOD = 10**9+7
N = int(input())

X = [[] for _ in range(N)]

for _ in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)
    
P = [-1] * N
def dfs(i):
    for j in X[i]:
        if j != 0 and P[j] < 0:
            P[j] = i
            dfs(j)

dfs(0)

for i in range(N):
    if i != 0:
        X[i].remove(P[i])

ans = 0
B = [0] * N
W = [0] * N

def dfs2(i):
    _ansb = 1
    _answ = 1
    for j in X[i]:
        __ansb, __answ = dfs2(j)
        _ansb *= __answ
        _answ *= (__ansb+__answ)
        _ansb %= MOD
        _answ %= MOD
    
    return (_ansb, _answ)

print(sum(dfs2(0)) % MOD)


Measured memory_bytes: 102064
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li l, r, d;
    cin >> l >> r >> d;
    li ans = (r / d) - ((l - 1) / d);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3612
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [x, y] <- getIntList

  let numA | x <= y = y - x
           | otherwise = inf

      numBA | (-x) <= y = (y - (-x)) + 1
            | otherwise = inf

      numAB | x <= (-y) = ((-y) - x) + 1
            | otherwise = inf

      numBAB | (-x) <= (-y) = ((-y) - (-x)) + 2
             | otherwise = inf

      ans = min numA (min numBA (min numAB numBAB))

  print ans

Measured memory_bytes: 380
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
 int a,b,c,x,y; cin >> a >> b >> c >> x >> y;
  if(a+b <= 2*c){
    cout << a*x+b*y;
    exit(0);
  }
  
  if(x>y){
    if(2*c<a){
      cout << 2*c*x;
      exit(0);
    } else {
      cout << 2*c*y+(x-y)*a;
      exit(0);
    }
  } else {
    if(2*c<b){
      cout << 2*c*y;
      exit(0);
    } else {
      cout << 2*c*x+(y-x)*b;
    }
  }
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
#define MOD 998244353

ll n,a,b,k,ans;
ll fact[300010];
ll choose(ll n,ll r){return fact[n]*invp(fact[r]*fact[n-r],MOD)%MOD;}
int main(){
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%MOD;
	rep(i,0,n+1){
		ll j=(k-i*a)/b;
		if(0<=j&&j<=n&&i*a+j*b==k)ans=(ans+choose(n,i)*choose(n,j))%MOD;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2560
import itertools
N = int(input())
K = int(input())

ans = float("inf")
# 長さN, 0と1の全ての組み合わせのリストを作る

# N<=10だからbrute forceでも1024通りで済む．
# ビット演算がシンプル?
for i in range(2**N):
    curr_num = 1
    for _ in range(N):
        checker = i & 1
        if checker == 0:
            curr_num = curr_num * 2
        else:
            curr_num += K
        i >>= 1
    ans = min(ans, curr_num)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
    #include <string>
    #include <set>  
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
	#include <cassert>
    #include <iomanip>
    #include <sstream> 
    #include <cstdlib>
using namespace std;
int n,k,n_;
bool use[10];
bool f;
int main()
{
	scanf("%d%d",&n,&k);
	int a;
	for(int i=0;i<k;i++)
	{
		scanf("%d",&a);
		use[a]=1;
	}
	while(1)
	{
		n_=n;
		f=1;
		//cout<<n_<<endl;
		while(n_)
		{
			a=n_%10;
			if(use[a])
			{
				f=0;
				break;
			}
			n_/=10;
		}
		if(f)
		{	
			printf("%d\n",n);
			break;
		}
		n++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  sort(A.begin(),A.end());
  setComb();

  ll nans=0;
  for(ll i=0;i<N;i++){
    ll rest=N-(i+1);
    if(rest<K-1) continue;
    
    ll res=A[i]*comb(rest,K-1)%MOD;
    nans=(nans+res)%MOD;
  }

  reverse(A.begin(),A.end());

  ll ans=0;
  for(ll i=0;i<N;i++){
    ll rest=N-(i+1);
    if(rest<K-1) continue;
    
    ll res=A[i]*comb(rest,K-1)%MOD;
    ans=(ans+res)%MOD;
  }


  ans=(ans-nans+MOD)%MOD;
  cout<<(ans+MOD)%MOD<<endl;

  return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>

int main(void)
{
    int a, b, c;
    int notdiamond, diamond;

    notdiamond = 0;
    diamond = 0;
    while(scanf("%d,%d,%d", &a, &b, &c) != EOF){
        if(a + b < c) continue;
        if(a * a + b * b == c * c) notdiamond++;
        if (a == b) diamond++;
        
        //printf("%d\n%d\n", notdiamond, diamond);
    }
    printf("%d\n%d\n", notdiamond, diamond);

    return (0);
}


Measured memory_bytes: 2032
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		double[][] data=new double[65536][3];
		int ptr=0;
		while(sc.hasNext()){
			String[] str=sc.next().split(",");
			if(bmi(Double.parseDouble(str[1]),Double.parseDouble(str[2]))){
				for(int i=0;i<3;i++){
					data[ptr][i]=Double.parseDouble(str[i]);
				}
				ptr++;
			}
		}
		for(int i=0;i<ptr;i++){
			System.out.println((int)data[i][0]);
		}
	}
	static boolean bmi(double w,double h){
		return w/(h*h)>=25?true:false;
	}
}

Measured memory_bytes: 22596
#include <cmath>
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int x[3], y[3];
int main() {
	while (scanf("%d%d%d%d%d%d", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2]), x[0] | y[0] | x[1] | y[1] | x[2] | y[2]) {
		double l0 = hypot(1.0 * (x[1] - x[2]), 1.0 * (y[1] - y[2]));
		double l1 = hypot(1.0 * (x[2] - x[0]), 1.0 * (y[2] - y[0]));
		double l2 = hypot(1.0 * (x[0] - x[1]), 1.0 * (y[0] - y[1]));
		double t0 = ((x[1] - x[0]) * (x[2] - x[0]) + (y[1] - y[0]) * (y[2] - y[0])) / (l1 * l2);
		double t1 = ((x[2] - x[1]) * (x[0] - x[1]) + (y[2] - y[1]) * (y[0] - y[1])) / (l2 * l0);
		double t2 = ((x[0] - x[2]) * (x[1] - x[2]) + (y[0] - y[2]) * (y[1] - y[2])) / (l0 * l1);
		double a0 = 1.0 / tan(acos(t0) / 2.0);
		double a1 = 1.0 / tan(acos(t1) / 2.0);
		double a2 = 1.0 / tan(acos(t2) / 2.0);
		double l = 0.0, r = sqrt(min(l0, l1) / (a2 + 1.0)), lx = 0.0, ly = 0.0;
		for (int i = 0; i < 60; i++) {
			double m = (l + r) * 0.5;
			double dx = a0 * l1 + (1.0 - a0 * a2) * m * m;
			double dy = a1 * l0 + (1.0 - a2 * a1) * m * m;
			lx = (-1.0 * m + sqrt(dx)) / a0;
			ly = (-1.0 * m + sqrt(dy)) / a1;
			double lz = a0 * lx * lx + 2.0 * lx * ly + a1 * ly * ly;
			if (lz < l2) r = m;
			else l = m;
		}
		printf("%.10lf %.10lf %.10lf\n", lx * lx, ly * ly, l * l);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool check = false;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (N == i * j) {
        check = true;
      }
    }
  }
  if (check) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

using namespace std;
using ll = long long int;

int main()
{
  int n1, n2, n3, n4;
  cin >> n1 >> n2 >> n3 >> n4;
  bool one = false;
  bool seven = false;
  bool nine = false;
  bool four = false;
  if(n1 == 1 || n2 == 1 || n3 == 1 || n4 == 1) one = true;
  if(n1 == 7 || n2 == 7 || n3 == 7 || n4 == 7) seven = true;
  if(n1 == 9 || n2 == 9 || n3 == 9 || n4 == 9) nine = true;
  if(n1 == 4 || n2 == 4 || n3 == 4 || n4 == 4) four = true;
  if(one && seven && nine && four)
  {
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    string s;
    cin >> s;
    map<char, ll> mp;
    rep(i, N) {
        mp[s[i]]++;
    }
    ll count = 1;
    for(pair<char, ll> p : mp) {
        count *= p.second + 1;
        count %= MOD;
    }
    print(count -1);
    return 0;
}


Measured memory_bytes: 512
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=5e5+5;
int st[N],pk[N],a[N],nxt[N],las[N],xia[N],n,pos,top;ll k;
int main(){
	scanf("%d%lld",&n,&k);
	fp(i,1,n)scanf("%d",&a[i]),nxt[las[a[i]]]=i,las[a[i]]=i;
	fp(i,1,n)nxt[las[a[i]]]=i,las[a[i]]=i;
	fp(i,1,n-1)xia[i]=i+1;xia[n]=1;
	st[++top]=1,pk[top]=1,pos=1;
	do{
		++top,pk[top]=pk[top-1]+(nxt[pos]<=pos)+(nxt[pos]==n);
		st[top]=pos=xia[nxt[pos]];
	}while(st[top]!=st[1]);
	k-=(k-1)/(pk[top]-1)*(pk[top]-1);
	R int j=1;
//	fp(i,1,top)printf("%d %d %d\n",i,st[i],pk[i]);
//	printf("%lld\n",k);
	while(j<=top-1&&pk[j+1]<=k)++j;
//	if(j==top-1)return 0;
//	fp(i,st[j],n)printf("%d ",a[i]);
	for(R int i=st[j];i<=n;++i){
		if(nxt[i]>i)i=nxt[i];
		else printf("%d ",a[i]);
	}
	return 0;
}


Measured memory_bytes: 10880
N = int(input())
A = list(map(int, input().split()))
flag = True
swap = 0
while flag:
    flag = False
    for j in range(N - 1, 0, -1):
        if A[j] < A[j - 1]:
            A[j], A[j - 1] = A[j - 1], A[j]
            swap += 1
            flag = True
print(" ".join(list(map(str, A))))
print(swap)

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

int func(string s,string t){
  int ans=0;
  for (char c='a';c<='z';c++){
    bool founds=false, foundt=false;
    rep(i,s.length()){
      if(s[i]==c){
        founds=true;
      }
    }
    rep(i,t.length()){
      if(t[i]==c){
        foundt=true;
      }
    }
    if(founds&&foundt)ans++;
  }
  return ans;
}
int main(){
  int N;
  string s;
  cin>>N>>s;
  int ans=0;
  rep(i,N){
    int tmp=func(s.substr(0,i),s.substr(i));
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def nCr(self, n, r):
        r = min(n - r, r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

    def nHr(self, n, r):
        return self.nCr(n - 1 + r, r)


def main():
    MOD = 10 ** 9 + 7

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

    B = [-1] * (N + 1)  # はじめて出現する位置(0-ind)
    d = None  # 重複要素の出現位置(2点)
    for i, x in enumerate(A):
        if ~B[x]:
            d = B[x], i
            break
        B[x] = i

    # 重複要素L,R(d[0],d[1]),一度だけ出現する数の列X,Y,Z(|X|>=0,|Y|>=0,|Z|>=0)
    # X...LY...RZ...
    # 重複計上: choose(N+1,K)
    # ここから重複分を差し引く
    # LRを含む個数
    # 0個: 重複計上なし
    # 1個: (X,L,YZ)と(XY,R,Z)が一致する場合に重複計上になる==(X,L/R,Z)
    # ->
    # #==sum(choose(X,a)*choose(Z,K-1-a)),(0<=a<=K-1)
    # 見方を変える
    # Yの区間以外からK個選ぶ
    # ただし,Yの区間外のうちLRから0個取るものと2個取るものを差し引く
    # 残りは(X,L/R,Z)を二重計上したものなので,半分にする
    # (choose(N+1-Y,K) - choose(N+1-2-Y,K) - choose(N+1-2-Y,K-2)) // 2
    # 2個: 重複計上なし

    calc = Calc(max_value=N + 1, mod=MOD)
    ans = []
    Y = d[1] - 1 - d[0]
    div2 = pow(2, MOD - 2, MOD)
    for k in range(1, N + 2):
        t = (
                    calc.nCr(N + 1, k)
                    - (
                            calc.nCr(N + 1 - Y, k)
                            - calc.nCr(N + 1 - 2 - Y, k)
                            - calc.nCr(N + 1 - 2 - Y, k - 2)
                    ) * div2 % MOD
            ) % MOD
        ans.append(t)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 28268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

#define square(x) (x)*(x)
typedef long double ld;
ld solve(){
    ld res = 0;
    int N,M; cin >> N >> M;
    vector<ld> L(N),a(N),b(N);
    for(int i = 0; i < N;i++) cin >> L[i] >> a[i] >> b[i];
    for(int i = 0; i < (1<<N);i++){
        if(__builtin_popcount(i) != M) continue;
        ld T = 0;
        for(int j = 0; j < N;j++){
            if((i>>j)&1){
                for(int k = j+1;k < N;k++){
                    if((i>>k)&1){
                        T += (square(L[j]-L[k]) + square(a[j]-a[k]) + square(b[j]-b[k]));
                    }
                }
            }
        }
        res = max(res,T);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) << solve() << endl;
    return 0;
}



Measured memory_bytes: 3292
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int res = 0;
		res+=Math.min(A, K);
		K -= res;
		if(K==0) {
			System.out.println(res);
			System.exit(0);
		}
		K-=B;
		if(K>0) {
			res-=Math.min(K, C);
		}
		System.out.println(res);

	}
}

Measured memory_bytes: 36028
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L> T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){return i?B[i]+M(i-(i&-i)):0;}L S(L x,L i){for(x=G(x)-M(i+1)+M(i++);i<1<<17;B[i]+=x,i+=i&-i);}L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33480
from functools import reduce

def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]

    buf = [abs(p - x) for p in points]
    print(reduce(lambda a,b: euclid(a, b), buf))


Measured memory_bytes: 14596
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int pasuta[] = new int[3];
		int jusu[] = new int[2];
		pasuta[0] = scan.nextInt();
		int minP = pasuta[0];
		for(int i = 1 ; i < 3 ; i++){
			pasuta[i] = scan.nextInt();
			if(minP > pasuta[i]){
				minP = pasuta[i];
			}
		}
		jusu[0] = scan.nextInt();
		jusu[1] = scan.nextInt();
		if(jusu[0] < jusu[1]){
			System.out.println((minP+jusu[0]-50));
		}else{
			System.out.println((minP+jusu[1]-50));
		}
	}
}

Measured memory_bytes: 26144
#include<bits/stdc++.h>
using namespace std;
#define ll         long long
#define mod        1000000007
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf        1e18
#define ps(x,y)    fixed<<setprecision(y)<<x

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	int n, k;
	cin >> n >> k;
	long long int sum = 0;
	long long int cnt = 0;
	vector<bool> v(n + 1, 0);
	v[0] = 1;

	for (int i = 1; i <= n && v[i] == 0 ; ++i)
	{
		v[i] = 1;
		cnt = 0;
		if ((i * 2) % k == 0)
		{
			cnt = 1;
			int temp = i;
			while (temp + k <= n)
			{
				v[temp + k] = 1;
				temp += k;
				cnt++;
			}
		}
		// if (cnt)
		// cout << i << " " << cnt << endl;
		long long int a = 0, b = 0, c = 0;
		if (cnt >= 1)
			a = cnt;
		if (cnt >= 2)
		{b = (cnt * (cnt - 1)) / 2;}
		if (cnt >= 3)
		{c = (b * (cnt - 2)) / 3; c = c * 6;}
		sum += (a + b * 6 + c);
	}
	cout << sum ;

}

Measured memory_bytes: 3632