akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> finalpos;
long long initpos[100005];
long long finpos[100005];
bool clockwise[100005];
long long finalans[100005];
long long n,l,T;

int main(){
    scanf("%lld%lld%lld",&n,&l,&T);
    for (int x = 0; x<n; x++){
        int t;
        scanf("%lld%d",&initpos[x],&t);

        clockwise[x]= (t==1);

    }
    for (int x = 0; x<n; x++){
        finalpos.push_back(((initpos[x]+(clockwise[x]?T:(-T)))+T*l)%l);
        finpos[x] = finalpos[x];
    }
    sort(finalpos.begin(),finalpos.end());

    int finalnum = 0;
    for (int x = 1; x<n; x++){
        if (clockwise[0]&&!clockwise[x]) {
            finalnum += 2*(T/l);
            int dist1 = initpos[x]-initpos[0];
            int dist2 = dist1+l;
            if ((T%l)*2<=dist1) ;
            else if ((T%l)*2<=dist2) finalnum++;
            else finalnum += 2;

        }
        if (clockwise[x]&&!clockwise[0]){
            finalnum -= 2*(T/l);
            int dist1 = initpos[0]+l-initpos[x];
            int dist2 = dist1+l;
            //printf("d %d\n",dist2);
            if ((T%l)*2<dist1) ;
            else if ((T%l)*2<dist2) finalnum--;
            else finalnum -= 2;
        }
        finalnum%=n;
        //printf("%d\n",finalnum);
    }
    finalnum+=n;
    finalnum%=n;

    int t = lower_bound(finalpos.begin(),finalpos.end(),finpos[0])-finalpos.begin();
    finalans[finalnum] = finalpos[t];
    for (int x = 1; x<n; x++){
        finalans[(finalnum+x)%n] = finalpos[(t+x)%n];
    }
    for (int x = 0; x<n; x++){
        printf("%d\n",finalans[x]);
    }


}


Measured memory_bytes: 4088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string s=cin.next();
        string s1=cin.next();
        string ans="NO";
        if(s[0]==s1[2]&&s[1]==s1[1]&&s[2]==s1[0])ans="YES";
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

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

