akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll N, M;
vector<ll> A;

void solve(){
  cin >> N >> M;
  A.resize(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
   ll use = A[N-1] + A[N-1];
   ll unuse = 0;
   while(use - unuse > 1){
     ll mid = (use + unuse) / 2;
     ll cnt = 0;
     rep(i, N){
       ll x = upper_bound(A.begin(), A.end(), mid - A[i]) - A.begin();
       cnt += N - x;
     }
     if(cnt > M){
       unuse = mid;
     }else{
       use = mid;
     }
   }
   vector<ll> sum(N+1, 0);
   rep(i, N) sum[i+1] = sum[i] + A[i];

   ll ans = 0;
   rep(i, N){
     ll x = upper_bound(A.begin(), A.end(), use - A[i]) - A.begin();
     M -= (N - x);
     ans += (N - x) * A[i];
     ans += sum[N] - sum[x];
   }
   ans += M * use;
   cout << ans << endl;
}

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


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 2e5 + 5;

typedef long long ll;

int n, mn1 = inf, mn2 = inf, mx1, mx2;
ll ans = 2e18;
pair <int, int> a[N];

int main()
{
    cin >> n;

    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i].fr >> a[i].sc;
        if(a[i].fr > a[i].sc) swap(a[i].fr, a[i].sc);
        mn1 = min(a[i].fr, mn1);
        mn2 = min(a[i].sc, mn2);
        mx1 = max(a[i].fr, mx1);
        mx2 = max(a[i].sc, mx2);
    }

    ans = mx1 - mn1;
    ans *= (mx2 - mn2);

    sort(a + 1, a + n + 1);

    mx1 = mx2, mn2 = a[2].fr;

    ll l = 1e9, r = a[n].fr;
    for(int i = 1; i <= n; i ++)
    {
        l = min(l, a[i].sc * 1ll);
        r = max(r, a[i].sc * 1ll);
        ans = min(ans, (mx1 - mn1) * 1ll * (r - min(l, a[i + 1].fr * 1ll)));
    }
    cout << ans << endl;
}


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

int main() {
	string S;
	static long long D, DP[10010][100][10] = {}, MOD = 1000000007;
	cin >> S >> D;
	DP[0][0][0] = 1;
	for (int i = 1; i <= S.size(); i++) {
		for (int j = 0; j < D; j++) {
			for (int k = 0; k < 10; k++) {
				for (int l = 0; l < 10; l++) {
					DP[i][(j + l) % D][l] += DP[i - 1][j][k];
					DP[i][(j + l) % D][l] %= MOD;
				}
			}
		}
	}
	long long NOW = 0, ANS = 0;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S[i] - '0'; j++) {
			ANS += DP[S.size() - i][NOW][j];
			ANS %= MOD;
		}
		NOW = (NOW - (S[i] - '0') % D + D) % D;
	}
	if (NOW != 0) ANS = (ANS - 1 + MOD) % MOD;
	cout << ANS << endl;
}

