akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace ConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {


            //int  postition=0,range=0;
            string[] eatmass = Console.ReadLine().Split(' ');
            string[] mass = Console.ReadLine().Split(' ');

            string[] greed = Console.ReadLine().Split(' ');
            string[] bonus = Console.ReadLine().Split(' ');

            int[] pointlist = new int[mass.Length];
            int Eatmass = int.Parse(eatmass[0]);

            for (int i = 0; i < Eatmass; i++)
            {
                pointlist[i] = int.Parse(mass[i]);
            }

            int[] greedlist = new int[greed.Length];
            for (int i = 0; i < Eatmass; i++)
            {
                greedlist[i] = int.Parse(greed[i]);
            }

            int[] bonuslist = new int[bonus.Length];
            for (int i = 0; i < bonus.Length; i++)
            {
                bonuslist[i] = int.Parse(bonus[i]);
            }

            int result = 0,eaten=0;

            for(int i=0;i< Eatmass; i++)
            {

                result += greedlist[pointlist[i]-1];
               
                if(eaten!=0)
                {
                    if(pointlist[i]  == eaten+1)
                    {
                        result += bonuslist[eaten-1];
                    }
                }
                eaten = pointlist[i];

            }
            //int[] listinput = new int[mass.Length];

            //for (int i = 0; i < mass.Length; i++)
            //{
            //    listinput[i] = int.Parse(mass[i]);
            //}


            Console.Write(result);



            //postition = int.Parse(mass[1]);

            //int nowposition = postition - (range - 1);

            //for(int i= 0; i<=(range-1)*2;i++)
            //{

            //    Console.Write(nowposition);
            //    Console.Write(" ");
            //    nowposition++;
            //}

            result = 0;

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 5000;

long long n, k;
long long p[N + 1];
long long c[N + 1];

long long mx(int i, int j, vector<long long>& v)
{
    if (j < i)
        return 0;
    i--;
    j--;
    long long maxx = v[i];
    for (; i <= j; i++)
        maxx = max(maxx, v[i]);
    return maxx;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> k;
    
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];
        
    long long ans = -1e18;
    vector<long long> sum;
    for (int i = 1; i <= n; i++)
    {
        long long currans;
        int j = p[i];
        sum.clear();
        while (j != i)
        {
            if (sum.size() != 0)
                sum.push_back(sum.back() + c[j]);
            else
                sum.push_back(c[j]);
            j = p[j];
        }
        sum.push_back(sum.back() + c[i]);
        
        if (k > sum.size())
        {
            if (sum.back() > 0)
            {
                currans = ((k - 1) / sum.size()) * sum.back();
                long long m = mx(1, (k - 1) % sum.size() + 1, sum);
                if (m > 0)
                    currans += m;
            }
            else
                currans = mx(1, sum.size(), sum);
        }
        else
            currans = mx(1, k, sum);
        
        ans = max(ans, currans);
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  LLI a,b,k;
  while(cin >> a >> b >> k){

    if(a <= k){
      k -= a;
      a = 0;


      if(b <= k){
        b = 0;
      }else{
        b -= k;
      }
      
    }else a -= k;

    cout << a << " " << b << endl;
  }


  return 0;
}


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


long long N, M;
long long a[3000];
long long b[3000];
long long c[3000];
long long dist[3000];
bool loop[3000];

int main(){
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;b[i]--;c[i] = -c[i];
	}

	for(long long i = 0; i < 3000; i++){
		dist[i] = LONG_MAX/3;
		loop[i] = false;
	}
	dist[0] = 0;

	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < M; j++){
			if(dist[a[j]] == LONG_MAX/3)
				continue;

			dist[b[j]] = min(dist[b[j]], dist[a[j]] + c[j]);
		}
	}

	long long ans = dist[N-1];


	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < M; j++){
			if(dist[a[j]] == LONG_MAX/3)
				continue;

			if(dist[b[j]] > dist[a[j]] + c[j]){
				dist[b[j]] = min(dist[b[j]], dist[a[j]] + c[j]);
				loop[b[j]] = true;
			}

			if(loop[a[j]])
				loop[b[j]] = true;

		}
	}
	
	if(loop[N-1])
		cout << "inf" << endl;
	else
		cout << -ans << endl;




}


