akhauriyash/Code-Regression huggingface dataset:
/*********************************************************************************************/
/**                                                                                          //
//                            _ooOoo_                                                        //
//                           o8888888o                                                       //
//                           88" . "88                                                       //
//                           (| -_- |)                                                       //
//                            O\ = /O                                                        //
//                        ____/`---'\____                                                    //
//                      .   ' \\| |// `.                                                     //
//                       / \\||| : |||// \                                                   //
//                     / _||||| -:- |||||- \                                                 //
//                       | | \\\ - /// | |                                                   //
//                     | \_| ''\---/'' | |                                                   //
//                      \ .-\__ `-` ___/-. /                                                 //
//                   ___`. .' /--.--\ `. . __                                                //
//                ."" '< `.___\_<|>_/___.' >'"".                                             //
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |                                          //
//                 \ \ `-. \_ __\ /__ _/ .-` / /                                             //
//         ======`-.____`-.___\_____/___.-`____.-'======                                     //
//                            `=---='                                                        //
//                                                       //                                  //
//         .............................................                                     //
//                  佛祖保佑             永无BUG                                            //
********************************************************************************************/
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
const int mod=1000000009;
int vis[10000];
int main()
{
    int a[10000];
    int n;
    cin>>n;
    int sum=0,flag=0;
    for(int i=1;i<=n;i++)
        cin>>a[i],sum+=a[i];
    if(sum/n*n!=sum)
        flag=1;
    sum/=n;
    sum+=flag;
    int cnt=0,cnt1=0;
    for(int i=1;i<=n;i++)
        cnt+=(a[i]-sum)*(a[i]-sum), cnt1+=(a[i]-sum+1)*(a[i]-sum+1);
    cout<<min(cnt,cnt1)<<endl;
}


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

