akhauriyash/Code-Regression huggingface dataset:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_C

class Array
  # ????´????to_i?????????????????????????????????
  def avg
    inject(0.0){|r,i| r+=i.to_i }/size
  end
  # ????´????to_i?????????????????£???????????????
  def variance
    a = avg
    inject(0.0){|r,i| r+=(i.to_i-a)**2 }/size
  end
  # ????´????to_i?????????????¨?????????????????????????
  def standard_deviation
    Math.sqrt(variance)
  end
end

while true do
    n = gets.to_i
    break if n==0
    puts gets.split.map(&:to_i).standard_deviation
end

Measured memory_bytes: 6160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vec A(n);
    rep(i,n) cin>>A[i];
    if(k>=50) rep(i,n) cout<<n<<" ";
    else{
        rep(i,k){
            vec B(n+1,0),C;
            rep(j,n){
                B[max((ll)0,j-A[j])]++,B[min((ll)n,j+A[j]+1)]--;
            }
            rep(j,n){
                B[j+1]+=B[j];
            }
            A=B;
        }
        rep(i,n) cout<<A[i]<<" ";
    }
}

Measured memory_bytes: 7952
#include <iostream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep1(i, s, n) for (int i = (s); i >= (n); i--)

int main()
{
	int N, mini, swap = 0, tmp;

	cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	rep(i, N) {
		mini = i;
		rep1(j, i, N - 1) {
			if (A[j] < A[mini]) mini = j;
		}
		if (i != mini) swap++;
		tmp = A[i];
		A[i] = A[mini];
		A[mini] = tmp;
	}

	rep(i, N - 1) cout << A[i] << " ";
	cout << A[N - 1] << endl;
	cout << swap << endl;

	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

#define int ll

ll solve(ll N,V<int> a,V<int> b){	//-a[i] -> b[i]
	int K = a.size();
	if(K==0) return N;
	if(K==1){
		return N + N/a[0] * (b[0]-a[0]);
	}
	if(K==2){
		ll res = 0;
		rep(i,N+1){
			if(N - a[0]*i < 0) break;
			int j = (N-a[0]*i)/a[1];
			chmax(res,N + i * (b[0]-a[0]) + j * (b[1]-a[1]));
		}
		return res;
	}
	if(K==3){
		assert(N <= 5000);
		ll res = 0;
		rep(i,N+1) rep(j,N+1){
			ll n = N - a[0] * i - a[1] * j;
			if(n<0) break;
			int k = n/a[2];
			chmax(res,N+i*(b[0]-a[0])+j*(b[1]-a[1])+k*(b[2]-a[2]));
		}
		return res;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	V<int> a(3),b(3);
	cin >> N;
	rep(i,3) cin >> a[i];
	rep(i,3) cin >> b[i];
	ll now = N;
	rep(t,2){
		V<int> aa,bb;
		rep(t,3) if(a[t]<b[t]) aa.pb(a[t]),bb.pb(b[t]);
		now = solve(now,aa,bb);
		swap(a,b);
	}
	cout << now << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,x,y;
vector<int>v[N];
int dis[2003][2003],inq[2003];
void dfs(int x){
  for(int i=1;i<=n;i++)dis[x][i]=1e9;
  dis[x][x]=0;
  queue<int>q;
  q.push(x);
  inq[x]=1;
  while(!q.empty()){
    int y=q.front();
    inq[y]=0;
    q.pop();
    for(auto k:v[y]){
      if(dis[x][k]>dis[x][y]+1){
        dis[x][k]=dis[x][y]+1;
        if(!inq[k]){
          inq[k]=1;
          q.push(k);
        }
      }
    }
  }
}
int ans[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>x>>y;
  for(int i=1;i<n;i++){
    v[i].pb(i+1);
    v[i+1].pb(i);
  }
  v[x].pb(y);
  v[y].pb(x);
  for(int i=1;i<=n;i++){
    dfs(i);
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      ans[dis[i][j]]++;
    }
  }
  for(int i=1;i<n;i++){
    cout<<ans[i]/2<<'\n';
  }
  return 0;
}

Measured memory_bytes: 20736
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
#define MOD  998244353
#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n,a,b,k;
long long ab;
long long N;
long long ans;
long long m;
long long ka;
long long tt;
long long ttt;
long long mm;
long long t;
long long ta,tta,ttta;
long long nn;
long long kai[1000000];
long long g[1000000];
long long gcd(long long x,long long y)
{
	if(y==0)return x;
	else return gcd(y,x%y);
}
vector<long long> list_mod_inverse(long long n, long long m)
{
    vector<long long> inv(n + 1);
    inv[1] = 1;
    for (long long i = 2; i <= n; ++i)
        inv[i] = inv[m % i] * (m - m / i) % m;
    return inv;
}
int main()
{
	cin>>N>>a>>b>>k;
	ab=gcd(a,b);
	if(k%ab!=0)
	{
		printf("0\n");
		return 0;
	}
	k/=ab;
	a/=ab;
	b/=ab;
	//
	vector<long long> gyaku=list_mod_inverse(N,MOD);
	rep2(i,1,N+1)
	{
		if(i==1)g[i]=gyaku[i];
		else g[i]=(gyaku[i]*g[i-1])%MOD;
	}
	g[0]=1;
	//
	kai[0]=1;
	rep2(i,1,N+1)
	{
		if(i==1)kai[i]=1;
		else kai[i]=(kai[i-1]*i)%MOD;
	}
	rep2(i,1,10)
	{
		//cout<<kai[i]<<"---------"<<g[i]<<endl;
	}
	ka=k%a;
	rep(i,a+1)
	{
		if((i*b)%a==ka)
		{
			mm=i;
			nn=(k-b*mm)/a;
			break;
		}
	}
	//cout<<"mm"<<mm<<endl;
	//cout<<"nn"<<nn<<endl;
	//rep2(i,mm,N)
	for(long long i=mm;i<=N;i+=a)
	{
		
		m=i;
		n=(k-b*m)/a;
		if(n<0)break;
		if(n>N)continue;
	//	cout<<"m"<<m<<endl;
	//cout<<"n"<<n<<endl;
		t=g[m];
		tt=g[N-m];
		t=(t*tt)%MOD;
		ttt=(t*kai[N])%MOD;
		ta=g[n];
		tta=g[N-n];
		ta=(ta*tta)%MOD;
		ttta=(ta*kai[N])%MOD;
		ttt=(ttt*ttta)%MOD;
		//cout<<"ttt"<<ttt<<endl;
		ans+=ttt;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i<(n) ; i++);

int main() {
	int x;
	cin >>x;
	int y = x / 500 * 1000;
	int z = (x % 500) / 5 * 5;
	cout << y + z << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int K,P,N,i;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d %d",&K,&P);
        if(K%P)
            printf("%d\n",K%P);
        else
            printf("%d\n",P);
    }
    return 0;
}

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

int main(){

	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for(int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int ans = 1000000001;
	for(int i = 0; i < N-K+1; i++)
	{
		ans = min(ans, h[i+K-1] - h[i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
def main():
    N,M = map(int,input().split(' '))
    ori_data = input().split(' ')
    data = [int(ori_data[i]) for i in range(N)]
    all = 0
    for per in data:
        all += per

    judge = all / (4 * M)
    count = 0
    for per in data:
        if(per >= judge):
            count += 1
    if(count >= M):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,M;
	cin >> N >> M;
	VV<int> G(N*3);
	rep(i,M){
		int x,y;
		cin >> x >> y;
		x--,y--;
		G[x].pb(y+N);
		G[x+N].pb(y+N+N);
		G[x+N+N].pb(y);
	}
	int inf = 1e9;
	V<int> d(N*3,inf);
	int S,T;
	cin >> S >> T;
	S--,T--;
	d[S] = 0;
	queue<int> que;
	que.push(S);
	while(!que.empty()){
		int v = que.front();
		que.pop();
		for(int u: G[v]) if(d[u] == inf){
			d[u] = d[v] + 1;
			que.push(u);
		}
	}
	if(d[T] == inf) cout << -1 << endl;
	else cout << d[T]/3 << endl;
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
#define ll long long
int M=1e9+7;
using namespace std;
int main()
{
	int n,cnt=0,ans=0;
	cin>>n;
	pair<int,int> p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;
		if(p[i].first==p[i].second)
		cnt++;
		else
		cnt=0;
		if(cnt>=3)
		ans=1;
	}
	if(ans)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b;
    cin >>a>>b;

    b+= 3*a;

    cout << b/2 << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
#include <queue>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n, m;
  cin >> n >> m;

  priority_queue<ull> a;
  each(i, n) {
    ull tmp;
    cin >> tmp;
    a.emplace(tmp);
  }

  while (m > 0) {
    const auto current = a.top() / 2;
    a.pop();
    m--;
    a.emplace(current);
  }

  ull result = 0;
  each(i, n) {
    result += a.top();
    a.pop();
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

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

int main(){

  int n, m; cin>> n>> m;
  vector<vector<int>> g(n);
  rep(_, m){
    int a, b; cin>> a>> b;
    g[a-1].push_back(b-1);
  }

  vector<int> deg_in(n, 0);
  rep(i, n)for(int j: g[i]) deg_in[j]++;
  queue<int> Q;
  rep(i, n)if(deg_in[i]==0) Q.push(i);
  vector<int> order;
  bool multi=false;
  while(Q.size()>0){
    auto i=Q.front(); Q.pop();
    order.push_back(i);
    int cnt=0;
    for(int j: g[i]){
      if((--deg_in[j])==0){
        Q.push(j);
        cnt++;
      }
    }
    if(cnt>=2) multi=true;
  }

  for(int i: order) cout<< i+1<< endl;
  if(multi) cout<< 1<< endl;
  else cout<< 0<< endl;

  return 0;
}


Measured memory_bytes: 3876
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans = 0

    mode = 0

    for i in range(1, n):
        if a[i] > a[i - 1]:
            if mode == -1:
                ans += 1
                mode = 0
            else:
                mode = 1
        elif a[i] < a[i - 1]:
            if mode == 1:
                ans += 1
                mode = 0
            else:
                mode = -1
        else:
            pass

    ans += 1

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 14224
s = input()
flag = True
for ss in range(len(s)):
    if (ss+1) % 2 == 0 and s[ss] == 'R':
        flag = False
        break
    if (ss+1) % 2 == 1 and s[ss] == 'L':
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38256
n=int(input())
a=str(input())
l=[]
l=list(map(int,a.split()))

l.sort()
l.reverse()
plus=0
for i in range(n):
    if i==0:
        pass
    else:
        plus+=l[i]
if l[0]<plus:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn int
using ll = long long;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int a[1000000];

signed main() {
	int n,i;
	cin >> n;
	vector<int> v;
	rep(i, n) {
		int z;
		cin >> z;
		z--;
		v.pb(z);
	}
	int now = 0, c = 0;
	while (true) {
		if (now == 1) {
			cout << c << endl;
			break;
		}
		if (c >= n) {
			cout << -1 << endl;
			break;
		}
		c++;
		now = v[now];
	}
	return 0;
}

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

const int MAX_SIZE = 86400;

bool ok(int N, int L, int s[], int t[], int u[], double m) {
  double w = L, e[2];
  for (int j = 0; j < 2; ++j) {
    for (int i = 0; i < N + 2; ++i) {
      w += (m - u[i]) * (t[i] - s[i]);
      if (w <= 0.0) {
        return false;
      }
      if (i < N + 1) {
        w += m * (s[i + 1] - t[i]);
      }
      if (w > L) w = L;
    }
    e[j] = w;
  }
  return e[1] >= e[0];
}

double calc(int N, int L, int s[], int t[], int u[]) {
  double l = 0.0, r = 1e6, m;
  while (true) {
    if (r - l < 1e-7) break;
    m = (l + r) / 2;
    if (ok(N, L, s, t, u, m)) {
      r = m;
    } else {
      l = m;
    }
  }
  return m;
}

int main() {
  int N, L, s[MAX_SIZE + 2], t[MAX_SIZE + 2], u[MAX_SIZE + 2];
  while (true) {
    cin >> N >> L;
    if (!N) break;
    for (int i = 0; i < N; ++i) {
      cin >> s[i + 1] >> t[i + 1] >> u[i + 1];
    }
    s[0] = 0; t[0] = s[1]; u[0] = 0;
    s[N + 1] = t[N]; t[N + 1] = 86400; u[N + 1] = 0;
    cout << fixed << setprecision(7) << calc(N, L, s, t, u) << endl;
  }
}

Measured memory_bytes: 2248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<int>Ws(N);
    map<string,bool>siritori;
    char last = '1';
    for (int i=0; i<N; i++){
        string wi;
        cin >> wi;
        if (siritori[wi] == true || (i != 0 && wi[0] != last)){
            cout << "No" << endl;
            return 0;
        }
        siritori[wi] = true;
        last = wi[wi.size()-1];
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define R register
int n,m,fa[100005],val[100005],x,y,z;
int find(int x)
{
	if(x==fa[x])return x;
	int par=fa[x];
	fa[x]=find(fa[x]);
	val[x]+=val[par];
	return fa[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		int xx=find(x),yy=find(y);
		if(xx==yy)
		{
			if(val[y]-val[x]!=z)
			{
				puts("No");
				return 0;
			}
		}
		else
		{
			fa[yy]=xx;
			val[yy]=val[x]+z-val[y];
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, 0, n) cin >> l[i];
  sort(l.begin(), l.end());

  int answer = 0;
  rep(i, 0, n) {
    rep(j, i + 1, n) {
      int ij = l[i] + l[j];
      rep(k, j + 1, n) {
        if (ij > l[k]) {
          answer++;
        } else {
          break;
        }
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(int& rnLeft, int& rnRigt)
{
  cin >> rnLeft >> rnRigt;
}
  
int fnRemainMin2019(int nLeft, int nRigt)
{
  if (nLeft + 2018 < nRigt) return 0;

  int nRemMin2019 = INT_MAX;

  for (int i = nLeft; i < nRigt; i++)
    for (int j = i + 1; j < nRigt + 1; j++)
    {
      int nRem2019 = (llong)i * j % 2019;
      nRemMin2019 = min(nRemMin2019, nRem2019);
    }

  return nRemMin2019;
}
  
int main()
{
  int nLeft, nRigt;
  fnInput(nLeft, nRigt);
  cout << fnRemainMin2019(nLeft, nRigt) << endl;

  return 0;
}

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

int main() {
	int n; cin>>n;
	string s; cin>>s;
	
	stack<int> open, close;
	for (char i : s) {
		if (i=='(') {
			open.push('1');
		}
		else {
			if (!open.empty()) {
				open.pop();
			}
			else {
				close.push('1');
			}
		}
	}
	
	for (int i=0; i<close.size(); i++) cout << '(';
	cout << s;
	for (int i=0; i<open.size(); i++) cout << ')';
	cout << endl;
	return 0;
}

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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}
int main() {
	ll x, y;
	cin >> x >> y;
	cout << x + y - gcd(x, y) + 1 << endl;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int ans=0;
  for(int i=0;i<N-1;i++){
    if(a[i]==a[i+1])a[i+1]=-1,ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
num_list = []
sum_ = 0
for i in range(n):
    num_list.append(int(input()))
num_list.sort()
for i in range(n):
    sum_ += num_list[i]
sum_1 = sum_
if sum_ % 10 != 0:
    print(sum_)
else:
    for i in range(n):
        if num_list[i] % 10 != 0:
            sum_ -= num_list[i]
            print(sum_)
            break
for i in range(n):
    if num_list[i] % 10 == 0:
        sum_1 -= num_list[i]
if sum_1 == 0:
    print(sum_1)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] array = new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int[][] ans = new int[2][n];
        ans[0][0] = array[0][0];
        for (int i = 0; i < n-1; i++) {
            ans[0][i+1] = ans[0][i] + array[0][i+1];
        }
        ans[1][0] = array[0][0] + array[1][0];
        for (int i = 1; i < n; i++) {
            ans[1][i] = Math.max(ans[0][i], ans[1][i-1]) + array[1][i];
        }
        System.out.println(ans[1][n-1]);
    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main(){
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int MAX = 10000;
			int num[] = new int[MAX];
			while(true){
				int a = cin.nextInt() - 1;
				int b = cin.nextInt() - 1;
				if(a==-1) break;
				num[a]++; num[b]++;
			}
			boolean flag = true;
			if(num[0]%2==0) flag = false;
			if(num[1]%2==0) flag = false;
			for(int i=2;i<MAX;i++){
				if(num[i]%2!=0) flag = false;
			}
			if(flag) System.out.println("OK");
			else System.out.println("NG");
		}
	}
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        String a=sc.next();
        
        if(Character.isUpperCase(a.charAt(0))){
            System.out.println("A");
        }else{
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 35572
A, B, C, D = map(int, input().split())
count = 0
while True:
    if count % 2 == 0:
        C -= B
        if C <= 0:
            print("Yes")
            break
    else:
        A -= D
        if A <= 0:
            print("No")
            break
    count += 1


Measured memory_bytes: 9172
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int N, A, B;
ll C[51][51];

void com_math(){
    for(int i = 0; i < 51; i++){
        C[i][0] = 1LL;
        for(int j = 1; j <= i; j++)
            C[i][j] = C[i-1][j-1] + C[i-1][j];
    }
}

int main(){
    com_math();
    scanf("%d%d%d", &N, &A, &B);
    vector<ll> v;
    ll t;
    for(int i = 0; i < N; i++){
        scanf("%lld", &t);
        v.push_back(t);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    double max_average = 0.0;
    for(int i = 0; i < A; i++){
        max_average += v[i];
    }
    max_average /= A;

    int n = 0,k = 0;
    for(int i = 0; i < N; i++){
        if(v[i] == v[A-1]){
            n++;
            if(i < A)k++;
        }
    }
    ll ans = 0LL;
    if(k == A){
        for(int i = A; i <= B; i++)
            ans += C[n][i];
    }
    else{
        ans += C[n][k];
    }
    printf("%lf\n%lld\n", max_average, ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

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

int main() {
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;

    if (e - a > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(n, m);
    vi g(n+1, 0);

    rep(i, m) {
        int2(a, b);
        g[a]++;
        g[b]++;
    }
    Rep(i, n+1) {
        cout << g[i] << endl;
    }


    return 0;
}



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

int main()
{
   int n,c=0,w=0,t=0,r=0;
   cin>>n;
   string a[n];
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
   for(int i=0;i<n;i++){
    if(a[i]=="AC"){
        c++;
    }
    else if(a[i]=="WA"){
        w++;
    }
    else if(a[i]=="TLE"){
        t++;
    }
    else if(a[i]=="RE"){
        r++;
    }
   }
   cout<<"AC x "<<c<<endl;
   cout<<"WA x "<<w<<endl;
   cout<<"TLE x "<<t<<endl;
   cout<<"RE x "<<r<<endl;



    return 0;
}


Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
int n,k,x=0,ans=0;
std::vector<int> v;
std::vector<int> a;
int main(){
  cin >> n >> k;
  a.resize(n);v.resize(n+1);for(size_t i = 0; i <= n; i++)v[i]=0;
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    if(v[a[i]] == 0)x++;
    v[a[i]]++;
  }
  sort(all(v));
  if(x-k <= 0){
    cout << 0 << endl;
    return 0;
  }
  for (size_t i = 0; i < (x-k)+(n-x+1); i++) {
    ans += v[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var x = new int[N];
            var y = new int[N];
            var h = new int[N];

            bool flg = true;

            int testHeightIndex = 0;

            for (int i = 0; i < N; i++) {
                var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

                x[i] = st[0];
                y[i] = st[1];
                h[i] = st[2];

                if (h[i] != 0 && flg) {
                    testHeightIndex = i;
                    flg = false;
                }
            }

            int ans_cx = 0;
            int ans_cy = 0;
            int ans_H = 0;

            for (int cx = 0; cx <= 100; cx++) {
                for (int cy = 0; cy <= 100; cy++) {
                    int H = h[testHeightIndex] + Math.Abs(x[testHeightIndex] - cx) + Math.Abs(y[testHeightIndex] - cy);

                    for (int i = 0; i < N; i++) {
                        if (h[i] != Math.Max(H - Math.Abs(x[i] - cx) - Math.Abs(y[i] - cy), 0)) {
                            goto skip;
                        }
                    }
                    ans_cx = cx;
                    ans_cy = cy;
                    ans_H = H;

                    skip:;
                }
            }

            Console.WriteLine(ans_cx + " " + ans_cy + " " + ans_H);
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        int sqrtN=(int)Math.sqrt(N);
        int result=0;
        for(int i=1;i<sqrtN+1;i++){
            if(N%i==0){
                result=(int)Math.log10(N/i)+1;
            }
        }
        System.out.println(result);
        return;


    }
}


Measured memory_bytes: 21588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int l;
	while(cin >> l && l)
	{
		int res = 0;
		rep(i, 12)
		{
			int n, m;
			cin >> n >> m;
			l -= n - m;
			

			if(l <= 0 && !res)
				res = i + 1;
		}

		if(res)
			cout << res << endl;
		else
			cout << "NA" << endl;
	}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    sort(all(H));

    ll res = 0;
    for(int i = N - 1; i >= 0; --i) {
        if(K==0) {
            res = accumulate(all(H), 0LL);
            break;
        }

        H[i] = 0;
        K--;
    }

    cout << res << endl;
}

Measured memory_bytes: 1792
def abc062_c():
    h, w = map(int, input().split())
    # 2 <= h, w のため1の場合は考えない
    # どちらかが3の倍数ならぴったり3分割できる (平行2線)
    if h % 3 == 0 or w % 3 == 0:
        print(0)
        return
    # 平行2線で割るときの差分最小は、短辺1本分
    ans = min(h, w)
    # それ以外は例2例3の割り方 (直交2線)
    for x, y in [(w, h), (h, w)]:
        for i in range(1, x):
            sa = i * y
            sb = (x - i) * (y // 2)
            sc = (x - i) * (y - y // 2)
            diff = max(sa, sb, sc) - min(sa, sb, sc)
            ans = min(diff, ans)
    print(ans)

abc062_c()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
double N;
  in(N);
  cout << fixed<<setprecision(10)<<N*2*pi<<endl;
}


Measured memory_bytes: 3776
n = int(input())
b_arr = list(map(int, input().split()))
a_arr = [0]*n
a_arr[0] = b_arr[0]
a_arr[-1] = b_arr[-1]

for i in range(1, n-1):
    a_arr[i] = min(b_arr[i-1], b_arr[i])

print(sum(a_arr))

Measured memory_bytes: 3064
#include <iostream>

int main(int argc, char *argv[])
{
    int x, a;
    int ans;

    std::cin >> x >> a;

    if (x < a) {
        ans = 0;
    } else {
        ans = 10;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n, m,ans = 0,now=0;

	cin >> n >> m;

	vecll a(m);
	vecbool f(n+1,true);

	forll(i, 0, m)
		cin >> a[i];

	forll(i, 0, m)
	{
		f[a[i]] = false;
	}

	vecll dp(n+1);

	dp[0] = 1;

	forll(i, 0, n)
	{
		forll(j, i+1, min(n+1, i + 3))
		{
			if (f[j])
			{
				dp[j] += dp[i];
				dp[j] %= 1000000007;
			}
		}
	}

	cout << dp[n];

}

Measured memory_bytes: 1792
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

A = 0
for ibit in range(2 ** H):
    for jbit in range(2 ** W):
        B = 0
        for i in range(H):
            for j in range(W):
                if (ibit & (1 << i)) or (jbit & (1 << j)):
                    continue
                if c[i][j] == '#':
                    B += 1
        if B == K:
            A += 1
print(A)

Measured memory_bytes: 9192
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
const int N = 101010;

inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
template<typename T>
inline void read(T &x) {
  static char c; x = 0; int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}

int n, m, a, b;
int vis[N];

int main(void) {
  read(n); read(m);
  for (int i = 1; i <= m; i++) {
    read(a); read(b);
    vis[a]++; vis[b]++;
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] & 1) {
      puts("NO"); return 0;
    }
  puts("YES");
  return 0;
}


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

struct restaurant {
	int num;
	string name;
	int point;
};

bool my_compare(restaurant a, restaurant b) {
	if(a.name != b.name) {
		return a.name < b.name;
	} else {
		return a.point > b.point;
	}
}

int main() {
	int N;
	cin >> N;
	vector<restaurant> book;
	for(int i = 0; i < N; i++) {
		restaurant res;
		res.num = i + 1;
		cin >> res.name >> res.point;
		book.push_back(res);
	}
	
	sort(book.begin(), book.end(), my_compare);
	
	for(int i = 0; i < N; i++) {
		printf("%d\n", book[i].num);
	}
	
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        t: usize,
        edges: [(usize, usize); n],
    }
    let mut ret = 1001;
    for e in edges{
        if ret > e.0 && t >= e.1 {
            ret = e.0;
        }
    }
    if ret == 1001 {
        println!("TLE");
    } else {
        println!("{}", ret);
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include <string.h>
using namespace std;

#define MAX 200000
long long sum_A[MAX], sum_B[MAX];

int binarySearch(long long l[], int n, int key) {
    int left = 0;
    int right = n;
    int mid;
    while ( left < right ) {
        mid = (left + right) / 2;
        if ( key == l[mid] ) {
            return mid + 1;
        }
        if ( key > l[mid] ) {
            left = mid + 1;
            if ( right == left ) {
                return right;
            }
        } else if ( key < l[mid] ) {
            right = mid;
            if ( right == left ) {
                return right;
            }
        }
    }
    return 0;
}

int main() {
    int N, M, K, tmp;
    int idx;
    int w_ans = 0, ans = 0;
    
    cin >> N >> M >> K;
    for ( int ii = 0; ii < N; ii++ ) {
        cin >> tmp;
        if ( ii == 0 ) {
            sum_A[ii] = tmp;
        } else {
            sum_A[ii] = sum_A[ii - 1] + tmp;
        }
    }
    for ( int ii = 0; ii < M; ii++ ) {
        cin >> tmp;
        if ( ii == 0 ) {
            sum_B[ii] = tmp;
        } else {
            sum_B[ii] = sum_B[ii - 1] + tmp;
        }
    }
    
    idx = binarySearch(sum_A, N, K);
    if ( idx == 0 ) {
        tmp = K;
    } else {
        tmp = K - sum_A[idx - 1];
    }
    ans = w_ans = idx;
    
    while ( 1 ) {
        int tmp_idx = binarySearch(sum_B, M, tmp);
        w_ans += tmp_idx;
        if ( w_ans > ans ) {
            ans = w_ans;
        }
        idx--;
        if ( idx < 0 ) {
            break;
        }
        if ( idx == 0 ) {
            tmp = K;
        } else {
            tmp = K - sum_A[idx - 1];
        }
        w_ans = idx;
    }
    
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6708
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  else:
    if a[i+1]+a[i]>=b[i]:
      cnt+=b[i]
      a[i+1]=a[i+1]+a[i]-b[i]
    else:
      cnt+=a[i]+a[i+1]
      a[i+1]=0
print(cnt)
      

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

using namespace std;

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

    int N,M; cin>>N>>M;
    vector<int> graph[N];
    for (int i = 0; i < M; i++) {
        int x,y,z;
        cin>>x>>y>>z;
        x--,y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    vector<bool> visited(N, false);
    int cnt = 0;
    function<void(int)> traverse = [&](int f) {
        visited[f] = true;
        if (++cnt == N)
            return;
        for (auto t : graph[f]) {
            if (visited[t])
                continue;
            traverse(t);
        }
    };
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (graph[i].size() == 0 or
            visited[i])
            continue;
        traverse(i);
        ans++;
    }
    for (auto v : visited) {
        if (not v)
            ans++;
    }
    cout << ans << endl;
    
    return 0;
}



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

int fx (int n){
  string s;
  s =to_string(n);
  int cnt =0;
  for (int i=0;i<s.size();i++){
    if(s[i] != s[s.size()-1-i]){
      break;
    }else if (i == s.size()-1-i){
      cnt =1;
      break;
    }
  }
  return cnt;
}

int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  for (int i=a;i<=b;i++){
    ans +=fx(i);
  }
  cout <<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 100000
 
int Partition(int,int);
int A[N];
 
int main(void){  
  int i,n,p=0,r,mid;
     
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
     
  r=n-1;
  mid=Partition(p,r);
     
   
  for(i=0;i<mid;i++) printf("%d ",A[i]);   
  
  printf("[%d] ",A[mid]);
  
  for(i=mid+1;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
     
  return 0;
}

int Partition(int p,int r){
  int x,i,j,y;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
    }
  }
  y=A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}



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

string S; int p[3][100009]; long long ans = 0, mod = 1000000007, power3[100009];

int range(int t, int l, int r) {
	if (l == 0) return p[t][r];
	return p[t][r] - p[t][l - 1];
}

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '?') p[0][i] = 1;
		if (S[i] == 'A') p[1][i] = 1;
		if (S[i] == 'C') p[2][i] = 1;
	}
	for (int h = 0; h < 3; h++) {
		for (int i = 1; i < S.size(); i++) p[h][i] += p[h][i - 1];
	}
	power3[0] = 1; for (int i = 1; i <= 100000; i++) power3[i] = (power3[i - 1] * 3LL) % mod;
	
	long long ans = 0;

	for (int i = 1; i < (int)S.size() - 1; i++) {
		if (!(S[i] == 'B' || S[i] == '?')) continue;
		long long va = range(0, 0, i - 1);
		long long s1 = range(1, 0, i - 1) * power3[va];
		long long s2 = va; if (va >= 1) s2 *= power3[va - 1]; s1 %= mod; s2 %= mod;

		long long vc = range(0, i + 1, S.size() - 1);
		long long t1 = range(2, i + 1, S.size() - 1) * power3[vc];
		long long t2 = vc; if (vc >= 1) t2 *= power3[vc - 1]; t1 %= mod; t2 %= mod;

		long long ret = ((s1 + s2) % mod) * ((t1 + t2) % mod); ret %= mod;
		ans += ret; ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  int output = 1;
  int outputCount = 0;

  cin >> n;

  for (int i = 1; i <= n; ++i) {
    int multi = i;
    int count = 0;
    while(multi % 2 == 0) {
      multi /= 2;
      ++count;
    }
    if (count > outputCount) {
      output = i;
      outputCount = count;
    }
  }

  cout << output;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  string S;
  
  for (int i=0; i<W+2; i++)
    cout <<"#";
  
  cout <<endl;
  
  for (int i=0; i<H; i++) {
    cin >> S;
    cout <<"#" <<S <<"#" <<endl;
  }
  
  for (int i=0; i<W+2; i++)
    cout <<"#";
  
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define inp(a) int a; cin>>a;
#define inpa(a,n) vector<int>a(n); FOR(i,0,n-1) cin>>a[i];
#define PI 3.141592653589793238
#define QUICK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vec(x) vector<x>
#define pii pair<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define FOR(i,j,n) for(int i= j; i<=n; i++)
#define srt(a); sort(a.begin(), a.end())
#define CASE int t; cin>>t; while(t--)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define print(x) for(auto c : x) cout << c << " ";
#define dbg(x) cerr << #x << " :: "<< x << endl;
#define dbg2(x,y) cerr << #x << " :: "<<x <<"\t" << #y << " :: "<<y <<endl;
#define upcase(s)  transform(s.begin(), s.end(), s.begin(), ::toupper)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define int ll
const int INF = 1e6 + 7;
const int SIZE = 150007;
const int MOD = 1e9 + 7; 
//////////// template ends here //////////////////////////

int bottomup(int n, vec(int) h, int dp[]){

	FOR(i,1,n){
		int sub1 = INF, sub2 = INF;
		if(i-1 >= 0)
			sub1 = dp[i-1] + abs(h[i]-h[i-1]);
		if(i-2 >=0)
			sub2 = dp[i-2] + abs(h[i]-h[i-2]);
		dp[i] = min(sub1, sub2);
	}
	return dp[n];


}


void solve(){	
	inp(n);
	inpa(h,n);
	int dp[n+2] = {0};
	dp[0] = 0;
	cout << bottomup(n-1, h, dp);
	
}



int32_t main(){
	#ifndef ONLINE_JUDGE 
		freopen ("input.txt","r",stdin);
		freopen ("output.txt","w",stdout);
	#endif	
	QUICK;
	
	solve();
	printclock;
}

Measured memory_bytes: 5548
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int dp[1000];
char a[1000];
int main()
{
    scanf("%s",a+1);
    int len=strlen(a+1);
    for(int i=1;i<=len;i++){
        if(a[i]=='A'||a[i]=='G'||a[i]=='C'||a[i]=='T'){
            dp[i]=1;
            dp[i]+=dp[i-1];
        }
    }
    int ans=0;
    for(int i=1;i<=len;i++) ans=max(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

int main() {
  int k,a, b;
  cin >> k >> a >> b;
  for(int i=k; i <= b; i+=k) {
    if(a <= i && i <= b){ cout << "OK" << endl; return 0;}
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
string s;
int i,flagc=0,flagf=0;
int main()
{
    cin>>s;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='C'&&flagf==0)
            flagc=1;
        if(s[i]=='F'&&flagc==1)
            flagf=1;
    }
    if(flagc&&flagf)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 384
MOD = 10**9 + 7


def main():
    N = int(input())
    S = [input() for _ in range(2)]
    dp = [0] * N
    if S[0][0] == S[1][0]:
        dp[0] = 3
    else:
        dp[0] = 3 * 2
    for i in range(1, N):
        if S[0][i] == S[0][i-1]:
            dp[i] = dp[i-1] % MOD
            continue
        l = 1 if S[0][i-1] == S[1][i-1] else 2
        r = 1 if S[0][i] == S[1][i] else 2
        if l == 1:
            dp[i] = dp[i-1] * 2 % MOD
        elif r == 2:
            dp[i] = dp[i-1] * 3 % MOD
        else:
            dp[i] = dp[i-1] % MOD
    print(dp[N-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<vector>

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n+1);   
    a[1] = 0;
    b[1] = 0;

    for(int i = 2;i <= n;i++){
    cin >> a[i];
    b[i] = 0;
        }
    for(int i = 2;i <= n;i++){
    b[a[i]]++;
        }
    for(int i = 1;i <= n;i++){
    cout << b[i] << endl;
        }
    return 0;
}

Measured memory_bytes: 4820
#include<iostream>
#include<string>
#include<vector>
using namespace std;

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

int main(void){
  string s;
  getline(cin,s);
  vector<string> pa;
  string add = "";
  s+=" ";
  rep(i,s.size()){
    if(s[i] == ' '){
      if(add.size() >= 5){
	string res = "";
	for(int i = 0 ; i < add.size() ; i ++){
	  if(add[i + 0] == 'a' &&
	     add[i + 1] == 'p' &&
	     add[i + 2] == 'p' &&
	     add[i + 3] == 'l' &&
	     add[i + 4] == 'e' 
	     ){
	    res += "peach";
	    i += 4;
	    continue;
	  }
	  if(add[i + 0] == 'p' &&
	     add[i + 1] == 'e' &&
	     add[i + 2] == 'a' &&
	     add[i + 3] == 'c' &&
	     add[i + 4] == 'h' 
	     ){
	    res += "apple";
	    i += 4;
	    continue;
	  }
	  res += add[i];
	}
	add = res;
      }
      pa.push_back(add);
      
      add = "";
    }else{
      add += s[i];
    }
  }
  rep(i,pa.size()-1){
    cout<<pa[i]<<" ";
  }
  cout<<pa[pa.size()-1]<<endl;
}

Measured memory_bytes: 1188
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

yes = "Possible"
no = "Impossible"

N, L = map(int, input().split())
a = [0] + list(map(int, input().split()))

c = 0
Mi = -1
for i in range(1, N):
	if c < a[i] + a[i+1]:
		c = max(c, a[i] + a[i+1])
		Mi = i

if c < L:
	print(no)
else:
	print(yes)
	for i in range(1, N):
		if i != Mi:
			print(i)
		else:
			break
	for i in reversed(range(1, N)):
		if i != Mi:
			print(i)
		else:
			break
	print(Mi)


Measured memory_bytes: 14724
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long K,A,B;
    cin >> K >> A >> B;
    for(int i = A; i <= B; i++){
        if(i%K == 0){
            cout << "OK" << endl;
        return 0;
    }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3620