int main() {
  int N;
  cin >> N;
  
  int a[N+1];
  for (int i = 1; i < N+1; i++) cin >> a[i];
  
  int ans[N+1] = {0};
  int count = 0;
  
  for (int i = N; i > 0; i--) {
    int sum = 0;
    int j = i;
    
    while(j + i <= N) {
      sum += ans[j+i];
      sum %= 2;
      j += i;
    }
    
    ans[i] = abs(sum - a[i]);
    if (ans[i]) count++;
  }
  
  cout << count << endl;
  for (int i = 1; i < N+1; i++) {
    if (ans[i]) {
      cout << i << " ";
    }
  }
  
  
}

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

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int> > v(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> v[i][j];
  for (int i = 0; i < r; i++) {
    v[i][c] = accumulate(v[i].begin(), v[i].end() - 1, 0);
  }
  for (int j = 0; j < c + 1; j++) {
    for (int i = 0; i < r; i++)
      v[r][j] += v[i][j];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << v[i][j];
      if (j < c)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
#define int long long

int A[1000000];

signed main(){
	int N,B,C;
	while(cin>>N,N){
		int cnt[4001]={};
		bool NAflag=true,used[4001]={};
		for(int i=0;i<N;i++){
			cin>>A[i]>>B>>C;
			cnt[A[i]] += B*C;
		}
		for(int i=0;i<N;i++){
			if(cnt[A[i]]>=1000000 && used[A[i]]==false){
				printf("%d\n",A[i]); used[A[i]] = true; NAflag = false;
			}
		}
		if(NAflag==true) puts("NA");
	}
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    int multiple_4 = 0, multiple_2_without_4 = 0;

    rep(i, n)
    {
        if (a.at(i) % 4 == 0)
        {
            multiple_4++;
        }
        else if (a.at(i) % 2 == 0)
        {
            multiple_2_without_4++;
        }
    }

    if (multiple_2_without_4 == 0 & n - multiple_4 - multiple_2_without_4 <= multiple_4 + 1)
    {
        cout << "Yes" << endl;
    }
    else if (multiple_2_without_4 != 0 & n - multiple_4 - multiple_2_without_4 <= multiple_4)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

#define ll long long 
#define inf 1000000007

ll math[25]; // 1 ~ 100までの素因数が25であることは既に計算済み
vector<ll> so;

ll jo (ll x) {
  for (ll i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return 0;  
    }  
  }   
  return 1;
}

void jojo (ll x) {
  for (ll i = 0; i < 25; i++) {
    while (x % so[i] == 0) {
      x = x / so[i];
      math[i]++;    
    }  
  }  
}

int main () {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i <= 100; i++) {
    if (jo(i) == 1) {
      so.push_back(i);
    }
  }
  for (ll i = 0; i < 25; i++) {
    math[i] = 0;  
  }
  for (ll i = 1; i <= n; i++) {
    jojo(i);       
  }
  vector<ll> itr;
  for (ll i = 0; i < 25; i++) {
    if (math[i] >= 2) {
      itr.push_back(i);  
    }
    if (math[i] >= 74) {
      ans++;  
    }
  }
  for (ll i = 0; i < itr.size(); i++) {
    if (math[i] >= 24) {
      for (ll j = 0; j < itr.size(); j++) {
        if (i != j) {
          ans++;  
        }  
      }  
    }  
    if (math[i] >= 14) {
      for (ll j = 0; j < itr.size(); j++) {
        if (i != j && math[j] >= 4) {
          ans++;  
        }  
      }  
    }
  }
  for (ll i = 0; i < itr.size(); i++) {
    // iが2を使う候補
    for (ll j = 0; j < itr.size(); j++) {
      if (i != j && math[j] >= 4) {
        for (ll l = j + 1; l < itr.size(); l++) {
          if (i != l && math[l] >= 4) {
            ans++;    
          }
        }  
      }  
    }
  } 
  cout << ans << endl;  

}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A = []
	for i in range(3):
		a = getlist()
		A.append(a)
	bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

	N = int(input())
	for k in range(N):
		b = int(input())
		for i in range(3):
			for j in range(3):
				if A[i][j] == b:
					bingo[i][j] = 1
	
	judge = "No"
	for i in range(3):
		if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
			judge = "Yes"
	for i in range(3):
		if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
			judge = "Yes"

	if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
		judge = "Yes"
	if bingo[2][0] == 1 and bingo[1][1] == 1 and bingo[0][2] == 1:
		judge = "Yes"

	print(judge)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
use std::error::Error;
use std::io::{self, BufRead, BufWriter, Write};

type AppResult<T> = Result<T, Box<dyn Error>>;

fn solve<R, W>(reader: R, mut writer: W) -> AppResult<()>
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().ok_or("no lines")??;
    let mut splited = a_line.trim().split_whitespace();
    let mut a: u32 = splited.next().ok_or("a not found")?.parse()?;
    let mut b: u32 = splited.next().ok_or("b not found")?.parse()?;
    // let b: u32 = splited.next().ok_or("b not found")?.parse()?;

    let (a, b) = if a < b { (a, b) } else { (b, a) };

    for _ in 1..=b {
        write!(&mut writer, "{}", a)?;
    }
    writeln!(&mut writer, "")?;

    Ok(())
}

fn main() -> AppResult<()> {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output)
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"4 3
", br"3333
",
        ),
        (
            br"7 7
",
            br"7777777
",
        ),
        // (br"", br""),
    ];

    #[test]
    fn test_b() -> AppResult<()> {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output)?;
            let expected_str = String::from_utf8(expected.to_vec())?;
            let output_str = String::from_utf8(output)?;
            assert_eq!(expected_str, output_str);
        }
        Ok(())
    }
}


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

int GetMax(int A, int B, int C, int K){
    auto x = max(A, max(B, C));
    return A + B + C - x + (x << K);
}

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    auto n = GetMax(A, B, C, K);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 

////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define print(...) for(auto xas:{__VA_ARGS__})cerr<<xas<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)
#define coutd(x,y) printf("%0.y lf",x);

////////////////////////////////////////////////////////////////////////////////

