akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxn = 100010;
int N, K;
int A[maxn];

template <unsigned Mod> struct Modular {
  using M = Modular;
  unsigned v;
  Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= mdpow(r, Mod - 2); }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
  friend M mdpow(M b, unsigned exp) {
    Modular res(1);
    while(exp) {
      if (exp & 1) {
        res *= b;
        if ((res.v += Mod) >= Mod) res.v -= Mod;
      }
      b *= b;
      exp >>= 1;
    }
    return res;
  }
};

constexpr long long mod = 1e9 + 7;
using Mint = Modular<mod>;
vector<Mint> fact, inv_fact, minv;

void prep(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1;
  inv_fact[n] = 1 / fact[n];
  // cout << inv_fact[n].v << endl;
  for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}

Mint binom(int n, int k) {
  if (k < 0 || k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}

int main() {
  fastio;
  cin >> N >> K;
  prep(N);
  // rep(i, N) cout << inv_fact[i].v << endl;
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  sort(A, A + N);
  Mint res(0);
  Mint choose;
  for (int i = 0; i < N; i++) {
    Mint val(A[i]);
    choose = binom(N - i - 1, K-1);
    res -= (val * choose);
    choose = binom(i, K-1);
    res += (val * choose);
  }
  cout << res.v << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> student(n), point(m);
    for(auto& i : student){
        cin >> i.first >> i.second;
    }
    for(auto& i : point){
        cin >> i.first >> i.second;
    }
    REP(i, n){
        int p = 0, dmin = 1e9;
        REP(j, m){
            int d = abs(student[i].first - point[j].first) + abs(student[i].second - point[j].second);
            if(d < dmin){
                dmin = d;
                p = j;
            }
        }
        cout << p+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>


#define mp(a,b) make_pair(a,b)
#define rep(i,n) for (size_t i = 0; i < (n); ++i)
typedef long long ll;


using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r and (n bitor r) != 0){
    string s;
    for (int i = n; i > 0; --i)  s.push_back(i+'0');
    int p,c;
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      s = s.substr(p-1,c) + s.substr(0,p-1)
	+ s.substr(p+c-1);
    }
    cout << (int)(s[0] - '0') << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int D,N;
    cin >> D;
    cin >> N;
    if(N == 100)
        N++;
    if(D == 0)
        cout << N << endl;
    else if(D == 1)
        cout << N * 100 << endl;
    else
        cout << N * 10000 << endl;
}


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



    int main(){
      int A,B,H,M;
      string buf;
      getline(cin,buf);
      stringstream line(buf);
      line >> A >> B >> H >> M;
      double th1,th2;
      th1 = 2 * M_PI * H / 12.;
      th2 = 2 * M_PI * M / 60.;
      th1 += 2 * M_PI / 12. * M / 60.;
      double Lx = A * sin(th1) - B * sin(th2);
      double Ly = A * cos(th1) - B * cos(th2);
      cout << setprecision(12) << sqrt(Lx* Lx + Ly* Ly) <<endl;
    }

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<int,int>
#define pli pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
int n,ql,qr,q[205];ll s;
void sol(ll s)
{
	if(s==1)return;
	if(s&1){sol(s-1);q[--ql]=++n;}
	else {sol(s/2);q[++qr]=++n;}
}
int main()
{
	s=rd();s++;ql=101;qr=100;n=0;sol(s);
	printf("%d\n",n*2);
	rep(i,ql,qr)printf("%d ",q[i]);
	rep(i,1,n)printf("%d ",i);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
using namespace std;
typedef complex<double> P;

const int MAXN = 22;
const double pi = acos(-1);
const double inf = 1e100;
const double eps = 1e-5;

int N;
double R, T;
P ps[MAXN];
double G[MAXN][MAXN][MAXN]; // from, to, pre
double dp[2][MAXN][MAXN]; // t, pos, pre

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

int main() {
  while(cin >> N) {
    cin >> R >> T;
    T = T * pi / 180.0;
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    fill(G[0][0], G[MAXN][0], inf);
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
	if(i == j) continue;
	G[i][j][N] = abs(ps[i] - ps[j]);
	for(int k = 0; k < N; ++k) {
	  if(i == k || j == k) continue;
	  P a = ps[j] - ps[i];
	  P b = ps[k] - ps[i];
	  double angle = pi - acos(dot(a,b)/(abs(a)*abs(b)));
	  if(equals(angle, T) || angle < T) {
	    G[i][j][k] = abs(ps[i] - ps[j]);
	  }
	}
      }
    }
    fill(dp[0][0], dp[2][0], inf);
    dp[0][0][N] = 0;
    int res = 0;
    for(int t = 0; ; ++t) {
      bool flag = false;
      int p = t % 2;
      int q = 1 - p;
      for(int i = 0; i < N; ++i)
	for(int j = 0; j <= N; ++j)
	  dp[q][i][j] = inf;
      for(int i = 0; i < N; ++i) {
	for(int j = 0; j <= N; ++j) {
	  for(int k = 0; k < N; ++k) {
	    if(dp[p][i][j] == inf) continue;
	    double ncost = dp[p][i][j] + G[i][k][j];
	    if(!equals(ncost, R) && ncost > R) continue;
	    dp[q][k][i] = min(dp[q][k][i], ncost);
	    flag = true;
	    res = t+1;
	  }
	}
      }
      if(!flag) break;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1400
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: i64 = input();
    let b: i64 = input();
    let x: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut ans = 0;
    for i in 1..n {
        let aa = a * (x[i] - x[i - 1]);
        if aa < b {
            ans += aa;
        } else {
            ans += b;
        }
    }
    println!("{}", ans);
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

double R0, W0, C, R;

signed main() {
	for (; cin >> R0 >> W0 >> C >> R && (R0 || W0 || C || R);) {
		cout << max(0.0,ceil((C*W0-R0)/R)) << endl;
	}

	return 0;
}

Measured memory_bytes: 3264
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,A,B = map(int,input().split())
X = [int(i) for i in input().split()]

X.sort()
ans = (X[-1]-X[0])*A
for i in range(N-1):
    if (X[i+1] - X[i])*A > B:
        ans += B - (X[i+1] - X[i])*A
print(ans)


Measured memory_bytes: 16708
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict
def main():
    n,m=map(int,input().split())
    ac=[False]*n
    wa=[0]*n
    pena=0
    for i in range(m):
        k,s=input().split()
        k=int(k)-1
        if s=="WA":wa[k]+=1
        elif ac[k]:continue
        else:
            ac[k]=True
            pena+=wa[k]
    print(sum(ac),pena)


if __name__=='__main__':
    main()

Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4+1;

int n,a[N],d[N],xx[N],yy[N],fa[N];
ll dmx;
vector<int>g[N];
pair<ll,ll>ans;
void dfs(int x,ll de=1){
	dmx=max(dmx,de);
	d[x]=0;
	for(int i=0;i<g[x].size();++i)
	if(g[x][i]!=fa[x]){
		d[x]++;
		fa[g[x][i]]=x;
		dfs(g[x][i],de+1);
	}
}

void cal(int x,int y=0){
	static int k[N],q[N];
	q[0]=k[0]=0;
	q[++q[0]]=x;
	if(y)q[++q[0]]=y;
	ll zero=0;int dn=dmx;
	while(q[0]){
		dn--;
		if(!dn){
			if(make_pair(dmx,zero+q[0])<ans)ans=make_pair(dmx,zero+q[0]);
			return;
		}
		int dx=0;
		for(int i=1;i<=q[0];++i)dx=max(dx,d[q[i]]);
		zero=zero*dx;
		for(int i=0;i<=q[0];++i)k[i]=q[i];
		q[0]=0;
		for(int i=1;i<=k[0];++i){
			int x=k[i];
			for(int j=0;j<g[x].size();++j)
			if(g[x][j]!=fa[x]){
				q[++q[0]]=g[x][j];
			}
			zero+=dx-d[x];
		}
	}
}

int main(){
	cin>>n;
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		xx[i]=x;yy[i]=y;
	}
	ans=make_pair(2e18,2e18);
//	fa[3]=6;fa[6]=3;dfs(6);dfs(3);
//	cal(6,3);
	for(int i=1;i<=n;++i){
		fa[i]=dmx=0;
		dfs(i);
		cal(i);
	}
	for(int i=1;i<n;++i){
		int x=xx[i],y=yy[i];
		dmx=0;
		fa[y]=x;fa[x]=y;
		dfs(x);dfs(y);
		cal(x,y);
	}
	cout<<ans.first<<" "<<ans.second<<endl;
}

Measured memory_bytes: 512
#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 pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000


int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size())cout<<"UNRESTORABLE";
    else{ 
        int size=s.size()-t.size();
        int index=-1;
        for(int i=size;i>=0;i--){
            bool flag=false;
            rep(j,t.size()){
                if(s[j+i]!=t[j]&&s[i+j]!='?'){
                    flag=true;
                    break;
                }
            }
            if(!flag){
                index=i;
                break;
            }
        }
        if(index==-1)cout<<"UNRESTORABLE";
        else{
            rep(i,s.size()){
                if(index<=i&&i<index+t.size()){
                    cout<<t[i-index];
                }
                else {
                    if(s[i]=='?')cout<<'a';
                    else cout<<s[i];
                } 
            }
        }
    }
    return 0;
}
    



