akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
class Crossing{
private:
public:
  int horz, vert;
  Crossing(): horz(0), vert(0){}
  Crossing(int horz, int vert): horz(horz), vert(vert){}
};

int main(){
  int h, w;
  char a;
  cin >> h >> w;
  Crossing c[h+2][w+2];
  //空欄以外のところを1埋め
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a;
      if (a == '.') {
        c[i][j].vert = 1;
        c[i][j].horz = 1;
      }
    }
  }

  //上端からの距離と左端からの距離を埋めていく
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (c[i+1][j].vert != 0) {
        c[i+1][j].vert = c[i][j].vert + 1;
      }
      if (c[i][j+1].horz != 0) {
        c[i][j+1].horz = c[i][j].horz + 1;
      }
    }
  }

  //上端からの距離と左端からの距離を埋めていく
  for (int i = h; i >= 1; i--) {
    for (int j = w; j >= 1; j--) {
      if (c[i][j].vert * c[i][j].horz != 0){
        if (c[i-1][j].vert != 0){
          c[i-1][j].vert = c[i][j].vert;
        }
        if (c[i][j-1].horz != 0){
          c[i][j-1].horz = c[i][j].horz;
        }
      }
    }
  }
  int lighted_blocks = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (lighted_blocks < c[i][j].vert + c[i][j].horz - 1){
        lighted_blocks = c[i][j].vert + c[i][j].horz  - 1;
      }
    }
  }

  cout << lighted_blocks << endl;
}

Measured memory_bytes: 31616
#include <iostream>
#include <cstring>
using namespace std;
#define NN 2019
int main(void){
    char S[200001];
    std::cin >> S;
    int N = std::strlen(S);
    int cnt = 0;
    int l[NN] = {};
    int prevl[NN];
    for(int i = 0; i < N; i++){
        int k = S[i]-'0';
        // std::cout << k << std::endl;
        for(int j = 0; j < NN; j++){
            l[j] = 0;
        }
        if(i > 0){
            for(int j = 0; j < NN; j ++){
                l[(10*j+k)%NN] = prevl[j];
            }
        }
        l[k] += 1;
        cnt += l[0];
        for(int j = 0; j < NN; j++){
            // std::cout << l[j];
            prevl[j] = l[j];
        }
        // cout << endl;
    }
    // std::cout << std::strlen(S) << std::endl;
    // std::cout << S << std::endl;
    
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 3740
n, m = map(int, input().split())

li_1 = [2 for i in range(n)]
li_2 = [1 for i in range(m)]
li = li_1 + li_2

res = 0
for i in range(len(li)):
    if len(li[i+1:]) >0:
        for j in li[i+1:]:
            if (li[i]+j)%2 == 0:
                res+=1

print(res)


Measured memory_bytes: 3060
//file_name:ABC87_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);



    int ans = x;

    ans-=a;
    while(ans>=b){
        ans-=b;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 764
# include <iostream>

using namespace std;

//https://atcoder.jp/contests/abc080/tasks/abc080_b

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

    int sum=0;
    int tmp = N;
    while(tmp){
        sum += tmp % 10;
        tmp /= 10.0;
    }
    if(N % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x(n), y(n), a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> a[i];
    }
    vector<vector<int>> grid(h, vector<int>(w, 0));
    for (int i = 0; i < n; i++)
    {
        switch (a[i])
        {
        case 1:
            for (int xx = 0; xx < x[i]; xx++)
            {
                for (int yy = 0; yy < h; yy++)
                {
                    grid[yy][xx] = 1;
                }
            }
            break;

        case 2:
            for (int xx = x[i]; xx < w; xx++)
            {
                for (int yy = 0; yy < h; yy++)
                {
                    grid[yy][xx] = 1;
                }
            }
            break;

        case 3:
            for (int xx = 0; xx < w; xx++)
            {
                for (int yy = 0; yy < y[i]; yy++)
                {
                    grid[yy][xx] = 1;
                }
            }
            break;

        case 4:
            for (int xx = 0; xx < w; xx++)
            {
                for (int yy = y[i]; yy < h; yy++)
                {
                    grid[yy][xx] = 1;
                }
            }
            break;
        default:
            break;
        }
    }

    int cnt = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cnt += (grid[i][j] == 0 ? 1 : 0);
            // cout << grid[i][j] << ' ';
        }
        // cout << endl;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("out.o", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 != 0) {
		cout << "No";
	}
	else {
		string t = s.substr(0, n / 2), v = s.substr(n / 2, n);
		if (t == v)cout << "Yes";
		else cout << "No";
	}
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;
 