Measured memory_bytes: 78464
package main

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

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getScanner() *bufio.Scanner {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func main() {
	scanner := getScanner()

	writer := bufio.NewWriter(os.Stdout)

	ll := getNextString(scanner)

	l := len(ll)
	dp := make([][2]int, l+1)
	dp[0][0] = 2
	dp[0][1] = 1

	for i := 1; i < l; i++ {
		for ii := 0; ii < 2; ii++ { // 未満確定かどうか
			if ii == 1 {
				dp[i][1] += dp[i-1][ii] * 3
				dp[i][1] %= 1000000007
				continue
			}
			dp[i][0] += dp[i-1][ii]

			if ll[i] == '1' {
				dp[i][0] += dp[i-1][ii]
				dp[i][1] += dp[i-1][ii]
			}
			dp[i][0] %= 1000000007
			dp[i][1] %= 1000000007
		}
	}

	fmt.Fprintln(writer, (dp[l-1][0]+dp[l-1][1])%1000000007)
	writer.Flush()
}


Measured memory_bytes: 2432
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

#define lowbit(x) (x)&(-x)

const int maxn=(int)(3e5)+5;
int a[maxn],C[maxn],res[maxn];
int n,m;

struct node {
    int x,ty,r,sgn,id;
    node() {x=ty=r=id=sgn=0;}
} p[maxn*22];

inline bool operator < (node a,node b) {
    if(a.x!=b.x) return a.x<b.x;return a.ty<b.ty;
}

inline void add(int x,int v) {
    for(;x<=m;x+=lowbit(x)) C[x]+=v;
}

inline int sum(int x) {
    int res=0;
    for(;x;x-=lowbit(x)) res+=C[x];
    return res;
}

int main() {
    int tot=0;
    read(n);read(m);
    REP(i,1,n) {
        int l,r;
        read(l);read(r);
        ++tot;p[tot].x=l;p[tot].ty=0;p[tot].r=r;p[tot].id=i;
    }
    REP(i,1,m) {
        int tmp=0;
        for(int j=0;j*i<=m;j++) a[++tmp]=j*i;if(a[tmp]!=m) a[++tmp]=m+1;
        REP(j,2,tmp) {
            int l=a[j-1],r=a[j];
            if(l+1<=r-1) {
                l++;r--;
                ++tot;p[tot].x=l-1;p[tot].ty=1;p[tot].sgn=-1;p[tot].r=r;p[tot].id=i;
                ++tot;p[tot].x=  r;p[tot].ty=1;p[tot].sgn= 1;p[tot].r=r;p[tot].id=i;
            }
        }
    }
    sort(p+1,p+tot+1);
    REP(i,1,tot) {
        if(p[i].ty==0) add(p[i].r,1);
        else res[p[i].id]+=p[i].sgn*sum(p[i].r);
    }
    REP(i,1,m) printf("%d\n",n-res[i]);
    return 0;
}

Measured memory_bytes: 131072
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

ll n , cost[4];

int main(){
    rep(i,0,4) cin >> cost[i];
    cin >> n;
    rep(i,1,4) cost[i] = min(cost[i] , cost[i-1] * 2);
    n *= 4;
    ll ans = 0;
    per(i,0,4) {
        ll c = n >> i;
        ans += c * cost[i];
        n -= c << i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int d;

    scanf("%d", &d);
    switch(d){
        case 25:
            printf("Christmas\n");
            break;
        case 24:
            printf("Christmas Eve\n");
            break;
        case 23:
            printf("Christmas Eve Eve\n");
            break;
        case 22:
            printf("Christmas Eve Eve Eve\n");
            break;
    } 
    return 0;
}

Measured memory_bytes: 1628
T=str(input())
T2=list(T)
if T2[0]=="?":
    T2[0]="D"

if T2[len(T)-1]=="?":
    T2[len(T)-1]="D"

for i in range(1,len(T2)-1):
    if T2[i]=="?":
        if T2[i-1]=="D" and T2[i+1]!="P":
            T2[i]="P"
            
        else:
            T2[i]="D"
ans="".join(T2)    
print(ans)

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

int main(){
  string S,T;
  cin >> S >> T;
  int ans=T.size();
  for(int i=0; i<=S.size()-T.size(); i++){
    int diff=0;
    for(int j=0; j<T.size(); j++){
      if(T[j]!=S[i+j]){
        diff++;
      }
    }  
    ans = min(ans,diff);
  }
  cout << ans << endl;
  return 0;
}  

Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    int K;
    cin >> s >> K;
    set<string> Q;
    int L = s.size();
    for (int i = 0;i < L;i++) {
        for (int j = 1;j <= 5;j++) {
            if (i + j <= L) Q.insert(s.substr(i, j));
        }
    }
    set<string>::iterator it = Q.begin();
    for (int i = 1;i < K;i++) it++;
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main ()
{
    int a=0;
    int b=0;
    cin>>a>>b;
    (a==b)?cout<<"Yes":cout<<"No";
   /* int z=0;
    for (int i=1;i<100000;i++)
    {
     a=a-b;
     if(a<=0){
     cout<<i<<endl;
      break;}
    }*/
    return 0;
}


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

int main(void)
{

    long long L, R;
    long long divL, divR;
    long long modL;
    long long modR;
    long long min;

    cin >> L >> R;

    modL = L % 2019;
    modR = R % 2019;
    divL = (L - modL) / 2019;
    divR = (R - modR) / 2019;
    min = __LONG_LONG_MAX__;

    if (divL != divR)
    {
        cout << 0 << endl;
    }
    else
    {
        for (long long i = L; i < R; i++)
        {
            for (long long k = i + 1; k <= R; k++)
            {
                if ((i * k) % 2019 == 0)
                {
                    cout << 0 << endl;
                    return 0;
                }
                
                if (min > (i * k) % 2019)
                {
                    min = (i * k) % 2019;
                }
            }
        }

        cout << min << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: usize = read()[0];
    let v: Vec<Vec<Vec<usize>>> = (0..n)
        .map(|_| {
            let m: usize = read()[0];
            (0..m).map(|_| read()).collect()
        })
        .collect();

    let mut ans = 0;
    for b in 0..1 << n {
        if (0..n).all(|j| (b >> j) & 1 == 0 || v[j].iter().all(|q| (b >> (q[0] - 1)) & 1 == q[1])) {
            ans = std::cmp::max(ans, b.count_ones());
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

// char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
//        'j','k','l','m','n','o','p','q','r','s','t','u','v',
//        'w','x','y','z'};


int32_t main(){
 	fastIO;
	int n;
	cin>>n;
	set<string> st;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		st.insert(s);
	}
	cout<<st.size()<<endl;
}		



Measured memory_bytes: 19244
N, X = [int(i) for i in input().split(' ')]
from collections import deque

import sys
hs = []
for line in sys.stdin:
    h, = line.strip().split(" ")
    hs.append(int(h))
hs = deque(sorted(hs))
counter = 0

minh = None
for i in range(N):
    if (i + (X-1)) > N-1:
        break
    ch = hs[i+(X-1)] - hs[i]
    if minh == None:
        minh = ch
    elif ch < minh:
        minh = ch
print(minh)


Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int r=0;
	for(int i=0;i<=n;i++){
		int c=0;
		int t=i;
		for(int j=0;j<5;j++)c+=t%10,t/=10;
		if(a<=c&&c<=b)r+=i;
	}printf("%d\n",r);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var gcd = GCD(AB[0], AB[1]);

            var isPrime = new bool[(int)Math.Sqrt(gcd) + 1];
            for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            isPrime[0] = false; isPrime[1] = false;
            for (int i = 2; i < isPrime.Length; i++)
            {
                if (isPrime[i]) continue;
                for (int j = 2; i * j < isPrime.Length; j++) isPrime[i * j] = false;
            }

            var primefactor = new List<int>();
            for (int i = 2; i <= Math.Sqrt(gcd); i++)
            {
                if (!isPrime[i]) continue;
                if (gcd % i != 0) continue;
                primefactor.Add(i);
                while (gcd % i == 0) gcd /= i;
            }
            if (gcd != 1) primefactor.Add((int)gcd);
            Console.WriteLine(primefactor.Count + 1);
        }

        static long GCD(long A, long B)
        {
            if (B > A) return GCD(B, A);
            if (A % B == 0)
            {
                return B;
            }
            else
            {
                return GCD(B, A % B);
            }
        }
    }
}

Measured memory_bytes: 13220
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(v) begin(v), end(v)

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

	constexpr int mod = 10007;

	int idx[128];
	idx['J'] = 0;
	idx['O'] = 1;
	idx['I'] = 2;

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<int> dp(1 << 3, 0);
	dp[(1 << idx['J'])] = 1;

	for(const auto &c : s) {
		const int id = idx[c];
		vector<int> next(1 << 3, 0);

		rep(i, 1 << 3) {
			rep(j, 1 << 3) {
				if((j & i) && (j & (1 << id))) {
					next[j] = (next[j] + dp[i]) % mod;
				}
			}
		}

		dp = move(next);
	}

	cout << accumulate(ALL(dp), 0) % mod << endl;

	return EXIT_SUCCESS;
}

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

using namespace std;
using ll = long long;

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

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    string s;
    cin >> s;
    int c = 0;
    for(int i = 0; i < sz(s); i++)
    {
        if(c&(1<<(s[i]-'a'))){
            cout << "no" << endl;
            return 0;
        }
        c |= (1 << (s[i] - 'a'));
    }

    cout << "yes" << endl;

    return 0;
}