Measured memory_bytes: 384
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int gcd(int a, int b){
    if (b == 0) {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}


void printc(char c, int n){
    for (int i = 0; i < n; i++) {
        cout << c;
    }
}


void printar(string dir, int tate, int yoko){
    printc(dir[0], tate);
    printc(dir[1], yoko);
    printc(dir[2], tate + 1);
    printc(dir[3], yoko + 1);
    printc(dir[4], tate + 1);
    printc(dir[5], 1);
    printc(dir[6], 1);
    printc(dir[7], yoko + 1);
    printc(dir[8], tate + 1);
    printc(dir[9], 1);

}

void solve(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int tate = abs(ty - sy), yoko = abs(tx - sx);
    string dir;

    if (sx <= tx) {
        printc('R', tx - sx);

        if (sy <= ty) {
            dir = "ULDRULULDR";
            printar(dir, tate, yoko);
        } else {
            dir = "DLURDLDLUR";
            printar(dir, tate, yoko);
        }
    }else{
        printc('L', yoko);

        if (sy <= ty) {
            dir = "URDLURURUL";
            printar(dir, tate, yoko);
        } else {
            dir = "DRULDRDRUL";
            printar(dir, tate, yoko);
        }
    }

    cout << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    wl = [int(i) for i in input().split()]
    ans = sum(wl)
    for i in range(1, n):
        ans = min(ans, abs(sum(wl[:i] )- sum(wl[i:])))
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n;
	cin >> n;
	vector<int> v(n), c(n);
	int ans=0;
	for(int i=0; i<n; i++){
		cin >> v[i];
	}
	for(int i=0; i<n; i++){
		cin >> c[i];
		v[i]-=c[i];
	}
	for(int i=0; i<n; i++){
		if(v[i]>0){
			ans+=v[i];
		}
	}
	cout << ans << endl;


	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    int n = (N + 999) / 1000;
    cout << n * 1000 - N << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

using VT = vector<int>;
struct RollingHash {
	static const ll mo0=1000000021,mo1=1000000009;
	static ll mul0,mul1;
	static const ll add0=1000010007, add1=1003333331;
	static vector<ll> pmo[2];
	VT s; int l; vector<ll> hash_[2];
	void init(VT s) {
		this->s=s; l=s.size(); int i,j;
		hash_[0]=hash_[1]=vector<ll>(1,0);
		if(!mul0) mul0=10009+(((ll)&mul0)>>5)%259,mul1=10007+(((ll)&mul1)>>5)%257;
		if(pmo[0].empty()) pmo[0].push_back(1),pmo[1].push_back(1);
		FOR(i,l) hash_[0].push_back((hash_[0].back()*mul0+add0+s[i])%mo0);
		FOR(i,l) hash_[1].push_back((hash_[1].back()*mul1+add1+s[i])%mo1);
	}
	pair<ll,ll> hash(int l,int r) { // s[l..r]
		if(l>r) return make_pair(0,0);
		while(pmo[0].size()<r+2)
			pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((hash_[0][r+1]+(mo0-hash_[0][l]*pmo[0][r+1-l]%mo0))%mo0,
			             (hash_[1][r+1]+(mo1-hash_[1][l]*pmo[1][r+1-l]%mo1))%mo1);
	}
	pair<ll,ll> hash(VT s) { init(s); return hash(0,s.size()-1); }
	static pair<ll,ll> concat(pair<ll,ll> L,pair<ll,ll> R,int RL) { // hash(L+R) RL=len-of-R
		while(pmo[0].size()<RL+2) pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((R.first + L.first*pmo[0][RL])%mo0,(R.second + L.second*pmo[1][RL])%mo1);
	}
};
vector<ll> RollingHash::pmo[2]; ll RollingHash::mul0,RollingHash::mul1;
RollingHash ar,br;

int N;
int A[202020];
int B[202020];
vector<int> As,Bs;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	FOR(i,N) cin>>A[i];
	FOR(i,N) cin>>B[i];
	FOR(i,N*2+5) As.push_back(A[i%N]^A[(i+1)%N]);
	FOR(i,N*2+5) Bs.push_back(B[i%N]^B[(i+1)%N]);
	ar.init(As);
	br.init(Bs);
	
	vector<pair<int,int>> V;
	FOR(i,N) {
		if(ar.hash(i,i+N-2)==br.hash(0,N-2)) {
			cout<<i<<" "<<(A[i]^B[0])<<endl;
		}
	}
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 38096
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;
const ll m = 1000000007;

ll pw(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2) {
        return (a * pw(a, n-1)) % m;
    }
    ll a2 = pw(a, n/2);
    return (a2 * a2) % m;
}

ll ch(ll n, ll k) {
    ll ans = 1;
    ll rec = 1;
    for (int i = 0; i < k; ++i) {
        ans = (ans * (n-i)) % m;
        rec = (rec * (i+1)) % m;
    }
    return (ans * (pw(rec, m-2))) % m;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll t1, t2, t3;
    t1 = pw(2, n);
    t2 = ch(n, a);
    t3 = ch(n, b);

    ll ans = t1 - t2 - t3 - 1;
    ans %= m;
    ans = (ans + m) % m;
    cout << ans << endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll K;
int A[202020];
int F[202020];

int ok(ll v) {
	ll sum=0;
	int i;
	FOR(i,N) {
		ll ma=v/F[i];
		if(ma<A[i]) sum+=A[i]-ma;
		if(sum>K) return 0;
	}
	return 1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	ll S=0;
	FOR(i,N) {
		cin>>A[i];
		S+=A[i];
	}
	FOR(i,N) cin>>F[i];
	
	if(S<=K) return _P("0\n");
	
	sort(A,A+N);
	sort(F,F+N);
	reverse(F,F+N);
	ll mi=1LL<<60;
	for(i=59;i>=0;i--) if(ok(mi-(1LL<<i))) mi-=1LL<<i;
	cout<<mi<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from collections import*;n,*v=map(int,open(0).read().split());a,b=[Counter(v[i::2]).most_common()+[(0,0)]for i in(0,1)];i,x=a[0];j,y=b[0];print(n-[x+y,max(x+b[1][1],y+a[1][1])][i==j])\n"
"\"";
  system(s);
  return 0;
}            

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define pb                push_back
#define vii               vector<int> 
#define pii               pair<int,int>
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define mset(a,f)         memset(a,f,sizeof(a))
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 107, inf = 1e18;
int n, W;
pii arr[N];
int  dp[N][100007];

int getval(int it, int v)
{            
      if( v == 0 ) return 0;
      if( v < 0 || it == 0 ) return inf;  
      if( dp[it][v] != -1 ) return dp[it][v];
      int a = inf , b = inf;
      a = arr[it].ff + getval(it - 1, v - arr[it].ss);
      b = getval(it - 1, v);
      return dp[it][v] = min(a,b);
}

int32_t main() {
    fastio;
    
      cin >> n >> W;
      loop(i,1,n+1)  cin >> arr[i].ff >> arr[i].ss;
      mset(dp,-1);
      int ans = 0;
      loop(v,0,100001) if( getval(n,v) <= W ) ans = v;
      cout << ans << endl; 

}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln
#define YES(x) if(x)cout<<"YES"<<ln;else cout<<"NO"<<ln
#define Yes(x) if(x)cout<<"Yes"<<ln;else cout<<"No"<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b;
vl v(55);
ll c[55][55];

// パスカルの三角形を作る
void comb() {
	rept(i,n) {
		rept(j,i) {
			if (j==i || j==0) c[i][j] = 1;
			else c[i][j] = c[i-1][j-1] + c[i-1][j];
		}
	}
}

int main() {
	cin >> n >> a >> b;
	rep(i,n) cin >> v[i];
	comb();
	
	// まず平均はでかい順にa個取るのが明らかに最善
	sort(v.rbegin(), v.rend());
	double ave = 0;
	rep(i,a) ave += v[i];
	ave /= a;
	printf("%.24lf\n", ave);
	
	// この場合は選ぶ品物の数を増やすほど平均値が減っていく
	if (v[0]!=v[a-1]) {
		int x = 0, y = 0;
		rep(i,n) if (v[i]==v[a-1]) x++;
		rep(i,a) if (v[i]==v[a-1]) y++;
		printf("%lld\n", c[x][y]);
	}
	// この場合はv[0]と同じ数がX(>=A)個あるとするとΣXCk(k=A..min(B,X))通り
	else {
		int x = 0;
		rep(i,n) if (v[i]==v[0]) x++;
		ll ans = 0;
		repst(i,a,b) ans += c[x][i];
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 256
# ABC094B - Toll Gates
from bisect import bisect_left


def main():
    N, M, X, *A = map(int, open(0).read().split())
    A.sort()
    cur = bisect_left(A, X)
    ans = min(cur, M - cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    atcoder::dsu uni(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        uni.merge(a, b);
    }
    cout << int(uni.groups().size()) - 1 << '\n';
    return 0;
}


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

using namespace std;
using ll = long long;

ll makeMaskFit(vector<int> &sets, ll msk) {
	ll ans = 0;
	for (int i = 0; i < sets.size(); ++i) {
		if (msk & (1LL << (ll)i)) ans |= (1LL << (ll)sets[i]);
	}
	return ans;
}

ll solve() {
	int n; scanf("%d", &n);
	vector<ll> piles(n);
	for (int i = 0; i < n; ++i) scanf("%lld", &piles[i]);
	ll k = 0;
	for (int i = 2; i < n; ++i) k ^= piles[i];
	swap(piles[0], piles[1]);
	ll s = piles[0] + piles[1];
	ll pinilit = s - k;
//	printf("%lld yeet\n", pinilit);
	if (pinilit < 0 || pinilit % 2 != 0) return -1; 
	pinilit >>= 1LL;
	if ((pinilit & k) != 0 || (pinilit | k) < piles[0]) return -1;
	vector<int> setInK;
	for (ll i = 0; i < 60; ++i) {
		if (k & (1LL << i)) setInK.push_back(i);	
	}
	ll lo = 0, hi = (1LL << (ll)setInK.size()) - 1;
	while (lo < hi) {
		ll mid = (lo + hi) / 2;
		ll bitArr = makeMaskFit(setInK, mid);
		if ((bitArr | pinilit) >= piles[0]) hi = mid;
		else lo = mid + 1;
	}
//	printf("TO RET %lld\n", lo);
	ll ans = makeMaskFit(setInK, lo) | pinilit;
	if (ans == s) return -1;
	else return ans - piles[0];
}

int main() {
	printf("%lld\n", solve());	
	return 0;
}


Measured memory_bytes: 3744
n, w = (int(x) for x in input().split())
wv = [[0, 0]]
for _ in range(n):
    wv.append([int(x) for x in input().split()])
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(w + 1):
    dp[0][i] = 0
for i in range(1, n + 1):
    for j in range(0, w + 1):
        if j - wv[i][0] >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wv[i][0]] + wv[i][1])
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[n][w])

Measured memory_bytes: 120172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,a,b;
    cin >>x>>a>>b;
    if(abs(x-a)<abs(x-b)) cout<<'A'<<endl;
    else cout<<'B'<<endl;
}


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000;