void add_self(int& a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}

int n;
string s;
int dp[N][N]; 
int pref[N][N];  

// TLE
// use prefix 

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n>>s;
	dp[1][1]=1;
	for(int pos=0;pos<n-1;++pos){
		int cur_sign=pos+2;
		for(int i=1;i<=cur_sign-1;++i){
			pref[cur_sign-1][i]=(pref[cur_sign-1][i-1]+dp[cur_sign-1][i])%mod;
		}
		for(int i=1;i<=cur_sign;++i){
			int l,r;
			if(s[pos]=='<'){
				l=1;
				r=i-1;
			}
			else{
				l=i;
				r=cur_sign-1;
			}
			if(l<=r){
				add_self(dp[cur_sign][i],(pref[cur_sign-1][r]-pref[cur_sign-1][l-1]+mod)%mod);
			}
		}
	}
	int ans=0 ;
	for(int i=1;i<=n;++i) add_self(ans,dp[n][i]);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 69504
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int pre = Integer.parseInt(s.substring(0,2));
        int post = Integer.parseInt(s.substring(2));

        boolean isPreMonth = pre <= 12 && pre != 0;
        boolean isPostMonth = post <= 12 && post != 0;
        if(isPreMonth && isPostMonth){
            System.out.println("AMBIGUOUS");
        } else if(isPreMonth){
            System.out.println("MMYY");
        } else if(isPostMonth){
            System.out.println("YYMM");
        } else {
            System.out.println("NA");
        }


    }
}


