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

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

int h, w;
vector<string> s;
vector<vector<edge>> g;

// 辺の長さを無視した距離
// depend:edge
vector<int> distance_nonweight(vector<vector<edge>> &g, int start) {
    vector<int> res(g.size(), INT_MAX);
    res[start] = 0;
    queue<int> bfs;
    bfs.push(start);
    while (!bfs.empty()) {
        int now = bfs.front();
        bfs.pop();
        for (auto e : g[now]) {
            int next = e.to;
            if (res[next] > res[now] + 1) {
                res[next] = res[now] + 1;
                bfs.push(next);
            }
        }
    }
    return res;
}

int main() {
    cin >> h >> w;
    s.resize(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    g.resize(h * w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                if (i - 1 >= 0 && s[i - 1][j] == '.') {
                    g[i * w + j].push_back(edge((i - 1) * w + j));
                }
                if (i + 1 < h && s[i + 1][j] == '.') {
                    g[i * w + j].push_back(edge((i + 1) * w + j));
                }
                if (j - 1 >= 0 && s[i][j - 1] == '.') {
                    g[i * w + j].push_back(edge(i * w + j - 1));
                }
                if (j + 1 < w && s[i][j + 1] == '.') {
                    g[i * w + j].push_back(edge(i * w + j + 1));
                }
            }
        }
    }
    int sharp = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') sharp++;
        }
    }
    vector<int> dist = distance_nonweight(g, 0);
    int ans = 0;
    if (dist.back() == INT_MAX) {
        ans = -1;
    } else {
        ans = h * w - sharp - dist.back() - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>

using namespace std;

#define MAX 1000000000;

bool is_divisor(int x, int y) {
  return x % y == 0;
}

// x >= y
int gcd(int x, int y) {
  if (is_divisor(x, y)) {
    return y;
  }

  return gcd(y, x % y);
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(max(x, y), min(x, y)) << endl;
}



Measured memory_bytes: 3108
n,k = gets.chomp.split.map(&:to_i)
ps = gets.chomp.split.map{|x| (x.to_f + 1)/2}
sum_array = Array.new(n,0)
ans = 0
ps.each_with_index do |p,i|
  if i != 0
    sum_array[i] = sum_array[i-1] + p
  else
    sum_array[i] = p
  end
end
(k-1..n-1).each do |i|
  if i != k-1
    ans = [ans,sum_array[i] - sum_array[i-k]].max
  else
    ans = [ans,sum_array[i]].max
  end
end
puts ans

Measured memory_bytes: 21124
#include <stdio.h>
#include <stdlib.h>
int main(){
   char one[10] = {0};
   char two[10] = {0};
   char three[10] = {0};
   scanf("%s %s %s",one,two,three);
   char alpha = one[0] - 32;
   char beta = two[0] -32;
   char gamma = three[0]-32;
    printf("%c%c%c\n",alpha,beta,gamma);
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
using namespace std;

signed main(){
  
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  
  vector<char> ans(500000, 'Z');
  int start = 200000;
  string S;
  cin >> S;
  int cnt = 0;
  for( int i = start; i < start + S.size(); i++ ){
    ans.at(i) = S.at(cnt);
    cnt++;
  }
  
  int Q;
  cin >> Q;
  
  int maecnt = 199999;
  int bcnt = start + S.size();
  
  bool fg = 1;
  //1のとき通常、0のとき反転
  for( int i = 0; i < Q; ++i ){
    int T;
    cin >> T;
    if( T == 1 ){
      if( fg ) fg = 0;
      else fg = 1;
    }
    
    else if( T == 2 ){
      int F;
      cin >> F;
      char C;
      cin >> C;
      if( F == 1 ){ //先頭に追加
        if( fg ){
          ans.at(maecnt) = C;
          maecnt--;
        }
        else{
          ans.at(bcnt) = C;
          bcnt++;
        }
      }else if( F == 2 ){ //末尾に追加
        if( fg ){
          ans.at(bcnt) = C;
          bcnt++;
        }else{
          ans.at(maecnt) = C;
          maecnt--;
        }
      }
    }
  }
  
  if( fg ){
    for( int i = 0; i < ans.size(); i++ ){
      if( ans.at(i) == 'Z' ) continue;
      cout << ans.at(i);
    }
    cout << endl;
  }
  else{
    for( int i = ans.size()-1; i >= 0; i-- ){
      if( ans.at(i) == 'Z' ) continue;
      cout << ans.at(i);
    }
    cout << endl;
  }
  
}


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

int main(){
int h,w;cin>>h>>w;
vector<string>s(2*h);
for(int i=0;i<h;i++){
	string x;cin>>x;
 s[2*i]=x;s[2*i+1]=x;
}
for(auto&& u:s)cout<<u<<endl;
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .chars()
        .map(|x| x.to_string().parse::<i32>().unwrap())
        .collect::<Vec<_>>();
    // 総当たり
    for i in 0..1 << 4 {
        let ap = i & 1 << 3 == 0;
        let bp = i & 1 << 2 == 0;
        let cp = i & 1 << 1 == 0;
        let dp = i & 1 << 0 == 0;

        let a = if ap { list[0] } else { -list[0] };
        let b = if bp { list[1] } else { -list[1] };
        let c = if cp { list[2] } else { -list[2] };
        let d = if dp { list[3] } else { -list[3] };

        if a + b + c + d == 7 && ap {
            return format!(
                "{}{}{}{}{}{}{}=7",
                list[0],
                if bp { "+" } else { "-" },
                list[1],
                if cp { "+" } else { "-" },
                list[2],
                if dp { "+" } else { "-" },
                list[3]
            ).to_string();
        }
    }
    panic!("");
}

#[test]
fn test() {
    let tests = vec![("1222", "1+2+2+2=7"), ("0290", "0-2+9+0=7")];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
		int N, M;
		cin >> N >> M;
		int l[M], r[M];
		int max_l = 0, min_r = 1e9;
		for (int i = 0; i < M; i++) {
				cin >> l[i] >> r[i];
				max_l = max(max_l, l[i]);
				min_r = min(min_r, r[i]);
		}

		cout << max(min_r - max_l + 1, 0) << endl;
		return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
int main(){
  int n,k,l[100001]={},r[100001]={},t=2001001001,ln=0,rn=0,i,x;
  std::cin>>n>>k;
  for(i=0;i<n;++i){
    std::cin>>x;
    if(x<0){++ln;l[ln]=-x;}
    else if(x>0){++rn;r[rn]=x;}
    else{--k;}
  }
  std::sort(l,l+ln+1);
  if(k==0)t=0;
  else for(i=std::max(0,k-rn);i<std::min(ln+1,k+1);++i)t=std::min(std::min(l[i],r[k-i])*2+std::max(l[i],r[k-i]),t);
  std::cout<<t<<"\n";
}

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

int main(){
  double N,T,A,H;
  cin >>N>>T>>A;
  
  double a = 1000;
  int ans;
  rep(i,1,N){
    cin >>H;
    double ave = abs(T-H*0.006-A);
    if(ave<=a){
      ans = i;
      a = ave;
    }
  }
  cout <<ans<<endl;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i32 N = input(), K = input();
    vector<pair<i32, i32> > s(N);
    cin >> s;

    whole(sort, s,
          [](const auto &a, const auto &b) { return a.second > b.second; });

    priority_queue<i32> pq;
    vector<bool> use(N);
    i64 ans = 0, sum = 0, cnt = 0;

    range(i, 0, N) {
        i32 t = s[i].first, d = s[i].second;

        if (i < K) {
            if (use[t]) {
                pq.push(-d);
            } else {
                use[t] = true;
                cnt += 1;
            }
            sum += d;
            if (i + 1 == K) ans = sum + cnt * cnt;
            continue;
        }

        if (use[t]) continue;
        if (pq.empty()) break;

        use[t] = true;
        cnt += 1;
        sum += pq.top() + d;
        pq.pop();

        chmax(ans, sum + cnt * cnt);
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <map>

#define ll long long int
#define MAX 1000000

using namespace std;

int arr[MAX];

void Eratosthenes() 
{
	for (int i = 0; i < MAX; i++) {
		arr[i] = 1;
	}

	arr[1] = 0;

	for (int i = 2; i < sqrt(MAX); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < MAX; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < MAX; i++) {
		if (arr[i]) {
			//cout << i << endl;
		}
	}

}


int main(void)
{
	int a, d, n;
	int i;
	int count = 0;
	vector <int> ans;
	Eratosthenes();

	while (1) {
		count = 0;
		cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0) {
			break;
		}

		while (1) {

			if (arr[a] == 1) {
				count++;
			}


			if (count == n) {
				break;
			}



			a = a + d;

		}

		ans.push_back(a);

	}


	for (i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}




	return (0);
}

Measured memory_bytes: 7008
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
// run : ctrl + c 

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



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

    int x,y,z;
    cin>>x>>y>>z;
    int n = x+y+z;
    ll a[n],b[n],c[n];
    array<ll,3> v[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        v[i] = {b[i] - a[i],c[i],a[i]};
    }
    sort(v,v+n);
    ll pre[n]={}, pos[n]={};
    priority_queue<ll> pq;
    for(int i=0;i<x;i++){
        pq.push(v[i][1] - v[i][2]);
        pre[i] = v[i][2];
        if(i) pre[i] += pre[i-1];
        //cerr << pre[i] << endl;
    }
    for(int i=x;i<x+z;i++){
        pq.push(v[i][1] - v[i][2]);
        ll p = pq.top();
        pq.pop();
        pre[i] += v[i][2];
        pre[i] += pre[i-1] + p;
        //cerr << pre[i] << endl;
    }
    while(pq.size()) pq.pop();
    for(int i=0;i<y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0]+v[n-1-i][2]));
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        if(i) pos[n-1-i] += pos[n-i];
    }
    for(int i=y;i<z+y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0] + v[n-1-i][2]));
        ll p = pq.top();
        pq.pop();
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        pos[n-1-i] += pos[n-i] + p;
    }
    ll ans = 0;
    for(int i=x-1;i<x+z;i++){
        chmax(ans,pre[i]+pos[i+1]);
        
    }
    cout << ans << endl;



}


