akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct {
  int max_minus; // 0以下の数が入る
  int total;
} s;


bool psort(const s &a, const s &b) {
  return a.max_minus > b.max_minus;
}
bool msort(const s &a, const s &b) {
  return a.max_minus < b.max_minus;
}


int main(void) {
  int N;
  cin >> N;
  vector 
 plist, mlist;

  long long total_checker = 0;

  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int len = S.length();
    int max_min = 0;
    int pos = 0;
    for (int j = 0; j < len; j++) {
      if (S[j]=='(') {
        pos++;
      } else if (S[j]==')') {
        pos--;
        max_min = min(max_min, pos);
      }
    }
    if (pos > 0) {
      s wk;
      wk.max_minus = max_min;
      wk.total = pos;
      plist.push_back(wk);
    } else {
      s wk;
      wk.max_minus = max_min-pos;
      wk.total = -pos;
      mlist.push_back(wk);
    }
    total_checker += pos;
  }

  if (total_checker != 0) {
    cout << "No" << endl;
    return 0;
  }

  sort(plist.begin(), plist.end(), psort);
  sort(mlist.begin(), mlist.end(), psort);


  bool ans = true;
  int pos = 0;
  for (int i = 0; i < plist.size(); i++) {
    if ((pos + plist[i].max_minus) < 0) {
      ans = false;
      break;
    }
    pos += plist[i].total;
  }

  pos = 0;
  for (int i = 0; i < mlist.size(); i++) {
    if ((pos + mlist[i].max_minus) < 0) {
      ans = false;
      break;
    }
    pos += mlist[i].total;
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 11336
import java.util.Scanner;

public class Main {

	static int INF = 1001001001;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] C = new int[N];
		int[][] a = new int[12][12];
		for(int i = 0;i < N;i++){
			C[i]= sc.nextInt();
			for(int j = 0;j < M;j++){
				a[i][j] = sc.nextInt();
			}
		}
		int ans = INF;
		//ビット演算子を用いて2^n通りを試す
		for(int s = 0;s < (1<<N);s++){
			int cost = 0;
			int[] d = new int[M];
			for(int i = 0;i < N;i++){
				if((s>>i&1)==1){
					cost += C[i];
					for(int j = 0;j < M;j++){
						d[j] += a[i][j];
					}
				}
			}
			boolean flag = true;
			for(int j = 0;j < M;j++){
				if(d[j] < X)flag = false;
			}
			if(flag)ans = Math.min(ans, cost);
		}
		if(ans == INF){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 37556
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,b,a) for(i=b-1;i>=(ll)a;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  double N,M,D;
  cin>>N>>M>>D;
  if(D)print(2*(N-D)*(M-1)/N/N);
  else print((M-1)/N);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll solve(int n, int k) {
    ll a[n+1];
    a[0] = 0;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        a[i] += a[i-1];
    }

    ll ans = 0LL;
    for(int i=1;i<=n-k;++i) {
        ans = max(ans, a[i+k-1]-a[i-1]);
    }
    return ans;
}

int main() {
    int n, k;

    while(cin >> n >> k && n) {
        cout << solve(n, k) << endl;
    }
}


Measured memory_bytes: 3840
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, x;
  cin >> N >> x;
  vector<ll> vec(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> vec[i];
  }
  ll cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (vec[i] + vec[i - 1] > x) {
      cnt += (vec[i] + vec[i - 1]) - x;
      vec[i] -= (vec[i] + vec[i - 1]) - x;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(int, a, N);
  map<int, int> m;
  each(x, a) {
    m[x]++;
    m[x - 1]++;
    m[x + 1]++;
  }
  int ans = 0;
  each(x, m) {
    ans = max(ans, x.second);
  }
  print(ans);
}


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

int n, ma, mb;
int a[41], b[41], c[41];
int dp[41][410][410];
int ans = 10010;

int main(){
	cin >> n >> ma >> mb;
	for(int i=0; i<n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	for(int i=0; i<n; ++i)
		for(int j=0; j<=400; ++j)
			for(int k=0; k<=400; ++k)
				dp[i][j][k] = 10010;
	dp[0][0][0] = 0;
	dp[0][a[0]][b[0]] = c[0];
	for(int i=1; i<n; ++i)
		for(int j=0; j<=400; ++j)
			for(int k=0; k<=400; ++k){
				dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
				int p = j - a[i];
				int q = k - b[i];
				if(p >= 0 && q >= 0)
					dp[i][j][k] = min(dp[i][j][k], dp[i-1][p][q] + c[i]);
			}
	for(int i=1; max(ma, mb)*i<=400; ++i)
		ans = min(ans, dp[n-1][ma*i][mb*i]);
	if(ans == 10010) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 26880
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
    p_1 , p_2, p_3 = p[i], p[i + 1], p[i + 2]
    if p_1 < p_2 < p_3 or p_3 < p_2 < p_1:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
int N, H, W;

int main() {
   cin >> N >> H >> W;
   cout << (N - W + 1) * (N - H + 1) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const int MAXN = 2e5+5;
const ll MOD = 1e9+7;

double p[MAXN];
double res[MAXN];

double cal(int n)
{
    double ans = 0;
    rep(i, 1, n)
        ans += i;
    return ans/n;
}

int main()
{
    ms(res, 0);
    int k, n, num;
    double ans;
    cin >> n >> k;
    rep(i, 1, n)
    {
        cin >> num;
        p[i] = cal(num);
    }
    rep(i, 1, k)
        res[k] += p[i];
    ans = res[k];
    rep(i, k+1, n)
    {
        res[i] = res[i-1] + p[i] - p[i-k];
        ans = max(ans, res[i]);
    }
    printf("%.12f\n", ans);

    return 0;
}


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

typedef long long ll;

int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll cnt1=0;
  ll cnt2=0;
  ll cnt=0;
  int n=s.size();
  for(int i=0;i<n;++i){
    if(s[0]==s[i]) cnt++;
  }
  if(n==cnt){
    cout << (n*k)/2 << endl;
    return 0;
  }

  string t=s+s;
  for(int i=0;i<n;++i){
    if(s[i]==s[i+1]){
      s[i+1]='#';
      cnt1++;
    }
  }

  for(int i=0;i<2*n;++i){
    if(t[i]==t[i+1]){
      t[i+1]='#';
      cnt2++;
    }
  }
  //cout << cnt2 << endl;
  cout << cnt1+(cnt2-cnt1)*(k-1) << endl;
  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cerr<<#x<<" "<<x<<endl
#define siz 1005
#define f first
#define s second
#define endl "\n"
#define ci cin.ignore()
using namespace std;
ll ans = 0;
void dfs(vector<ll> *graph,ll *depth,bool *visited,ll source)
{
	visited[source] = 1;
	depth[source] = 0;
	for(auto x : graph[source])
	{
		if(visited[x] == 0)
		{
			dfs(graph,depth,visited,x);
		}
		depth[source] = max(depth[source],depth[x]+1);
	}
	ans = max(ans,depth[source]);
	
}
int main()
{
  fastio;
	ll n,m,i,j,a,b;
	cin>>n>>m;
	
	ll depth[n+1];
	vector<ll> graph[n+1];
	
	for(i = 0;i<m;i++)
	{
		cin>>a>>b;
		graph[b].push_back(a);
	}
	
	bool visited[n+1];
	memset(visited,0,sizeof(visited));
	
	for(i = 1;i<=n;i++)
	{
		if(visited[i] == 0)
		{
			dfs(graph,depth,visited,i);
		}
	}
		
	cout<<ans<<endl;
	
	
	
	
}

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

ll solve(ll x, ll y) {
    ll ans = 0, tmp = x;
    while(tmp <= y){
        tmp = tmp * 2;
        ++ans;
    }
    return ans;
}

int main(){
    ll x, y;
    cin >> x >> y;
    cout << solve(x, y) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      //入力
      int M =sc.nextInt();//モンスターの数
      int killhit =sc.nextInt();//必殺技回数
      long hp[] = new long[M];
      long ans =0;
      
      //各モンスターのHPを配列に
      for(int i=0; i<M; i++){
        hp[i] = sc.nextLong();
      }
      //HPを昇順に
      Arrays.sort(hp);
      
      //攻撃だけの回数をループ
      for(int i=0; i<M-killhit; i++){
          	ans += hp[i];
      }
          	System.out.println(ans);
    }
}

Measured memory_bytes: 62012
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    vl x(n);

    ll sum=0;rep(i,n){sum+=a[i];}
    sum/=2;

    for(ll i=1;i<n;i+=2){sum-=a[i];}//x1
    x[0]=sum;cout<<2*x[0]<<endl;

    rep(i,n-1){
        x[i+1]=a[i]-x[i];
        cout<<2*x[i+1]<<endl;
    }
    



}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 2000000
#define NIL -2000000

int n;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}
void heapIncreaseKey(int A[], int i, int key){
  int tmp;
  if (key < A[i]){
    return; //新しいキーは現在のキーより小さい
  }

  A[i] = key;
  while (i > 1 && A[parent(i)] < A[i]){
    tmp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = tmp;
    i = parent(i);
  }
}

void maxHeapInsert(int A[], int key){
  n = n + 1;
  A[n] = NIL;
  heapIncreaseKey(A, n, key);
}



void maxHeapify(int A[], int i){
  int l,r,largest,temp;
  l = left(i);
  r = right(i);
  if(l <= n && A[l] > A[i]){
    largest = l;
  }
  else 
    largest = i;
  if(r <= n && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    int tmp;
    temp = A[largest];
    A[largest] = A[i];
    A[i] = temp;
    maxHeapify(A, largest);
  }
}

void BuildMaxHeap(int A[]){
  int i;
  for(i=n/2;i >= 1;i--){
    maxHeapify(A,i);
  }
}

int heapExtractMax(int A[]){
  int max;
  if(n < 1)
    return 0; //ヒープアンダーフロー
  max = A[1];
  A[1] = A[n];
  n = n - 1;
  maxHeapify(A, 1);
  return max;
}

main(){
  int i,x,a[N];
  char com[20];
  for( i = 1 ; i < N ; i++ ){
    scanf("%s",com);

    if(strcmp(com,"end")==0){
      break;
    }

    if(com[0]=='i'){
      scanf("%d",&x);
      maxHeapInsert(a,x);
    }

    else{
      printf("%d\n",heapExtractMax(a));
    }
  }
  return 0;
}

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

int main()
{
    int a[32] = {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;
    cout << a[k - 1] << endl;
    // system("pause");
}

Measured memory_bytes: 888
import math
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=2*x/(a*b)
    d=c**2+b**2
    d=d**(1/2)
    ans=math.acos(c/d)
    print(ans*180/3.1415926535)
else:
    x=a*a*b-x
    c=2*x/(a*a)
    d=c**2+a**2
    d=d**(1/2)
    ans=math.acos(a/d)
    print(ans*180/3.1415926535)

Measured memory_bytes: 38460
x, y = map(int, raw_input().split())
v = [x, -x, y, -y]
dist = [[10**18]*4 for i in xrange(4)]
for i in xrange(4):
    for j in xrange(4):
        if v[j]-v[i] >= 0:
            dist[i][j] = v[j]-v[i]
dist[0][1] = dist[1][0] = dist[2][3] = dist[3][2] = 1
for k in xrange(4):
    for i in xrange(4):
        for j in xrange(4):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
print dist[0][2]

Measured memory_bytes: 2696
#include<iostream>
using namespace std;
long long i,n,t[109],temp,m,p[109],x[999999],j,sum;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>t[i];
	}
	cin>>m;
	for(i=1;i<=m;i++)
	{
		cin>>p[i]>>x[i];
	}
	for(i=1;i<=m;i++)
	{
		sum=0;
		temp=t[p[i]];
		t[p[i]]=x[i];
		for(j=1;j<=n;j++)
		{
			sum=sum+t[j];
		}
		t[p[i]]=temp;
		cout<<sum<<endl;
	}
}

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