int main(){
    int n; 
    string s;
    cin >> n >> s;
    vector<vector<int>> lttr(26);
    for(int i = 1; i <= n; i++){
        char c = s[i-1];
        lttr[c-'a'].push_back(i);
    }
    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int i; char c; 
            cin >> i >> c;
            int cnt1 = s[i-1] - 'a';
            s[i-1] = c;
            int cnt2 = c - 'a';
            if(cnt1 == cnt2) continue;
            int tmp = lower_bound(lttr[cnt1].begin(), lttr[cnt1].end(), i) - lttr[cnt1].begin();
            lttr[cnt1].erase(lttr[cnt1].begin() + tmp);
            tmp = lower_bound(lttr[cnt2].begin(), lttr[cnt2].end(), i) - lttr[cnt2].begin();
            lttr[cnt2].emplace(lttr[cnt2].begin() + tmp, i);
        }else{
            int l, r; cin >> l >> r;
            int ans = 0;
            for(int i = 0; i < 26; i++){
                if(lttr[i].empty()) continue;
                int cnt = lower_bound(lttr[i].begin(), lttr[i].end(), l) - lttr[i].begin();
                if(cnt == (int)lttr[i].size()) continue;
                if(lttr[i][cnt] <= r) ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 6932
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define MOD 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

ll Extgcd(ll a, ll b, ll &x, ll &y) {
	ll g = a;
	if (b != 0) {
		g = Extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return g;
}
int ModInverse(ll a, ll m)
{
	ll x, y;
	Extgcd(a, m, x, y);
	return (x % m + m) % m;
}
const int MAX_N = 2 * 100010;
vector<ll> fact(MAX_N), rfact(MAX_N);
void Init() {
	fact[0] = rfact[0] = 1;
	for (int i = 1; i < MAX_N; ++i) {
		fact[i] = (fact[i - 1] * i) % MOD;
		rfact[i] = (rfact[i - 1] * ModInverse(i, MOD)) % MOD;
	}
}
inline ll Combination(ll n, ll k) {
	return ((fact[n] * rfact[n - k]) % MOD) * rfact[k] % MOD;
}

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

	Init();
	int h,w,a,b;
	cin >> h >> w >> a >> b;

	int ans = 0;
	for (int i = 1; i <= h - a; ++i) {
		ll l1 = Combination(i + b - 2, min((ll)i - 1, b - 1));
		ll l2 = Combination(h - i + w - b - 1, min(w - b - 1, h - i));
		ans = (ans + (l1 * l2) % MOD) % MOD;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int x;
  cin >> x;
  cout << !x << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,st,ed) for(int i = st; i < ed; ++i)
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
const ll mod = 1e9 + 7;
const ll N = 2e5 + 200;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;


int main(){
	ll x;
	cin>>x;
	for(ll i = 0; i <= 2000; i++){
		for(ll j = 0; j <= 2000; j++){
			ll tmpa = i*i*i*i*i;
			ll tmpb = j*j*j*j*j;
			if(tmpa - tmpb == x){
				cout<<i<<" "<<j<<endl;
				return 0;
			}else if(tmpa + tmpb == x){
				cout<<i<<" "<<-1LL*j<<endl;
				return 0;
			}
		}
	}



	return 0;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"os"
)

func main() {
	var X int
	fmt.Scan(&X)

	switch X {
	case 3:
		fmt.Println("YES");
		os.Exit(0)
	case 5:
		fmt.Println("YES");
		os.Exit(0)
	case 7:
		fmt.Println("YES");
		os.Exit(0)
	}

	fmt.Println("NO");

}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
	int n;
	while(~scanf("%d",&n)){
		int i=0;
		for(int a=0;a<10;a++)
			for(int b=0;b<10;b++)
				for(int c=0;c<10;c++)
					for(int d=0;d<10;d++)
						if(a+b+c+d==n)i++;
		printf("%d\n",i);
	}
}


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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    cout << (b-a)*(b-a+1)/2 - b << endl;


    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
#define F first
#define S second

signed solve(){
  string s;
  cin>>s;
  ll n=s.size();

  const ll OFS = n+100;
  vector<ll> cnt(OFS*2,0);
  cnt[OFS+0]++;

  string t;
  vector<ll> vs(n+1,0);
  ll res=0;

  vector<ll> lst(OFS*2,-1);

  using P = pair<ll, ll>;
  stack<P> st,sl;
  for(char c:s){
    if(c=='-'){
      cnt[OFS+vs[t.size()]]--;

      if(t.back()==')') res-=cnt[OFS+vs[t.size()]];

      assert(!st.empty()&&!sl.empty());
      P p=st.top(),q=sl.top();
      st.pop();sl.pop();
      cnt[p.F]=p.S;
      lst[q.F]=q.S;

      t.pop_back();
    }else{
      if(c=='(') vs[t.size()+1]=vs[t.size()]+1;
      if(c==')') vs[t.size()+1]=vs[t.size()]-1;
      t+=c;

      ll val=OFS+vs[t.size()];
      st.emplace(val,cnt[val]);
      sl.emplace(val,lst[val]);

      if(lst[val]<lst[val-1]) cnt[val]=0;
      if(t.back()==')') res+=cnt[val];

      cnt[val]++;
      lst[val]=t.size();
    }
    //cout<<vs[t.size()]<<":"<<cnt[OFS+vs[t.size()]]<<":";
    cout<<res<<"\n";
  }
  cout<<flush;
  return 0;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
  return 0;
}



Measured memory_bytes: 17640
x = int(input())
ans = 2

p = [2]
i = 1
Flag = True
while i**2 < 100001:
    i += 2
    for j in p:
        if i%j == 0:
            break
        elif j == p[-1]:
            p.append(i)
for i in range(100000):
    if x+i in p:
        ans = x+i
        break
    elif x+i > p[-1]:
        for j in p:
            if (x+i)%j == 0:
                break
            elif j == p[-1]:
                ans = x+i
                break
        if ans == x+i:
            break

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int w[105],v[105];
ll dp[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)
		for(int j=m;j>=w[i];j--)
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	cout<<dp[m]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin>>n;

	ll ar[n],ans[n];
	for(int i=0;i<n;i++)
		cin>>ar[i];
	
	ans[0]=0;
	ans[1]=abs(ar[1]-ar[0]);

	for(int j=2;j<n;j++)
		ans[j]=min(ans[j-1]+abs(ar[j]-ar[j-1]),ans[j-2]+abs(ar[j]-ar[j-2]));

	cout<<ans[n-1];
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[60];
int main()
{
	int n,k;
	while(~scanf("%d%d",&n,&k))
	{
		for(int i=1;i<=n;i++)scanf("%d",a+i);
		sort(a+1,a+1+n);
		long long sum=0;
		for(int i=n;i>=n-k+1;i--)
		{
			sum+=a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
// #include"myfile.h"

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


void solve() {
	int h, w;
	cin >> h >> w;

	vector<string> grid(h);
	for (string &s : grid) cin >> s;

	vector<vector<int>> ans(h, vector<int>(w));

	for (int i = 0; i < h; i++) {
		int val = 0;
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '.') val++;
			else val = 0;
			ans[i][j] += val;
		}
	}


	for (int i = 0; i < h; i++) {
		int val = 0;
		for (int j = w - 1; j >= 0; j--) {
			if (grid[i][j] == '.') val++;
			else val = 0;
			ans[i][j] += val;
		}
	}


	for (int i = 0; i < w; i++) {
		int val = 0;
		for (int j = 0; j < h; j++) {
			if (grid[j][i] == '.') val++;
			else val = 0;
			ans[j][i] += val;
		}
	}


	for (int i = 0; i < w; i++) {
		int val = 0;
		for (int j = h - 1; j >= 0; j--) {
			if (grid[j][i] == '.') val++;
			else val = 0;
			ans[j][i] += val;
		}
	}

	int val = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#') continue;
			val = max(val, ans[i][j] - 3);
		}
	}

	cout << val << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

Measured memory_bytes: 38780
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*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.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count

def kruskal(n,edges):
    u=UnionFind(n)
    ans=0
    for x in edges:
        s,t,w=x
        if u.are_same(s,t)==False:
            u.union(s,t)
            ans+=w

    return ans

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    v,e=map(int,readline().split())
    edges=[list(map(int,readline().split())) for _ in range(e)]
    edges.sort(key=lambda x:x[2])
    print(kruskal(v,edges))

if __name__=="__main__":
    main()


Measured memory_bytes: 28208
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)


int main(){
    int k,n;
    cin >> k >> n;
    int m=0;
    vi a(n);
    rep(i,n) cin >> a[i];

   int b,c;
    rep(i,n-1){
        b = a[i+1]-a[i];
        m = max(m,b);
    }
    c = a[0]+(k-a[n-1]);
    m = max(m,c);

    cout << k-m << endl;
 return 0;
}


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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int gcd(int a, int b) {
    if (a < b)
        swap(a, b);
    return b ? gcd(b, a % b) : a;
}

int main() {
    int N;
    cin >> N;
    V<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    V<int> L(N), R(N);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            L[i] = A[i];
        } else {

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

            R[i] = gcd(R[i + 1], A[i]);
        }
    }

    int ans = max(R[1], L[N - 2]);
    for (int i = 1; i < N - 1; i++) {
        ans = max(ans, gcd(L[i - 1], R[i + 1]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}



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

ll N, M, V, P;
vector<int> A;
vector<int> cumsum;

bool check(int i){
    ll capacity = 0;
    ll border = A[i] + M;
    for(int k=(i < P - 1 ? P : P - 1);k<N;k++){
        if(i == k) continue;
        if(A[k] > border) return false;
        capacity += min(border - A[k], M);
    }
    return (capacity >= M * (V - 1 - (P - 1)));
}

int main(){
    cin >> N >> M >> V >> P;

    A.resize(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

//    for(int i=0;i<N;i++){
//        cout << i << ": " << check(i) << endl;
//    }

    ll l = 0, r = N + 1;
    while(r - l > 1){
        ll n = (l + r) / 2;
        int i = n - 1;
//        cout << i << ": " << check(i) << " " << l << " " << r << endl;
        if(check(i)){
            l = n;
        }else{
            r = n;
        }
    }
    cout << l << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int N; cin >> N;
	int* a = new int[N];
	for (int i = 0; i < N; i++) {
		a[i] = 1000000;
	}
	for (int i = 0; i < N - 1; i++) {
		int b; cin >> b;
		a[i] = min(a[i], b);
		a[i + 1] = min(a[i + 1], b);
	}

	int s = 0;
	for (int i = 0; i < N; i++) {
		s += a[i];
	}

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
// #define base 100001
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld:\n", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int N = 300010;
ll n, b[N],c[N],res;
pair<ll, ll>a[N];
multiset<ll>st, st2;
int solve() {
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		in2(a[i].first, a[i].second);
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		b[i]=a[i].first+a[i].second;
		c[i]=a[i].first-a[i].second;
		st.insert(b[i]);
		st2.insert(c[i]);
	}
	for(int i=0;i<n-1;i++){
		st.erase(st.find(b[i]));
		ll mn = *st.begin();
		auto it=st.end();
		it--;
		ll mx = *it;
		res=max(res,max(abs(b[i]-mn), abs(mx-b[i])));
		st2.erase(st2.find(c[i]));
		mn = *st2.begin();
		it=st2.end();
		it--;
		mx = *it;
		res=max(res,max(abs(c[i]-mn), abs(mx-c[i])));
	}
	printf("%lld\n", res);
	return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return solve();
}

Measured memory_bytes: 28776
import math
a, b, x = map(int, input().split())


if x > a*a*b/2:
  ｘ = x /(a*a)*2
  ok = 0
  ng = 90
  while ng-ok > 10**(-7):
    y = (ok + ng) /2
    if x/2 + a*math.tan(math.radians(y))/2 > b:
      ng = y
    else:
      ok = y
  print(ng)
else:
  x = x/a
  ok = 0
  ng = 90
  while ng-ok > 10**(-7):
    y = (ok + ng) /2
    if x*2/b * math.tan(math.radians(y)) > b:
      ng = y
    else:
      ok = y
  print(ng)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int m[2][111111];
int N,H;
int main(){
    cin>>N>>H;
    for(int i=0;i<N;i++){
        int x,y;
        cin>>x>>y;
        m[0][i]=x;
        m[1][i]=y;
    }
    int x=*max_element(m[0],m[0]+N);
    sort(m[1],m[1]+N,greater<>());
    int i;
    for(i=0;m[1][i]>x&&i<N;i++){
        H-=m[1][i];
        if(H<=0){
            printf("%d",i+1);
            return 0;
        }
    }
    printf("%d",i+(H+x-1)/x);
    return 0;
}


Measured memory_bytes: 1024
// Last Change: 04/11/2019 23:53:13.
//////////////////////////////////////////////////////////////////////////////
// priority_queueのgreaterをどうするかがいまいちよくわからん。
// -> うまくgreaterをつかって小さいものを出せるようにした。
//今回はごまかした。
//
//マニピュレータの使い方。
//////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, M;
  cin >> N >> M;

  vector<
      priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>>
      pref(N + 1);
  vector<pair<ll, ll>> city(M + 1);

  ll year;
  for (ll i = 0; i < M; ++i) {
    // prefNum, year
    cin >> city[i].first >> year;
    pref[city[i].first].push(make_pair(year, i));
  }

  ll cnt;
  for (ll i = 1; i <= N; ++i) {
    cnt = 1;
    while (!pref[i].empty()) {
      city[pref[i].top().second].second = cnt;
      pref[i].pop();
      ++cnt;
    }
  }

  cout << setfill('0');

  for (ll i = 0; i < M; ++i) {
    cout << setw(6) << city[i].first;
    cout << setw(6) << city[i].second;
    cout << '\n';
  }
  cout << flush;

  //NS::LoopUntilZeroInpput();
}



Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
const ll len = 1e6 + 10;

bool is_prime[len];
ll ans = 0;
ll A, B;
int Eratosthenes(ll g)
{
    int res = 0;
    for (ll i = 2; i * i <= g; i++) {
        if (g % i != 0) {
            continue;
        }
        int num = 0;
        while (g % i == 0) {
            g /= i;
        }
        ++res;
    }
    if (g != 1) {
        ++res;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> A >> B;
    ll g = __gcd(A, B);
    ans = Eratosthenes(g);
    cout << ans + 1LL << endl;
    return 0;
}

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

int main(){
    string a,b;
    cin >> a;
    cin >> b;
    int alen, blen;
    alen = a.length();
    blen = b.length();
    if( alen > blen){
        cout << "GREATER" << endl;
    }
    else if(alen < blen){
        cout << "LESS" << endl;
    }
    else{
        int flag = 0;
        for(int i=0;i<alen;i++){
            if(flag == 0){
                if((int)a[i] > (int)b[i]) flag = 1;
                if((int)a[i] < (int)b[i]) flag = 2;
            }
        }
        if(flag == 1) cout << "GREATER" << endl;
        if(flag == 2) cout << "LESS" << endl;
        if(flag == 0) cout << "EQUAL" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
struct Node{
    int index, number;
}a[N];
int n;

bool cmp(const Node &x,const Node &y)
{
    return x.number < y.number;
} 
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].number);
        a[i].index = i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        printf("%d ",a[i].index);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 4472
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;

int main(){
    int n; cin >> n;
    n %= 10;
    if(n == 2 ||n == 4 ||n== 5 ||n== 7 ||n== 9){
        cout << "hon" << endl;
        return 0;
    }else if(n==0 || n == 1 || n==6||n==8){
        cout << "pon" << endl;
        return 0;
    }else{
        cout << "bon" << endl;
        return 0;
    }
}


Measured memory_bytes: 3028
n=int(input())
p=list(map(int, input().split()))
result=0

for i in range(len(p) - 2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        result+=1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        result+=1

print(result)



Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long int n, t=0, x;
	cin >> n;
	int c[n+1];
	for(int i = 0; i < n+1; i++)
	    cin >> c[i];
	for(int i = 0; i < n; i++)
	{
	    cin >> x;
	    if(x<=c[i])
	    {
	        t+=x;
	        c[i]-=x;
	        x=0;
	    }
	    else
	    {
	        t+=c[i];
	        x-=c[i];
	        c[i]=0;
	        if(x<=c[i+1])
	        {
	            t+=x;
	            c[i+1]-=x;
	            x=0;
	        }
	        else
	        {
	           t+=c[i+1];
	           x-=c[i+1];
	           c[i+1]=0;
	        }
	    }
	}
	cout << t << '\n';
}

Measured memory_bytes: 640
// header file section
#include "bits/stdc++.h"

using namespace std;
using llong = long long;

// library section
// ===

int main() {
    llong n, u, v;
    llong ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        ans += i * (n - i + 1);
    }
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << endl;
    return 0;
};



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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  int num_c = 9;
  vector<int> colors(num_c,0);
  
  rep(i,n){
    int tmp; cin >> tmp;
    if(1<=tmp && tmp<=399) colors[0]++;
    else if(400<=tmp && tmp<=799) colors[1]++;
    else if(800<=tmp && tmp<=1199) colors[2]++;
    else if(1200<=tmp && tmp<=1599) colors[3]++;
    else if(1600<=tmp && tmp<=1999) colors[4]++;
    else if(2000<=tmp && tmp<=2399) colors[5]++;
    else if(2400<=tmp && tmp<=2799) colors[6]++;
    else if(2800<=tmp && tmp<=3199) colors[7]++;
    else colors[8]++;
  }

  int m = 0,M = 0;
  rep(i,num_c-1){
    if(colors[i]>0){
      m++;
      M++;
    }
  }
  if(m==0) m++;
  M+=colors[8];

  printf("%d %d\n",m,M);
  
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< int > l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    int ans = 0;
    sort(l.begin(), l.end());
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          for(int k=j+1; k<n;k++){
          	if(abs(l[i]-l[j])<l[k]&&l[k]<l[i]+l[j])	ans++;
          }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    if(n==1){
      System.out.println(array[0]+" "+array[0]+" "+array[0]);
    }else{
      int min=array[0];
      for(int i=0;i<array.length-1;i++){
        min=Math.min(min,array[i+1]);
      }
      int max=array[0];
      for(int i=0;i<array.length-1;i++){
        max=Math.max(max,array[i+1]);
      }
      long sum=0;
      for(int i=0;i<array.length;i++){
        sum+=array[i];
      }
      System.out.println(min+" "+max+" "+sum);
    }
  }
}