Measured memory_bytes: 3608
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;

fn main() {
    let s = str2vec(&input_line_str());
    let mut prev = s[0];
    let mut ans = 0;
    for z in s {
        if prev != z {
            ans += 1;
            prev = z;
        }
    }
    p(ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================








int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int H, W;
	cin >> H >> W;

	vstring S(H);
	for (int i = 0; i < H; i++)
	{
		cin >> S[i];
	}


	vvint dp(H);
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			dp[i].emplace_back(INF);
		}
	}


	if (S[0][0] == '#')
	{
		dp[0][0] = 1;
	}
	else
	{
		dp[0][0] = 0;
	}


	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{

			if (h == 0 && w == 0)
			{
				continue;
			}

			if (h == 0)
			{
				bool b_W = S[h][w - 1] == '.' && S[h][w] == '#';
				dp[h][w] = dp[h][w - 1] + b_W;
				continue;
			}
			else if (w == 0)
			{
				bool b_H = S[h - 1][w] == '.' && S[h][w] == '#';
				dp[h][w] = dp[h - 1][w] + b_H;
				continue;
			}

			bool b_W = S[h][w - 1] == '.' && S[h][w] == '#';
			bool b_H = S[h - 1][w] == '.' && S[h][w] == '#';
			dp[h][w] = min(dp[h - 1][w] + b_H, dp[h][w - 1] + b_W);


		}
	}


	cout << dp[H - 1][W - 1];

}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int x = 0;
  
  for (int i; i < S.size(); i++){
    if (S.at(i) != T.at(i) ){
      cout << "No" << endl;
      break;
    }
    else{
      x++;
    }
  }
  
  if (x == S.size() ){
    cout << "Yes" << endl;
  }
}



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