typedef vector<int> vec; 
typedef pair<int, int> pa; 
typedef vector<pa> vecp; 
typedef set<int> se;
typedef map<int,int> ma;

////////////////////////////////////////////////////////////////////////////////


bool isprime(int n)
{
    if(n<=1)
        return false;
    for(int i=2;i*i<=n;++i)
    if(n%i==0)
        return false;
    return true;
}

int expo(int a,int n)
{
    if(n==0)
        return 1;
    if(n==1)
        return a;
    int tmp=expo(a,n/2);
    tmp=(tmp*tmp)%mod;
    if(n&1)
        tmp=(tmp*a)%mod;
    return tmp;
}


////////////////////////////////////////////////////////////////////////////////



signed main() {
bew;

    int ans=0;
    tar(n);
    tar(k);
    ++n;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vec ar(n);
    
    loop(n)
        ar[i]=i;
    
    vec pre(n);
    partial_sum(all(ar),pre.begin());
    reverse(all(ar));
    vec suf(n);
    partial_sum(all(ar),suf.begin());
    
    
        
    for(int i=k-1;i<n;++i)
    {
        ans=(ans+suf[i]-pre[i]+1)%mod;
    }
cout<<ans;
    
















return 0;
}

Measured memory_bytes: 7884
#include<iostream>
#include<vector>
#define ll long long
#define mod (1000000007LL)
using namespace std;
vector<vector<int> > adj;
ll ans[100005][2];
vector<bool> vis;
const int WHITE = 0, BLACK = 1;

void edge(int u, int v) {
	adj[u].push_back(v);
	adj[v].push_back(u);
}
ll fix(ll v) {
	v = v % mod;
	if(v < 0)
		v += mod;
	return v;
}
ll dfs(int u) {
	if(vis[u]) return fix(ans[u][WHITE] + ans[u][BLACK]);
	vis[u] = true;
	ll ansWhite = 1;
	ll ansBlack = 1;
	for(int v : adj[u]) {
		if(!vis[v]) {
			dfs(v);
			ansWhite = ansWhite * (ans[v][BLACK] + ans[v][WHITE]) % mod;
			ansBlack = ansBlack * ans[v][WHITE] % mod;
		}
	}
	ans[u][WHITE] = ansWhite;
	ans[u][BLACK] = ansBlack;
	return fix(ans[u][WHITE] + ans[u][BLACK]);
}
int main() {
	int n;
	cin>>n;
	vis.resize(n+1, false);
	adj.resize(n+1);
	for(int i = 1; i < n; i++) {
		int u, v;
		cin>>u>>v;
		edge(u,v);
	}
	cout<<dfs(1)<<endl;
	return 0;
}

Measured memory_bytes: 12800
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int w, h, n; cin >> w >> h >> n;
    vector<vector<bool>> f(w, vector<bool>(h, 0));
    rep(i, n) {
        int X, Y, a; cin >> X >> Y >> a;
        rep(x, w) {
            rep(y, h) {
                if(a == 1) {
                    if(x < X) f[x][y] = 1;
                } else if(a == 2) {
                    if(x >= X) f[x][y] = 1;
                } else if(a == 3) {
                    if(y < Y) f[x][y] = 1;
                } else {
                    if(y >= Y) f[x][y] = 1;
                }
            }
        }
    }
    int ans = 0;
    rep(i, w) {
        rep(j, h) {
            //cerr << (f[i][j] ? '#' : ' ');
            if(f[i][j]) ++ ans;
        }
        //cerr << endl;
    }
    cout << h * w - ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

#define cerr if(0) cout	

const int MAXN = 200005;

vector<int> adj[MAXN];
int num[MAXN], col[MAXN];
vector<tuple<int,int,int> > que;

void dfs(int x, int d, int c) {
	if (!col[x]) col[x] = c;
	if (num[x] >= d) return;
	num[x] = d;
	if (!d) return;
	for (auto it: adj[x]) {
		dfs(it,d-1,c);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u,v;
		cin >> u >> v;
		adj[u].emplace_back(v);	
		adj[v].emplace_back(u);
	}	
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int u,d,c;
		cin >> u >> d >> c;
		que.emplace_back(u,d,c);
	}
	for (int i = q-1; i >=0; --i)  {
		int u,d,c;
		tie(u,d,c) = que[i];
		dfs(u,d,c);
	}
	for (int i = 1; i <= n; ++i) cout << col[i] << '\n';
    return 0;
}