int main(){
  cout << setprecision(10);
  int N, M;
  cin >> N >> M;
  int full = pow(2, N) -1;

  vector<vector<ll>>  dp(M, vector<ll>(full+1, MAX));

  vector<ll> a(M);
  vector<ll> b(M, 0);

  for(int i = 0; i < M; i++){
    int tmp;
    cin >> a[i] >> tmp;

    for(int j = 0; j < tmp; j++){
      int tmp1;
      cin >> tmp1;
      tmp1--;
      b[i] += pow(2, tmp1);
    }

  }

  // initialize
  for(int i = 0; i < M; i++){
    dp[i][0] = 0;
  }
  dp[0][b[0]] = a[0];
  // cerr << b[0] << " " << dp[0][b[0]] << endl;

  for(int i = 0; i < M-1; i++){
    for(int j = 0; j <= full; j++){
      // i+1を使う時
      dp[i+1][j | b[i+1]] = min(dp[i+1][j | b[i+1]], dp[i][j] + a[i+1]);
      // i+1 を使わない時
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }


  if(dp[M-1][full] == MAX){
    cout << -1 << endl;
  } else {
    cout << dp[M-1][full]  << endl;
  }
}


Measured memory_bytes: 32256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x,d;cin>>n>>x>>d;
  if(d<0){
    x=-x;
    d=-d;
  }
  if(d==0){
    if(x==0){
      cout<<1<<endl;
      return 0;
    }
    cout<<n+1<<endl;
    return 0;
  }

  vector<vector<ll>>ama(n+2);
  map<ll,ll>id,rid;
  rep(sz,n+1){
    ll a=sz*x%d;
    if(a<0)a+=d;
    if(!id.count(a)){id[a]=id.size();rid[id[a]]=a;}
    ama[id[a]].push_back(sz);
  }
  ll res=0;
  rep(i,ama.size()){
    vector<pair<ll,ll>>ran;
    for(auto sz:ama[i]){
      ll l;
      ll r;
      if(x!=0){
        l=((sz*x)/d-rid[i])+sz*(sz-1)/2;
        r=((sz*x)/d-rid[i])+sz*(2*n-sz-1)/2+1;
      }
      else {
        l=sz*(sz-1)/2;
        r=sz*(2*n-sz-1)/2+1;
      }

      //cout<<"sz "<<sz<<" "<<l<<" "<<r<<endl;
      ran.push_back({l,r});
    }
    sort(all(ran));
    ll len=ran.size();
    ll cnt=0;
    ll tl=-1e17,tr=-1e17;
    rep(j,len){
      if(ran[j].first<=tr){
        chmax(tr,ran[j].second);
      }
      else {
        cnt+=tr-tl;
        tl=ran[j].first;
        tr=ran[j].second;
      }
    }
    cnt+=tr-tl;
    res+=cnt;
  }
  cout<<res<<endl;

  return 0;

}


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

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

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