Measured memory_bytes: 256
# ABC 106: B – 105
n = int(input())
num = 0

for i in range(1, n + 1, 2):
    divides = 0

    for j in range(1, i + 1):
        if i % j == 0:
            divides += 1

    if divides == 8:
        num += 1

print(num)

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

int main(){
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double s=30*h+m/2,l=6*m;
  double x=(max(s,l)-min(s,l))*acos(-1)/180;
  printf("%.12f\n",sqrt(a*a+b*b-2*a*b*cos(x)));
}

Measured memory_bytes: 4160
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    using namespace std;
    using Graph = vector<vector<int>>;

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    const int dx[4] = {1,0,-1,0};
    const int dy[4] = {0,1,0,-1};
    
    
    
    int main(){
      int n;
      cin>>n;
      VEC(double,v,n);
      sort(v.begin(),v.end());
      double sum = (v[0]+v[1])/2;
      REP(i,2,n-1){
        sum = (sum+v[i])/2;
      }
      cout <<sum;
    }

    

    

Measured memory_bytes: 256
#include <iostream>

int gcd(int a,int b){
  int x=std::min(a,b),y=std::max(a,b);
  bool c=true;
  while (x!=0&&y!=0){
    if(c)y%=x;
    else x%=y;
    c=!c;
  }
  return x+y;
}
int main(){
  int n,i,ans;
  std::cin>>n;
  int a[n],l[n],r[n];
  for (i=0;i<n;i++)std::cin>>a[i];
  l[0]=a[0];r[0]=a[n-1];
  for (i=1;i<n;i++){
    l[i]=gcd(l[i-1],a[i]);
    r[i]=gcd(r[i-1],a[n-1-i]);
  }
  ans=std::max(l[n-2],r[n-2]);
  for (i=0;i<n-2;i++)ans=std::max(ans,gcd(l[i],r[n-3-i]));
  std::cout<<ans<<'\n';
}