Measured memory_bytes: 41232
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<"\n";//cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1e5+10;

vector<int> arr(N),siz(N,1);
int cur;

void init(int n)
{
    for(int i=1;i<=n;++i)
        arr[i]=i;
}

int root(int x)
{
    while(x!=arr[x])
    {
        arr[x]=arr[arr[x]];
        x=arr[x];
    }

    return x;
}

void uni(int a,int b)
{
    int ra=root(a);
    int rb=root(b);
    if(ra==rb)
        return;

    if(siz[ra]<siz[rb])
        swap(ra,rb);

    arr[rb]=ra;

    cur-=siz[ra]*siz[rb];			//the crux

    siz[ra]+=siz[rb];
    siz[rb]=0ll;
}

void solve()
{
    int n,m;
    cin>>n>>m;

    vector<pii> v(m);
    for(int i=m-1;i>=0;--i)
        cin>>v[i].F>>v[i].S;

    init(n);

    vector<int> ans(m);
    cur=(n*(n-1))/2;
    for(int i=0;i<m;++i)
    {
        ans[m-1-i]=cur;
        uni(v[i].F,v[i].S);
    }

    show(ans);
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 5248
#include<iostream>
using namespace std;
int main(){
  int sum=0;
  int a;
  for(int i=0; i<5; i++){
    cin >> a ;
    if(a<40){
      sum+=40;
    }else{
      sum+=a;
    }
  }
  cout << sum/5 << endl;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>

using namespace std;

string read;
string s;

int main()
{
    cin >> read;
    for(int i = 0;i < read.size();i++){
      if(read[i] == 'B'){
        if(s.size() > 0){
          s.pop_back();
        }
      }else{
        s.push_back(read[i]);
      }
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "4", "2 5 4 6" ].solve == 5 );
	assert( [ "9", "0 0 0 0 0 0 0 0 0" ].solve == 45 );
	assert( [ "19", "885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1" ].solve == 37 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	// 2進数表記で繰り上がりのない足し算とbit和がイコールなので、xorとbit和がイコールになる状態、つまりas[l..r]で各bitごとの合計が0か1なら条件を満たせる
	// 条件が成り立つ範囲内ならlとrを内側にずらしても条件が成り立たなくなることは無いので、しゃくとり法で計算できる
	auto ans = as.length.signed;
	auto t = 0L;
	for( auto l = 0L, r = 0L; l < as.length; t -= as[ l ], l++ )
	{
		for( ; r < as.length && t + as[ r ] == ( t ^ as[ r ] ); t += as[ r ], r++ )
		{
			ans += r - l;
		}
	}
	return ans;
}


Measured memory_bytes: 11724
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define pb push_back
#define X first
#define Y second
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
#ifdef umang99m
    #include "/home/umang/Desktop/folder/home/.templates/header.h"
#else
    #define dbg(args...)
    #define timer()
#endif
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<vi>out(n, vi(0)), in(n,vi(0));
    vi outd(n,0);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        out[x].pb(y);
        outd[x]++;
        in[y].pb(x);
    }
    queue<ll>q;
    for(int i=0; i<n; i++){
        if(outd[i] == 0){
            q.push(i);
        }
    }
    vi topo;
    while(!q.empty()){
        ll cur = q.front();
        q.pop();
        topo.pb(cur);
        for(auto x: in[cur]){
            outd[x]--;
            if(outd[x] == 0){
                q.push(x);
            }
        }
    }

    vi dp(n,1);
    vi tpos(n,0);
    rep(i,n) tpos[topo[i]]=i;
    rep(i,n){
        for(auto x: in[topo[i]]){
            dp[tpos[x]] = max(dp[tpos[x]], dp[i]+1);
        }
    }
    // dbg(dp);
    // dbg(out);
    // dbg(topo);
    cout<<*max_element(dp.begin(), dp.end())-1<<endl;;


    timer();
    return 0;
}