int main(){
    long long int n;
    cin >> n;
    vector<long long int> v(n),a(n), b(n);
    REP(i,n){
        cin >> a[i];
        v[i] = 1+i;
    }
    REP(i,n){
        cin >> b[i];
    }

    long long int A, B,tmp=0;
    do{
        if(a==v){
            A = tmp;
        }
        if(b==v){
            B = tmp;
        }
        tmp++;

    } while (next_permutation(v.begin(), v.end()));
    cout << abs(B - A) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
ios_base::sync_with_stdio(false); \
cin.tie(0);                       \
cout.tie(0);
#define test  \
int t;    \
cin >> t; \
while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
for (auto i : a)      \
    cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
for (int u = 0; u < n; u++) \
{                           \
    cout << ar[u] << " ";   \
}                           \
cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
	rootdada;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// // 	freopen("error.txt", "w", stderr);
// #endif
	int x, k, d;
	cin >> x >> k >> d;
	if (x < 0)
		x *= -1;
	int p = x / d;
	if (p > k)
		p = k;
	k -= p;
	x -= (d * p);


	int ans;
	if (k % 2 == 0)
		ans = x;
	else
		ans = abs(x - d);
	cout << ans << endl;
	// cout << x << k << d << endl;



}


Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int a,b;
char mp[101][105];