int main()
{
	bool k[200]{};
	string c = "yuiophjklnm";
	for (char d : c)k[d] = true;
	string a;
	while (cin >> a, a != "#") {
		bool b = k[a[0]];
		int sum = 0;
		for (int i = 1; i < a.length(); i++) {
			if (k[a[i]] != b) { b = k[a[i]]; sum++; }
		}
		cout << sum << endl;
	}
}

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	sort(v.begin(), v.end());
	
	int minsum = 100000000;
	int i = v[0];
	do {
		int sum = 0;
		for(int j = 0; j < n; j++) {
			if (v[j] != i) sum += (v[j] - i) * (v[j] - i);
		}
		if (minsum > sum) minsum = sum;
		i++;
	}while(i < v[n-1]);
	cout << minsum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll N;
    cin >> N;
    vector<ll> a(N*3);
    rep(i,N*3){
        cin >> a[i];
    }

    sort(a.begin(),a.end(),greater<ll>());

    ll ans=0;
    rep(i,N){
        // cout << a[((i+1)*2)-1] << endl;
        ans += a[((i+1)*2)-1];
    }

    cout << ans << endl;





}

Measured memory_bytes: 5580
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#include <list>

int main(){
  int n,m;
  long long k;
  list<long long> A(0), B(0);
  long long imp;
  cin >> n >> m >> k;
  rep1(i, n){
    cin >> imp;
    A.push_back(imp);
  }
  rep1(i, m){
    cin >> imp;
    B.push_back(imp);
  }

  long long now = accumulate(A.begin(), A.end(), 0LL);
  while(now > k){
    now -= A.back();
    A.pop_back();
  }
  now = accumulate(B.begin(), B.end(), 0LL);
  while(now > k){
    now -= B.back();
    B.pop_back();
  }

  int tem = A.size();
  int max = A.size();
  int count = B.size();
  now = accumulate(A.begin(), A.end(), 0LL);
  rep1(i, count){
    A.push_front(B.front());
    tem += 1;
    now += B.front();
    B.pop_front();

    while(!A.empty() && now > k){
      now -= A.back();
      A.pop_back();
      tem -= 1;
    }

    if(tem > max){
      max = tem;
    }
    
  }
  
  cout << max;
 
}

