akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; ll k;
	cin >> s >> k;
	REP(i, s.size()) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
		if (i == k - 1) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << '1' << endl;
}

Measured memory_bytes: 256
string = input()
K = int(input())
from collections import defaultdict
if len(set(string)) ==1:
    print(K*len(string)//2)
else:
    if(string[0]==string[-1]):
        ## 両端が同じ文字なら…
        start = string[0]
        startFlag = True
        cnt = defaultdict(int)
        length = 0
        
        for char in string:
            #print(char,start,length)
            if char == start:
                length +=1
                
            else:
                if startFlag:
                    startlen = length
                    startFlag = False
                cnt[length] +=1
                start = char
                length = 1
        else:
            ## 両端をカウントしない
            cnt[startlen] -= 1
            cnt[startlen +length] += 1
        print(sum([(key//2)*value*K for key,value in cnt.items()])-(startlen+length)//2+startlen//2+length//2)
    else:
        ## 両端が同じ文字なら…
        start = string[0]
        cnt = defaultdict(int)
        length = 0
        for char in string:
            #print(char,start,length)
            if char == start:
                length +=1
                
            else:
                cnt[length] +=1
                start = char
                length = 1
        else:
            ## 両端をカウントしない
            cnt[length] += 1
        print(sum([(key//2)*value*K for key,value in cnt.items()]))
              

Measured memory_bytes: 38384
n=int(input())
a=[]
for i in range(2):
  a.append([])
for i in range(2):
  a[i]=list(map(int,input().split()))
dp=[[0]*n for i in range(2)]
dp[0][0]=a[0][0]

dp[1][0]=dp[0][0]+a[1][0]

for i in range(1,n):
  dp[0][i]=dp[0][i-1]+a[0][i]
for i in range(1,n):
  dp[1][i]=max(dp[0][i],dp[1][i-1])+a[1][i]

print(dp[1][n-1])

Measured memory_bytes: 9224
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   int n, q;
   cin >> n ;
   vector<int> v;
   for(int i = 0; i < n; i++){
	  int x;
	  cin >> x;
	  v.push_back(x);   
	}
  cin >> q;
  for(int i = 0; i < q; i++){
	  int start, end, idx;
	  cin >> start >> end >> idx;
		 for(int k = 0; k < (end - start); k++){
		  swap(v[start + k], v[idx + k]);  
		}  
	}
  for(int i = 0; i < n; i++){
	  if (i == n - 1) cout << v[i];
	  else cout << v[i] <<  " ";  
	}
  cout << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3140
# Python3 code to Maximize volume of 
# cuboid with given sum of sides 
  
# Return the maximum volume. 
def maxvolume( s ): 
  
    # finding length 
    length = s / 3 
      
    s -= length 
      
    # finding breadth 
    breadth = s / 2
      
    # finding height 
    height = s - breadth 
      
    return length * breadth * height
s = int(input())
print( maxvolume(s) ) 

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=105;
ll ans=9e18;
int mx[N],d,dep[N],son[N],s[N],t[N];
vector<int> v[N];
int dfs(int p,int fa){
	son[p]=0;
	int ans=dep[p];
	for(auto i:v[p])if(i!=fa){
		dep[i]=dep[p]+1; son[p]++;
		ans=max(ans,dfs(i,p));
	}
	return ans;
}
int main(){
	int n=read();
	For(i,1,n-1){
		s[i]=read(); t[i]=read();
		v[s[i]].pb(t[i]); v[t[i]].pb(s[i]);
	}
	For(i,1,n){dep[i]=0;d=max(d,dfs(i,0));}
	For(i,1,n-1){
		dep[s[i]]=dep[t[i]]=0;
		if(dfs(s[i],t[i])<=d/2&&dfs(t[i],s[i])<=d/2){
			memset(mx,0,sizeof(mx));
			For(i,1,n)mx[dep[i]]=max(mx[dep[i]],son[i]);
			ll jb=2;
			For(i,0,d/2-1)jb=jb*mx[i];
			ans=min(ans,jb);
		}
	}
	if(d%2==0){
		For(i,1,n){
			dep[i]=0;
			if(dfs(i,0)==d/2){
				memset(mx,0,sizeof(mx));
				For(i,1,n)mx[dep[i]]=max(mx[dep[i]],son[i]);
				ll jb=1;
				For(i,0,d/2-1)jb=jb*mx[i];
				ans=min(ans,jb);
			}
		}
	}
	cout<<d/2+1<<" "<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   string S;
   cin >> S;
   if(S=="ABC"){
   	cout << "ARC" << endl;
   }else{
    cout << "ABC" << endl;
   }
   
}

Measured memory_bytes: 3548
N,M = list(map(int,input().split()))
AB = []
for i in range(N):
  ab = tuple(map(int,input().split()))
  AB.append(ab)
AB.sort()
res = 0
drnk = 0
for i in AB:
  if drnk + i[1] >= M:
    res = res + i[0]*(M-drnk)
    break
  else:
    drnk = drnk + i[1]
    res = res + i[0]*i[1]
print(res)

Measured memory_bytes: 16988
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int m, d;
    cin >> m >> d;

    int ans = 0;
    for (int i = 4; i <= m; i++) {
        for (int j = 2; j < 10; j++) {
            for (int k = 2; k < 10; k++) {
                if (j * 10 + k <= d) {
                    if (i == j * k) {
                        ans++;
                    }
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
inline void solve()
{
	double n;cin>>n;
	n/=3;
	printf("%.6lf\n",n*n*n);
}
int main()
{
	solve();
	return 0;
}




Measured memory_bytes: 888
#include <stdio.h>

void swap (int *, int *);

int main (void) {
    int faces[6];
    int ch;

    for (int i=0; i<6; i++) {
        scanf ("%d", faces+i);
    }

    for (;(ch = getchar())!=EOF;) {
        if (ch=='N') {
            swap (faces, faces+1);
            swap (faces+1, faces+5);
            swap (faces+5, faces+4);
        } else if (ch=='E') {
            swap (faces, faces+3);
            swap (faces+3, faces+5);
            swap (faces+5, faces+2);
        } else if (ch=='W') {
            swap (faces, faces+2);
            swap (faces+2, faces+5);
            swap (faces+5, faces+3);
        } else if (ch=='S') {
            swap (faces, faces+4);
            swap (faces+4, faces+5);
            swap (faces+5, faces+1);
        }
    }

    printf ("%d\n", faces[0]);

    return 0;
}

void swap (int *p, int *q) {
    int tmp;
    tmp = *p;
    *p = *q;
    *q = tmp;
}



Measured memory_bytes: 2108
#include<stdio.h>
int main() {

	long long int n;
	long long int a[100];
	long long int i;
	long long int j = 0;
	long long int money = 1000;
	scanf("%lld",&n);
	for (i = 0;i < n;i++)
	{
		scanf("%lld", &a[i]);
	}
	
	for (i = 0;i < n;i++)
	{
		if (i == n - 1)
		{
			money += j * a[i];
			j = 0;
		}
		else if (j == 0) {
			if (a[i] >= a[i + 1])
				continue;
			else
			{
				j = money / a[i];
				money %= a[i];
			}
		}
		else
		{
			if (a[i] <= a[i + 1])
			{
				continue;
			}
			else
			{
				money += j * a[i];
				j = 0;
			}
		}

	}
	printf("%lld", money);



	return 0;
}

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

int main()
{
  int64_t N, K, ans = 0;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  queue<int64_t> Q, S, R; // S: selected, R: removed
  for (int64_t i = 0; i < N; i++)
  {
    int64_t s = 0;
    for (int64_t j = i; j < N; j++)
    {
      s += A.at(j);
      Q.push(s);
    }
  }
  for (int64_t i = 60; i >= 0; i--)
  {
    int64_t n = Q.size();
    while (Q.size())
    {
      if (Q.front() & (1LL << i))
      {
        S.push(Q.front());
      }
      else
      {
        R.push(Q.front());
      }
      Q.pop();
    }
    if (S.size() < K)
    {
      while (R.size())
      {
        Q.push(R.front());
        R.pop();
      }
      while (S.size())
      {
        Q.push(S.front());
        S.pop();
      }
    }
    else
    {
      ans |= (1LL << i);
      while (R.size())
      {
        R.pop();
      }
      while (S.size())
      {
        Q.push(S.front());
        S.pop();
      }
    }
  }
  cout << ans << endl;
}

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

#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'

using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;


const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 312345;
const double pi = 3.14159265359;
const double eps = 0.000000001;
int v[500];
int main() {
    int n, K;
    scanf("%d %d", &n, &K);
    for (int i = 0; i<n; ++i) {
        scanf("%d", v+i);
        v[i+n] = v[i];
    }
    
    set<ii> s;
    int sum, ret, ans = 0;
    for (int k = K, ld, d = 0; k>0; --k, ++d) {
        sum = 0, ret = 0;
        s.clear();
        for (int i = max(n-k, 0); i<n && i < 2*n; ++i) {
            sum += v[i];
            s.emplace(v[i], i);
        }
        ld = 0;
        for (auto it = s.begin(); it != s.end() && ld < d; ++ld, ++it) {
            if (it->first < 0) {
                //printf("%d\n",it->first);
                ret += it->first;
            }
        }
        ans = max(ans,sum-ret);
        //printf("from: %d %d %d\n", max(n-k, 0), n-1, sum -ret);
        for (int i = max(n-k, 0)+1, j = n; i <= n && j < 2*n; ++j, ++i) {
            sum += v[j] - v[i-1]; 
            ret = 0;
            s.erase({v[i-1], i-1});
            s.emplace(v[j], j);
            ld = 0;
            for (auto it = s.begin(); it != s.end() && ld < d; ++ld, ++it) {
                if (it->first < 0) {
                    //printf("%d\n",it->first);
                    ret += it->first;
                }
            }
            //printf("%d %d %d\n",i,j  , sum-ret);
            ans = max(ans, sum - ret);
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int h,w,d;cin>>h>>w>>d;
    vector<vector<int>> a(h,vector<int>(w));
    map<int,pair<int,int>> mp;
    rep(i,h)rep(j,w){
        int a;
        cin>>a;a--;
        mp[a]={i,j};
    }
    vector<int> D(90003,0);
    rep(i,d){
       int tmp=0;
       int y=mp[i].first,x=mp[i].second;
       //cout<<y<<" "<<x<<endl;
       for(int j=1;d*j+i<h*w;j++){
           int ny=mp[j*d+i].first,nx=mp[j*d+i].second;
           tmp+=abs(ny-y)+abs(nx-x);
           //cout<<d*j+i<<" "<<ny<<" "<<nx<<endl;
           D[j*d+i]=tmp;
           y=ny;x=nx;
       }
    }
    //rep(i,h*w)cout<<D[i]<<endl;
    int q;cin>>q;
    rep(i,q){
        int l,r;cin>>l>>r;l--;r--;
        int res=D[r]-D[l];
        cout<<res<<endl;
    }
}


Measured memory_bytes: 7424
<?php

while (($line = trim(fgets(STDIN)))) {
    sscanf($line, '%d %s %d', $a, $op, $b);

    switch ($op) {
        case '+':
            $result = $a + $b;
            break;
        case '-':
            $result = $a - $b;
            break;
        case '*':
            $result = $a * $b;
            break;
        case '/':
            $result = $a / $b;
            break;
        default:
            break 2;
    }

    echo (int)$result, PHP_EOL;
}

Measured memory_bytes: 6572
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    int min=Integer.MAX_VALUE;
	    for(int i=1; i<=Math.floorDiv(n,2)+1;i++) {
	    	int a=i;
	    	int b=n-i;
	    	int ac=0;
	    	int bc=0;
	    	while(a>0) {
	    		int q=a%10;
	    		ac+=q;
	    		a=(a-q)/10;
	    	}
	    	while(b>0) {
	    		int q=b%10;
	    		bc+=q;
	    		b=(b-q)/10;
	    	}
	    	if(min>ac+bc) {
	    		min=ac+bc;
	    	}
	    	
	    }
	   
//	    if (s>x) {
//	    	System.out.println(n-1);
//	    } else {
//	    	Arrays.parallelSort(a);
//
//	    	System.out.println(c);
//	    }
	    System.out.println(min);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    string s,t;
    cin>>s>>t;
    
    int n=t.size();
    int m=s.size();
    
    int ans = INT_MAX;
    
    for (int i=0;i< (m-n+1);i++)
    {
        int min_char=0;
        
        for (int j=0;j<n;j++)
        {
            if (s[i+j] != t[j])
            min_char++;
        }
        ans = min(min_char,ans);
    }
    cout<<ans<<endl;
    
    return 0;
    
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}

int main(){
    int n; scanf("%d",&n);
    vector<ll> a(n);
    for(auto &v:a) scanf("%lld",&v);
    map<ll,int> ck;
    for(int i=0;i<n;i++){
        if(ck[a[i]-i]) ck[a[i]-i]++;
        else ck[a[i]-i]=1;
    }
    ll cnt=0;
    for(int i=0;i<n;i++) if(ck[-a[i]-i]) cnt+=ck[-a[i]-i];
    printf("%lld\n",cnt);
}

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

int main(){
  int N, res; cin >> N;
  vector<int> h(110);
  int cnt = 0;
  for (int i = 0; i < N; i++){
    cin >> res;
    h[res] = !h[res];
  }
  for (int i = 0; i < 110; i++){
    if (h[i]) cnt = i - cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 100010
int n;
int total;
vector<int> G[MX];
int colr[MX];
void DFS(int x,int pre,int c,int &tot)
{
    if (colr[x]==-c) return;
    tot++;
    for (int i=0;i<G[x].size();i++)
        if (G[x][i]!=pre)
            DFS(G[x][i],x,c,tot);
}
 
 void dfs(int u,int pre,int s,int &ok)
 {
     if (u==n)
     {
         ok=s;
         return;
     }
     for (int i=0;i<G[u].size();i++)
    {
        if (ok) break;
        if (G[u][i]!=pre)
            dfs(G[u][i],u,s+1,ok);
    }
    if (ok)
    {
        if (u!=1&&s<=ok/2) colr[u]=1;
        if (u!=n&&s>ok/2) colr[u]=-1;
    }
    return;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    colr[1]=1; 
    colr[n]=-1;
    int ok=0;
    dfs(1,-10,0,ok);
    int num_1=0;
    DFS(1,-10,1,num_1);
    int num_2=0;
    DFS(n,-10,-1,num_2);
    if (num_1-num_2>=1)
        cout<<"Fennec";
    else
        cout<<"Snuke";
    return 0;
 }

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

using namespace std;

int main() {

    int a, b, c;
    scanf("%d%d%d", &a,&b,&c);

    printf("%d\n", max(max(a*10+b+c, b*10+c+a), c*10+b+a));


	return 0;

}

Measured memory_bytes: 256
c = []

3.times do
  row = gets.chomp.split.map(&:to_i)
  c << row
end

a = [0]
b = []

b << c[0][0]
b << c[0][1]
b << c[0][2]

a << c[1][0] - b[0]
a << c[2][0] - b[0]


[1,2].each do |i|
  [1, 2].each do |j|
    unless c[i][j] == a[i] + b[j]
      puts 'No'
      exit
    end
  end
end


puts 'Yes'

Measured memory_bytes: 3836
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

// GCC __gcd(long long A, long long B)

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

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

int main() {
  int N, A[SIZE];
  int L[SIZE], R[SIZE];

  cin >> N;

  for (int i = 0; i < N; i++) cin >> A[i];

  L[1] = A[0];
  for (int i = 1; i < N; i++) {
    L[i + 1] = gcd(L[i], A[i]);
  }

  R[N - 2] = A[N - 1];
  for (int i = N - 2; i > 0; i--) {
    R[i - 1] = gcd(R[i], A[i]);
  }

  int ans = max(R[0], L[N - 1]);

  for (int i = 0; i < N; i++) {
    ans = max(ans, (int)gcd(L[i], R[i]));
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    int n,m;
    char x;
    cin>>n;
    int S[13],H[13],C[13],D[13];
    for (int j = 0; j < 13; ++j) {
        S[j]=0;H[j]=0;C[j]=0;D[j]=0;
    }
    for (int i = 0; i < n; ++i) {
        cin>>x>>m;
        switch (x)
        {
            case 'S':
                S[m-1]=1;
                break;
            case 'H':
                H[m-1]=1;
                break;
            case 'C':
                C[m-1]=1;
                break;
            case 'D':
                D[m-1]=1;
                break;
            default:break;
        }
    }
    for (int k = 0; k < 13; ++k) {
        if (S[k]==0)
        {
            cout<<"S "<<k+1<<endl;
        }
    }
    for (int k = 0; k < 13; ++k) {
        if (H[k]==0)
        {
            cout<<"H "<<k+1<<endl;
        }
    }
    for (int k = 0; k < 13; ++k) {
        if (C[k]==0)
        {
            cout<<"C "<<k+1<<endl;
        }
    }
    for (int k = 0; k < 13; ++k) {
        if (D[k]==0)
        {
            cout<<"D "<<k+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;

int main(){
    int h,w;cin>>h>>w;
    char c[h][w];
    char ans[2*h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<2*h;i++){
        for(int j=0;j<w;j++){
            int h=i/2;
            ans[i][j]=c[h][j];
        }
    }
    for(int i=0;i<2*h;i++){
        for(int j=0;j<w;j++){
            cout<<ans[i][j];
        }
        cout<<endl;
    }        
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.se!=b.se)
        return a.se<b.se;
    else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------    
    //ll T;cin>>T;
    //while(T--){

    //}
    string s;cin>>s;
    for(ll i=0;i<s.lg-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<Endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------
















































Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1e8;
const double EPS = 1e-8;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<int> x(n),r(n);
        rep(i,n) scanf(" %d %d", &x[i], &r[i]);

        auto check = [&](double a){
            double s = INF, e = -INF;
            rep(i,n){
                if(2*r[i]+EPS < a) continue;
                double theta = asin(a/r[i]/2);
                double dx = r[i]*cos(theta);

                double L = x[i]-dx, R=x[i]+dx;
                // printf(" %d:  %f %f\n",i,L,R);

                if(max(s,L) > min(e,R)){
                    s = L;
                    e = R;
                }
                else{
                    s = min(s,L);
                    e = max(e,R);
                }

                if(e-s>a) return true;
            }
            return false;
        };

        double ok=0, ng=200000;
        rep(loop,80){
            double mid = (ok+ng)/2;
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        printf("%.10f\n", ok);
    }
    return 0;
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n;
vi a;
ll dp[5][222222];

ll solve(int st, int p)
{
	if (dp[st][p] >= 0) return dp[st][p];
	if (p == n) return 0;
	ll res = 1e9;
	if (st == 0)
	{
		chmin(res, solve(0, p + 1) + a[p]);
	}
	if (st <= 1)
	{
		if(a[p] == 0) chmin(res, solve(1, p + 1) + 2);
		else chmin(res, solve(1, p + 1) + a[p] % 2);
	}
	if (st <= 2)
	{
		if (a[p] == 0) chmin(res, solve(2, p + 1) + 1);
		chmin(res, solve(2, p + 1) + (1 - a[p] % 2));
	}
	if (st <= 3)
	{
		if(a[p] == 0) chmin(res, solve(3, p + 1) + 2);
		else chmin(res, solve(3, p + 1) + a[p] % 2);
	}
	if (st <= 4)
	{
		chmin(res, solve(4, p + 1) + a[p]);
	}
	return dp[st][p] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	MS(dp, -1);
	cin >> n;
	a.resize(n); cin >> a;
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 23040
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N = 0;
    cin >> N;
    int i=0;
    int k=0;
    int X[20];
    int Y[20];
    long ans = 0;
    int tmp = 0;
    int p = 0;
    for(i=0;i<20;i++) Y[i]=N;
    for(i=0;i<N;i++){
        cin >>tmp;
        for(k = 0;k<20;k++){
            if(tmp>0) {
                if (tmp % 2 == 1) {
                    X[k] = 1;
                } else {
                    X[k] = 0;
                }
                tmp /= 2;
            }else{
                X[k]=0;
            }
        }
        for(k=0;k<20;k++){
            if(X[k]==1){
                if(Y[k]==N){
                    Y[k]=i;
                }else{
                   if(Y[k]+1>p) {p=Y[k]+1;}
                   Y[k]=i;
                }
            }
        }
        for(k=0;k<20;k++){
            if(Y[k]<p){Y[k]=N;}
        }
        ans += i-p+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<string>
using namespace std;
int main() {
  int N,D,X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  
  int sum = 0;
  for (int i=0; i<N; i++) {
    int j=1;
    int cnt = 0;
    bool flag = 1;
    while(flag) {
      if (A[i]*j+1<=D) {
        cnt++;
        j++;
      }
      else flag = 0;
    }
    sum += cnt;
  }
  int ans = sum+N+X;
  cout << ans << endl;
}

Measured memory_bytes: 256
s = int(input())

h = str(int((s - s % 3600 ) / 3600 ))
m = str(int((s% 3600 - (s % 3600)  % 60) /60 ))
s = str(int((s % 3600)  % 60 ))
print ( h + ":" + m + ":" + s)

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



signed main(){
   string p="AKIHABARA";
   string s;
   cin>>s;
   int i=0,j=0,ans=1;
   while(i<9&&j<s.size()){
       if(p[i]==s[j]){
           i++;j++;
       }else{
           if(p[i]=='A')i++;
           else {
               ans=0;
               break;
           }
       }
   }
   if(j!=s.size()||(i!=9&&i!=8))cout<<"NO";
   else cout<<"YES";



    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 200

int top;
int S[MAX];

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(int);
void keisan(char);

int main( ){

  int i,n=0;
  char handan;

  initialize();

  
  for(i=0;i<MAX*2;i++){
    
    scanf("%c",&handan);
    //printf("i = %d\n", i);
    /*if(handan>=48&&handan<=57&&n!=0){
      n=n*10+atoi(&handan);
      printf("wa-i\n");
      printf("%d\n",n);
      }*/
      
    if(handan=='\n')break;
    else if(handan==' '){
      if(n!=0)push(n);
      n=0;
      continue;}

    //printf("wa-i2\n");
    
    else if(handan=='+'||handan=='-'||handan=='*'||handan=='/'){
      keisan(handan);
      // printf("wa-i2\n");
    }
    else{
      if(handan>=48&&handan<=57){
	n=n*10+atoi(&handan);
	//printf("%d\n",n);
      }
      // printf("%d\n",n);
      // printf("wa-i\n");
    }
      
  }

  printf("%d\n",S[top]);
  
  return 0;
}

void initialize(){
  top=0;
}

int isEmpty(){
  if(top ==0)return 1;
  else return 0;
}

int isFull(){
  if(top>=MAX - 1)return 1;
  else return 0;
}

void push(int x){
  if(isFull() ==1) exit(1);
  
    top++;
    S[top]=x;
    // printf("\n%d\n",S[top]);

}
int pop(int x){

  
  if( isEmpty()==1 ) exit(2);

  top--;
  return S[top+1];
}

void keisan(char hugou){
  
  int n1,n2,n;
  
  n1=pop(S[top]);
  n2=pop(S[top]);

  // printf("%d %d\n",n1,n2);
  
  //printf("wa-i3");

  switch(hugou){

  case '+':
    //printf("wa-i4");
    n=n2+n1;
    //printf("add %d\n",n);
    break;

  case '-':
    n=n2-n1;
    break;

  case '*':
    n=n2*n1;
    break;

  case '/':
    n=n2/n1;
    break;

  }
  
  push(n);
  
}

  

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
/*
如果数组是从小到大排序
那么lower_bound(b+1,b+n+1,a[i])-b : 输出b数组中第一个>=a[i]的值的下标
那么upper_bound(b+1,b+n+1,a[i])-b : 输出b数组中第一个>a[i]的值的下标

如果数组是从大到小排序
那么lower_bound(b+1,b+n+1,a[i],greater <int>())-b : 输出b数组中第一个<=a[i]的值的下标
那么upper_bound(b+1,b+n+1,a[i],greater <int>())-b : 输出b数组中第一个<a[i]的值的下标

*/

bool cmp(const int x,const int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    int maxx=-1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        maxx=max(maxx,a[i]);
    }
    sort(a+1,a+n+1,cmp);

    int sum=0;
    for(int i=1;i<=maxx;i++)
    {
        int k=upper_bound(a+1,a+n+1,i,greater <int>())-a;
        //cout<<i<<" "<<n-k+1<<endl;
        if(k-1==n-k+1)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 640
N, M, X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

def main():
    list = [0] * (N + 1)
    for _ in range(M):
        a = A.pop()
        list[a] = 1
    left = list[:X + 1]
    right = list[X:]
    ans = min(sum(left), sum(right))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, d, x;
	cin >> n >> d >> x;
	while (n--)
	{
		int a;
		cin >> a;
		x += (d - 1) / a + 1;
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define M 1010
#define mmp make_pair
#define ll long long
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
int n, m, note[M][M];
char s[M];
queue<pair<int, int> >q;
const int xn[4] = {0, 0, 1, -1}, yn[4] = {1, -1, 0, 0};
int main() {
	n = read(), m = read();
	for(int i = 1; i <= n; i++) {
		scanf("%s", s + 1);
		for(int j = 1; j <= m; j++) {
			if(s[j] == '#') q.push(mmp(i, j)), note[i][j] = 1;
		}
	}
	int ans = 0;
	while(!q.empty()) {
		int nowi = q.front().first, nowj = q.front().second;
		q.pop();
		ans = max(note[nowi][nowj] - 1, ans);
		for(int i = 0; i < 4; i++) {
			int nx = nowi + xn[i], ny = nowj + yn[i];
			if(nx < 1 || ny < 1 || nx > n || ny > m || note[nx][ny]) continue;
			note[nx][ny] = note[nowi][nowj] + 1;
			q.push(mmp(nx, ny));
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 12432
from collections import deque

N = int(input())

G = [[] for _ in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  
pars = [-1] * N
pars[0] = 0
stack = deque([0])
visited = [False] * N
visited[0] = True

while stack:
  now = stack.pop()
  for nxt in G[now]:
    if visited[nxt]:
      continue
    visited[nxt] = True
    pars[nxt] = now
    stack.append(nxt)

now = N-1
roads = []
while now != 0:
  now = pars[now]
  roads.append(now)

roads.reverse()
roads.append(N-1)
stack = deque([])
for i in range((len(roads)+1)//2):
  stack.append(roads[i])

stop = roads[(len(roads)+1)//2]
visited = [False] * N
for i in roads:
  visited[i] = True

black = (len(roads)+1)//2

while stack:
  now = stack.pop()
  for nxt in G[now]:
    if visited[nxt] or (nxt==stop):
      continue
    visited[nxt] = True
    stack.append(nxt)
    black += 1

white = N - black
if black > white:
  print('Fennec')
else:
  print('Snuke')
  



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a; cin>>a;
  cout<<(3*a*a)<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,count=0; cin >> N;
  vector<int> A(N);
  for(int i=1; i<=N; i++) {
    cin >> A[i];
    if(A[i]%2!=0) count++;
  }
  if(count%2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3736
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ijt func(vector<ijt> a, ijt mid) {
	ijt n = a.size();
	ijt cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] > mid) {
			cnt += (a[i] - mid + n) / (n + 1);
		}
	}
	return cnt;
}
int main(void) {
	ijt n; cin >> n;
	vector<ijt> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(all(a)); reverse(all(a));
	ijt ub = a[0] + 1, lb = -(1ll << 59);
	while (ub - lb > 1) {
		
		ijt mid = (ub + lb) / 2;
		//cout << mid << " " << n - 1 - func(a, mid) << endl;
		if (mid <= n - 1 - func(a,mid)) {
			lb = mid;
		}
		else {
			ub = mid;
		}
	}
	cout << endl;
	//cout << ub << " " << 2 * n << endl;
	for (ijt i = ub + 2000; i >= ub - 2000; i--) {
		//cout << i << " " << n - 1 - func(a, i) << endl;
		if (i <= n - 1 - func(a, i)) {
			cout << func(a,i) << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;


fn main() {
    let (n, x) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut an = read::<usize>();
    let mut ans: usize = 0;

    for a in an.iter_mut() {
        if *a > x { ans += *a - x; }
        *a = cmp::min(*a, x);
    }

    for i in 0..n - 1 {
        let total: usize = an[i] + an[i + 1];
        if total > x {
            an[i + 1] = x - an[i];
            ans += total - x;
        }
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

const int N = 1e5;
vector<int> g[N];
int n;

int dfs(int i) {
  if(g[i].size() == 0) return 0;
  vector<int> v;
  for(int j : g[i]) {
    v.emplace_back(dfs(j));
  }
  sort(begin(v), end(v));
  int ma = 0;
  for(int i = 0; i < v.size(); i++) ma = max(ma, (int) v.size() - i + v[i]);
  return ma;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for(int i = 1; i < n; i++) {
    int a; cin >> a;
    a--;
    g[a].emplace_back(i);
  }
  cout << dfs(0) << endl;
}


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

int main() {
	int n, m, k, ans;
	cin >> n >> m >> k;
	if (n >= m && n >= k) ans = m + k;
	else if (m >= n && m >= k) ans = n + k;
	else ans = n + m;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b" << endl;;
	if (a > b)
		cout << "a > b" << endl;;
	if (a == b)
		cout << "a == b" << endl;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	int m, n;
	
	int ans;
	
	vector<int> v;
	
	string str;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		cin >> m;
		cin >> str;
		
		int pre = -100;
		int len = 0;
		
		for(int i = 0; i < m - 2; i++){
			if(str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I'){
				if(pre == i - 2){
					len++;
				}else{
					v.push_back(len);
					len = 1;
				}
				pre = i;
			}
		}
		v.push_back(len);
		ans = 0;
		for(int i = 0; i < v.size(); i++){
			ans += max(v.at(i) - n + 1, 0);
		}
		v.erase(v.begin(), v.end());
		
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	int L = 0, R = n;
	rep(i,m){
		int l,r;cin >> l >> r;
		L = max(L, l);
		R = min(R, r);
	}
	cout << max(0, R - L + 1) << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int n,A[50];
int solve(int i,int m){
  int res;
  if(m==0) return 1;
  if(i>=n) return 0;
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}

int main(){
  int q,i,M;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner sc = new Scanner(System.in);
		    
		    int sx = sc.nextInt();
		    int sy = sc.nextInt();
		    int tx = sc.nextInt();
		    int ty = sc.nextInt();
		    
		    int yoko = tx -sx;
		    int tate = ty -sy;
		    
		    for(int i = 0; i<yoko; i++) {
		    	System.out.print("R");
		    }
		    for(int i = 0; i<tate; i++) {
		    	System.out.print("U");
		    }
		    for(int i = 0; i<yoko; i++) {
		    	System.out.print("L");
		    }
		    for(int i = 0; i<tate + 1; i++) {
		    	System.out.print("D");
		    }
		    for(int i = 0; i<yoko + 1; i++) {
		    	System.out.print("R");
		    }
		    for(int i = 0; i<tate + 1; i++) {
		    	System.out.print("U");
		    }
		    System.out.print("L");
		    System.out.print("U");
		    for(int i = 0; i<yoko + 1; i++) {
		    	System.out.print("L");
		    }
		    for(int i = 0; i<tate + 1; i++) {
		    	System.out.print("D");
		    }
		    System.out.print("R");
		    sc.close(); }
		  }

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

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

  char mas[100][101];

  for(int i = 0;i < 50;i++){
    for(int j = 0;j < 100;j++){
      mas[i][j] = '#';
    }
    mas[i][100] = '\0';
  }

  for(int i = 50;i < 100;i++){
    for(int j = 0;j < 100;j++){
      mas[i][j] = '.';
    }
    mas[i][100] = '\0';
  }

  a--;
  b--;

  for(int i = 0;i < 50;i+= 2){
    for(int j = 0;j < 100; j+= 2){
      if(a > 0){
        a--;
        mas[i][j] = '.';
      }
    }
  }

  for(int i = 99;i >= 50;i-= 2){
    for(int j = 0;j < 100; j+= 2){
      if(b > 0){
        b--;
        mas[i][j] = '#';
      }
    }
  }

  cout << 100 << " " << 100 << endl;
  for(int i = 0;i < 100;i++) cout << mas[i] << endl;

  return 0;

}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int h, w;
  cin >> h >> w;

  string s;
  
  FOR(i,0,h){
    cin >> s;
    FINA(s);
    FINA(s);
  }
 return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  
  int cnt=0;
  int max_at=0;
  int max=0;
  
  for(int i=0; i<N; i++) cin >> d.at(i);
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(d.at(j)>max){
        max=d.at(j);
        max_at=j;
      }
      else if(d.at(j)==max) d.at(j)=0;
    }
    if(max==0) break;
    cnt++;
    d.at(max_at)=0;
    max=0;
    max_at=0;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,i,c=1;
  cin>>n;
  vector<int64_t> a(n);
  vector<pair<int64_t,int64_t>> b;
  for(i=0;i<n;i++) cin>>a.at(i);
  sort(a.begin(),a.end());
  for(i=1;i<n;i++){
    if(a.at(i)==a.at(i-1)) c++;
    else{
      if(c>1) b.push_back(make_pair(a.at(i-1),c));
      c=1;
    }
  }
  if(c>1) b.push_back(make_pair(a.at(i-1),c));
  if(b.size()<1) cout<<0<<endl;
  else if(b.size()==1&&b.at(0).second<4) cout<<0<<endl;
  else{
    reverse(b.begin(),b.end());
    if(b.at(0).second>=4) cout<<b.at(0).first*b.at(0).first<<endl;
    else cout<<b.at(0).first*b.at(1).first<<endl;
  }
}

Measured memory_bytes: 4852