int main(){
        cin >> a >> b;
        for(int i = 1; i <= 50; i++)
        {
                for(int j = 1; j <= 100; j++)
                {
                        mp[i][j] = '.';
                }
        }
        for(int i = 51; i <= 100; i++)
        {
                for(int j = 1; j <= 100; j++)
                {
                        mp[i][j] = '#';
                }
        }

        b--;
        for(int i = 1; i <= 50 && b; i += 2)
        {
                for(int j = 1; j <= 100 && b; j += 2)
                {
                        mp[i][j] = '#';
                        b--;
                }
        }

        a--;
        for(int i = 100; i > 50 && a; i -= 2)
        {
                for(int j = 1; j <= 100 && a; j += 2)
                {
                        mp[i][j] = '.';
                        a--;
                }
        }

        cout << "100 100" << endl;
        for(int i = 1; i <= 100; i++){
                for(int j = 1; j <= 100; j++){
                        cout << mp[i][j];
                }
                cout << endl;
        }

        return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    if (r < 1200) {
      cout << "ABC" << '\n';
    } else if (r < 2800) {
      cout << "ARC" << '\n';
    } else {
      cout << "AGC" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector <int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    for (int i=0;i<a.size();i++) {
       if (i==k-1) {
           cout << a[i];
           break;
       }
    }
}

Measured memory_bytes: 256
# 約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

  
n = int(input())
d = make_divisors(n)
ans = 10**13
for i in d:
    j = n // i
    ans = min(ans, i+j-2)
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    int l = 0 , r = s.size() - 1;
    int ans = 0;
    while(l<r){
        if(s[l] == s[r]){
            l++;
            r--;
        }else if(s[l]=='x'){
            l++;
            ans++;
        }else if(s[r]=='x'){
            r--;
            ans++;
        }else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n; i>0; i--)
#define rep1(i, n) for(int i=1; i<n; i++)
#define all(v) v.begin(), v.end()
using pint = pair<int, int>;
using tint = tuple<int, int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr double PI=3.14159265358979323846;
constexpr int INF = INT_MAX/2;

int type = 26;

int main() {
	int D;
	cin >> D;
	// 不開催により低下する満足度
	int dec = 0;
	vector<int64_t> c(type);
	vector<vector<int64_t>> l(type, vector<int64_t>(1, -1));
	rep(i, type) {
		cin >> c.at(i);
		dec += c.at(i);
	}
	// 開催により増加する満足度
	vector<vector<int64_t>> s(D, vector<int64_t>(type));
	rep(i, D) {
		rep(j, type) {
			cin >> s.at(i).at(j);
		}
	}

	// 日程変更クエリ
	int M = 20000000;
	vector<pint> dq(M);
	// srand((unsigned int)time(NULL));
	rep(i, M) {
		dq.at(i).first = rand() % D;
		dq.at(i).second = rand() % type;
	}

	// 初期解の満足度計算
	int64_t a=0, b=0, x, y, z;
	vector<int64_t> t(D);
	rep(i, D) {
		// i日目に開催するtype
		x = 0;
		y = 0;
		rep(j, type) {
			if(chmax(y, s.at(i).at(j))) {
				x = j;
			}
		}
		t.at(i) = x;
		// 開催による増加
		a += s.at(i).at(x);
		// 不開催による減少
		b += (dec - c.at(x)*(i-l.at(x).at(l.at(x).size()-1)));
		l.at(x).push_back(i);
		a -= b;
		// 暫定満足度
		// cout << a << endl;
	}
	rep(i, type) {
		l.at(i).push_back(D);
	}

	// 変更処理
	rep(i, M) {
		int64_t p = a;
		x = dq.at(i).first;
		y = t.at(x);
		z = dq.at(i).second;
		if (y == z) continue;
		// 開催による増加差分
		a -= s.at(x).at(y);
		a += s.at(x).at(z);
		// 不開催による減少差分 増加
		int f = 0;
		// l.at(z).push_back(x);
		rrep(j, l.at(z).size()-1) {
			if (l.at(z).at(j-1) <= x) {
				f = j;
				break;
			}
		}
		a += (l.at(z).at(f) - x) * (x - l.at(z).at(f-1)) * c.at(z);
		// 不開催による減少差分 減少
		f = 0;
		rep1(j, l.at(y).size()) {
			if (l.at(y).at(j-1) == x) {
				break;
			} else {
				f = j;
			}
		}
		// l.at(y).pop_back();
		a -= (l.at(y).at(f) - x) * (x - l.at(y).at(f-1)) * c.at(y);
		// 暫定満足度
		// cout << a << endl;
		if (p > a) {
			a = p;
		} else {
			t.at(x) = z;
			for(int j = f; j < l.at(y).size(); j++) {
			// rep1(j, l.at(y).size()) {
				if (l.at(y).at(j-1) == x) {
					l.at(y).at(j-1) = l.at(y).at(j);
					l.at(y).at(j) = x;
				}
			}
			l.at(y).pop_back();
			l.at(z).push_back(x);
			rrep(j, l.at(z).size()-1) {
				if (l.at(z).at(j-1) > x) {
					l.at(z).at(j) = l.at(z).at(j-1);
					l.at(z).at(j-1) = x;
				} else {
					break;
				}
			}
		}
	}

	// 解
	rep(i, D) {
		cout << t.at(i)+1 << '\n';
	}
}


Measured memory_bytes: 159540
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long s = 1;
    bool over = false;
    bool zero = false;
    for (int i = 0; i < n; i++) {
        long long a;
        cin >> a;
        long long x = a % 1000000000;
        long long y = a / 1000000000;
        long long z = s % 1000000000;
        long long w = s / 1000000000;
        if ( y * w > 1  || x * z / 1000000000 + y * z + x * w + y * w * 1000000000 > 1000000000 ||
                x * z / 1000000000 + y * z + x * w + y * w * 1000000000 == 1000000000 && x * z % 1000000000 != 0) {
            over = true;
        }
        if (!over) {
            s *= a;
        }
        if (a == 0) {
            zero = true;
        }
    }
    cout << (zero ? 0 : (over ? -1 : s)) << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>                          
using namespace std;    
int h,w,a[101],b[101];
char s[105][105];
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=h;i++)
	{
		int x=0;
		for(int j=1;j<=w;j++) 
		    if(s[i][j]=='.') x++;
		if(x==w) a[i]=1;
	}
	for(int i=1;i<=w;i++)
	{
		int x=0;
		for(int j=1;j<=h;j++)
		    if(s[j][i]=='.') x++;
	    if(x==h) b[i]=1;
	}
	for(int i=1;i<=h;i++)
	{
		int flag=0;
		for(int j=1;j<=w;j++){
			if(a[i]||b[j]) continue;
			flag=1;
			printf("%c",s[i][j]);
		}
		if(flag) printf("\n");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++){
        cin >> p.at(i);
    }

    int ans = 0;

    for (int i = 1; i < n - 1; i++){
        if (p[i] > min(p[i-1],p[i+1]) && p[i] < max(p[i-1],p[i+1])){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

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


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void) {
    int n;
    int x[1000] = {};
    int y[1000] = {};
    double a;
    
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for(int i = 0; i < n; ++i) {
        cin >> y[i];
    }
    
    for(int i = 1; i <= 3; ++i) {
        a = 0;
        for(int j = 0; j < n; ++j) {
            a += pow(abs(x[j] - y[j]), i);
        }
        a = pow(a, (double)1 / i);
        printf("%lf\n", a);
    }
    a = 0;
    for(int i = 0; i < n; ++i) {
        if(a < abs(x[i] - y[i])) {
            a =  abs(x[i] - y[i]);
        }
    }
    printf("%lf\n", a);
    
    return 0;
    
}


Measured memory_bytes: 3348
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0066
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			char[][] cs = new char[3][3];
			String s = sc.next();
			for (int i = 0; i < 9; i++)
				cs[i / 3][i % 3] = s.charAt(i);
			
			char res = 'd';
			for (int i = 0; i < 3; i++) {
				char c = cs[i][0];
				if (c == 's') continue;
				boolean ok = true;
				for (int j = 1; j < 3; j++) 
					if (c != cs[i][j])
						ok = false;
				
				if (ok) res = c;
			}
				
			for (int j = 0; j < 3; j++) {
				char c = cs[0][j];
				if (c == 's') continue;
				boolean ok = true;
				for (int i = 1; i < 3; i++) 
					if (c != cs[i][j])
						ok = false;
				
				if (ok) res = c;
			}
			
			char c = cs[0][0];
			if (c == 's') {
			
			} else {
				if (c == cs[1][1] && c == cs[2][2])
					res = c;
			}
			
			c = cs[0][2];
			if (c == 's') {
				
			} else {
				if (c == cs[1][1] && c == cs[2][0])
					res = c;
			}
			System.out.println(res);
			
		}
	}
}

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