Measured memory_bytes: 14456
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a){
    cout<<k;
    return 0;}
  if(k>a&&k<=a+b){
    cout<<a;
    return 0;}
  if(k>a+b){
    cout<<a-(k-a-b);
    return 0;
  }
  
	return 0;
}

Measured memory_bytes: 3636
b=[[] for i in range(10)]
b[0]=[1,2,3,4,5,6,7,8,9]
for j in range(9):  
    for k in b[j]:
        b[j+1].append(int(str(k)+str(k)[-1]))
        if str(k)[-1]!="9":b[j+1].append(int(str(k)+str(int(str(k)[-1])+1)))
        if str(k)[-1]!="0":b[j+1].append(int(str(k)+str(int(str(k)[-1])-1)))            
    b[j+1]=list(set(b[j+1]))
c=[]
for j in range(10): c=c+b[j]
c=sorted(c)
print(c[int(input())-1])

Measured memory_bytes: 18124
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve m ps
 
solve :: Int -> [Pair] -> Int
solve m = fst . foldl' f e
  where
    e = (0,0)
    f (!s,!n) (a,b)
      | n == m = (s,n)
      | n+b > m = until ((m==).snd) (\(!s,!n) -> (s+a,n+1)) (s,n)
      | otherwise = (s+a*b, n+b)

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = do
  [x,y] <- readInts
  return (x,y)