Measured memory_bytes: 21588
#include<stdio.h>
int main(){
	int x,n,num[4][13]={0};
	char y;
	scanf("%d",&n);
	for(int a=0;a<n;a++){
		scanf(" %c %d",&y,&x);
		if(y=='S'){
			num[0][x-1]=1;
		}
		else if(y=='H'){
			num[1][x-1]=1;
		}
		else if(y=='C'){
			num[2][x-1]=1;
		}
		else{
			num[3][x-1]=1;
		}
	}
	for(int c=0;c<4;c++){
		for(int d=0;d<13;d++){
			if(c==0&&num[c][d]==0){
				printf("S %d\n",d+1);
			}
			if(c==1&&num[c][d]==0){
				printf("H %d\n",d+1);
			}
			if(c==2&&num[c][d]==0){
				printf("C %d\n",d+1);
			}
			if(c==3&&num[c][d]==0){
				printf("D %d\n",d+1);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <algorithm>

using namespace std;

int dp[1001][1001];

int lcs(string x, string y) {
    int lx = x.size(), ly = y.size();
    for (int i = 1; i <= ly; ++i) {
        for (int j = 1; j <= lx; ++j) {
            dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1] + (x[j - 1] == y[i - 1]));
        }
    }
    return dp[ly][lx];
}

int main() {
    int n;
    string x, y;
    cin >> n;
    while (n--) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}


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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

int main()
{
    string s;
    cin >> s;

    for (char c : s)
    {
        if (c == ',')
        {
            c = ' ';
        }
        print(c);
    }

    println("");
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int x;
	cin >> x;
	cout << (x < 1200 ? "ABC" : "ARC") << endl;

	return 0;
}

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

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;
    map<string, int> mp;
    REP(i, n)
    {
        string s;
        cin >> s;
        mp[s] += 1;
    }

    int num = 0;
    for (auto v : mp)
    {
        if (v.second > num)
            num = v.second;
    }

    for (auto v : mp)
    {
        if (v.second == num)
        {
            cout << v.first << endl;
        }
    }

    return 0;
}

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

int main(){
    std::string S;
    int ans = 0;
    std::cin >> S;

    for(auto i = 0; i < S.size() / 2; i++){
        if(S.at(i) != S.at(S.size() - 1 - i)){
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut it = buf.split_whitespace();
    let a: i32 = it.next().unwrap().parse().unwrap();
    let b: i32 = it.next().unwrap().parse().unwrap();
    let c: i32 = it.next().unwrap().parse().unwrap();
    let d: i32 = it.next().unwrap().parse().unwrap();
    if (c-a).abs()<=d {
        println!("Yes");
    } else if (b-a).abs()<=d && (c-b).abs()<=d {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
N,M=map(int,input().split())
flg=[0]*(N+1)
flg[1]=1
flg2=[1]*(N+1)
for _ in range(M):
    xy=list(map(int,input().split()))
    if flg[xy[0]]==1:
        flg[xy[1]]=1
    flg2[xy[1]]+=1
    flg2[xy[0]]-=1
    if flg2[xy[0]]==0:
        flg[xy[0]]=0
print(sum(map(lambda x:x>0,flg)))

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

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    
    if(abs(a - b) % 2 == 1) cout << "Borys" << endl;
    if(abs(a - b) % 2 == 0) cout << "Alice" << endl;

}

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

int main(void){

	char str[21] = {0};
	char rvs[21] = {0};
	int len;
	int i = 0,j=0;

	scanf("%s", str);
	len = strlen(str);

	j = len-1;
	for (i = 0; i < len; i++,j--){
		rvs[i] = str[j];
	}
	printf("%s\n", rvs);
	return 0;
}

Measured memory_bytes: 524
stack = []

for s in input().split():
    if s == '+':
        stack.append(stack.pop() + stack.pop())
    elif s == '-':
        stack.append(-stack.pop() + stack.pop())
    elif s == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(s))
print(stack[0])

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

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++)
        cin >> A.at(i);
    int s=0;
    for(int i=0;i<N;i++){
        if(A.at(i)==(s+1)){
            s++;
        }
    }
    if(s==0)
        cout << -1;
    else if(s==N)
        cout << 0;
    else
        cout << N-s;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e5+5;
const int M = 1e4;
const int INF = 0x3f3f3f3f;

int h[N];
bool vis[N];

int main() {
	int n,m,u,v;
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i) scanf("%d",&h[i]),vis[i] = 1;
	for(int i = 1;i <= m;++i){
		scanf("%d%d",&u,&v);
		if(h[u] > h[v]) vis[v] = 0;
		else if(h[u] < h[v]) vis[u] = 0;
		else vis[v] = vis[u] = 0;
	}
	
	int ans = 0;
	for(int i = 1;i <= n;++i){
		if(vis[i]) ans++;
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4312
#include<stdio.h>
int main(void){
	int a,b,d,count;
	char c;
	while(1){
		scanf("%d %c %d",&a,&c,&b);
		if(c =='+'){
			printf("%d\n",a+b);
			count=count+1;
		}
		else if(c=='-'){
			printf("%d\n",a-b);
			count=count+1;
		}
		else if(c=='*'){
			printf("%d\n",a*b);
			count=count+1;
		}
		else if(c=='/'){
			printf("%d\n",a/b);
			count=count+1;
		}
		else if(c=='?'){
			goto hata;
		}
	}
	hata:
	return 0;
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Solver {
    void solve(Scanner sc) {
        int N = sc.nextInt();
        long K = sc.nextLong();
        int Q = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < Q; i++) {
            A[sc.nextInt() - 1]++;
        }
        System.out.println(Arrays.stream(A).mapToLong(p -> K - Q + p).mapToObj(l -> l > 0 ? "Yes" : "No").collect(Collectors.joining("\n")));
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int a, p;

bool read() {
    if (!(cin >> a >> p))
        return false;

    return true;
}

void solve() {
    auto ans = 0;

    for (int i = 0; i <= a; ++i)
        ans = max(ans, (a - i) + (3 * i + p) / 2);

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    int res = 0;

    string s;

    cin >> s;
    int n = (int)s.size();

    for(char c : s) {
        res += c - '0';
    }

    int tot = 0;

    for(int i = 0;i < n;i++) {
        if(s[i] != '0') {
            int tmp = s[i] - '0' - 1;
            tmp += (n - i - 1) * 9;
            tmp += tot;
            res = max(res, tmp);
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ref = {}

a = list(map(int, input().split()))
del a[0]
a = set(a)
ref = a

for i in range (n - 1):
    a = list(map(int, input().split()))
    del a[0]
    a = set(a)
    ref = ref & a

print(len(ref))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		int four = 0;
		int two = 0;
		for (int i = 0; i < n; i++) {
			long a = scanner.nextLong();
			if (a % 4 == 0) {
				four++;
			} else if (a % 2 == 0) {
				two++;
			}
		}

		if (four >= n / 2) {
			System.out.println("Yes");
		} else if (four >= (n - four - two) && two >= 2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 47964
package main

import (
	"fmt"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)

	t := 0
	for i := 0; i < n; i++ {
		t += l + i
	}

	min := 99999
	ans := 0
	for i := 0; i < n; i++ {
		t2 := 0
		for j := 0; j < n; j++ {
			if j == i {
				continue
			}
			t2 += l + j
		}
		if abs(t-t2) < min {
			min = abs(t - t2)
			ans = t2
		}
	}

	fmt.Println(ans)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


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

int main(){
	int a;
	int b[100] = {};
	cin >> a;
	for(int i = 0; i < a; i++){
		cin >> b[i];
	}
	for(int j = a-1; j >= 0; --j){
		cout << b[j];
		if(j == 0){
			break;
		}
		cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3088
a, b = map(int, input().split())
while a > 0 or b > 0:
	for i in range(a):
		for j in range(b):
			if i > 0 and i < a - 1 and j > 0 and j < b - 1:
				print(".", end="")
			elif j == b - 1:
				print("#")
			else:
				print("#", end="")
	print("")
	a, b = map(int, input().split())



Measured memory_bytes: 7000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N, M;
  while(cin >> N >> M, N){
    vector<int> P(N);
    for(int i=0;i<N;i++)cin >> P[i];
    vector<int> cand;
    for(int i=0;i<N;i++)for(int j=i;j<N;j++)if(P[i] + P[j] <= M){
      cand.push_back(P[i] + P[j]);
    }
    for(int x : P)if(x <= M)cand.push_back(x);
    sort(cand.begin(), cand.end());
    int j = cand.size() - 1;
    int res = 0;
    for(int i=0;i<cand.size();i++){
      while(j > 0 && cand[i] + cand[j] > M)--j;
      if(cand[i] + cand[j] <= M){
        res = max(res, cand[i] + cand[j]);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 6788
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
b=[]
for i in range(2**n):
  b.append(format(i,'0'+str(n)+'b'))
ans=[]
for i in range(2**n):
  y=0
  ct=[0]*m
  for j in range(n):
    if b[i][j]=='1':
      y+=l[j][0]
      for k in range(1,m+1):
        ct[k-1]+=l[j][k]
  ct2=0
  for j in range(m):
    if ct[j]>=x:
      ct2+=1
  if ct2==m:
    ans.append(y)
if len(ans)==0:
  print(-1)
else:
  print(min(ans))

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

int main() {
  int H, W;
  std::cin >> H >> W;
  std::string S[H];
  for (int i = 0; i < H; ++i) {
    std::cin >> S[i];
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if ( S[i][j] != '#' ) {
        int cnt = 0;
        if ( S[i][j + 1] == '#' && j + 1 < W ) ++cnt;
        if ( S[i][j - 1] == '#' && j - 1 > -1 ) ++cnt;
        if ( S[i + 1][j] == '#' && i + 1 < H ) ++cnt;
        if ( S[i - 1][j] == '#' && i - 1 > -1 ) ++cnt;
        if ( S[i + 1][j + 1] == '#' && j + 1 < W && i + 1 < H ) ++cnt;
        if ( S[i - 1][j + 1] == '#' && j + 1 < W && i - 1 > -1 ) ++cnt;
        if ( S[i + 1][j - 1] == '#' && j - 1 > -1 && i + 1 < H ) ++cnt;
        if ( S[i - 1][j - 1] == '#' && j - 1 > -1 && i - 1 > -1 ) ++cnt;
        std::cout << cnt;
      }
      else {
        std::cout << S[i][j];
      }
    }
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long int
using namespace std;
int main()
{
    ll i,j,k,n,m,s=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>k;
        s+=k;
    }
    if(s==n)
    {
        cout<<0<<endl;
    }
    else if(s<n)
    {
        cout<<n-s<<endl;
    }
    else
    cout<<-1<<endl;



    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

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

int main() {
	int N;

	cin >> N;

  	vector<int> a(N);
  
  int bitc[32] = {0};
  
    for (auto& i : a) {
      cin >> i;
      
      for (int j = 0; j < 32; j++) {
        if (i & 1)
          bitc[j]++;
        i >>= 1;
      }
    }
  
  
  for (int i : bitc)
    if ((i % 2) != 0) {
      cout << "No" << endl;
      return 0;
    }
  
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mod -1000000007
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
vector<int> v;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a,n,x;
    cin>>n>>x;
    v.push_back(x);
    for (int i=0;i<n;i++) {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    x = v[1]-v[0];
    for (int i=2;i<=n;i++) {
        x = __gcd(x,v[i]-v[i-1]);
    }
    cout<<x;
}


Measured memory_bytes: 892
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

#[derive(Debug, Clone, Copy, PartialEq)]
struct Polar {
    theta: f64,
    r: f64,
}
impl Polar {
    const PI: f64 = std::f64::consts::PI;
    const PI2: f64 = std::f64::consts::PI * 2.0;
    fn new(theta: f64, r: f64) -> Self {
        let mut t = theta;
        let r = if r >= 0.0 {
            r
        } else {
            t += Self::PI;
            -r
        };
        t %= Self::PI * 2.0;
        if t < 0.0 {
            t += Self::PI * 2.0;
        }
        Polar { theta: t, r }
    }
    fn distance(&self, other: &Self) -> f64 {
        (self.r.powi(2) + other.r.powi(2)
            - 2.0 * self.r * other.r * (self.theta - other.theta).abs().cos())
        .sqrt()
    }
}

fn main() {
    let mut sc = Scanner::new();
    let a: f64 = sc.cin();
    let b: f64 = sc.cin();
    let h: f64 = sc.cin();
    let m: f64 = sc.cin();
    let theta_a = (60.0 * h + m) / 720.0 * Polar::PI2;
    let theta_b = m / 60.0 * Polar::PI2;
    let x = Polar::new(theta_a, a);
    let y = Polar::new(theta_b, b);
    put!(x.distance(&y));
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 3032
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

func parseProblem() []request {
	n := scanInt(sc)
	cs := make([]request, n)
	for i := 0; i < n; i++ {
		cs[i] = request{
			t: scanInt(sc),
			x: scanInt(sc),
			y: scanInt(sc),
		}
	}
	return cs
}

type request struct {
	t, x, y int
}

func dist(x, y request) int {
	return abs(x.x-y.x) + abs(x.y-y.y)
}

func isReachable(s, t request) bool {
	l := t.t - s.t
	d := dist(s, t)
	if d <= l && d%2 == l%2 {
		return true
	}
	return false
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func resolve(cs []request) {
	cur := request{t: 0, x: 0, y: 0}
	for i := 0; i < len(cs); i++ {
		if !isReachable(cur, cs[i]) {
			fmt.Println("No")
			return
		}
		cur = cs[i]
	}
	fmt.Println("Yes")
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5328
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        m: usize,
        d: usize
    }
    let mut ans = 0;
    for i in 22..d + 1 {
        let a = i / 10;
        let b = i % 10;
        if a >= 2 && b >= 2 && a * b <= m {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;
ll dp[110][100100];


int main(){
    int n;
    cin >> n;
    int a=0,w=0,t=0,r=0;
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC") a++;
        if(s=="WA") w++;
        if(s=="TLE") t++;
        if(s=="RE") r++;
           }
    cout << "AC" <<' ' << 'x' <<' '<< a <<endl;
    cout << "WA" <<' ' << 'x' <<' ' <<w<<endl;
    cout << "TLE" <<' ' << 'x' <<' '<< t <<endl;
    cout << "RE" <<' ' << 'x' <<' '<< r <<endl;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
	long long int N, sum = 0;
	cin >> N;
	for(int i = 1; i <= N; i++)
	{
		if(i % 3 != 0 && i % 5 != 0)
		{
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624
def gcd(x, y):
  if y == 0:
    return x
  else:
    x %= y
    x, y = y, x
    return gcd(x, y)

a, b, c, d = map(int, input().split())

x = c * d // gcd(c, d)

t1 = b // c
t2 = (a - 1) // c
u1 = b // d
u2 = (a - 1) // d
v1 = b // x
v2 = (a - 1) // x

ans = (b - a + 1) - (t1 - t2) - (u1 - u2) + (v1 - v2)
print(ans)

Measured memory_bytes: 3064
# ワーシャルフロイド　全点最短経路、負の距離あっても可　o(n**3)
def warshall_floyd(d,ans):
    #d[i][j]: iからjへの最短距離
    flag=True
    for i in range(n):
        for j in range(n):
            x=d[i][j]
            y=float('inf')
            for k in range(n):
                if k!=i and k!=j:
                    y = min(d[i][k] + d[k][j],y)
            if x==y:
                ans-=y
            elif x<y:
                continue
            else:
                flag=False
                break

    return flag,ans

##############################
n=int(input())

d = [list(map(int, input().split())) for i in range(n)]
ans=0
for i in range(n):
    ans+=sum(d[i])


a1,a2=warshall_floyd(d,ans)

if a1:
    print(a2//2)
else:
    print(-1)

Measured memory_bytes: 43244
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;

#define MOD 1000000007

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

    ll N;
    cin >> N;

    vector<ll> A(N);

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

    sort(A.begin(), A.end(), greater<ll>());

    if(N % 2) {
        ll ans = A[0] + A[N / 2LL];
        for(ll i = 1LL; i < N / 2LL; i++) {
            ans += A[i] * 2LL;
        }
        cout << ans << endl;
    } else {
        ll ans = A[0];
        for(ll i = 1LL; i < N / 2LL; i++) {
            ans += A[i] * 2LL;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll X, N;
    cin >> X >> N;
    vector<ll> p(N);
    map<ll,int> mp;
    rep(i, N){
        cin >> p[i];
        mp[p[i]]++;
    }
    ll diff = INFLL;
    ll ans = -1;
    rep(i,1000){
        if(mp[i] == 0 && chmin(diff, abs(X - i))){
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }else if(a>=6&&a<=12){
    cout<<b/2<<endl;
  }else{
    cout<<"0"<<endl;
  }
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b, m, k;

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

int main() {
	cin >> n >> k;
	cin >> a;
	m = a;
	rep(i,n-1) {
		cin >> b;
		a = gcd(a, b);
		chmax(m, b);
	}
	if (k<=m && k%a==0) cout << "POSSIBLE" << ln;
	else cout << "IMPOSSIBLE" << ln;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  var x,a;
  x = Number(input.split('\n')[0].split(' ')[0]);
  a = Number(input.split('\n')[0].split(' ')[1]);
  
  console.log(x < a ? 0 : 10);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj=j
    if i!=minj:
        count+=1
    R=A[i]
    A[i]=A[minj]
    A[minj]=R
Z=[str(a) for a in A]
Z=" ".join(Z)
print(Z)

print(count)



Measured memory_bytes: 5604
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	System.out.println(gcd(x, y));
    }
    private static int gcd(int x, int y) {
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
}



Measured memory_bytes: 26312
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 200000 + 10; 

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
vector<int> G[maxn];

int dep[maxn], sz[maxn];
bool dfs(int u, int f = 0) {
    if(u == n) return 1;

    sz[u] = 1;
    bool a = 0;
    for(int i = 0; i < int(G[u].size()); ++i) {
        int v = G[u][i];
        if(v == f) continue;

        dep[v] = dep[u] + 1;
        bool flag = dfs(v, u);

        if(!flag || dep[v] <= (dep[n]+1) / 2) { sz[u] += sz[v]; }
        a |= flag;
    }
    return a;
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
    
    cin >> n;
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        G[u].pb(v);
        G[v].pb(u);
    }

    dep[1] = 1;
    dfs(1);
    printf(sz[1] > n/2 ? "Fennec" : "Snuke");

    return 0;
}


Measured memory_bytes: 16640
import math
import statistics
n = int(input())
x = [int(i) for i in input().split()]

x_sorted = sorted(x)
lower_med = statistics.median(x_sorted[1:])
upper_med = statistics.median(x_sorted[:len(x)-1])

median = statistics.median(x)

for i in range(n):
    if x[i] < median:
        print(lower_med)
    else:
        print(upper_med)


Measured memory_bytes: 110708
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main(void){

  string c;
  stack<int> st;

  while( cin >> c ){
    if( c == "+" ){
      int x = st.top();
      st.pop();
      int y = st.top();
      st.pop();
      st.push(y + x);
    }else if( c == "-" ){
      int x = st.top();
      st.pop();
      int y = st.top();
      st.pop();
      st.push(y - x);
    }else if( c == "*" ){
      int x = st.top();
      st.pop();
      int y = st.top();
      st.pop();
      st.push(y * x);
    }else{
      int s = 0;
      int a = 1;
      for( int i = c.size() - 1 ; i >= 0 ; i-- ){
	s += (c[i]- '0') * a; 
	a *= 10;
      }
      st.push(s);
    }
  }
  cout << st.top() << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  rep(i, 0, n) {
    cout << s[i] << t[i];
  }
  cout << "\n";
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI D(N);
  rep(i,N) cin>>D[i];
  ll ans=0;
  rep(i,N) rep(j,N){
    if(i<j) ans+=(D[i]*D[j]);
  }
  cout<<ans<<endl;
}



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

#define rep(i, a) for(int i = 0; i < a; i++)
#define llint long long int
using namespace std;

const int MAX_x = 100005;
const llint INF = 999999999999999;

int main()
{
    int k;
    string s;
    cin >> s >> k;
    int l = s.size();

    rep(i, l) {
        if (s[i] != '1' || i + 1 == k) {
            cout << s[i];
            break;
        }
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> 
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	int x,y;
	string s;
	cin >>x >>y;
	
	cout << x + y/2 <<"\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm> // sort
#include <iomanip>
#include <queue>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
typedef pair<int,int> pint;

const int MOD = 1000000007;

ll to[10][10];
ll cost[10];
vector <bool> visited(10 , false);

int dfs(int m, ll c, int s, vector<bool> visited)
{
    if(m == 1)
    {
        cost[s] = min(cost[s], c);
        return 0;
    }
    //時間がかかりすぎるのでテコ入れ
    //0->1の最短を最初に求めるので、 i 未満なら、最短を知っている(cost[i])
    if(m < s)
    {
        cost[s] = min(cost[s], c + cost[m]);
        return 0;
    }

    if(visited[m])return 0;
    visited[m] = true;
    REP(i,10)
    {
        if(i == m)continue;
        dfs(i, c + to[m][i], s, visited);
    }
}

int main(){

#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    //方針:各数値の -> 1までの最短経路探索
    ll h,w;
    cin >> h >> w;
    ll c;
    //iから1にいくまでのコスト
    REP(i,10)
    {
        REP(j,10)
        {
            cin >> c;
            to[i][j] = c;
        }
    }

    REP(i,10)
    {
        cost[i] = INF;
    }

    REP(i,10)
    {
        dfs(i, 0, i, visited);
    }

#if DEBUG
    REP(i,10)
    {
        cout << cost[i] << endl;
    }
#endif

    ll res;

    REP(i,h)
    {
        REP(j,w)
        {
            ll a;
            cin >> a;
            res += cost[a];
        }
    }
    cout << res << endl;

    return 0;     
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>


using namespace std;


#define ll long long


int main()
{
  ll n, k, a, b, d[1000000]={0}, cnt=0;

  cin >> n >> k;
  for (ll i=0; i<n; i++){
    cin >> a >> b;
    d[a] += b;
  }

  for (ll i=1; i<1000000; i++){
    cnt += d[i];
    if (cnt >= k){
      cout << i << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[3300][3300];
void chmax(int &a,int b){
	if(a < b)a = b;
}
signed main(){
	string s,t;cin >> s >> t;
	int n = s.size();
	int m = t.size();
	rep(i,n+1)rep(j,m+1){
		// if(i == 0 || j == 0)continue;
		if(i-1 >= 0)chmax(dp[i][j],dp[i-1][j]);
		if(j-1 >= 0)chmax(dp[i][j],dp[i][j-1]);
		if(i-1 >= 0 && j-1 >= 0 && s[i-1] == t[j-1])chmax(dp[i][j],dp[i-1][j-1]+1);
	}
	// cout << dp[n][m] << endl;
	string ret;
	while(n > 0 && m > 0){
		if(dp[n][m] == dp[n-1][m])n--;
		else if(dp[n][m] == dp[n][m-1])m--;
		else {
			ret = s[n-1] + ret;
			n--;m--;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 80996