Measured memory_bytes: 11248
import sys
def input(): return sys.stdin.readline().rstrip()
class mod_comb3:
    def __init__(self,mod=10**9+7,n_max=1):
        self.mod,self.n_max=mod,n_max
        self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1]
        if 1<n_max:setup_table(n_max)
    def comb(self,n,r):
        if r<0 or n<r:return 0
        if self.n_max<n:self.setup_table(n)
        return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod
    def setup_table(self,t):
        for i in range(self.n_max+1,t+1):
            self.fact.append(self.fact[-1]*i%self.mod)
            self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod)
            self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod)
        self.n_max=t

def main():
    s = int(input())
    mod = 10**9+7
    mod_c = mod_comb3()
    ans = 0
    for k in range(1,s//3+1):
        ans = (ans + mod_c.comb(s-2*k-1,k-1))%mod
    print(ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 9304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<int> V(N);
    rep(i,N){cin>>V.at(i);}
    vector<int> v(0),u(0);
    rep(i,N){
        if(i%2==0){v.pb(V.at(i));}
        else{u.pb(V.at(i));}
    }
    sort(u.begin(),u.end());
    sort(v.begin(),v.end());
    int cu=1,cv=1;
    vector<P> ut(0),vt(0);
    rep(i,N/2-1){
        if(u.at(i+1)==u.at(i)){
            cu++;
        }
        else{
            ut.pb({cu,u.at(i)});
            cu=1;
        }
        if(v.at(i+1)==v.at(i)){
            cv++;
        }
        else{
            vt.pb({cv,v.at(i)});
            cv=1;
        }
    }
    ut.pb({cu,u.at(N/2-1)});
    vt.pb({cv,v.at(N/2-1)});
    sort(ut.rbegin(),ut.rend());
    sort(vt.rbegin(),vt.rend());
/*rep(i,sz(ut)){
    cout<<"("<<ut.at(i).first<<","<<ut.at(i).second<<")";
}
cout<<endl;
rep(i,sz(vt)){
    cout<<"("<<vt.at(i).first<<","<<vt.at(i).second<<")";
}
cout<<endl;*/
    if(ut.at(0).second!=vt.at(0).second){
        cout<<N-ut.at(0).first-vt.at(0).first<<endl;
        return 0;
    }
    if(ut.size()==1 && vt.size()==1){
        cout<<N/2<<endl;
        return 0;
    }
    if(ut.size()==1){
        cout<<N-ut.at(0).first-vt.at(1).first<<endl;
        return 0;
    }
    if(vt.size()==1){
        cout<<N-ut.at(1).first-vt.at(0).first<<endl;
        return 0;
    }
    cout<<N-max(ut.at(0).first+vt.at(1).first,ut.at(1).first+vt.at(0).first)<<endl;
}

Measured memory_bytes: 5160
// C - Many Medians
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<pair<int,int>> X(N+1);//<value,index>
	rp(i, 1, N+1){
		int x; cin>>x;
		X[i] = make_pair(x, i);
	}
	sort(all(X));
	int mid = N/2;//中央値: ((N-1) + 1)/2 番目
	vi ans(N+1);
	rp(i, 1, N+1) ans[X[i].second] = i<=mid? X[mid + 1].first: X[mid].first;
	rp(i, 1, N+1) cout<< ans[i] <<endl;
}

Measured memory_bytes: 4480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		
		for (int i = 0; i < N; i++) {
			BigInteger a = new BigInteger(br.readLine());
			BigInteger b = new BigInteger(br.readLine());
			
			BigInteger c = a.add(b);
			String ans = c.toString();
			
			if (ans.length() > 80) {
				System.out.println("overflow");
			} else {
				System.out.println(ans);
			}
		}
	}

}