Measured memory_bytes: 56700
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b, c, x, y = map(int, input().split())
    z = min(x, y)
    if c >= (a + b) * 0.5:
        return x * a + y * b
    else:
        if c < a * 0.5 and c < b * 0.5:
            return c * 2 * max(x, y)
        elif c < a * 0.5:
            return c * 2 * x + max(0, y - x) * b
        elif c < b * 0.5:
            return c * 2 * y + max(0, x - y) * a
        else:
            return c * 2 * z + (x - z) * a + (y - z) * b

print(main())


Measured memory_bytes: 3700
import com.sun.security.jgss.GSSUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader r=new FastReader();
    public static final int INF=1000000005;

    public static int []f;
    public static int find(int x){
        if(f[x]==x) return x;
        return f[x]=find(f[x]);
    }
    public static void main(String[] args) {
        int n=r.nextInt();
        int q=r.nextInt();
        f=new int[n];
        for(int i=0;i<n;++i){
            f[i]=i;
        }
        while(q-->0){
            int t=r.nextInt();
            int u=r.nextInt();
            int v=r.nextInt();
            if(t==0){
                int uu=find(u);
                int vv=find(v);
                f[vv]=uu;
            }
            else{
                int uu=find(u);
                int vv=find(v);
                if(uu==vv) System.out.println(1);
                else System.out.println(0);
            }
        }
    }
}


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