int main() {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N; cin >> N;
vector<int> p(N);{
for (int i=0; i<N;++i){
cin >> p[i];
}
  int count =0;
  for(int i=1; i<N-1; ++i){
if(p[i]>p[i-1]&&p[i]<p[i+1])
count++;
  else if(p[i]>p[i+1]&&p[i]<p[i-1])
    count++;}
  cout << count << endl;
}}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using ll = long long;
using namespace std;
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int a, b;
    cin >> a;
    cin >> b;
 
    cout << b * 2 - a << "\n";
    return 0;
}

Measured memory_bytes: 256
import math

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distance(self, pnt):
        return math.sqrt((self.x - pnt.x)**2 + (self.y - pnt.y)**2)

class Segment():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)
        if self.p1.x == self.p2.x:
            self.a = float('inf')
            self.b = None
        else:
            self.a = (self.p1.y - self.p2.y)/(self.p1.x - self.p2.x)
            self.b = self.p1.y - self.a*self.p1.x

    def is_intersect(self, seg):
        a = (seg.p1.x - seg.p2.x) * (self.p1.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p1.x)
        b = (seg.p1.x - seg.p2.x) * (self.p2.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p2.x)
        c = (self.p1.x - self.p2.x) * (seg.p1.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p1.x)
        d = (self.p1.x - self.p2.x) * (seg.p2.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p2.x)
        e = (self.p1.x - seg.p1.x)*(self.p2.x - seg.p2.x)
        f = (self.p1.x - seg.p2.x)*(self.p2.x - seg.p1.x)
        g = (self.p1.y - seg.p1.y)*(self.p2.y - seg.p2.y)
        h = (self.p1.y - seg.p2.y)*(self.p2.y - seg.p1.y)
        return a*b <= 0 and c*d <= 0 and (e <= 0 or f <= 0) and (g <= 0 or h <= 0)

    def cross_point(self, seg):
        if self.is_intersect(seg) == False: return None
        if self.a == float('inf'):
            return self.p1.x, seg.a * self.p1.x + seg.b
        elif seg.a == float('inf'):
            return seg.p1.x, self.a * seg.p1.x + self.b
        else:
            x = -(self.b - seg.b)/(self.a - seg.a)
            y = seg.a * x + seg.b
            return x, y

    def distance_with_point(self, pnt):
        vec_a = Point(self.p2.x - self.p1.x, self.p2.y - self.p1.y)
        vec_b = Point(pnt.x - self.p1.x, pnt.y - self.p1.y)
        ip = vec_a.x*vec_b.x + vec_a.y*vec_b.y
        dist2 = (self.p1.x - self.p2.x)**2 + (self.p1.y - self.p2.y)**2
        if ip/dist2 <= 0:
            return pnt.distance(self.p1)
        elif ip/dist2 >= 1:
            return pnt.distance(self.p2)
        else:
            tmppnt = Point(self.p1.x + vec_a.x*(ip/dist2), self.p1.y + vec_a.y*(ip/dist2))
            return pnt.distance(tmppnt)

    def distance_with_segment(self, seg):
        if self.is_intersect(seg): return 0
        a = self.distance_with_point(seg.p1)
        b = self.distance_with_point(seg.p2)
        c = seg.distance_with_point(self.p1)
        d = seg.distance_with_point(self.p2)
        return min(a, b, c, d)

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Segment(x0, y0, x1, y1), Segment(x2, y2, x3, y3)
    dist = line1.distance_with_segment(line2)
    print('%.9f'%dist)