Measured memory_bytes: 1408
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b)
  l[b-1].append(a)
ans=[-1]*n
ans[0]=0
x=[1]
y=[]
count=1
while x!=[]:
  for i in x:
    for j in l[i-1]:
      if ans[j-1]==-1:
        ans[j-1]=i
        y.append(j)
        count+=1
  x=y
  y=[]
print('Yes')
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 33916
n,m = map(int,input().split())
a = set()
b = set()
for i in range(m):
    a_,b_ = map(int,input().split())
    if a_ == 1:
        a.add(b_)
    if b_ == n:
        b.add(a_)
print("POSSIBLE" if a&b else "IMPOSSIBLE")

Measured memory_bytes: 18892
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,res=0,maxcol=0,mod;
	vector<int> a;
	cin >> n;
	a.resize(n);
	for(int i=0;i<n;i++){cin >> a[i];maxcol=max(maxcol,a[i]);}
	while(true){
		mod=0;
		for(int i=0;i<n-2;i++){
			if(a[i]==a[i+1]&&a[i+1]==a[i+2]){
				a.erase(a.begin()+i,a.begin()+i+2);
				n-=2;mod++;res++;
			}
		}
		if(mod==0)break;
	}
	while(true){
		mod=0;
		for(int i=0;i<n-1;i++){
			if(a[i]==a[i+1]){
				if(0<=i-1&&i+2<=n-1&&a[i-1]==a[i+2])a[i]=++maxcol;
				else{
					a.erase(a.begin()+i,a.begin()+i+2);
					n-=2;
				}
				mod++;res++;
			}
		}
		if(mod==0)break;
	}
	cout << res << endl;
	return 0;
}


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

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i];

	ll sum{0}, res{0}, r{0};
	for (ll l = 0; l < N; ++l)
	{
		while (r < N && (sum + A[r] == (sum ^ A[r])))
		{
			sum += A[r];
			++r;
		}
		res += r - l;
		if (r == l) ++r;
		else sum -= A[l];
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define int long long

signed main() {
	int a,b;
	cin >> a >> b;
	//vector<int> a(n);
	int ans = 0;
	if (a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}
	if (a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
tmp = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        tmp += 1
print(tmp)

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    L = lmi()
    current_min = float('inf')
    cnt = 0
    for elm in L:
        if elm <= current_min:
            cnt += 1
            current_min = elm
    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25716
rept :: Int -> Int -> (a,a) -> [a]
rept n i dt@(a,b)
  | i > n = []
  | (mod i 2) == 1 = a : rept n (i + 1) dt
  | otherwise = b : rept n (i + 1) dt

makeFrame :: Int -> Int -> [String]
makeFrame h w = rept h 1 (fstl,scdl)
  where 
    fstl = rept w 1 ('#','.')
    scdl = rept w 1 ('.','#')

main = do
  contents <- getContents
  let
    dat = takeWhile (/= [0,0])
      $ map (map (read :: String -> Int))
      $ map words
      $ lines contents
    ansList = map (\[h,w] -> makeFrame h w) dat
  mapM_ (putStrLn . unlines) ansList


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

#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rnd(time(0));
#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("avia.in", "r", stdin); freopen("avia.out", "w", stdout);
#define _GLIBCXX_DEBUG
//#define s second
//#define f first
#define pb push_back
#define add insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pii pair<int,int>
#define res resize
#define NO cout<<"NO"<<'\n'; return;
#define YES cout<<"YES"<<'\n'; return;
#define PI acos(-1)
#define gggg cout << "NO";return;
const ll INF = 1e9;//9223372036854775807L; //LONG_MAX;
constexpr ll mod = 1e9 + 7;


void solve() {
    int n;
    cin >> n;
    vector<int> arr(62);
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        for (int j = 0; j < 62; j++)if (x & (1LL << j))arr[j]++;
    }
    ll ans = 0;
    for (int i = 0; i < 62; i++) ans = (ans + ((((((1LL << i) % mod) * arr[i]) % mod) * (n - arr[i])) % mod)) % mod;
    
    cout << ans;
}

signed main() {
    ioss
    //file
    //id.resize(3e5);
    int t = 1;                                                                                                                                                                        //ll
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

bool hoge(char a, char b) {
  // cout << a << b << endl;
  // cout << (a=='(') << " " << (b==')') << endl;
  if (a==')')
    return b=='(';
  if (a=='(')
    return b==')';
  return a==b;
}

int main() {
  string s;
  cin >> s;
  int res = 0;
  for (int i=0, j=s.size()-1; i<j; ++i, --j) {
    if (!hoge(s[i],s[j])) {

      res++;
    }
  }
  if (s.size()%2) 
    if(s[s.size()/2] == '(' || s[s.size()/2] == ')')
      res++;
  cout << res << endl;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] p = new int[m];
        String[] s = new String[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            s[i] = sc.next();
        }

        int ac = 0;
        int wa = 0;
        boolean[] solved = new boolean[n];
        int[] numOfWa = new int[n];
        for (int i = 0; i < m; i++) {
            if (solved[p[i] - 1]) {
                continue;
            }
            if ("AC".equals(s[i])) {
                ac++;
                solved[p[i] - 1] = true;
                wa += numOfWa[p[i] - 1];
            } else {
                numOfWa[p[i] - 1]++;
            }
        }
        System.out.println(ac + " " + wa);
    }

}


Measured memory_bytes: 70864
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    if s[0].is_lowercase() {
        return "a".to_string();
    }

    return "A".to_string();
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(3);
  REP(i, 3) cin >> A[i];

  vector<string> s(N);
  REP(i, N) cin >> s[i];

  vector<char> ans;

  auto push = [&](int p, int q){
    ans.emplace_back('A'+p);
    A[p]++; A[q]--;
  };

  REP(i, N){
    char p = s[i][0]-'A', q = s[i][1]-'A';
    
    if(!A[p] && !A[q]){
      No;
      return 0;
    }
    else if(!A[p]) push(p, q);
    else if(!A[q] || i == N-1) push(q, p);
    else{
      int np = s[i+1][0]-'A', nq = s[i+1][1]-'A';
      if(p == np || p == nq) push(p, q);
      else push(q, p);
    }
  }

  Yes;
  REP(i, N){
    cout << ans[i] << "\n";
  }

  return 0;
}