Measured memory_bytes: 7672
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

int mem[3005][3005];
pair<int,int> arr[3005];
int n,t;

int go(int x,int y)
{
	if(y>=t) return 0;
	if(x>=n) return 0;
	if(mem[x][y]!=-1) return mem[x][y];
	return mem[x][y]=max(go(x+1,y),arr[x].S+go(x+1,y+arr[x].F));
}

int main()
{
	cin >> n >> t;
	for(int i=0;i<n;i++)
		cin >> arr[i].F >> arr[i].S;
	sort(arr,arr+n);
	memset(mem,-1,sizeof mem);
	cout << go(0,0) << endl;
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	int i=sqrt(n);
	for(i;i>=1;i--){
		if(n%i==0){
			cout<<i+n/i-2;
			break;
		}
		
		
		
	}
	
	
	
	
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n, a[10001], b[10001], i,d;
	char c[10001];
	i = 1;
	d = 1;
	while (1) {
		scanf("%d %c %d", &a[i], &c[i], &b[i]);
		if (c[i] == '?') { break; };
		d = d + 1;
		i++;
	}
	n = 1;
	while (n <= d) {
		if (c[n] == '+') { printf("%d\n", a[n] + b[n]); }
		else if (c[n] == '-') { printf("%d\n", a[n] - b[n]); }
		else if (c[n] == '*') { printf("%d\n", a[n] * b[n]); }
		else if (c[n] == '/') { printf("%d\n", a[n] / b[n]); }
		n++;
	}
	return 0;
}