int main() {
    int n=3;
    string c[n];
    for(int i=0; i<n; i++){
        cin>>c[i];
    }
    for(int i=0; i<n; i++){
        cout<<c[i][i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1,j=m+1;i<j;i++,j--){
        cout<<i<<" "<<j<<endl;
    }
    
    for(int i=m+2,j=m*2+1;i<j;i++,j--){
        cout<<i<<" "<<j<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

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

money = 1000
for i in range(len(a)-1):
    if a[i] < a[i+1]:
        money += (money//a[i]) * (a[i+1]-a[i])
    else:
        continue
print(money)

Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 200005
using namespace std;
int n,a[N];
int mp1[N],mp2[N];
int mx=0,pos=0,mn=0;
int mx2=0,pos2=0,mn2=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",a+i);
for(int i=1;i<=n;i+=2){mp1[a[i]]++;if(mp1[a[i]]>mx)mx=mp1[a[i]],pos=a[i];else if(mp1[a[i]]>mn)mn=mp1[a[i]];}
for(int i=2;i<=n;i+=2){mp2[a[i]]++;if(mp2[a[i]]>mx2)mx2=mp2[a[i]],pos2=a[i];else if(mp2[a[i]]>mn2)mn2=mp2[a[i]];}
// cout<<mx<<" "<<pos<<" "<<mx2<<" "<<pos2<<endl;
if(pos!=pos2)  printf("%d\n",n-mx-mx2);
else   printf("%d\n",n-max(mx+mn2,mx2+mn));
return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N < 105){
        cout << 0 << endl;
    }else{
        if(N < 3*3*3*5){
            cout << 1 << endl;
        }else if(N < 3*5*11){
            cout << 2 << endl;
        }else if(N < 3*3*3*7){
            cout << 3 << endl;
        }else if(N < 3*5*13){
            cout << 4 << endl;
        }else{
            cout << 5 << endl;
        }
    }
}

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

long long int N, b, c;

int main(){
    scanf("%lld", &N);
    vector<long long> A(N);
    for(int i = 0; i < N; ++i)scanf("%lld", &A[i]);
    sort(A.begin(), A.end());
    if(N == 2)return 0 & printf("%lld %lld\n", A[1], A[0]);
    auto a = lower_bound(A.begin(), A.end() - 2, *A.rbegin() / 2);
    b = *a;
    if(a - A.begin() >= 1)c = *(a - 1);
    else c = -1;
    printf("%lld %lld\n", *A.rbegin(), 2 * b - *A.rbegin() > *A.rbegin() - 2 * c ? c : b);
    return 0;
}


Measured memory_bytes: 1024
import math
a, b = map(int, input().split())

ma_min, ma_max = math.ceil(a / 0.08), math.ceil((a + 1) / 0.08 - 1)
mb_min, mb_max = math.ceil(b / 0.1), math.ceil((b + 1) / 0.1 - 1)

tmp_ans = max(ma_min, mb_min)
if ma_min <= tmp_ans <= ma_max and mb_min <= tmp_ans <= mb_max:
    ans = tmp_ans
else:
    ans = -1
print(ans)

Measured memory_bytes: 9200
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int mx;
int main(){
	int n,k,s;
	cin>>n>>k>>s;
	if(s==1000000000)mx=s-1;
	else mx=s+1;
	if(k==0){
		for(int i=0;i<n;i++)cout<<mx<<" ";
		return 0;
	}
	for(int i=0;i<k;i++)cout<<s<<" ";
	for(int i=0;i<n-k;i++)cout<<mx<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int main(){
  int64_t N,X;cin>>N>>X;
  vector<int64_t>S(N);
  for(int i=0;i<N;i++)
    cin>>S.at(i);
  sort(S.begin(),S.end());
  vector<vector<int64_t>>dp(N,vector<int64_t>(1+X,0));
  for(int j=0;j<=X;j++)
    dp[0][j]=j%S.at(0);
  for(int i=1;i<N;i++)
    for(int j=1;j<=X;j++){
    dp[i][j]=(i*dp[i-1][j]+dp[i-1][j%S[i]])%mod;
    }cout<<dp[N-1][X]<<endl;
  return 0;
}

Measured memory_bytes: 160700
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  int64_t x, y;
  cin >> x >> y;
  int64_t a = x;
  int64_t ans = 0;
  while (a <= y) {
    a *= 2;
    ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  int n,k;
  cin>>n>>k;
  int a[n];
  frn(i,n) cin>>a[i];
  int total = 0;
  frn(i,n) {
    total += min(2*a[i], 2*(k-a[i]));
  }
  cout<<total;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=8;
int row[N],col[N],lt[N*N],rb[N*N];
int n;
int ans[N][N];
void print()
{
    for(int r=0; r<N; r++)
    {
        for(int c=0; c<N; c++)
        {
            if(ans[r][c]==1)
            {
                if(row[r]!=c) return;
            }
        }
    }
    for(int r=0; r<N; r++)
    {
        for(int c=0; c<N; c++)
        {

            if(row[r]==c) printf("Q");
            else printf(".");

        }
        printf("\n");
    }
}
void recursive(int r)
{
    if(r==N)
    {
        print();
        return;
    }
    for(int c=0; c<N; c++)
    {
        if( col[c]==1||lt[r+c]==1||rb[c-r]==1) continue;
        row[r]=c;
        col[c]=lt[r+c]=rb[c-r]=1;
        recursive(r+1);
        row[r]=col[c]=lt[r+c]=rb[c-r]=-1;
    }
}

int main(void)
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int r,c;
    for(int i=0; i<N; i++)
    {
        row[i]=col[i]=-1;
    }
    for(int i=0; i<2*N; i++)
    {


        lt[i]=rb[i]=-1;

    }
    while(n--)
    {
        scanf("%d%d",&r,&c);
        ans[r][c]=1;

    }
    recursive(0);


    return 0;
}

Measured memory_bytes: 2660
def solve():
  N = int(input())
  X = input()
  bl = X.count('1')
  bitp = 0
  for i in range(N):
    bitp += int(X[i])*pow(2,N-1-i,bl+1)
    bitp %= bl+1
  bitm = 0
  if bl>1:
    for i in range(N):
      bitm += int(X[i])*pow(2,N-1-i,bl-1)
      bitm %= bl-1
  
  ans = [0]*N
  dp = [0]*(N+1)
  for i in range(1,N+1):
    dp[i] = dp[i%(bin(i).count('1'))]+1
  for i in range(N):
    if X[i]=='1':
      bl1 = bl-1
      if bl1==0:
        ans[i] = 0
        continue
      bit1 = bitm - pow(2,N-1-i,bl1)
    else:
      bl1 = bl+1
      bit1 = bitp + pow(2,N-1-i,bl1)
    ans[i] = dp[bit1%bl1]+1
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 85208
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[]= new int[n];
    for(int i=0; i<n; i++){
        A[i] = sc.nextInt();
    }
    int q = partition(A, 0, n-1);
    for(int i=0; i<n; i++){
        if(i!=0) System.out.print(" ");
        if(i==q) System.out.print("[");
        System.out.print(A[i]);
        if(i==q) System.out.print("]");
    }
    System.out.println();
    }
     
    public static int partition(int A[], int p, int r){
    int t;
    int x = A[r];
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j]<=x){
        i++;
        t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i+1;
    }
}

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