Measured memory_bytes: 16116
#include<cstdio> 
#include<cstdlib> 
#include<string> 
#include<iostream> 
using namespace std;

struct Node {
    int key; 
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL; 
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node)); 
    z->key = k; 
    z->left = NIL; 
    z->right = NIL;
    
    while ( x != NIL ) {
        y = x; 
        if ( z->key < x->key ) {
        x = x->left; 
        } else {
            x = x->right;
        }
    }
    z->parent = y; 
    if ( y == NIL ){
        root = z; 
    } else { 
        if ( z->key < y->key ) {
            y->left = z; 
        } else {
            y->right = z;
        }
    }
}

void inorder (Node *u) {
    if ( u == NIL ) return; 
    inorder(u->left); 
    printf(" %d", u->key); 
    inorder(u->right);
}
void preorder (Node *u) {
    if ( u == NIL ) return; 
    printf(" %d", u->key); 
    preorder(u->left); 
    preorder(u->right);
}

int main() {
    int n, i, x; 
    string com;
    scanf("%d", &n);
    for (i = 0; i < n; i++ ) { 
        cin >> com; 
        if ( com == "insert" ) {
            scanf("%d", &x);
            insert(x); 
        } else if ( com == "print" ) {
            inorder(root); 
            printf("\n"); 
            preorder(root); 
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 26656
#include<iostream>
#include<string>
#include<vector>
#include<cctype>
#include<cstring>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int stoi(string s){
	int size=s.size();
	int ret=0;
	rep(i,size){
		ret+=(int)(s[i]-'0')*(int)pow(10,(size-i-1));
	}
	return ret;
}

int main(){
	vector<string> spot;
	string s;
	while(getline(cin,s)){
		spot.push_back(s);
	}
	int ans=0;
	rep(i,spot.size()){
		rep(j,spot[i].size()){
			if(isdigit(spot[i][j])){
				int start=j;
				while(isdigit(spot[i][j]))j++;
				string alt="";
				alt=spot[i].substr(start,j-start);
				ans+=stoi(alt);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1232
from collections import deque
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
XY = [(-1, 0), (1, 0), (0, 1), (0, -1)]
ans = 0

def dfs(h, w):
    Step = [[0]*W for _ in range(H)]
    Step[h][w] = 0
    stack = deque([(h, w)])
    visited =[[False]*W for _ in range(H)]
    while stack:
        i, j = stack.popleft()
        visited[i][j] = True
        for dx, dy in XY:
            x = i + dx
            y = j + dy
            if 0 <= x <= H-1 and 0 <= y <= W-1:
                if x == h and y == w:
                    continue
                if Step[x][y]:
                    continue
                if S[x][y] == '#':
                    continue
                stack.append((x, y))
                Step[x][y] = Step[i][j] + 1
    ans = 0
    for step in Step:
        ans = max(ans, max(step))
    return ans

for h in range(H):
    for w in range(W):
        if S[h][w] != '#':
            ans = max(ans, dfs(h, w))

print(ans)

Measured memory_bytes: 9240
#include<bits/stdc++.h>
#include<cmath>
#define  debug(x)   cout << '>' << #x << ':' << x << endl;

#define  fo(i,n)    for(ll i=0;i<n;i++)
#define  all(x)     (x).begin(), (x).end()
#define  unq(vec)   sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
typedef long long ll;


using namespace std;
const int     MO = int(1e9) + 7;



int main()
{ ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,n;
  cin>>a>>b>>n;
  ll x;
  if((b-1) > n){
    x=n;
  }else{
  x=b-1;
  }
  cout<<(a*x)/b;
}



Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n);
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long ans = 0, carry = 0;
  for (int i = 0; i < n; i++) {
    if (carry >= a[i]) {
      ans += a[i];
      carry = b[i];
    } else if (carry + b[i] >= a[i]) {
      ans += a[i];
      carry = carry + b[i] - a[i];
    } else {
      ans += carry + b[i];
      carry = 0;
    }
  }
  ans += min(carry, 1LL * a[n]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>

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

using namespace std;

int main(){
	int A, B;
	char op;
	cin >> A >> op >> B;
	if(op == '+') cout << A + B << endl;
	else cout << A - B << endl;
	return 0;
}


Measured memory_bytes: 256
/*
    ->->->->-> Vora Mahammasasim <-<-<-<-<-
*/
#include<bits/stdc++.h>
#include<stdio.h>
#define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
#define ps(a) partial_sum(all(a),a.begin())
using namespace std;





signed main(){

    Quick;
    int ans = 0;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
                ans++;
            }
        }
    }
    cout<<ans;

}



Measured memory_bytes: 3652
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M = map(int, input().split())
uf = UnionFind(N)
for m in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.union(x, y)

print(sum([x < 0 for x in uf.parents]))


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

int main(){
  ll n,a[100009];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  ll sum=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      sum+=a[i];
    }
    else{
      sum-=a[i];
    }
  }

  ll now=sum/2;
  ans.push_back(now);
  for(int i=0;i<n-1;i++){
    now=a[i]-now;
    ans.push_back(now);
  }

  for(int i=0;i<n;i++){
    cout<<ans[i]*2;
    if(i+1==n)cout<<endl;
    else cout<<' ';
  }

  return(0);
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin >> n;
    map<char,char> m = {{'1', '9'}, {'9', '1'}};
    n[0] = m[n[0]];
    n[1] = m[n[1]];
    n[2] = m[n[2]];
  	cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()
	nn := make([]int, 0, n)
	for i := 0; i < n; i++ {
		nn = append(nn, nextInt())
	}

	sort.Sort(sort.IntSlice(nn))
	h := n / 2

	divless := nn[h-1]
	divmore := nn[h]

	fmt.Println(divmore - divless)
}

func IntReverse(vv []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(vv)))
}


