akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    reverse(_all(in));
    int n = in.size();

    vector<vi> dp(n + 1, vi(2, inf));
    dp[0][0] = 0;

    rep(i, n){
        int num = in[i] - '0';
        int ni = i + 1;

        rep(j, 2){
            int cur = dp[i][j];
            if(cur == inf) continue;

            if(j == 0){
                // direct
                chmin(dp[ni][0], cur + num);

                // indirect
                if(num != 0){
                    chmin(dp[ni][1], cur + (10 - num));
                }
            }
            else {
                // direct
                chmin(dp[ni][0], cur + num + 1);
                
                // indirect
                chmin(dp[ni][1], cur + (9 - num));
            }
        }
    }

    cout << min(dp[n][0], dp[n][1] + 1) << endl;

    return 0;
}


Measured memory_bytes: 55964
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
vector<int> p(5001),s(5001);
int mx=-1e18,k;
void trav(int i,int o){
    int c=0,sum=0,mxs=-1e18,szz=0;
   int vis[5001]={0};
   vector<int> temp;
    while(!vis[i]){
        sum+=s[i];
        if(sum>mxs){
            mxs=sum;
            szz=c+1;
        }
        temp.pub(mxs);
        c++;
        vis[i]=1;
        i=p[i];
        if(c==k)break;
    }
    if(sum>=0){
        int hm=k/c;
        rep(j,0,k%c){
            mx=max(mx,temp[j]+hm*sum);
        }
        hm--;
        rep(j,0,c){
            mx=max(mx,temp[j]+hm*sum);
        }
    }
    if(sum<0){
        mx=max(mx,mxs);
    }
    //cout<<mx<<"\n";
}
int32_t main(){
    int n; cin>>n>>k;
    rep(i,1,n+1)cin>>p[i];
    rep(i,1,n+1)cin>>s[i];
    rep(i,0,n){
        trav(i+1,0);
    }
    cout<<mx<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read question. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


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

long long n, k, res = 0;
vector<long long> h;

int main() {
  cin >> n >> k;
  h.resize(n);
  for(int i = 0; i < n; ++i) cin >> h[i];
  sort(h.begin(), h.end());
  for(int i = 0; i + k < n; ++i) res += h[i];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
  
int main()
{
    int a, b, c;
    int tmp;
  
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) tmp = a, a = b, b = tmp;
    if (b > c) {
        tmp = b, b = c, c = tmp;
        if (a > b) tmp = a, a = b, b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2068
# input
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

# main
for i in range(n):
  v[i] -= c[i]

ans = 0
for i in range(n):
  if v[i] >= 0:
    ans += v[i]
    
# output
print(ans)

Measured memory_bytes: 3060
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, K, a, b, c, d, e, H, W;
long long A[200001] = {};
//long long t[200001] = {};
bool f[1000][1000] = {};
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <pl>vpl;


int main() {
	cin >> N >> K;

	for (long long i = 1; i <= N; i++) {
		A[i%K]++;
	}
	a = A[0] * A[0] * A[0];
	if (K % 2 == 0) {
		a += A[K / 2] * A[K / 2] * A[K / 2];
	}

	cout << a << endl;

	return 0;
}

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

using namespace std;

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

    cin >> a >> b >> c;

    int d = a * c;

    if(d <= b){
        cout << c << endl;
    }
    else{
        cout << b / a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import heapq
N = int(input())
H = list(map(int, input().split()))
heapq.heapify(H)
while len(H) >= 2:
  f = heapq.heappop(H)
  s = heapq.heappop(H)
  heapq.heappush(H, (f + s) / 2)
print(H[0])


Measured memory_bytes: 3060
h, w = map(int, input().split())
import math
if h == 1 or w == 1:
  print(1)
  
elif h%2 == 0 and w%2 == 0:
  print(h * w // 2)
  
elif h%2 == 0 or w%2 == 0:
  if h%2 == 0:
    we = w//2
    wo = math.ceil(w/2)
    print(we * h//2 + wo * h//2)
    
  else:
    he = h//2
    ho = math.ceil(h/2)
    print(ho * w//2 + he * w//2)

else:
  	# odd
	we = w//2
	wo = math.ceil(w/2)
	he = h//2
	ho = math.ceil(h/2)
	print(ho * wo + he * we)
    
  
  

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    long int A[N+1], a[N+1], B[N], b[N], i;
    for(i=0; i<N+1; i++) {
        cin >> A[i];
        a[i] = A[i];
    }
    long int max=0;
    for(i=0; i<N; i++) {
        cin >> B[i];
        b[i] = B[i];
        if(A[i]-B[i]>=0) {
            max += B[i];
            B[i] = 0;
            // cout << "1   " << max << endl;
        } else {
            max += A[i];
            B[i] -= A[i];
            // cout << "2   " << max << endl;
            if(A[i+1]-B[i]>=0) {
                max += B[i];
                // cout << "3   " << max << endl;
                A[i+1] -= B[i];
            } else {
                max += A[i+1];
                // cout << "4   " << max << endl;
                A[i+1] = 0;
            }
        }
    }

    int sum=0;
    // for(i=N-1; i>-1; i--) {
    //     if(a[i+1]-b[i]>=0) {
    //         sum += b[i];
    //         b[i] = 0;
    //     } else {
    //         sum += a[i+1];
    //         b[i] -= a[i+1];
    //         if(a[i]-b[i]>=0) {
    //             sum += b[i];
    //             a[i] -= b[i];
    //         } else {
    //             sum += a[i];
    //             a[i] = 0;
    //         }
    //     }
    // }


    if(sum>max) {
        cout << sum << endl;
    } else {
        cout << max << endl;
    }

    return 0;
    
}

Measured memory_bytes: 3328
#include<cstdio>
using namespace std;

long long int gcd(long long int x,long long int y)
{
	if(y==0) return x;
    return gcd(y,x%y);
}

int main()
{
	int n;
	long long int awddwddwdwdwdwd=0;
	//long long int sum=0;
	scanf("%d",&n);
	scanf("%lld",&awddwddwdwdwdwd);
	for(int i=2;i<=n;i++)
	{
		long long awdawdwd;
		scanf("%lld",&awdawdwd);
		awddwddwdwdwdwd=awddwddwdwdwdwd/gcd(awdawdwd,awddwddwdwdwdwd)*awdawdwd;
	}
	printf("%lld\n",awddwddwdwdwdwd);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int sum = 0;
	int maximum = max(max(a,b),c);
	sum = 10*maximum + (a + b + c - maximum);
	cout << sum <<endl;
	return 0;
}




Measured memory_bytes: 256
def main():
    i = list(map(int, input().split()))
    x = i[0]
    a = i[1]
    b = i[2]

    if not (1 <= x and x <= 1000 and 1 <= a and a <= 1000 and 1 <= b and b <= 1000):
        return
    if x == a or a == b or b == x or abs(x-a) == abs(x-b):
        return

    if(abs(x-a) < abs(x-b)):
        print('A')
    else:
        print('B')

if __name__ == "__main__":
    main()

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

int main() {

    char b;
    cin >> b;

    if (b == 'A') {
        cout << 'T';
            }
    else if (b == 'T') {
        cout << 'A';
            }
    else if (b == 'C') {
        cout << 'G';
            }
    else if (b == 'G') {
        cout << 'C';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include<queue>
#include<list>
#include<algorithm>

int main()
{
    int n,q,b,e,t;
    std::cin>>n;
    std::vector<int> S;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        S.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        std::cin>>b>>e>>t;
        swap_ranges(S.begin()+b, S.begin()+e, S.begin()+t);
    }
    printf("%d",S[0]);
    for(int i = 1; i < n; i++)
    {
        printf(" %d",S[i]);
    }
	printf("\n");

    return 0;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
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); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
	cin >> n;
	vi v(n), va(n);
	REP(i,n) {
		cin >> v[i];
	}
	va = v;
	sort(ALL(va));
	m = va[n / 2 - 1];
	k = va[n / 2];
	REP(i,n) {
		if(v[i]<m){
			cout << k << endl;
		}else if(v[i]==m){
			cout << k << endl;
		}else if(v[i]==k){
			cout << m << endl;
		}else{
			cout << m << endl;
		}
	}
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

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

    int res=0;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            res = max(res, abs(A[i] - A[j]));
        }
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
 {
	
	
	    int n;
	    cin>>n;
	    int arr[n];
	    for(int i=0; i<n; i++){
	        cin>>arr[i];
	    }
	    if(n<2){
	    	cout<<"0"<<endl;
		}
	    else{
			long long int dp[n]={0};
		    
		    dp[0]=0;
		    dp[1]=abs(arr[1]-arr[0]);
		    
		    for(int i=2; i<n; i++){
		    	int n1 = dp[i-2] + abs(arr[i-2] - arr[i]);
		        int n2 = dp[i-1] + abs(arr[i-1] - arr[i]);
		        dp[i] = min(n1, n2);
			}
			
			cout<<dp[n-1]<<endl;
		}
	
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();

    const int64_t MOD = 1e9+7;

    // dp[i][j] : i文字目までを見た時に作れる数で、13で割った余りがjであるものの個数（を、MODで割った余り）
    static int64_t dp[100001][13] = {0};
    // 初期状態。dp[0][0]に「数字を1文字も付け足していないもの」1通りを追加
    dp[0][0] = 1;

    for(int i=0; i<N; i++){
        // 13通りの遷移元を全て回る
        for(int j=0; j<13; j++){
            // Sのi+1文字目を確認するが、0-indexedなのでS[i]として見る
            if(S[i] == '?'){
                // ?なら10通り遷移
                for(int b=0; b<=9; b++){
                    int j2 = (10*j+b) % 13;
                    dp[i+1][j2] = (dp[i+1][j2] + dp[i][j]) % MOD;
                }
            }else{
                // 数字ならその数だけ遷移
                int b = S[i] - '0';
                int j2 = (10*j+b) % 13;
                dp[i+1][j2] = (dp[i+1][j2] + dp[i][j]) % MOD;
            }
            // dpの計算の途中で随時、MOD=1e9+7で割った余りを取る
        }
    }

    // これが答え
    cout << dp[N][5] << endl;
    return 0;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    string s; cin>>s;
    ll cnt=0;
    rep(i,6) cnt+=s[i]=='1';
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;


int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,0,n-1)cin >> a[i];
    int ans = 0;
    rep(i,1,n-1)ans = max(a[i]-a[i-1],ans);
    ans = max(ans,a[0]+k-a[n-1]);
    ans = k - ans;

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
    
}

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

int main() {
    const ll mod = 1000000007;
    int n;
    cin >> n;
    map<int, int> mp = {{0, 3}};
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans *= mp[x];
        ans %= mod;
        mp[x]--;
        mp[x + 1]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


void proc() {
	LOAD(int, N);
	LOAD(int, X);
	LOADVEC(int, S, N);
	std::sort(S.begin(), S.end());
	//
	int SIZE = 100001;
	std::vector<int>dp(SIZE), tmp(SIZE);
	dp[X] = 1;
	for (int n = 0; n < N - 1; ++n) {
		for (int i = 0; i < SIZE; ++i) {
			tmp[i] = (dp[i] * (N - n - 1)) % MOD;
		}
		for (int i = 0; i < SIZE; ++i) {
			tmp[i%S[N - n - 1]] += dp[i];
			tmp[i%S[N - n - 1]] %= MOD;
		}
		std::swap(dp, tmp);
	}
	//
	int res = 0;
	for (int i = 0; i < SIZE; ++i) {
		res += dp[i] * (i%S[0]);
		res %= MOD;
	}
	cout << res;
}

#else
//E
LOAD(int, B);
LOAD(int, W);
int N = B + W;
std::vector<int>bunsi(B + 1), bunbo(B + 1);
for (int i = 0; i < B + 1; ++i) {
	bunbo[i] = 1;
}
bunsi[B] = 1;
//
for (int n = 0; n < N; ++n) {

}

#endif


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007

ll sum[401];

ll solve(vector<int> &vec, int l, int r, vector<vector<ll>> &dp){
    if (l>r)
        return INT64_MAX;
    if (r==l)
        return 0;
    if (dp[l][r]!=INT64_MAX)
        return dp[l][r];

    ll ans = INT64_MAX;
    ll val = sum[r]-sum[l-1];
    for (int i=l; i<r; i++){
        ans = min(ans, solve(vec, l, i, dp)+solve(vec, i+1, r, dp) + val);
    }
    return dp[l][r] = ans;
}

signed main() {
    //freopen("input1.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<int> vec(n+1);

    for (int i=1; i<=n; i++)
        cin >> vec[i];
    
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, INT64_MAX));
    
    sum[0]=0;
    for (int i=1; i<=n; i++)
        sum[i] = sum[i-1]+vec[i];
    
    cout << solve(vec, 1, n, dp);
    
    return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  vector<char> v;
  for (ll i = 0; i < (ll)s.size(); i++) {
    if (s[i] == 'B') {
      if (!v.empty()) v.pop_back();
    }
    else v.push_back(s[i]);
  }
  for (ll i = 0; i < (ll)v.size(); i++) {
    cout << v[i];
  }
  cout << endl;


  return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    n-=k;
    if(k==1) cout<<0<<endl;
    else cout<<n<<endl;
}

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

a = list(map(int,input().split()))

A = [0]
for i in a:
    A.append(i)

A.append(0)


mon = 0

for i in range(len(A)-1):
    mon += max( A[i+1] - A[i] , A[i] - A[i+1])

for i in range(N):
    i += 1

    now = mon - ( max( A[i+1] - A[i] , A[i] - A[i+1]) + max( A[i-1] - A[i] , A[i] - A[i-1]) ) + max( A[i+1] - A[i-1] , A[i-1] - A[i+1])

    print (now)
    


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    long long ans = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        ans += min(x[i], abs(x[i] - k)) * 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = 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

    def size(self, x):  # グループのサイズ
        return - self.parents[self.find(x)]

    def same(self, x, y):  # 同じグループか否か
        return self.find(x) == self.find(y)


n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uf = Unionfind(n)
ans, cnt = [], n * (n - 1) // 2
for a, b in ab[::-1]:
    ans.append(max(cnt, 0))
    if not uf.same(a - 1, b - 1):
        cnt -= uf.size(a - 1) * uf.size(b - 1)
        uf.union(a - 1, b - 1)
print(*ans[::-1], sep='\n')


Measured memory_bytes: 103084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
	static boolean bElapsed = false;
	StringBuilder sb = new StringBuilder();
	List<String> list = new ArrayList<>();
	Set<String> set = new HashSet<>();
	Map<String,String> map = new HashMap<>();

	void solve(BufferedReader br) throws Exception {
		String line = br.readLine();
		boolean bC = false;
		boolean bF = false;
		for (int i=0; i<line.length(); i++) {
			char ch = line.charAt(i);
			if (!bC && ch == 'C') {
				bC = true;
			} else if (bC && ch == 'F') {
				bF = true;
				break;
			}
		}
		if (bF) 
			pln("Yes");
		else
			pln("No");
	}

	class Person {
		int no;
		int a;
		public Person(int no, int a) {
			this.no = no;
			this.a = a;
		}
	}
	class PersonComp implements Comparator<Person> {
		public int compare(Person o1, Person o2) {
			return o2.a - o1.a;
		}
	}
	void p(char c) {
		System.out.print(c);
	}
	void pln(char c) {
		System.out.println(c);
	}
	void p(long l) {
		System.out.print(l);
	}
	void pln(long l) {
		System.out.println(l);
	}
	void p(String s) {
		System.out.print(s);
	}
	void pln(String s) {
		System.out.println(s);
	}
	//Integer.MAX_VALUE=2147483647>10^9
	//Long.MAX_VALUE=9223372036854775807L>10^18
	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		new Main().solve(br);
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.out.println((end-start) + "ms");
		}
	}
}


Measured memory_bytes: 8148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
// const int k_mod = 1e9 + 7;
const int k_mod = 998244353;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	int a;
	int b;
} P;