const ll mod=1e9+7;

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

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> num;
    int now=1;
    int cnt=0;
    rep(i,n){
      if(s[i]==(char)(now+'0')){
        cnt++;
      }else{
        num.push_back(cnt);
        now=1-now;
        cnt=1;
      }
    }
    if(cnt!=0) num.push_back(cnt);
    if(len(num)%2==0) num.push_back(0);
    int ans=0;
    for(int i=0;i<len(num);i+=2){
      int right=i;
      int left=min(i+2*k,(int)len(num)-1);
      int check=0;
      for(int j=right;j<=left;j++){
        check+=num[j];
      }
      ans=max(ans,check);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1020
N = int(input())
S = [input()[:1] for _ in range(N)]
c = [S.count(s) for s in 'MARCH' if S.count(s)]
ans = 0
if len(c) > 2:
    ans += c[0]*c[1]*c[2]

if len(c) > 3:
    for i in c[3:]:
        for j in range(3):
            tmp = c[:3]
            tmp[j] = i
            ans += tmp[0]*tmp[1]*tmp[2]
if len(c) > 4:
    tmp = c[3:]
    for j in range(3):
        ans += tmp[0]*tmp[1]*c[j]
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long
const ll M = 1e9 + 7;

int32_t main(){
	ll n, k, ans = 0, su1 = 0, su2 = 0;
	cin >> n >> k;
	for (ll i = 0; i <= n; i++){
		su1 += i;
		su2 += n - i;
//		cout << su1 << ' ' << su2 << endl;
		if (i >= k - 1){
			ans += su2 - su1 + 1;
			ans %= M;
//			cout << ans << endl;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int l,r;
    cin>>l>>r;
    int x=2019,f=0;
    for(int i=l;i<=r;i++)
    {
        for(int j=i+1;j<=r;j++)
        {
            x=min(x,((i%2019)*(j%2019))%2019);
            if(x==0)
            {
               f=1;
               break;
            }
            
        }
        if(f)
            break;
    }

    cout<<x;
    
}


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

#define IO                       \
    std::ios_base::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define LL long long
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;

const int INF = 0x3f3f3f3f;

int main(void) {
    IO;

    int a, b;
    cin >> a >> b;

    if (a > b) {
        string s(a, b+'0');
        cout << s << endl;
    } else {
        string s(b,a+'0');
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >> S;
  
  if (K >= S.size()) {
    cout << S << endl;
  } else {
    string _s = "";
    for (int i = 0; K > i; i++ ) {
      _s.push_back(S.at(i));
    }
    cout << _s << "..." << endl;
  }
}

Measured memory_bytes: 3624
n = int(input())
A = list(map(int, input().split()))
max_val = max(A)
half = max_val // 2
r = None
diff = float('inf')
for a in A:
    d = abs(half - a)
    if d < diff and a != max_val:
        diff = d
        r = a
print(max_val, r)

Measured memory_bytes: 14052
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

int main()
{
	std::size_t N, K;
	std::cin >> N >> K;

	std::vector<std::pair<std::size_t, std::size_t>> set;

	for (std::size_t i = 0; i < N; i++) {
		std::size_t a_i, b_i;
		std::cin >> a_i >> b_i;
		set.emplace_back(a_i, b_i);
	}

	std::sort(set.begin(), set.end());

	std::size_t k = 0;
	for (const auto& s : set) {
		if (K <= k + s.second) {
			std::cout << s.first << std::endl;
			break;
		}
		k += s.second;
	}

	return 0;
}

Measured memory_bytes: 2420