Measured memory_bytes: 6668
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll inc(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll h,n;
 sc(h);sc(n);
 pr(inc(h,n));
  
return 0;}

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

int main(){
  int n;  cin >> n;
  double t, a; cin >> t >> a;
  vector<double> h(n);  rep(i,n) cin >> h[i];
  int ans = 0;
  double res = abs(a-(t-h[0]*0.006));
  rep(i,n){
    if(res > abs(a-(t-h[i]*0.006))){
      ans = i;
      res = abs(a-(t-h[i]*0.006));
    }
  }
  cout << ans+1;
  return 0;
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
  int K,sum=0;
  cin >> K;
  for(int k=1;k<=K;k++){
    for(int j=1;j<=K;j++){
      for(int i=1;i<=K;i++){
          sum += gcd(gcd(i,j),k);
      }
    }
  }
cout << sum;
return 0;
}

Measured memory_bytes: 3636
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const res = Array.from(Array(n), () => Array.from(Array(n), () => 0));
  lines.forEach((l, i) => l.split(' ').splice(2).forEach(e => res[i][e-1] = 1));
  console.log(res.map(r => r.join(' ')).join('\n'));
})();



Measured memory_bytes: 17100
#include<stdio.h>
int main()
{
    int n,c[510],s[510],f[510],i,j,k,sum=0;
    scanf("%d",&n);
    for(i=1;i<n;i++)
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    for(i=1;i<=n-1;i++)
    {
        sum=s[i]+c[i];
        for(j=1;j<n-i;j++)
        {
            int m;
            if(sum<s[i+j])
                m=s[i+j];
            else
            {
                for(k=1;;k++)
                {
                    m=s[i+j]+k*f[i+j];
                    if(m>=sum && m%f[i+j]==0)break;
                }
            }
            sum=m+c[i+j];
        }
        printf("%d\n",sum);
    }
    if(i==n)printf("0\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    long a,b,c;
    cin >> a >> b >> c;
    if (a%2==0 or b%2==0 or c%2==0)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << min({a*b,b*c,c*a}) << endl;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(ld p){printf("%.12Lf\n",p);}
template<class T>inline                             void outml(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outol(T V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  int N;
  in(N);
  vector<int>A(N),B(N);
  ins(A);ins(B);
  priority_queue<int>q;
  long lack=0;
  long cnt=0;
  long sum=0;
  rep(i,N)sum+=A[i]-B[i];
  if(sum<0){
    out(-1);
    return;
  }
  rep(i,N){
    if(A[i]>B[i])q.push(A[i]-B[i]);
    if(A[i]<B[i])lack+=B[i]-A[i],cnt++;
  }
  while(!q.empty()){
    int e=q.top();q.pop();
    if(lack<=0){
      out(cnt);
      return;
    }
    lack-=e;
    cnt++;
  }
  if(lack<=0)out(cnt);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 1408
import sys

input = sys.stdin.readline


def main():
    X, Y = map(int, input().split())

    if 2 * X <= Y <= 4 * X and Y % 2 == 0:
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	multiset<ll> ms;
	ll N; cin>>N;
	rep(i,N){
		ll tmp; cin>>tmp;
		ms.insert(tmp);
	}
	ll M; cin>>M;
	rep(i,M){
		ll tmp; cin>>tmp;
		auto itr=ms.find(tmp);
		if(itr!=ms.ed){
			ms.erase(itr);
		}
		else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";	
}

Measured memory_bytes: 9600
#include <stdio.h>
 
int main()
{
    int n,i=1,x;
    scanf("%d",&n);
    while(i<=n){
        if(i%3==0){
            printf(" %d",i);
        }
        else{
            if(i%10==3){
                printf(" %d",i);
            }
            else{
                x=i;
                while(x){
                    if(x%10!=3){
                    x/=10;
                    }
                    else{
                        printf(" %d",i);
                        break;
                    }
                }
            }
        }
        i++;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>

long long int kaijou(int k){
    if(k==0)return 1;
    else return (k*kaijou(k-1))%1000000007;
}

int main(void){
    int N,M;
    long long int kotae=1;
    scanf("%d %d",&N,&M);
    if(N<M){
        int kari;
        kari=M;
        M=N;
        N=kari;
    }
    if(N-M>1)printf("0");
    else{
        if(N-M==1)kotae=kaijou(N)*kaijou(M);
        if(N-M==0)kotae=2*kaijou(N)*kaijou(N);
        kotae%=1000000007;
        printf("%lld",kotae);
    }
    return 0;
}


Measured memory_bytes: 1664
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
if D[0] != 0: print(0)
else:
    D = sorted(D)
    levels = [0 for _ in range(D[-1]+1)]
    for d in D:
        levels[d] += 1
    if 0 in levels or levels[0] > 1: print(0)
    else:
        ans = 1
        for l1, l2 in zip(levels, levels[1:]):
            ans = (ans * pow(l1, l2, MOD)) % MOD
        print(ans)

Measured memory_bytes: 14396
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
if N & 1:
    ans1 = 2*sum(A[N//2:])-A[N//2]-A[N//2+1]-2*sum(A[:N//2])
    ans2 = 2*sum(A[N//2+1:])-2*sum(A[:N//2+1])+A[N//2]+A[N//2-1]
else:
    if N == 2:
        ans1 = ans2 = abs(A[0]-A[1])
    else:
        ans1 = 2*sum(A[N//2:])-A[N//2]-2*sum(A[:N//2])+A[N//2-1]
        ans2 = 2*sum(A[N//2+1:])-A[N//2+1]-2*sum(A[:N//2+1])+A[N//2]
print(max(ans1, ans2))


Measured memory_bytes: 51416
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        a[i] = in();
    }

    bool one = true;
    REP(i,n-1){
        if (a[i] >= a[i+1]) one = false;
    }
    if (one){
        cout << 1 << endl;
        return 0;
    }

    int ok = n, ng = 1;
    while (ok - ng > 1){
        int k = (ok + ng) / 2;
        bool f = true;
        map<int, int> mp;

        // cout << "   " << k << endl;
        FOR(i,1,n-1){
            // cout << i << endl;
            if (a[i] > a[i-1]) continue;
            auto itr = mp.lower_bound(a[i]);
            auto itr2 = mp.lower_bound(a[i-1]);
            mp.erase(itr, itr2);
            int x = a[i] - 1;
            mp[x]++;
            while (x > 0) {
                if (mp[x] == k){
                    mp.erase(x);
                    mp[x-1]++;
                    x--;
                }else{
                    break;
                }
            }
            if (mp[0] >= k){
                f = false;
                break;
            }

            // for (P p : mp) cout << p.first << " " << p.second << endl;
        }

        if (f) ok = k;
        else ng = k;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        long count = 0;
        long[] X = new long[N];
        long[] Y = new long[N];
        int[] CX = new int[N];
        int[] CY = new int[N];
        for(int i=0;i<N;i++){
            string[] str = Console.ReadLine().Split(' ');
            X[i] = int.Parse(str[0]);
            Y[i] = int.Parse(str[1]);
            CX[i] = i;
            CY[i] = i;
        }
        Array.Sort(X,CX);
        Array.Sort(Y,CY);
        long[] DX = new long[N-1];
        long[] DY = new long[N-1];
        int[] CDX = new int[N-1];
        int[] CDY = new int[N-1];
        for(int i=0;i<N-1;i++){
            DX[i] = X[i+1]-X[i];
            DY[i] = Y[i+1]-Y[i];
            CDX[i] = i;
            CDY[i] = i;
        }
        Array.Sort(DX,CDX);
        Array.Sort(DY,CDY);
        UnionFind U = new UnionFind(N);
        int p = 0;
        int q = 0;
        while(p < N-1 || q < N-1){
            if(q == N-1 || (p < N-1 && (DX[p] < DY[q]))){
                if(!U.Same(CX[CDX[p]],CX[CDX[p]+1])){
                    U.Union(CX[CDX[p]],CX[CDX[p]+1]);
                    count += DX[p];
                }
                p++;
            }
            else{
                if(!U.Same(CY[CDY[q]],CY[CDY[q]+1])){
                    U.Union(CY[CDY[q]],CY[CDY[q]+1]);
                    count += DY[q];
                }
                q++;
            }
        }
        sb.Append(count+"\n");
    }
}
class UnionFind{
    int[] par;
    public UnionFind(int n){
        par = new int[n];
        for(int i=0;i<n;i++){
            par[i] = i;
        }
    }
    public void Union(int x,int y){
        par[Get(x)] = Get(y); 
    }
    public bool Same(int x,int y){
        return Get(x) == Get(y);
    }
    int Get(int x){
        if(x != par[x]){
            par[x] = Get(par[x]);
        }
        return par[x];
    }
}

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

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

  int temp[5] = {a, b, c, d, e};
  bool flag = true;

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      if (temp[j] - temp[i] > k) {
        flag = false;
      }
    }
  }

  if (flag) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
}


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

const int maxn = 1e5+5;
int N, cost[3][maxn];
int dp[3][maxn];

int f(int t, int i) {
    if (i == N) return 0;
    if (dp[t][i] != -1) return dp[t][i];
    for (int j = 0; j < 3; j++) {
        if (t == j) continue;
        dp[t][i] = max(dp[t][i],f(j,i+1) + cost[j][i]);
    }
    return dp[t][i];
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> cost[j][i];
        }
    }
    memset(dp,-1,sizeof(dp));
    int ans = max(max(f(0,0),f(1,0)),f(2,0));
    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 10368
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>

typedef long long ll;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	cin >> n;
	deque<ll> dq;
	rep(i, n) {
		ll a;
		cin >> a;
		if (i % 2 != n % 2) {
			dq.push_front(a);
		}
		else {
			dq.push_back(a);
		}
	}
	rep(i, n) {
		cout << dq[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3840