Measured memory_bytes: 5720
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while(true) {
        int m,f,r; cin >> m >> f >> r;
            if (m==-1 && f == -1 &&  r == -1 ) return 0;
            if (m==-1 || f == -1 || m+f<30) {
                ct('F');
            } else if(m+f>=80){
                ct('A');
            } else if (m+f>=65 && m+f<80) {
                ct('B');
            } else if(m+f>=50 && m+f<65) {
                 ct('C');
            } else if (m+f>=30 && m+f<50 && r>=50) {
                ct('C');
            } else if (m+f>=30 && m+f <50 && r<50) {
                ct('D');
            } 
    }
}


Measured memory_bytes: 3160
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        
        for(int i=0; i<k*2-1; i++){
            System.out.print((x-(k-1))+i + " ");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    cout << (n+m-3)/(m-1)<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, A, B;
	string S;
	cin >> N >> A >> B >> S;
	int pass = 0, other = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'c') {
			cout << "No" << endl;
		}
		else if (S[i] == 'a') {
			if (pass < A + B) {
				cout << "Yes" << endl;
				pass++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			if (pass < A + B && other < B) {
				cout << "Yes" << endl;
				pass++;
				other++;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

	int n;
	cin >> n;
	vt<pi> v(n);
	rep(i, 0, n) {
		int x, l;
		cin >> x >> l;
		v[i] = {x, l};
	}
	sort(all(v));

	int r_max = v[0].first + v[0].second, ans = n;
	rep(i, 1, n) {
		if(v[i].first - v[i].second < r_max) {
			ans--;
			r_max = min(r_max, v[i].first + v[i].second);
		}
		else r_max = v[i].first + v[i].second;
	}
	cout << ans << endl;
}

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

int main(){
	int n, l; cin >> n >> l;
	vector<string> s;
	for(int i = 0; i < n; i++){
		string t; cin >> t;
		s.push_back(t);
	}
	sort(s.begin(), s.end());
	for(int i = 0; i < n; i++){
		cout << s[i];
	}
	cout << endl;
	return 0;	
}

Measured memory_bytes: 256
/*
[agc029] C - Lexicographic constraints
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 2e5;

int N;
ll A[MAX_N];

bool can(int n) {
    map<ll, int> m;
    for (int i = 1; i < N; i++) {
        if (A[i] > A[i - 1]) {
            continue;
        }
        m.erase(m.upper_bound(A[i]), m.end());
        if (m.find(A[i]) == m.end()) {
            if (n == 1) {
                return false;
            }
            m[A[i]] = 1;
        } else {
            m[A[i]]++;
            for (int j = A[i]; m[j] == n; j--) {
                if (j == 1) {
                    return false;
                }
                m[j] = 0;
                if (m.find(j - 1) == m.end()) {
                    m[j - 1] = 1;
                } else {
                    m[j - 1]++;
                }
            }
        }
    }

    return true;
}

ll solve() {
    int ng = 0;
    int ok = MAX_N;
    while (ok - ng > 1) {
        int m = (ok + ng) / 2;
        if (can(m)) {
            ok = m;
        } else {
            ng = m;
        }
    }

    return ok;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>

using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60
 
int main() {
    int N;
    ll M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
 
    // dp[l][r]: (l, r)内の組の総数
    map<ll, ll> mod_map;
    vector<ll> mod(N+1);
    mod_map[0] = 1;
    FOR(i, 1, N) {
        mod[i] = (mod[i-1] + A[i-1]) % M;
        if(mod_map.find(mod[i]) == mod_map.end()) {
            mod_map[mod[i]] = 1;
        } else {
            mod_map[mod[i]] += 1;
        }
    }

    // cerr << "mod_map.size = " << mod_map.size() << endl;
    // for(auto itr = mod_map.begin(); itr != mod_map.end(); ++itr) {
    //     cerr << itr->first << " : " << itr->second << endl;
    // }

    ll ans = 0;
    for(auto itr = mod_map.begin(); itr != mod_map.end(); ++itr) {
        ans += itr->second * (itr->second - 1);
    }

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

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

constexpr long long INF = std::numeric_limits<long long>::max();
constexpr long long NINF = std::numeric_limits<long long>::min();

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

    vector<long long> A(3*N);

    for (auto &a : A) {
        cin >> a;
    }

    priority_queue<long long, vector<long long>, greater<long long>> qf;
    long long sum = 0;
    for (long long i = 0; i < N; i++) {
        sum += A[i];
        qf.push(A[i]);
    }

    vector<long long> memo;
    memo.push_back(sum);

    for (long long i = N; i < 2*N; i++) {
        sum += A[i];
        qf.push(A[i]);
        sum -= qf.top();
        qf.pop();
        memo.push_back(sum);
    }

    priority_queue<long long> qe;
    reverse(A.begin(), A.end());
    sum = 0;
    for (long long i = 0; i < N; i++) {
        sum += A[i];
        qe.push(A[i]);
    }

    vector<long long> memo_e;
    memo_e.push_back(sum);

    for (long long i = N; i < 2*N; i++) {
        sum += A[i];
        qe.push(A[i]);
        sum -= qe.top();
        qe.pop();
        memo_e.push_back(sum);
    }

    reverse(memo_e.begin(), memo_e.end());

    long long ans = NINF;
    for (long long i = 0; i < memo.size(); i++) {
        ans = max(ans, memo[i] - memo_e[i]);
    }

    cout << ans << endl;
}

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

    if (n < 2)
    {
        cout << 1;
        return 0;
    }

    int v = 1;
    while (true)
    {
        if (v * 2 > n)
        {
            break;
        }
        v *= 2;
    }
    cout << v;
}

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

int main() {

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

    int cnt = 0;

    for (int i = a; i <= b; i++) {
        
        int s = i % 10;
        int t = i / 10000 % 10;
        int u = i /10 % 10;
        int v = i / 1000 % 10;

        if (s == t && u == v) 
            cnt ++;
        
    }
     
    cout << cnt << endl;

    return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  vector<bool> ac(n, false);
  vector<int> cnt(n, 0);
  rep(i, m) {
    ll no;
    string res;
    cin >> no;
    no--;
    cin >> res;
    if (res == "AC")
      ac[no] = true;
    else if (!ac[no])
      cnt[no]++;
  }
  ll accnt = 0, pen = 0;
  rep(i, n) {
    if (ac[i]) {
      accnt++;
      pen += cnt[i];
    }
  }
  cout << accnt << " " << pen << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--; B--; C--; D--;
    string S;
    cin >> S;
    rep(i, A+1, max(C-1,D-1)){
        if(S[i] == '#' && S[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }
    
    if(D > C){
        cout << "Yes" << endl;
        return 0;
    }

    bool f = false;
    rep(i, B-1, min(D, C-1)){
        if(S[i] == '.' && S[i+1] == '.' && S[i+2] == '.'){
            f = true;
        }
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            

            int plus = a+b;
            int minus = a-b;
            int mul = a*b;
            if(plus >= minus)
            {
                if(plus >= mul)
                    Console.WriteLine(plus);
                else
                    Console.WriteLine(mul);
            }    
            else
            {
                if(minus >= mul)
                    Console.WriteLine(minus);
                else
                    Console.WriteLine(mul);
            } 
    
        }
    }

Measured memory_bytes: 13140
import java.util.*;

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

        int res = 0;
        for (int a=0; a<=A; a++) {
            for (int b=0; b<=B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C)
                    res++;
            }
        }

        System.out.println(res);
    }
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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


int main(){
  ll n, m, c; cin >> n >> m >> c;
  Vi b(m); 
  REP(i, m) {cin >> b[i];}
  ll ans = 0;
  REP(i, n){
    Vi a(m); 
    REP(j, m) {cin >> a[j];}
    ll temp = c;
    REP(j, m){
      temp += a[j] * b[j];
    }
    if (temp > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int A,B;	cin>>A>>B;
	int ans;
	ans=max(0,A-2*B);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3624
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(N):
  left=min(A[i],B[i])
  ans+=left
  A[i]-=left
  B[i]-=left
  right=min(A[i+1],B[i])
  ans+=right
  A[i+1]-=right
  B[i]-=right
print(ans)

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

bool is_integer(double x){
    return std::floor(x) == x;
}

int main(){
    ll n; cin >> n;

    while(true){
        if(is_integer(sqrt(n))){
            put(n);
            return 0;
        }
        n--;
    }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;

int cnt[100005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll ans=1;
  rep(i,n){
    if(a[i]>=1){
      ll mae=cnt[a[i]-1];
      ans=(ans*(mae-cnt[a[i]]));
    }else ans*=3-cnt[a[i]];
    ans=ans%MOD;
    cnt[a[i]]++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    auto solve = [](const string& s, const string& t) {
        const int n = s.length(), m = t.length();
        string s1 = " " + s, t1 = " " + t;

        auto dp = make_v(n + 1, m + 1, 0);
        
        FOR(i, 1, n + 1)FOR(j, 1, m + 1) {
            if (s1[i] == t1[j]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j -  1] + 1);
            }
            dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }

        return dp[n][m];
    };

    REP(i, n) {
        string s, t; cin >> s >> t;

        cout << solve(s, t) << endl;
    }

    return 0;
}



Measured memory_bytes: 6768
import Data.List
import Control.Applicative

main = do
  _ <- getLine
  xs <-  map read <$> words <$> getLine :: IO [Int]
  --let xs = [1,2,2,3]
  let bp = length xs `div` 2
  let xs' = sort xs
  let b1 = xs' !! (bp - 1)
  let b2 = xs' !! bp
  mapM_ print $ map (\i -> if i > b1 then b1 else b2) xs


Measured memory_bytes: 148860
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>  
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll LCM = lcm(C,D);
    ll sumb = B/C + B/D - B/LCM;
    ll suma = (A-1)/C + (A-1)/D - (A-1)/LCM;
    cout << (B-A+1)-(sumb-suma) << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
int main()
{
    ll N;
    cin >> N;
    auto X = prime_factorize(N);
    // int MAX = N;24
    // vector<int> is_prime(MAX, 1);
    // is_prime[0] = 0, is_prime[1] = 0;
    // for (int i = 2; i*i < MAX; ++i) {
    //     if (!is_prime[i]) continue;
    //     for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    // }
    ll ans = 0;
    int max = X.size();
    //cout << max << endl;
    rep(i, X.size())
    {
        int p = 1;
        for(int j = 0 ; j < X[i].second; j+=p)
        {
            ans++;
            p++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string ret;
  for (int k = 0; k < 3; ++k) {
    string s;
    cin >> s;
    ret += s[0];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nm[0];
			int m = nm[1];

			var to = new List<int>[n];
			for (int i = 0; i < n; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < m; i++) {
				var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int a = ab[0] - 1;
				int b = ab[1] - 1;
				to[a].Add(b);
				to[b].Add(a);
			}

			foreach (int i in to[0]) {
				foreach (int j in to[i]) {
					if (j == n - 1) {
						Console.WriteLine("POSSIBLE");
						return;
					}
				}
			}

			Console.WriteLine("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 37676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL MOD = 1e9+7;

int main() {
  string S;
  cin >> S;
  
  vector<vector<LL>> dp(100001, vector<LL>(13));
  
  dp[0][0] = 1;
  int N = S.size();
  rep(i, N) {
    LL c;
    if (S[i] == '?') c = -1;
    else c = S[i] - '0';
    
    rep(j,10) {
      if (c != -1 && c != j) continue;
      rep(k,13) {
        dp[i+1][(k*10+j) % 13] += dp[i][k];
      }
    }
    rep(j,13) dp[i+1][j] %= MOD;
  }
  LL answer = dp[N][5];
  
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 13696
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));default:return i;}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],6);
  var output = 0;
  for(var i = 0; i < N-2; i++){
    if(list[i] == "A" && list[i+1] == "B" && list[i+2] == "C"){
       output++;
       }
  }
  myout(output);
}

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

using namespace std;

int main() {

    string in_data;
    string mae_data;
    string ato_data;

    cin >> in_data;

    mae_data = in_data.substr(0,2);
    ato_data = in_data.substr(2,2);

    int mae = atoi(mae_data.c_str());
    int ato = atoi(ato_data.c_str());

    bool mae_yy, mae_mm, ato_yy, ato_mm;
    mae_yy  = false;
    mae_mm  = false;
    ato_yy  = false;
    ato_mm  = false;

    if (mae >= 1 && mae <= 12) {
        //前がMM可能
        mae_mm = true;
    }

    if (mae >= 0 && mae <= 99) {
        //前がYY可能
        mae_yy = true;
    }

    if (ato >= 1 && ato <= 12) {
        //後がMM可能
        ato_mm = true;
    }

    if (ato >= 0 && ato <= 99) {
        //後がYY可能
        ato_yy = true;
    }

    string message;
    message = "";

    if (mae_mm && mae_yy && ato_mm && ato_yy) {
        //なんとも言えない
        message ="AMBIGUOUS";

    } else {

        if (mae_yy && ato_mm) {
            //YYMM
            message = "YYMM";

        } else if (ato_yy && mae_mm) {
            //MMYY
            message = "MMYY";

        } else {
            //other
            message = "NA";
        }

    }


    cout << message << endl;


    return 0;

}

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

int main(){
	int n,m;
	cin>>n>>m;
	priority_queue<int,vector<int>,less<int> >pq;
	
	while(n--){
		int price;
		cin>>price;
		pq.push(price);
	}
	while(m-- && pq.size()){
		int curr = pq.top();
		pq.pop();
		curr/=2;
		if(curr) pq.push(curr);
	}
	long long ret = 0;
	while(pq.size()){
		ret+=pq.top();
		pq.pop();
	}
	cout<<ret;
}

Measured memory_bytes: 3936
N, M = map(int, input().split())
favorite_food = { i for i in range(1,M+1)}
for _ in range(N):
  KandA = list(map(int, input().split()))
  Aset = set(KandA[1:])
  favorite_food = Aset & favorite_food
print(len(favorite_food))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if( (A+B) >= (A-B) ) {
			if( (A+B) >= (A*B) ) {
				System.out.print(A+B);
			} else if( (A+B) < (A*B) ) {
				System.out.print(A*B);
			}
		} else if ( (A+B) <= (A-B) ) {
			if( (A-B) >= (A*B) ) {
				System.out.print(A-B);
			} else if( (A-B) < (A*B) ) {
				System.out.print(A*B);
			}
		}
	}

}

Measured memory_bytes: 21844