Measured memory_bytes: 24580
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[100005];
int appear[100005];
const int modo=1000000007;
int power(int x,int y)
{
    if (y==0) return 1;
    int t=power(x,y/2);
    t=(long long)t*t%modo;
    if (y%2==1)
    {
        t=(long long)t*x%modo;
    }
    return t;
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    memset(appear,-1,sizeof(appear));
    int l,r;
    for (i=0;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if (appear[a[i]]==-1)
        {
            appear[a[i]]=i;
        }
        else
        {
            l=appear[a[i]];
            r=i;
        }
    }
    int p=1;
    int p2=1;
    for (i=0;i<=n;i++)
    {
        p=(long long)p*(n-i+1)%modo;
        p=(long long)p*power(i+1,modo-2)%modo;
        if (i==0)
        {
            p2=1;
        }
        else
        {
            p2=(long long)p2*(n-(r-l)+1-i)%modo;
            p2=(long long)p2*power(i,modo-2)%modo;
        }
        printf("%d\n",((p-p2)%modo+modo)%modo);
    }
    return 0;
}


Measured memory_bytes: 2048
from sys import stdin
a = stdin.readline().strip()
ans = 0
cur = 0
res = ''
for i in a:
 if i=='p':
  if cur:
   res += "p"
   cur-=1
  else:
   res += "g"
   cur += 1
   ans -=1
 else:
  if cur:
   res += 'p'
   ans += 1
   cur -= 1
  else:
   res += 'g'
   cur += 1
 
print ans

Measured memory_bytes: 2948
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] lines = line.split(" ", 0);
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        System.out.println((n*m) + " " + (2*n+2*m));
    }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<vector<int>> F(N, vector<int>(10));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 10; ++j) {
			cin >> F[i][j];
		}
	}
		
	vector<vector<ll>> P(N, vector<ll>(11));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 11; ++j) {
			cin >> P[i][j];
		}
	}

	ll res = -1e18;
	for (int i = 1; i < (1<<10); ++i) {
		vector<bool> bit(10, false);
		int x = i;
		for (int j = 0; j < 10; ++j) {
			if (x % 2 == 1) { bit[j] = true; }
			x /= 2;
		}

		ll tmp = 0;
		for (int j = 0; j < N; ++j) {
			int cnt = 0;
			for (int k = 0; k < 10; ++k) {
				if (bit[k] && F[j][k]) { ++cnt; }
			}

			tmp += P[j][cnt];
		}
		res = max(res, tmp);
	}

	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

int myPow(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    return x * myPow(x, p-1);
}

int main() {
    int K, X;
    cin >> K>>X;





    for(int i = -1000000; i<1000000; i++){
        if( i>=(X-(K-1)) && i<=(X+(K-1)) ){
            cout << i << " ";
        }
    }

    cout << endl;



    return 0;
}


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

// @@ !! LIM()

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

  ll x; cin >> x;
  ll y = x / 500;
  ll z = (x - y * 500) / 5;
  cout << 1000 * y + 5 * z << endl;

  return 0;
}



Measured memory_bytes: 3600
#include "stdio.h"