/*
 * @fn modpow
 * @brief O(logn): a^n % mod
 * @param a: 基数
 * @param n: 指数
 * @param mod: 法
 */
ll modpow( ll a, ll n, ll mod ) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main( void ){
	int N;
	string S;
	cin >> N >> S;
	vector <int> vec( N );
	rep( i, 0, N )
		vec[ i ] = ( int )( S[ i ] - '0' );
	int ans = 0;
	rep( seq, 0, 1000 ){
		int tag[] = {seq / 100, ( seq / 10 ) % 10, seq % 10};
		int cnt = 0;
		rep( i, 0, N ){
			if (vec[ i ] == tag[ cnt ]){
				cnt++;
				if (cnt > 2)
					break;
			}
		}
		if(cnt == 3)
			ans++;
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 512
N, A, B = gets.split.map{|i|i.to_i}
X = gets.split.map{|i|i.to_i}
s = 0
(N - 1).times{|i|
    d = X[i + 1] - X[i]
    if d * A < B
        s += d * A
    else
        s += B
    end
}
puts s


Measured memory_bytes: 8452
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
    cout<<s[i];
  }
  cout<<8;
  for(int i=4;i<10;i++){
    cout<<s[i];
  }
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

ll N, DP[61][3];

int main() {
	cin >> N;
	DP[60][0] = 1;
	for (int i = 59; i != -1; --i) {
		if (N&(1ll << i)) {
			DP[i][0] = DP[i + 1][0];
			DP[i][1] = DP[i + 1][0] + DP[i + 1][1];
			DP[i][2] = DP[i + 1][2] * 3 + DP[i + 1][1] * 2;
		}
		else {
			DP[i][0] = DP[i + 1][0] + DP[i + 1][1];
			DP[i][1] = DP[i + 1][1];
			DP[i][2] = DP[i + 1][2] * 3 + DP[i + 1][1];
		}
		for (int j = 0; j != 3; ++j)
			DP[i][j] %= mod;
	}
	cout << (DP[0][0]+DP[0][1]+DP[0][2])% mod << endl;
	return 0;
}

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

using ll = long long;
using ld=long double;

ld d[8][8];
int main(){
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    for(int i=0;i<n;i++)
    cin>>x[i]>>y[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            ld d1=sqrtl((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            d[i][j]=d1;
            d[j][i]=d1;
        }
    vector<int> p(n);
    int count=0;
    ld sum=0.0;
    for(int i=1;i<n;i++) p[i]=i;
    do{
        ld dist=0.0;
        for(int i=0;i<n-1;i++){
            dist+=d[p[i]][p[i+1]];
        }
        sum+=dist;
        count++;
    }while(next_permutation(p.begin(),p.end()));
    sum/=count;
    printf("%Lf",sum);
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
	fastIO;
	string s,w="";
	int cnt=0;	
	cin>>s;
	for(int i=(int)s.size()-1;i>=0;i--){
		if(s[i] == 'B')++cnt;
		else{
			if(cnt == 0)w+=s[i];
			else cnt--;
		}			
	}	
	for(int i=(int)w.size()-1;i>=0;i--){
		cout<<w[i];
	}
	cout<<'\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        
        if(A==1&&B==2 || A==2&&B==1) {
        	System.out.println(3);
        } 
        if(A==2&&B==3 || A==3&&B==2) {
        	System.out.println(1);
        } 
        if(A==1&&B==3 || A==3&&B==1) {
        	System.out.println(2);
        } 
 

	}
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
double PI=acos(-1.0);
signed main(){
    ll a,b,c,d,k;cin>>a>>b>>c>>d>>k;
    cout<<c*60+d-a*60-b-k<<endl;
}

Measured memory_bytes: 3608
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<=en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	int n, w;
	cin>>n>>w;
	// vector<pair<int, int>> v;
	int dp[n+1][w+1] = {0};
	vector<int> a;
	vector<int> v;
	int t1, t2;
	for(int i=0; i<n; i++){
		cin>>t1>>t2;
		a.pb(t1);
		v.pb(t2);
	}

	For(i, 0, n){
		For(j, 0, w){
			if(i==0 || j==0){
				dp[i][j]=0;
			}else if(a[i-1]<=j){
				dp[i][j] = max(dp[i-1][j], v[i-1]+dp[i-1][j-a[i-1]]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
			// cout<<i<<" "<<j<<" "<<a[i-1]<<" "<<w<<" "<<dp[i][j]<<endl;
		}
	}

	cout<<dp[n][w]<<endl;

	// For(i, 0, n){
	// 	For(j, 0, w){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
    return 0;
}
    



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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];

    int mi,mij,cou=0;

    for(int i=0;i<n;i++){
        mi=a[i];
        mij=i;
        for(int j=i;j<n;j++){
            if(mi>a[j]){
                mij=j;
                mi=a[j];
            }
        }
        if(i!=mij){
            swap(a[i],a[mij]);
            cou++;
        }
    }
    for(int i=0;i<n;i++)cout << a[i] << (i!=n-1?" ":"\n");
    cout << cou << endl;
}



Measured memory_bytes: 3188
import java.util.Scanner;

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

		long ans = 0L;

		for(int i = 0; i<N; i++) {
			A[i] = sc.nextLong();
		}

		for(int i = 0; i<N-1; i++) {
			long x =A[i+1] - A[i];
			if(x<0) {
				ans -= x;
				A[i+1] -=x;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 61548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

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

int main() {

    int A, B, C, K;
    cin >> A >> B >> C >> K;


    // A < B < C

    while (K > 0) {
        K--;
        if (A >= B) {
            B *= 2;
        }
        else {
            if (B >= C) {
                C *= 2;
            }
        }
        if (A < B and B < C) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
N, x = map(int,input().split())
A = list(map(int,input().split()))
ans = 0

if A[0]>x:
    ans += A[0] - x
    A[0] = x

for k in range(1,N):
    if A[k-1] + A[k] > x:
        ans += (A[k-1] + A[k]) - x
        A[k] = x - A[k-1]

print(ans)

Measured memory_bytes: 14052
K   = int(input())
Sum = 0
def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    r = 2  # 余り
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

for A in range(1,K+1):
    for B in range(1,K+1):
        AB = mygcd(A,B)
        if AB==1:
            Sum = Sum+K
        else:
            for C in range(1,K+1):
                Sum = Sum+mygcd(AB,C)
print(Sum)

Measured memory_bytes: 9136
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int k,q;
	cin>>k>>q;
	vi d(k);
	rep(i,k)cin>>d[i];
	while(q--){
		int n,x,m;
		cin>>n>>x>>m;
		int s=0,c=0;
		rep(i,k){
			s+=d[i]%m;
			if(d[i]%m==0)c++;
		}
		s*=(n-1)/k;
		c*=(n-1)/k;
		s+=x%m;
		rep(i,(n-1)%k){
			s+=d[i]%m;
			if(d[i]%m==0)c++;
		}
		cout<<n-1-s/m-c<<endl;
	}
}
// 3 6 7 11 14
// 1 0 1 1 0
// 1 2 3 3 4
// 1 1 1 0 1
// 4 2  3 1 








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

int main(){
    long H, W;
    cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    long ans = min(H, W);
    for(int i = 1; i <= H / 2; i++){
        long first = i * W, second = (H - i) * (W / 2), third = (H - i) * ((W + 1) / 2);
        ans = min(ans, max({first, second, third}) - min({first, second, third}));
    }
    for(int i = 1; i <= W / 2; i++){
        long first = i * H, second = (W - i) * (H / 2), third = (W - i) * ((H + 1) / 2);
        ans = min(ans, max({first, second, third}) - min({first, second, third}));
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
#include<string>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  char S[N+1];
  for(int i=1; i<N+1; i++){
    cin >> S[i];
  }

  int ans=0;

  for(int i=1; i<N-1; i++){
    if(S[i] == 'A' && S[i+1]=='B' && S[i+2]=='C'){
      ++ans;
    }
  }

  cout << ans << endl;

 return 0;
}

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

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=998244353;

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

signed main(){
	llin(n);
	vllin(a,n);
	vll g(n);
	vll u(n);
	g[0]=a[0];
	u[n-1]=a[n-1];
	vll gg(n);
	FOR(i,1,n-1){
		g[i]=gcd(g[i-1],a[i]);
	}
	rFOR(i,0,n-2){
		u[i]=gcd(u[i+1],a[i]);
	}
	gg[0]=u[1];
	gg[n-1]=g[n-2];
	FOR(i,1,n-2){
		gg[i]=gcd(g[i-1],u[i+1]);
	}
	rSORT(gg);
	sal(gg[0]);
}


Measured memory_bytes: 3328
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
bool isPalindrome(string str)
{
    int l = 0;
    int h = (str.size()) - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            return false;
        }
    }
    return true;
}
void solve(int test) {
    string s ;cin>>s;
    bool b1=isPalindrome(s);
    int n=s.size();
    string s1=s.substr(0,n-(n-1)/2-1);
//    cout<<s1<<endl;
    bool b2=isPalindrome(s1);
    string s2=s.substr((n+3)/2-1);
    bool b3=isPalindrome(s2);
//    cout<<s2<<endl;
    if(b1 && b2 && b3){
        cout<<"Yes"<<endl;
    } else{
        cout<<"No"<<endl;
    }



}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
        solve(i);
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/13
// Problem:ABC 068 BreakNumber b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int power(int x, int n)
{
  int res = 1;
  while(n > 0) {
    if (n & 1) {
      res = res * x;
    }
    x = x * x;
    n >>= 1;
  }
  //  debug(reas);
  return res;
}

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

  int N;
  cin >> N;
  int ans = 1;
  REP(i, 10) {
    if (power(2, i) > N){
      ans = power(2, i - 1);
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000007
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> P;


int main() {

	char c[4];
	int cc = 0;
	cin >> c[0] >> c[1] >> c[2];

	if (c[0] == 'o') { cc += 1; }
	if (c[1] == 'o') { cc += 1; }
	if (c[2] == 'o') { cc += 1; }

	cout << 700 + cc * 100 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tgmath.h>

static double expected(int a)
{
    int sum = 0;
    for (int i = 1; i <= a; i++) sum += i;
    return (double) sum / (double) a;
}

int main(int argc, char **argv)
{
    int n, k;
    scanf("%d %d", &n, &k);
    double e[n];
    e[0] = 0;
    for (int i = 0; i < n; i++) {
        int p;
        scanf("%d", &p);
        e[i + 1] = e[i] + expected(p);
    }
    double ans = 0;
    for (int i = 0; i < n - k + 1; i++) {
        double a = e[i + k] - e[i];
        ans = ans < a ? a : ans;
    }
    printf("%.7lf\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**7)

n,m,p=map(int,input().split())
g=[[] for _ in range(n)]
g2=[[] for _ in range(n)]
g3=[[] for _ in range(n)]
for _ in range(m):
    a,b,l=map(int,input().split())
    g[a-1].append([b-1,p-l])
    g2[a-1].append(b-1)
    g3[b-1].append(a-1)

f1=[False for _ in range(n)]
def dfs1(s):
    global f1
    global g2
    f1[s] = True
    for sg in g2[s]:
        if not f1[sg]:
            dfs1(sg)
f2=[False for _ in range(n)]
def dfs2(s):
    global f2
    global g3
    f2[s] = True
    for sg in g3[s]:
        if not f2[sg]:
            dfs2(sg)

dfs1(0)
dfs2(n-1)
f3 = []
for i in range(n):
    f3.append(f1[i] and f2[i])

def bellman_ford(g,n):
    INF = 10**10
    res = [INF for _ in range(n)]
    res[0] = 0
    for _ in range(n-1):
        for i in range(n):
            if res[i] != INF:
                for sa,sb in g[i]:
                    res[sa] = min(res[sa],res[i]+sb)
    ret = res[-1]
    for i in range(n):
        if res[i] != INF:
            for sa,sb in g[i]:
                if res[sa]>res[i]+sb:
                    if f3[sa]:
                        return False
    return ret

res = bellman_ford(g,n)
if type(res) == bool:
    print(-1)
elif res > 0:
    print(0)
else:
    print(res * -1)

Measured memory_bytes: 65240
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<set>
#include<iomanip>
#include<utility>
#include<deque>
#include<vector>
#include<locale>
#include<sstream>
#define f(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
int n,k,i,j,tong[200010],ans,t,p;
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&t);
		tong[t]++;
	}
	sort(tong+1,tong+n+1);
	for(i=n;i>n-k;i--) ans+=tong[i];
	printf("%d",n-ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int k,t;
    cin>>k>>t;
    vector<int> a(t);
    rep(i,t)cin>>a[i];
    sort(a.begin(),a.end());
    if(k-a[t-1]>=a[t-1])
    {
        cout<<0;
    }
    else
    {
        cout<<2*a[t-1]-k-1;
    }
    
}


Measured memory_bytes: 256
#define NOT_FOUND -1
#include <stdio.h>

int binarySearch(int a[], int n, int key){
	int cnt = 0;
	int left = 0;
	int right = n;
	int mid;

	while (left < right) {
		mid = (left + right) / 2;
		if (a[mid] == key) {
			return mid;
		}
		else if (a[mid] > key) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}

	return NOT_FOUND;
}

int main(void) {
	int n, q;
	int cnt = 0;
	int s[100000] = { 0 };
	int t[50000] = { 0 };
	int i, j;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &s[i]);
		if (i > 0) {
			if (s[i] < s[i - 1]) {
				printf("a");
				i--;
			}
		}
	}

	scanf("%d", &q);

	for (i = 0; i < q; i++) {
		scanf("%d", &t[i]);
		for (j = 0; j < i; j++) {
			if (t[i] == t[j]) {
				i--;
				break;
			}
		}
	}

	for (i = 0; i < q ;i++) {
		if (binarySearch(s, n, t[i]) >= 0) {
			cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}



Measured memory_bytes: 2380
import java.io._
import java.util.StringTokenizer

class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

class UnionFind(v: Int){
  // 根であれば *そのグループの要素数(負)* が、子であれば親の番号が入る。
  val uni = Array.fill(v)(-1)
 
  // 頂点 v の所属するグループを調べる
  def root(v: Int): Int =
    uni(v) < 0 match{
      case true  =>  // v が親の場合
        return v
      case false =>  // v が子の場合
        uni(v) = root(uni(v))  // 親のrootを調べる
        return uni(v)
    }
 
  // 頂点 a と頂点 b をつなぐ。もともと同じグループのとき、False を返す
  def connect(a: Int, b: Int): Boolean = {
    // まずはそれぞれ根の番号に置き換える
    var ra = root(a)
    var rb = root(b)
    if(ra == rb)
      return false  // a と b がそもそも同じグループに属しているなら即終了
 
    // ra を大きなグループにしたいので、逆であれば入れ替える
    if(uni(ra) > uni(rb)) {  // rbの方が要素数が多ければ
      var tmp = ra
      ra = rb
      rb = tmp
    }
 
    // ra と rb を結合し、rb の親を ra とする
    uni(ra) += uni(rb)
    uni(rb) = ra
    return true
  }
 
  // 頂点 a, b が同じグループであるかを調べる
  def isConnect(a: Int, b: Int): Boolean =
    root(a) == root(b)
 
  // 頂点 a を含むグループの頂点数を調べる
  def size(a: Int): Int = -uni(root(a))
}
 
object Main extends App {
  val in = new InputReader(System.in)
 
  val N = in.next().toInt
  val xp = new Array[(Int, Int)](N)
  val yp = new Array[(Int, Int)](N)
 
  for (i <- 1 to N){
    val x, y = in.next().toInt
    xp(i-1) = (x, i)
    yp(i-1) = (y, i)
  }
 
  scala.util.Sorting.quickSort(xp)
  scala.util.Sorting.quickSort(yp)
 
  // ret : (cost, (node1, node2))
  def makeCosts(pl: List[(Int, Int)]): List[(Int, (Int, Int))] = {
    def calc(pl: List[(Int, Int)], res: List[(Int, (Int, Int))]): List[(Int, (Int, Int))] = {
      pl match {
        case Nil | _ :: Nil => res
        case a :: b :: rest =>
          val cost = Math.abs(a._1 - b._1)
          calc(b :: rest, (cost, (a._2, b._2)) :: res)
      }
    }
    calc(pl, List())
  }
 
  val xc = makeCosts(xp.toList).toArray.sorted
  val yc = makeCosts(yp.toList).toArray.sorted 
 
  // // 
  val uf = new UnionFind(N+1)
 
  var xi = 0; var yi = 0
 
  var ans = 0L
  var flag = true
  while(flag) {
    val (costx, (ax, bx)) = xc(xi)
    val (costy, (ay, by)) = yc(yi)
    val (cost, (a, b)) = {
      if(costx <= costy) {
        xi += 1
        (costx, (ax, bx))
      }
      else {
        yi += 1
        (costy, (ay, by))
      }
    }
    if(!uf.isConnect(a, b)) {
      ans += cost
      uf.connect(a, b)
      if(uf.size(a) == N)
        flag = false
    }
  }
 
  println(ans)
}


Measured memory_bytes: 149768