string s;

int main(){
	cin >> s;
	int cnt = 0;
	for(int i=1;i<s.size()-1;i++){
		if(s[i+1] == s[i-1]) continue;
		cnt++;
	}
	int pan = s.size();
	if(s[0] == s[pan-1]) pan--;
	if(cnt == 0) cout << "Second\n";
//	else if(cnt == 1) cout << "First\n";
	else if(pan&1) cout << "First\n";
	else cout << "Second\n";
	return 0;
}


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

using namespace std;
using ll = long long;

void solve(long N, vector<long> A) {
  // count up balls with same bumbers
  vector<long> count(N, 0);
  rep(i, N)
    count[A[i] - 1]++;

  // sum up nC2
  ll total = accumulate(count.cbegin(), count.cend(), 0LL, [](long a, long i){return a + (i * (i - 1) / 2);});

  // remove combination with banned K-th ball
  rep(i, N)
    cout << total - (count[A[i] - 1]) + 1 << endl;
}

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

  long N;
  cin >> N;
  vector<long> A(N);
  for(long i = 0 ; i < N ; i++){
    cin >> A[i];
  }
  solve(N, move(A));
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int mod = 1000000007;
struct mint {
    ll x;
  //=にしたときにはこの式が行われる？
    mint(ll x = 0):x((x%mod+mod)%mod){}
    //値が変更されない場合は参照渡しじゃなくていい
    mint operator- () const{
        return mint(-x);
    }
    mint& operator+= (const mint a){
        (x += a.x) %= mod;
        return *this;
    }
    mint& operator-= (const mint a){
        (x += mod-a.x) %= mod;
        return *this;
    }
    mint& operator*= (const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+ (const mint a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator- (const mint a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator* (const mint a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint & operator/= (const mint a){
        //a.inv()っていうのは1/b(mod p)の計算結果
        return (*this) *= a.inv();
    }
    mint operator/ (const mint a) const{
        mint res(*this);
        return res/=a;
    }
};

mint choose(int n,int a){
    mint x = 1,y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n)-1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    set<string> tval;
    int n; cin >> n;
    FOR(i,n){
        string a; cin >> a;
        tval.insert(a);
    }
    cout << tval.size() << endl;
    return 0;
}


Measured memory_bytes: 19288
fun main(args: Array<String>) {
  var n = readLine()!!.toInt()
  var k = readLine()!!.toInt()
  var x = readLine()!!.toInt()
  var y = readLine()!!.toInt()
  if (n <= k) {
    println(x*n)
  } else {
    println(x*k+y*(n-k))
  }
}

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


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

    int tmp = n;

    int digit_sum = 0;

    while(tmp > 0){
        digit_sum += tmp % 10;
        tmp /= 10;
    }

    if(n % digit_sum == 0) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256