main(){

  int i, j, minj, n, c=0, swap, A[100];

  scanf("%d", &n);

 for(i=0 ; i<n ; i++){
    scanf("%d", &A[i]);
  }

 for(i=0 ; i<n ; i++){

   minj = i;

   for(j=i ; j<n ; j++){
     if(A[j]<A[minj]){
 minj = j;
     }
   }

   if(A[i] != A[minj]){
   swap = A[i];
   A[i] = A[minj];
   A[minj] = swap;
   c++;
   }
 }

 for(j=0 ; j<n ; j++){
  printf("%d", A[j]);
  if(j<(n-1)) printf(" ");
  else{printf("\n");
   }
  }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 604
h, w = map(int, input().split())

a = ''.join(input() + '#' for _ in range(h))
a = a.replace('.', '1').replace('#', '0')

bits = int(a, 2)

w1 = w + 1
h1 = h + 1
bits <<= w1

frame = (1 << w1) - 1
frame |= frame << h1 * w1
frame |= sum(1 << b for b in range(w1, h1 * w1, w1))

count = 0
while bits:
    count += 1
    mask = bits | frame
    #       up             down           left          right
    bits &= (mask << w1) & (mask >> w1) & (mask << 1) & (mask >> 1)
print(count)


Measured memory_bytes: 6132
import queue
import math


def root(node):
    if nodes[node] == node:
        return node
    nodes[node] = root(nodes[node])
    return nodes[node]


while True:
    n = int(input())
    if n == 0:
        break

    cells = [list(map(float, input().split())) for _ in range(n)]

    nodes = [i for i in range(n)]

    q = queue.PriorityQueue()
    cost = 0
    count = n
    for i in range(n - 1):
        for j in range(i, n):
            d = math.sqrt((cells[i][0] - cells[j][0])**2 + (cells[i][1] - cells[j][1])**2 + (cells[i][2] - cells[j][2])**2)
            if d <= cells[i][3] + cells[j][3]:
                if root(i) != root(j):
                    nodes[root(i)] = root(j)
                    count += 1
            else:
                q.put((d - cells[i][3] - cells[j][3], i, j))
    while not q.empty():
        if count <= 1:
            break
        d, i, j = q.get()
        if root(i) != root(j):
            nodes[root(i)] = root(j)
            count -= 1
            cost += d
    print('{:.3f}'.format(cost))



Measured memory_bytes: 7636
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int N, a[100001] = { 0 }, b;
	cin >> N;
	REP(i, N){
		cin >> b;
		if (b > 100000){
			a[0]++;
		}
		else{
			a[b]++;
		}
	}

	int ans = a[0];
	FOR(i, 1, 100001) {
		if (a[i] < i){
			ans += a[i];
		}
		else{
			ans += a[i] - i;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using ll = long long;

int main() {
    int n;
    vector<ll> a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int e;
        cin >> e;
        a.push_back(e);
    }

    sort(a.begin(), a.end());
    bool is_dist = true;
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i - 1]) {
            is_dist = false;
            break;
        }
    }

    if (is_dist) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