Measured memory_bytes: 3236
const main = (input) => {
  const args = input.split(' ');
  const A = parseInt(args[0], 10);
  const B = parseInt(args[1], 10);

  const sumNum = A+B
  const minusNum = A-B
  const doubleNum = A*B

  const result = Math.max(sumNum, minusNum, doubleNum)

  console.log(result) 

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <string>
#include <bitset>
     
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
    
void Baseball::hit(){
    runners <<= 1; //shift
    runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
    
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
    
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }else if(event == "HOMERUN"){
                game.homerun();
            }else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3032
#include<iostream>
#include<cstdio>
using namespace std;
long long n,k,a0,a1,ans;
int main()
{
	cin>>n>>k;
	ans=0;
	/*
	a1=0;
	for(int i=1;i<=n;i++)if(!(i%k))a1++;
	//*/
	///*
	a1=n/k;
	//*/
	ans+=(a1*a1*a1);
	if(!(k&1))
	{
		a0=(k>>1);
		///*
		a1=0;
		for(int i=0;i<=(n-a0);i++)if(!(i%k))a1++;
		//*/
		/*
		a1=((n-a0)/k)+1;
		//*/
		ans+=(a1*a1*a1);
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b, c;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> c;
  cout << ((a-c)*(b-c)<0 ? "Yes" : "No") << endl;
}

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

using namespace std;
typedef long long ll;
const int N = 105;
int h,w;
char s[N][N];
int dir[5][2]={0,1,0,-1,1,0,-1,0};
int judge(int a,int b)
{
    if(a<0||a>h||b<0||b>w)
        return 0;
    return 1;
}
int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++)
        scanf("%s",s[i]);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(s[i][j]=='#'){
            int flag=1;
            for(int k=0;k<4;k++){
                int x=i+dir[k][0];
                int y=j+dir[k][1];
                if(judge(x+1,y+1))
                    if(s[x][y]=='#')
                    {
                        flag=0;
                        break;
                    }
              }
              if(flag==0)
                continue;
              else{
                printf("No\n");
                return 0;
              }
          }
       }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