Measured memory_bytes: 2048
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const int mod = 1e9 + 7;
const int maxn = 3030;
int n;
char s[maxn];
int f[maxn][maxn];

void work() {
  n = read();
  scanf("%s", s + 2);
  rep(i, 1, n) f[1][i] = 1;
  rep(i, 2, n) {
    rep(j, 1, n) {
      if (s[i] == '<') f[i][j] = f[i - 1][j - 1];
      else f[i][j] = (f[i - 1][i - 1] - f[i - 1][j - 1] + mod) % mod;
    }
    rep(j, 1, n) (f[i][j] += f[i][j - 1]) %= mod;
  }
  printf("%d\n", f[n][n]);
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  LL sum =0;
  int cnt = 0;
  REPC(i,0,a){
    REPC(j,0,b){
      sum = 500*i+100*j;
      LL left = x-sum;
      if(left%50 == 0 && 50*c>=left && left>=0){
        ++cnt;
        //DUMP(i,j,left);
      }
    }
  }
  cout<<cnt<<endl;

  return 0;
}


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

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

	int mina = s.length();
	int maxz = 0;
	for(int i=0;i<(int)s.length();i++){
		if(s[i]=='a' || s[i]=='A') mina = min(mina,i);
		if(s[i]=='z' || s[i]=='Z') maxz = max(maxz,i);
	}


	cout<<(maxz-mina)+1;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int pm = 1000002;
		boolean[] prime = new boolean[pm+100];
		int[] s = new int[pm+100];
		for(int i=2;i<=pm;i++) prime[i] = true;
		for(int i=2;i<=pm+1;i++){
			s[i] = s[i-1];
			if(prime[i]){
				s[i]++;
				for(int j=i+i;j<=pm;j+=i){
					prime[j]=false;
				}
			}
		}
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int sum = 0;
			for(int i=0;i<n;i++){
				int p = sc.nextInt();
				int m = sc.nextInt();
				int x = 0;
				int max = Math.min(p+m, pm);
				int min = Math.max(p-m, 1);
				x = s[max]-s[min-1];
				if(x==0) sum--;
				else sum+=x-1;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 33116
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

using namespace std;
int main(){
	vector<int>Term(4);
	int num;
	cin >> num;
	rep(i, 4) {
		Term[3-i] = num % 10;
		num /= 10;
	}
	string ans = to_string(Term[0]);
	for (int tmp = 0; tmp < (1 << 3); tmp++) {	//演算子が入りうるすべての場所をbitで表現
		bitset<3>bit(tmp);	//取りうる最大のbit数　<>内は定数不可
		num = Term[0];
		rep(i, 3) {
			if (bit.test(2-i)) {
				num += Term[i+1] * (-1);
			}
			else {
				num += Term[i+1];
			}
		}
		if (num == 7) {
			rep(i, 3) {
				if (bit.test(2 - i)) {
					ans += "-" + to_string(Term[i+1]);
				}
				else {
					ans += "+" + to_string(Term[i+1]);
				}
			}
			break;
		}
	}
	cout << ans << "=7" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i,n) {
    cin >> a[i];
    a[i] -= (i+1);
    b[i] = a[i];
  }
  sort(all(b));
  ll ans = 0;
  ll x = b[n/2];
  rep(i,n) {
    ans += llabs(a[i] - x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3456
_,A,B=$<.map{|s|s.split.map &:to_i}
v=[]
w=0
c=A.zip(B).count{|a,b|a<b ? w+=b-a:!(v<<b-a)}+v.sort.count{|d|d<w+=d}
p w>0 ? -1:c

Measured memory_bytes: 21700
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e5 + 5;
const long long MNN = 2e3 + 200;
const long long MOD = 10;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n;
llong b[MXN], mx, cnt[65], ans;
llong sum;

llong maxXor(llong n){
    for (long long q = 60; q >= 0; --q) {
        for(llong j = 1; j <= n; j++) {
            if(((1LL << q) & b[j])) {
                int ok = 1;
                for (long long t = q + 1; t <= 60; ++t) {
                    if (((1LL << t) & b[j]) != 0) {
                        ok = 0;
                        break;
                    }
                }
                if (ok == 0) continue;
                for (int t = 1; t <= n; ++t) {
                    if (t == j) continue;
                    if ((1LL << q) & b[t]) {
                        b[t] ^= b[j];
                    }
                }
                break;
            }
        }
    }
    llong res = 0;
    for (llong i = 1; i <= n; i++) {
        //cout << b[i] << ' ';
        res ^= b[i];
    }
    //cout << nl;
    return res;
}

int main(){
    ios;
    cin >> n;
    for(llong i = 1; i <= n; i++){
        cin >> b[i];
        for(llong j = 61; j >= 0; j--){
            if((b[i] >> j) & 1){
                cnt[j]++;
            }
        }
    }
    for(llong i = 0; i <= 61; i++){
        if(cnt[i] % 2 == 1){
            ans += (1LL << i);
            for(llong j = 1; j <= n; j++) {
                if((b[j] >> i) & 1){
                    b[j] ^= (1LL << i);
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        //cout << b[i] << ' ';
        sum ^= b[i];
    }
    //cout << nl;
    llong mx = maxXor(n);
    cout << (sum ^ mx) + mx + ans;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

int main()
{
    int k, s;
    cin >> k >> s;

    ll ans = 0;
    rep(x, k + 1) {
        rep(y, k + 1) {
            int z = s - x - y;
            if (0 <= z && z <= k)
                ans++;
        }
    }
        
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector<int> a;
  for(int i=0;i<n;i++){
    int ai;
    cin >> ai;
    a.push_back(ai);
  }
  sort(a.begin(),a.end());
  bool yn = false;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      yn = true;
    }
  }
  if(yn==true){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<string.h>
int main()
  {
  char s[10003];
  int len,i,flag=0;
  scanf("%s",s);
  len=strlen(s);
  for(i=0;i<len-1;i++){
    if(s[i]==s[i+1]){flag=1;break;}
    }
  if(flag==1)printf("Bad\n");
  else printf("Good\n");
  return 0;
  }

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, d;
    cin >> n >> d;
    vector<VI> x(n, VI(d));
    FOR(i, 0, n)FOR(j, 0, d)cin >> x[i][j];

    int ans = 0;
    FOR(i, 0, n)FOR(j, i + 1, n) {
        int a = 0;
        FOR(k, 0, d)a += pow(x[i][k] - x[j][k], 2);
        if (pow((int)sqrt(a), 2) == a)ans++;
    }
    cout << ans << "\n";
}

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

int main()
{
  string s,t;
  ll a,b;
  string u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s==u) a--;
  else b--;
  cout << a << " " << b;
  return 0;
}

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

int insertionSort(int A[],int N){
    int v ,j ;

    for(int i = 1; i < N ; i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;


        for(int i = 0; i < N ; i++){
               if( i == N - 1){
                   cout << A[i] << endl;
               }
               else{
                   cout << A[i] << " ";
               }
        }
      
    }

    return 0;
}

int main(){
    int a, X[1000];
    cin >> a;
    for(int i = 0; i < a; i++)cin >> X[i];
    for(int i = 0; i < a - 1 ; i++){
           cout << X[i] << " ";
        } 
    cout << X[a - 1] << endl;
    insertionSort(X,a);


    return 0;
}


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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
char arr[mxn];
int n, m, k, q;
string s, t;
int ans = 0;
vector<string> grid;

void get(int curr, int num, vector<int> v, vector<vector<int>> &subsets) {
    if (curr == num) {
        subsets.pb(v);
        return;
    }
    get(curr + 1, num, v, subsets);
    v.pb(curr);
    get(curr + 1, num, v, subsets);
}

void solve(){
    int ans = 0;
    grid.resize(6);
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> grid[i];
    }
    vector<vector<int>> rows;
    get(0, n, vector<int> (0), rows);
    vector<vector<int>> cols;
    get(0, m, vector<int> (0), cols);
    for (int i = 0; i < rows.size(); i++) {
        for (int j = 0; j < cols.size(); j++) {
            vector<string> tmp = grid;
            for (int x : rows[i]) {
                for (int k = 0; k < m; k++) {
                    tmp[x][k] = '.';
                }
            }
            for (int x : cols[j]) {
                for (int k = 0; k < n; k++) {
                    tmp[k][x] = '.';
                }
            }
            int cnt = 0;
            for (string ss : tmp) {
                for (char c : ss) cnt += (c == '#');
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3684
//********rev 2;
#include <iostream>
#include <list>
#include <cctype>

using namespace std;

// data class
class D {
public:
	int n;
	int sets;

	list<D*> child;

	D() :child() {
		n = 0;
		sets = 0;
	};
};

// global var for input
char c[10002];

// get inputs
int get(D *d, int &l) {
	int sum = 0;
	if (c[l] == '[') { // if has datasets
		// loop for all sets
		list<int> ilist;
		while (c[l] == '[') {
			D *dd = new D();
			++l; // INFO: skip '['
			// INFO: rec.
			ilist.push_back(get(dd, l));
			// add to childlen
			d->child.push_back(dd);
			// inc. sets
			d->sets++;
			l++; // INFO: skip ']'
		}
		ilist.sort([](int &i1, int &i2){return i1 < i2;});
		auto iter = ilist.begin();
		for (int i = 0; i < d->sets / 2 + 1; i++) {
			sum += *iter;
			iter++;
		}
		d->n = sum;
		return sum;
	} else { // if has NO datasets (== only num)
		// char[] to num
		int num = c[l] - '0';
		for (l++; isdigit(c[l]); l++) {
			num = num * 10 + (c[l] - '0');
		}
		d->n = num / 2 + 1;
		return d->n;
	}
}

// solve from data
int ans(D *d) {
	if (d->sets == 0) { //if has NO datasets
		return d->n / 2 + 1; // min points for win
	}
	// else
	
	// function: conversion d with n
	auto func = [](D *d1, D *d2){return d1->n < d2->n;};
	// sort
	d->child.sort(func);
	// get lowlevel answer list
	// lowlevel ans list
	list <int> ilist;
	// iterator
	auto it = d->child.begin();
	for (int i = 0; i < d->sets; i++) {
		D *cur = *it;
		ilist.push_back(ans(cur));
		it++;
	}
	// sort for min
	ilist.sort([](int &i1, int &i2){return i1 < i2;});

	//get sum (== minpoints for win in thislevel)
	int sum = 0;
	auto iit = ilist.begin();
	for (int i = 0; i < d->sets / 2 + 1; i++) {
		sum += *iit;
		iit++;
	}
	return sum;
}

// solve
void solve() {
	int n;
	// input dataset length
	cin >> n;
	for (int i = 0; i < n; i++) {
		// input dataset
		cin >> c;
		D *d = new D();
		// INFO: 1: skip first '['
		int l = 1;
		// string to dataobj;
		get(d, l);
		// get answer
		//cout << ans(d) << endl;
		cout << d->n << endl;
		delete d;
	}
}



//----main----
int main(void) {
	solve();
}

Measured memory_bytes: 3252
import sys
import pdb
input = sys.stdin.readline

N, W = map(int, input().split())
ws = []
vs = []
for _ in range(N):
  w, v = map(int, input().split())
  ws.append(w)
  vs.append(v)

inf = 1e10

# Value[i番目までの品番][重さj以下]
Value = [[-inf for _ in range(W+1)] for __ in range(N)]

for load in range(W+1):
  if load < ws[0]:
    # 1番目の品物を入れようがなければスキップ
    Value[0][load] = 0
  else:
    Value[0][load] = vs[0]

for num in range(1, N):
  for load in range(W+1):
    if load >= ws[num]:
      # pdb.set_trace()
      # print(num, load, ws[num], vs[num])
      Value[num][load] = max(Value[num][load], Value[num-1][load], Value[num-1][load-ws[num]] + vs[num])
    else:
      Value[num][load] = max(Value[num][load], Value[num-1][load])

print(Value[N-1][W])


Measured memory_bytes: 286824
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, A ,B;
    cin >> N >> A >> B;

    int count_a = 0;
    int count_b = 0;
    int count_c = 0;

    for (int i = 0; i < N; i++){
        int P;
        cin >> P;
        if(P <= A){
            count_a++;
        }
        else if(A + 1 <= P && P <= B){
            count_b++;
        }
        else {
            count_c++;
        }
    }

    cout << min(count_a, min(count_b, count_c)) << endl;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};



int main(){
    LL N, K;
    cin >> N >> K;
    VI A(N);
    VI cnt(N, -1);
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }
    cnt[0] = 0;
    int now = 0;
    int restart = -1;
    int x = -1;
    while(true) {
        if(cnt[now] == K) {
            cout << now+1 << endl;
            return 0;
        }

        int next = A[now];
        if(cnt[next] == -1) {
            cnt[next] = cnt[now] + 1;
            now = next;
            continue;
        }

        K -= cnt[now] + 1;
        restart = next;
        x = cnt[now] + 1 - cnt[next];
        now = next;
        break;
    }

    LL mv = K % x;
    REP(i, mv) {
        now = A[now];        
    }

    cout << now+1 << endl;
    return 0;
}


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

int main() {
  //declare table(tab)
  int h, w;
  cin >> h >> w;
  vector<vector<char>> tab(h, vector<char>(w));
  //input
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++){
      cin >> tab.at(i).at(j);
    }
  }
  //mark rows which ISN'T filled with '.'
  vector<int> mark(0);
  for (int k = 0; k < h; k++){
    int count = 0;
    
    for (int l = 0; l < w; l++){
      if (tab.at(k).at(l) == '#'){
        count++;
      }
    }
    
    if (count != 0){
      mark.push_back(k);
    }
  }
  // do the same action with the row and the column switched
  vector<int> wark(0);
  for (int k = 0; k < w; k++){
    int count = 0;
    
    for (int l = 0; l < h; l++){
      if (tab.at(l).at(k) == '#'){
        count++;
      }
    }
    
    if (count != 0){
      wark.push_back(k);
    }
  }
  /***
  // for debug
  for (int m=0;m<mark.size();m++) cout<< mark.at(m);
  cout<< endl;
  for (int n=0;n<wark.size();n++) cout<< wark.at(n);
  cout<< endl;
  ***/
  // output the table
  //範囲for文は()内の変数に配列の中身が入ってしまうので今回のような場合は使えないことに注意
  for (int m = 0; m < mark.size(); m++){
    for (int n = 0; n < wark.size(); n++){
      cout << tab.at(mark.at(m)).at(wark.at(n));
    }
    cout << endl;
  }
}

Measured memory_bytes: 3516
n=55555
a=int(input())
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
b=[]
for i in primes:
    if i%5==3:
        b.append(i)

print(*b[:a])

Measured memory_bytes: 49516
#include<stdio.h>
#include<stdlib.h>
typedef struct pp{
  double k;
}P;
P *A;
void max(P *A,int j);
void build(P *A);
int n,i;
int main(){
  
  scanf("%d\n",&n);
  
  A=(P*)malloc((n*10)*sizeof(P));
  for(i=0;i<n*10;i++) A[i].k=3.14;
  for(i=1;i<=n;i++) scanf("%lf",&A[i].k);
  build(A);
  for(i=1;i<n;i++)printf(" %.0f",A[i].k);
  printf(" %.0f\n",A[n].k);

  return 0;
}
void max(P *A,int j){
  int left,right,largest;
  P swap;
 
  left=j*2;
  right=j*2+1;
  if(left<=n&&A[left].k>A[j].k) largest=left;
  else largest=j;
  if(right<=n&&A[right].k>A[largest].k) largest=right;
  if(A[j*2].k==3.14);
  else if(largest!=j){
    swap=A[j];
    A[j]=A[largest];
    A[largest]=swap;
    max(A,largest);
  }
}
void build(P *A){
  int j;
  for(j=n/2;j>=1;j--) max(A,j);
}



Measured memory_bytes: 40812