const double pi=3.141592653589793;
const double mi=0.0000005;
int main(){
    int n;cin>>n;
    rep(i,10){
        rep(j,10){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  map<int, int> cnt;
  REP(i, n) {
    int tmp = read();
    if (cnt.count(tmp) == 0)
      cnt[tmp] = 1;
    else
      cnt[tmp]++;
  }
  vi pairs(2);
  for (auto &p : cnt) {
    p.second /= 2;
    REP(i, p.second) { pairs.PB(p.first); }
  }
  sort(ALL(pairs), greater<int>());
  print(pairs[0] * pairs[1]);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, X;
    cin >> n >> X;
    int s[n];
    rep(i, n) {
        cin >> s[i];
    }
    sort(s, s + n);
    reverse(s, s + n);
    Mint<> dp[n + 1][X + 1];
    dp[0][X] = 1;
    for (int i = 0; i < n; i++) {
        for (int x = 0; x <= X; x++) {
            dp[i + 1][x % s[i]] += dp[i][x];
            dp[i + 1][x] += dp[i][x] * (n - 1 - i);
        }
    }
    Mint<> ans = 0;
    for (int x = 0; x <= X; x++) {
        ans += dp[n][x] * x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 82140
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    if(s[1] == 'B')
    	s[1] = 'R';
    else
    	s[1] = 'B';
    cout << s;

    return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <queue> //C++
using namespace std; //C++



int main(void) {
	
	int x, y;
	cin >> x >> y;
	int i;
	for (i = 0; i <= x; i++) {
		if (y == (4*x - 2*i)) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

}



Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include <cstring>
using namespace  std;
 
int main()
{
    //freopen("in.txt","r",stdin);
		
	int x,n,arr[120],big=-1;;
	cin>>x>>n;
	memset(arr,0,sizeof(arr));
 
	for(int i=1;i<=n;i++)
	{
		int temp;
		cin>>temp; big=max(big,temp);
		
		arr[temp]=1;
	}
 
    big=max(x,big);
	bool chk=false;
    int ans=4555,intdif=1233;


	for(int i=0;i<=101;i++)
	{
		if(arr[i]==0){
             int  newintdif = abs(i-x);
             if(intdif>newintdif)
             {
             	intdif=newintdif;
             	ans=i;
             }
		}	 
	}
	  
	
        cout<<ans;
	return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>

int main() {
	int N;
	int i;
	int a, b, c;

	scanf("%d\n", &N);

	for(i = 0; i < N; i++) {
		scanf("%d %d %d", &a, &b, &c);
		if (a > b && a > c)
			if (a*a == b*b + c*c)
				printf("YES\n");
			else
				printf("NO\n");
		else if(b > a && b > c)
			if(b*b == a*a + c*c)
				printf("YES\n");
			else
				printf("NO\n");
		else
			if(c*c == a*a + b*b)
				printf("YES\n");
			else
				printf("NO\n");
	}
	return 0;
}

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

int main() {
  int a, b, c, d, e, f, p, q; long double l = 0;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
  rep(i, f/100){
    bool g = 0;
    rep(j, (i+1)/b+1){
      if(i+1-j*b >= 0 && (i+1-j*b)%a == 0){
        g = 1;
        break;
      }
    }
    if(g){
      rep(j, min((i+1)*e+1, f-i*100-100+1)){
        bool h = 0;
        rep(k, j/d+1){
          if(j-k*d >= 0 && (j-k*d)%c == 0){
            h = 1;
            break;
          }
        }
        if(h && l*(i+1) <= j){
          p = i*100+100;
          q = j;
          long double m = j;
          l = m/(i+1);
          if(l == e) break;
        }
      }
    }
  }
  printf("%d %d\n", p+q, q);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;
int main()
{
    int x,t,n;n=0;
    scanf("%d %d",&x,&t);
    n=x-t;
    if(n<0)
    n=0;
    printf("%d",n);
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define inf 1000000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

int gcd(int a, int b)
{
    if(a==0){return b;}
    if(b==0){return a;}
    return gcd(b,a%b);
}
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    speed
    //global var
    int n;cin>>n;
    set<int> inp;
    int g=0;
    for(int i=0;i<n;++i){
        int tmp;cin>>tmp;
        g=gcd(g,tmp);
        if(tmp!=1){inp.insert(tmp);}
    }
    if(g!=1){cout<<"not coprime";return 0;}
    vector<int> vec;
    for(auto it:inp){vec.push_back(it);}
    n=vec.size();
    if(n>100000){
        cout<<"setwise coprime\n";return 0;
    }
    vector<bool> pres(1000000,false);
    bool setwise=false;
    for(int i=0;i<n and !setwise;++i){
        int num=vec[i];
        for(int i=2;i*i<=num and (!setwise);++i){
            if(num%i==0){
                if(pres[i]){setwise=true;break;}
                pres[i]=true;
                while(num%i==0){
                    num/=i;
                }
            }
        }
        if(num>1){
            if(pres[num]){setwise=true;break;}
            pres[num]=true;
        }
    }
    if(setwise){cout<<"setwise coprime\n";return 0;}
    else{cout<<"pairwise coprime";return 0;}
    
    
}
//try thinking from a different angle after spending some time


Measured memory_bytes: 58344
def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

sentinel = 10 ** 10

n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count)

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

using namespace std;

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

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

vpll v;
ll d;
unordered_map<ll,ll> DP;
ll dp(ll n) {
    if(DP.count(n)) return DP[n];
    if(n==0) return DP[n]=0;
    if(n==1) return DP[n]=d;
    ll ret = INF;
    if(ceil(log2(n))+ceil(log2(d))<64) ret=n*d;
    FF(3) {
        ll p = v[j].x;
        ll dv = v[j].y;
        ll i = (dv-(n%dv))%dv;
        if((n+i)/dv < n) ret=min(dp((n+i)/dv)+p+abs(i)*d, ret);
        i = n%dv;
        if((n-i)/dv < n) ret=min(dp((n-i)/dv)+p+abs(i)*d, ret);
    }
    return DP[n]=ret;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    ll t; cin >> t;
    while(t--) {
        DP.clear();
        ll n; cin >> n;
        v = vpll(3);
        vll w={2,3,5};
        F(3) {
            cin >> v[i].x;
            v[i].y = w[i];
        }
        cin >> d;
        ll ret = INF;
        ret = min(ret, dp(n));
        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    lint H,A = 0,C = 1;
    cin >> H;
    while(H!=1){
        H/=2;
        A+=C;
        C*=2;
    }
    A+=C;
    cout << A;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<P> A(N);
  REP(i,N) cin >> A[i].first >> A[i].second;
  
  sort(ALL(A));

  ll cnt = 0;
  ll ans = 0;
  REP(i,N){
    cnt+=A[i].second;
    if(cnt>=K){
      ans=A[i].first;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
s = input()
n = len(s)
ret = ''
for i in range(n - 1, 0, -1):
    if len(s[:i]) % 2 == 1:
        continue
    # print(s[:i // 2], s[i // 2:i])
    if s[:i // 2] == s[i // 2:i]:
        ret = s[:i]
        break
print(len(ret))


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

int n;
int A[2000];

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


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

	int q = 0, m[2000];
	cin >> q;
	for (int i = 0; i < q; i++) cin >> m[i];

	for (int i = 0; i < q; i++)
	{
		if (solve(0, m[i])) cout << "yes" << endl;
		else cout << "no" << endl;
	}

    return 0;
}


Measured memory_bytes: 3108
// Problem Code: abc174_b

#include <bits/stdc++.h>

using namespace std;

long long euclidean_distance(long long x, long long y) {
	return x * x + y * y;
}

int B(int N, long long D, vector<int>& X, vector<int>& Y) {
	int cnt = 0;
	for (int i = 0; i < N; i++)
		if (euclidean_distance(X[i], Y[i]) <= D * D)
			cnt++;
	return cnt;
}

int main() {
	int N, D;
	cin >> N >> D;
	vector<int> X(N), Y(N);
	for (int i = 0; i < N; i++)
		cin >> X[i] >> Y[i];
	cout << B(N, D, X, Y);
	return 0;
}

Measured memory_bytes: 4840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    ArrayList<Board> bs;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }


    private void read() {
        bs = new ArrayList<>();
        String[] elems;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            while (true) {
                elems = br.readLine().split(" ");
                if (elems[0].equals("0") && elems[1].equals("0"))
                    return;
                Board b = new Board(Integer.parseInt(elems[0]), Integer.parseInt(elems[1]));
                for (int i = 0; i < b.h; i++) {
                    elems = br.readLine().split(" ");
                    for (int j = 0; j < b.w; j++) {
                        b.board[i][j] = elems[j].equals("1");
                    }
                }
                bs.add(b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void solve() {
        for (Board b: bs) {
            boolean[][] used = new boolean[b.h][b.w];
            int ans = 0;
            for (int i = 0; i < b.h; i++) {
                for (int j = 0; j < b.w; j++) {
                    if (b.board[i][j] && !used[i][j]) {
                        dfs(b, j, i, used);
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }

    private void dfs(Board b, int x, int y, boolean[][] used) {
        if (used[y][x])
            return;
        used[y][x] = true;
        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                int _x = x + dx;
                int _y = y + dy;
                if (0 <= _x && _x < b.w &&
                        0 <= _y && _y < b.h &&
                        !used[_y][_x] && b.board[_y][_x])
                    dfs(b, _x, _y, used);
            }
        }
    }

    private class Board {
        int w, h;
        boolean[][] board;
        Board(int w, int h) {
            this.w = w;
            this.h = h;
            board = new boolean[h][w];
        }
    }

}

Measured memory_bytes: 27944
import numpy as np
# -*- coding: utf-8 -*-
_ = input()
arr = np.array(list(map(int, input().split())))

cnt = 0
while True:
    if ((arr / 2) == np.ceil(arr / 2)).all():
        cnt += 1
        arr = arr/2
    else:
        break
print(cnt)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(2e6+5);

void pre() {

}


void solve() {
  int n;  cin>>n;
  int mx = 0;
  map<string,int> cnt;
  rep(i,n) {
    string x; cin>>x;
    cnt[x]++;
    mx = max(mx,cnt[x]);
  }
  for(auto i:cnt) {
    if(i.ss == mx)  cout<<i.ff<<'\n';
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 19240