import sys
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**18


def binary_search(min_n, max_n, judge):

    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if judge(tn):
            max_n = tn
        else:
            min_n = tn

    return max_n


def main():
    N, K = in_nn()
    A = in_nl()

    Ap = []
    Am = []
    Nz = 0

    for i in range(N):
        if A[i] > 0:
            Ap.append(A[i])
        elif A[i] == 0:
            Nz += 1
        else:
            Am.append(A[i])

    Np = len(Ap)
    Nm = len(Am)

    m_count = Np * Nm
    z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2
    # p_count = Np * (Np - 1) // 2 + Nm * (Nm - 1) // 2

    if K <= m_count:

        Ap.sort()
        Am.sort()

        def judge(tn):

            count = 0
            for i in range(Nm):
                search = -(-tn // Am[i])
                j = bisect.bisect_left(Ap, search)
                count += Np - j

            return count >= K

        ans = binary_search(-INF, -1, judge)

    elif K <= m_count + z_count:
        ans = 0
    else:

        Ap.sort()
        Am = sorted([-a for a in Am])

        def judge(tn):

            count = 0
            for i in range(Np):
                search = tn // Ap[i]
                j = bisect.bisect_right(Ap, search)
                count += max(0, j - i - 1)

            for i in range(Nm):
                search = tn // Am[i]
                j = bisect.bisect_right(Am, search)
                count += max(0, j - i - 1)

            return count >= (K - m_count - z_count)

        ans = binary_search(1, INF, judge)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116504
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*d, b*c), max(a*c, b*d)) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int i,j,k,h,w;
    vector<int> vx,vy;
    while(1){
        cin>>h>>w;
        if(h==0&&w==0){
            break;
        }
        else{
            vx.push_back(h);
            vy.push_back(w);
        }
    }
    for(i=0; i<vx.size(); i++){
        for(j=0; j<vx[i];j++){
            for(k=0; k<vy[i]; k++){
                if(j%2==0){
                    if(k%2==0){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }   
                }
                else{
                    if(k%2==0){
                        cout<<".";
                    }
                    else{
                        cout<<"#";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,M,X;
    cin>>N>>M>>X;
    vector<int>A(M);
    for(int i=0;i<M;i++){
        cin>>A.at(i);
    }
    int sumb=0;int sums=0;
    for(int i=X;i<=N;i++){
        for(int j=0;j<M;j++){
            if(i==A.at(j)){sumb++;}
        }
    }
   
    for(int i=X;i>=0;i--){
        for(int j=0;j<M;j++){
            if(i==A.at(j)){sums++;}
        }
    }
    cout<<min(sumb,sums)<<endl;
   
    return 0;
}

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

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;



void chmax(ll &a,ll b) {
	if (a < b)a = b;
}

int fl(int a, int b) {
	if (a%b == 0)return a / b;
	else return a / b + 1;
}


int main() {
	int n, h;
	cin >> n >> h;
	vector<pair<int, int>>v(n);

	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		v.push_back({a,0});
		v.push_back({b,1});
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	int i = 0;
	int ans = 0;
	while (h>0) {
		if (v[i].second == 1) {
			h -= v[i].first;
			ans++;
			i++;
		}
		else {
			ans += fl(h,v[i].first);
			break;
		}
	}

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

Measured memory_bytes: 4848
# ABC077C

import bisect

N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
bCS=[0]*(N+1)
for i in range(N):
    bCS[i+1] = bCS[i]+bC[i]
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    ans+=bCS[N]-bCS[x]
        
print(ans)

Measured memory_bytes: 110820
import sys, math
import bisect, heapq
import collections

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline

gets = lambda: input().rstrip()
getn = lambda: int(input())
getmul = lambda: (int(i) for i in input().split())
getlist = lambda: [int(i) for i in input().split()]

s = gets()
if s == "ABC":
    print("ARC")
else:
    print("ABC")


Measured memory_bytes: 9352
#include <iostream>

using namespace std;

int main()
{
    int h;
    int in;
    int a[100];
    int i;
    while (cin >> h)
    {
        for(i = 0; i < h; i++)
        {
            cin >> in;
            *(a + i) = in;
        }
        *(a + i) = '\0';
        for(i = h - 1; i > 0; i--)
        {
            cout << a[i] << " ";
        }
        cout << a[0] << endl;
    }
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, MAXN = 1000010, i, j, k, ans, x;
	cin >> n;
	vector<int> ct(MAXN, 0);
	vector<bool> valid(MAXN, true);

	for (i = 0; i < n; i++) {
		cin >> x;
		ct[x]++;
	}

	ans = 0;
	for (i = 0; i < MAXN; i++) {
		if (valid[i] && (ct[i] == 1)) ans++;
		if (ct[i] > 0) {
			for (j = i + i; j < MAXN; j += i) valid[j] = false;
		}
	}
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 6844
package main

import "fmt"

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

	b := make(map[int]bool, m)
	var a int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		b[a] = true
	}

	dp := make([]int, n+5)
	dp[0] = 1
	dp[1] = 1
	if b[1] {
		dp[1] = 0
	}

	mod := int(1e9 + 7)
	for i := 2; i <= n; i++ {
		if b[i] {
			continue
		}

		dp[i] = (dp[i-1] + dp[i-2]) % mod
	}

	fmt.Println(dp[n])
}


Measured memory_bytes: 5504
fn main() {
    let line = read::<String>();
    let line = &line[0];
    if line == "RRR" {
        println!("3");
        return;
    }
    if line == "RRS" || line == "SRR" {
        println!("2");
    } else if line.contains('R') {
        println!("1");
    } else {
        println!("0");
    }
}

use std::io::{self, BufRead, Read};
use std::vec::Vec;
fn read<T: std::str::FromStr>() -> Vec<T> {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.lock().read_line(&mut buf).unwrap();
    parse_line(&buf)
}

fn read_lines<T: std::str::FromStr>(count: usize) -> Vec<Vec<T>> {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    let mut result = Vec::<Vec<T>>::with_capacity(count);
    for _ in 0..count {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        result.push(parse_line(&buf));
    }
    result
}

fn parse_line<T: std::str::FromStr>(string: &str) -> Vec<T> {
    string.trim().split(' ').map(|s| T::from_str(s).ok().unwrap()).collect()
}


Measured memory_bytes: 2124
#include <iostream>
using namespace std;
typedef long long ll;
ll n,k,bik[400001],MOD=1e9+7,A;
ll f(ll a,ll b){
    if(b==1)return a;
    if(b%2==1)return f(a,b-1)*a%MOD;
    return f(a,b/2)*f(a,b/2)%MOD;
}
ll comb(ll n,ll r){
    if(n<=200000)return bik[n]*f(bik[r],MOD-2)%MOD*f(bik[n-r],MOD-2)%MOD;
    else {
        ll L=1;
        ll LL=1;
        //cout<<L<<n<<r<<endl;
        for(ll i=0;i<r;i++){
            L*=(n-i);
            L%=MOD;
            LL*=(r-i);
            LL%=MOD;
            //cout<<L<<endl;
        }
        return L*f(LL,MOD-2)%MOD;
    }
}
int main(void){
    cin>>n>>k;
    bik[0]=1;
    for(ll i=0;i<200001;i++){
        bik[i+1]=bik[i]*(i+1)%MOD;
    }
    //A=0;
    if(n<=k+1){
        cout<<comb(n+n-1,n)<<endl;
        return 0;
    }
    else {
        for(ll i=k+1;i<n;i++){
            //cout<<i<<endl;
            A+=comb(n,i)*comb(n-1,i);
            //cout<<comb(n,i)*comb(n-1,i)<<endl;
            //cout<<A<<endl;
            A%=MOD;
            //cout<<A<<endl;
        }
        A=comb(n+n-1,n)-A;
        A%=MOD;
        A=(A+MOD)%MOD;
        cout<<A<<endl;
        return 0;
    }
}


Measured memory_bytes: 1920
let () =
  Scanf.scanf "%d %d\n" @@ fun n k ->
  let l = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let _ = Array.fast_sort (fun x y -> y-x) l in
  let ans = ref 0 in
  for i = 0 to k-1 do
    ans := !ans + l.(i)
  done;
  Printf.printf "%d\n" !ans

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

long int gcd(long int x,long int y){
    if(x % y == 0){
        return y;
    }
    return gcd(y,x % y);
}

int main(){
    long int A,B,C,D;
    cin >> A >> B >>C >> D;
    
    long int E = gcd(C,D);
    long int F = (C*D)/E;
    long int cntC = B/C -A/C ;
    long int cntD = B/D -A/D ;
    long int cntCD = B/F - A/F;
    if(A%C == 0) cntC += 1;
    if(A%D == 0) cntD += 1;
    if(A%F == 0) cntCD += 1;
    cout << B - A - cntC - cntD + cntCD + 1 << endl;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int n, x; cin >> n >> x;
    int A[n];
    for (int i=0;i<n;++i) {
        cin >> A[i];
    }
    sort(A,A+n);
    int count=0;
    for (int i=0;i<n;++i){
        if (x < A[i]) break;
        if (i==n-1) {
            if (x==A[i]) ++count;
            break;
        } 
        x -= A[i];
        ++count;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
int main() {
	cin >> N;
	string S;
	cin >> S;
	vl A(2*N);
	A[i] = 0;
	if (S[0] == 'W' || S[2*N - 1] == 'W') {
		cout << 0;
		exit(0);
	}
	for (i = 0; i < 2*N-1; i++) {
		if (S[i] == S[i + 1]) {
			A[i + 1] = (A[i] + 1) % 2;
		}
		else {
			A[i + 1] = A[i];
		}
	}
	vl R(2*N + 1), L(2*N + 1);
	R[0] = 0; L[0] = 0;
	for (i = 0; i < 2*N; i++) {
		R[i + 1] = R[i]; L[i + 1] = L[i];
		if (A[i] == 0) L[i + 1]++;
		else R[i + 1]++;
	}
	if (R[2*N] != L[2*N]) {
		cout << 0;
		exit(0);
	}
	ans = 1;
	for (i = 0; i < 2*N; i++) {
		if (A[i] == 1) {
			(ans *= (L[i] - R[i])) %= MOD;
		}
	}
	for (i = 1; i <= N; i++) {
		(ans *= i) %= MOD;
	}
	co(ans);
}


Measured memory_bytes: 8616
import sys
import fractions
from functools import reduce
input = sys.stdin.readline
n, m = [int(x) for x in input().strip().split()]
a = [int(x)//2 for x in input().strip().split()]
a = list(set(a))

def lcm_base(x, y): return x * y // fractions.gcd(x, y)
lcm = reduce(lcm_base, a, 1)


for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        break
else:
    print((m // lcm + 1) // 2)


Measured memory_bytes: 89580
n = int(input())
x = n % 2

ans = []
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if x == 0:
            if i == n+1-j:
                continue
            ans.append((i,j))
        else:
            if i == (n-j):
                continue
            ans.append((i,j))
            
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 74552
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,pos;
    cin>>n>>k;
    vector<int>x;
    int ans=0;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
    }
        cout << (n-1 + (k-2))/(k-1) << endl;
 
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations

def c(N, K):
    for i, n in enumerate(N):
        if n != 0:
            break
    N = N[i:]
    a = len(N)
    if a < K:
        return 0
    if K == 1:
        return N[0] + 9 * (a - 1)
    return (N[0] - 1) * c([9] * (a - 1), K - 1) + c(N[1:], K - 1) + c([9] * (a - 1), K)

def main():
    N = list(map(int, input()))
    K = int(input())
    return c(N, K)
    

print(main())


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    ll res = 0;
    FOR(i, 1, n + 1)
    {
        ostringstream oss;
        oss << i;
        string s = oss.str();
        if ((ll)s.length() % 2 != 0)
            res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define v vector<vector<long>>
using namespace std;
long util(int i,int j,v &dp,vector<long>&arr,vector<long>&sum){
	if(i>j)
		return 0;
	if(i==j){
		dp[i][j]=arr[i];
		return dp[i][j];
	}
	if(dp[i][j]!=-1)
		return dp[i][j];
	dp[i][j]=arr[i]+sum[j]-sum[i]-util(i+1,j,dp,arr,sum);
	long temp=arr[j]+sum[j-1];
	if(i-1>=0)
		temp-=sum[i-1];
	temp-=util(i,j-1,dp,arr,sum);
	dp[i][j]=max(dp[i][j],temp);
	return dp[i][j];
}
int main(){
	int n;
	cin>>n;
	vector<long>arr(n);
	vector<long>sum(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(i==0)
			sum[0]=arr[i];
		else
		sum[i]=sum[i-1]+arr[i];
	}
	v dp(n,vector<long>(n,-1));
	long x=util(0,n-1,dp,arr,sum);
	long y=sum[n-1]-x;
	cout<<x-y;
	return 0;
}

Measured memory_bytes: 71168
using System;
using System.Linq;
using System.Text;

namespace ALDS1_5_A {
    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.ReadLine();
            int[] M = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            
            bool[] memo = new bool[40001];  // max:(n:20)*(A.length:2000)
            memo[0] = true;
            int sum = 0;
            foreach (int a in A) {
                for (int j = sum; j >= 0; j--) {
                    memo[j + a] = memo[j + a] || memo[j];
                }
                sum += a;
            }

            StringBuilder sb = new StringBuilder();
            foreach (int m in M) {
                sb.AppendLine(memo[m] ? "yes" : "no");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main {
    static int matrixChainMultiplication(int n, int[] p) {
        int[][] m = new int[n + 1][n + 1];
	
        for (int l = 2; l <= n; l++) {
            for (int i = 1; i <= n - l + 1; i++) {
                int j = i + l - 1;
                m[i][j] = Integer.MAX_VALUE;
                for (int k = i; k <= j - 1; k++) {
                    m[i][j] = Math.min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
                }
            }
        }
        
        return m[1][n];
    }
    
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
             PrintWriter out = new PrintWriter(System.out)) {
	    
            int n = Integer.parseInt(in.readLine());
            int[] p = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                String[] line = in.readLine().split(" ");
                p[i - 1] = Integer.parseInt(line[0]);
                p[i] = Integer.parseInt(line[1]);
            }
	    
            out.println(matrixChainMultiplication(n, p));
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24732
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
data = list(map(int,read().split()))
abcd = data[:4*(n-1)]
xyuv = data[4*(n-1):]

root = 1
dbl_max = 20
dbl = [[0] * dbl_max for _ in range(n+1)]
depth = [0] * (n+1)
links = [[] for _ in range(n+1)]
it = iter(abcd)
for a,b,c,d in zip(it,it,it,it):
    links[a].append((b,c,d))
    links[b].append((a,c,d))

stack = [root]
while(stack):
    i = stack.pop()
    for j,c,d in links[i]:
        if(j==dbl[i][0]):
            continue
        dbl[j][0] = i
        depth[j] = depth[i]+1
        stack.append(j)

for i in range(1,dbl_max):
    for j in range(1,n+1):
        dbl[j][i] = dbl[dbl[j][i-1]][i-1]

def get_lca(x,y):
    if(depth[x] > depth[y]):
        x,y = y,x

    dif = depth[y]-depth[x]
    for i in range(dbl_max):
        if(dif==0):
            break
        if(dif>>i)&1:
            y = dbl[y][i]
            dif -= (1<<i)

    for i in range(dbl_max-1,-1,-1):
        if(dbl[x][i] != dbl[y][i]):
            x = dbl[x][i]
            y = dbl[y][i]

    if(x!=y):
        return dbl[x][0]
    else:
        return x

ans = [0] * q
query = [[] for _ in range(n+1)]
for i in range(q):
    x,y,u,v = xyuv[i*4:i*4+4]

    lca = get_lca(u,v)
    query[u].append((i,x,y,1))
    query[v].append((i,x,y,1))
    query[lca].append((i,x,y,-2))

tot = 0
c_cost = [[0,0] for _ in range(n)]
stack = []
for j,c,d in links[root]:
    stack.append((root,j,c,d,1))

while(stack):
    a,b,c,d,num = stack.pop()
    tot += d*num
    c_cost[c][0] += d*num
    c_cost[c][1] += num

    if(num==1):
        for qi,x,y,num_q in query[b]:
            ans[qi] += num_q * (tot - c_cost[x][0] + c_cost[x][1]*y)

        next = []
        for j,c,d in links[b]:
            if(j==dbl[b][0]):
                stack.append((b,j,c,d,-1))
            else:
                next.append((b,j,c,d,1))
        stack += next
    # print(c_cost)

print('\n'.join(map(str,ans)))

Measured memory_bytes: 245176
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
while(true){
var d=arr.shift();
if(d==0)break;
var n=arr.shift()-1;
var m=arr.shift();
var N=[0];
for(var i=0;i<n;i++)N.push(arr.shift());
var M=[];
for(var i=0;i<m;i++)M.push(arr.shift());
for(var i=0;i<n;i++)N.push(N[i]+d);
for(var i=0;i<n;i++)N.push(N[i]-d);
N.sort(function(a,b){return a-b;});
M.sort(function(a,b){return a-b;});

var sum=0;
M.forEach(function(value){
   var min=Infinity;
   var L=0;
   var R=N.length-1;
   while(true){
      var i=Math.floor((L+R)/2);
      if(N[i]==value){
         min=Math.min(min,Math.abs(N[i]-value));
         break;
      }else if(N[i]>value){
         min=Math.min(min,Math.abs(N[i]-value));
         R=i-1;
      }else if(N[i]<value){
         min=Math.min(min,Math.abs(N[i]-value));
         L=i+1;
      }
      if(L>R){
         min=Math.min(min,Math.abs(N[i]-value));
         break;
      }
   }
   sum+=min;
});
console.log(sum);
}

Measured memory_bytes: 38636
import java.util.Scanner;

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();
		sc.close();
		if(a <= c && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21972
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str1=input.readLine();
	int i=0;
	while(true)
	    {
		String str=input.readLine();
		String str2[]=str.split(" ");
		if(str.equals("END_OF_TEXT"))break;
		for(int j=0;j<str2.length;j++)
		    {
			
			if(str2[j].equalsIgnoreCase(str1))i++;
			
		    }
		
	    }
	System.out.println(i);
    }
}

Measured memory_bytes: 17088
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
print((n - 1) * (m - 1))

Measured memory_bytes: 3444
a = input().split()
ret = 0
s = []
for e in a:
    if e in ["+","-","*"]:
        if e == "+":
            s.append(s.pop()+s.pop())
        elif e == "-":
            t = s.pop()
            s.append(s.pop()-t)
        else:# e == "*":
            s.append(s.pop()*s.pop())
    else:
        s.append(int(e))
print(s[0])


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

using namespace std;

int main() {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    int64_t ac, ad, bc, bd;
    ac = a * c;
    ad = a * d;
    bc = b * c;
    bd = b * d;
    if (ac >= ad && ac >= ad && ac >= bd) {
        cout << ac << endl;
    }
    else if (ad >= bc && ad >= bd) {
        cout << ad << endl;
    }
    else if (bc >= bd) {
        cout << bc << endl;
    }
    else {
        cout << bd << endl;
    }
}

Measured memory_bytes: 3628
n=int(input())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
acc=0
carry=0
for i in range(n):
    ai=al[i]; bi=bl[i]
    if ai <= carry:
        acc+=ai
        carry=bi
    elif ai-carry <= bi:
        acc+=ai
        carry=bi-(ai-carry)
    else:
        acc+=bi+carry
        carry=0
if not carry==0:
    if al[n] <= carry:
        acc+= al[n]
    else:
        acc+=carry
print(acc)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;

int main()
{
    string S;
    cin >> S;
    int replaceNum = 0;
    for (size_t i = 0; i < S.size() / 2; i++)
    {
        char prev = S.at(i);
        char last = S.at(S.size() - i - 1);
        if (prev != last)
        {
            replaceNum++;
        }
    }
    cout << replaceNum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    string s;cin >> s;
    int n = s.size();
    ll ans = 0;
    ll sequenceAcount=0;
    for(int i=0;i<n-3+1;){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ++ans;
            s[i] = 'B';
            s[i+1] = 'C';
            s[i+2] = 'A';
            if(sequenceAcount>0){
                ans += sequenceAcount;
            }
            i += 2;
        }else if(s[i]=='A'){
            ++sequenceAcount;
            ++i;
        }else{
            sequenceAcount = 0;
            ++i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n,m;  cin >> n >> m;
  vector<pair<ll,ll> > p(n);
  rep0(i,n){
    ll a,b;  cin >> a >> b;
    p[i] = make_pair(a,b);
  }
  sort(all(p));
  ll ans = 0;
  for(int i = 0; 0 < m; i++){
    ll cnt = min(m,p[i].second);
    ans += cnt*p[i].first;
    m -= cnt;
  }
  cout << ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  if (n >= 1000) cout << "ABD" << endl;
  else cout << "ABC" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  if(a[0]==5&&a[1]==5&&a[2]==7){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256