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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n,h,w;
  cin>> n>>h>>w;
  vll a(n),b(n);
  REP(i,n)cin>>a[i]>>b[i];
  
  ll ans = 0;
  REP(i,n){
    if(a[i]>=h && b[i]>=w)
      ans++;
  }
  
  cout<<ans<<endl;

}

Measured memory_bytes: 256
/*
    B - 1 Dimensional World's Tale
    https://atcoder.jp/contests/abc110/tasks/abc110_b
*/
#include <bits/stdc++.h>
using namespace std;

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

    int n, m, x, y, input;
    cin >> n >> m >> x >> y;

    for (int i = 0; i < n; i++) {
        cin >> input;
        x = max(x, input);
    }

    for (int i = 0; i < m; i++) {
        cin >> input;
        y = min(y, input);
    }

    cout << ((x < y) ? "No " : "") << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <typeinfo>
#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll int,ll int>
#define pii             pair<ll int,ll int>
#define vi              vector<ll int>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll int)x.size()
#define hell            1000000007
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (long long int i=a;i<b;i++)
#define repr(i,a,b)     for (long long int i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define bs              binary_search
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/
 
//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll a,b;
    cin>>a>>b;
    if (a>b)swap(a,b);
    if (a==1 && b==2){
        cout<<3<<endl;
        return;
    }
    if (a==1 && b==3){
        cout<<2<<endl;
        return;
    }
    if (a==2 && b==3){
        cout<<1<<endl;
        return;
    }
}
 
signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	int n,r,p,c;

	while(cin >> n >> r){
		if((n==0)&&(r==0)){return 0;}
		vector<int> card;
		for(int i=0; i<n; i++){
			card.push_back( n-i );
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			rotate(card.begin(),card.begin()+p-1, card.begin()+p-1+c);
		}
		cout << card[0] << endl;
	}
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a;
    set<int> s;
    rep(i,n){
        cin>>a;
        s.insert(a);
    }
    if(s.size()==n){
        cout<<"YES"<<'\n';
    }
    else{
        cout<<"NO"<<'\n';
    }
    return(0);
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

  int m, d;
  cin >> m >> d;
  int cnt = 0;
  rep2(i, 1, m + 1) {
    rep2(j, 1, d + 1) {
      int d1 = j % 10;
      int d10 = j / 10;
      if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 764
#[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 (a, b, c): (usize, usize, usize);
    input!(a, b, c);
    let mut flag = false;
    for z in 0..b + 1 {
        if c == (z * a) % b {
            flag = true;
            break;
        }
    }
    if flag {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll x = n / (a+b);
  ll y = n % (a+b);

  cout << x * a + (y <= a ? y : a) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int N, K;
vi h, dp;

constexpr int INF = 1e9;
int dfs(int n) {
  // 今足場nにいる
  if (n == N-1) return 0; // ゴールにいるなら当然コストは0
  if (dp[n] != -1) return dp[n]; // メモがあれば使う
  int ans = INF;
  rep(i, K) {
    if (n+i+1 >= N)
      break;
    ans = min(ans, abs(h[n] - h[n+i+1]) + dfs(n+i+1));
  }
  return dp[n] = ans;
}
int main() {
  ins(N, K);

  h.resize(N);
  dp.resize(N, -1);
  rep(i, N) {
    cin >> h[i];
  }

  cout << dfs(0) << endl;

  return 0;
}


Measured memory_bytes: 7296
use std::io;
use std::collections::HashSet;

fn main() {
    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<i32>().unwrap();
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let iter = buf.trim().split_whitespace();
    let set = iter.collect::<HashSet<&str>>();

    println!("{}", if set.len() == 3 {
        "Three"
    } else {
        "Four"
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
string beauty(int a,int b,int c)
{
    if(b-a==c-b)
        return "YES";
    else
        return "NO";
}
int main()
{
    int a,b,c;
    string res;
    cin>>a>>b>>c;
    res=beauty(a,b,c);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>


using namespace std;

#define Max INT_MAX
#define Inf INT_MIN


#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
// s <= x < g ?
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
// 0 <= x < w && 0 <= y < h ?
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))



struct edge {
    int to, cost;
    edge(int t, int c){
        to = t;
        cost = c;
    }
};

//first=最短距離 second=頂点の番号
typedef pair<int, int> P;

int d[100];


//sからの最短距離をdに格納する
void dijkstra(int s, vector<edge> *G ){
    //フロンティア頂点集合
    priority_queue<P, vector<P>, greater<P> > que; //小さい順指定
    fill(d, d+100, Max);

    d[s] = 0;
    que.push( P(0,s) ); //s -> sは距離0

    while(!que.empty() ) {
        P p = que.top(); que.pop(); //フロンティアの中から一番小さい辺を取り出す 
        int v = p.second;
        if( d[v] < p.first) continue;

        rep(i, G[v].size() ) {
            edge e = G[v][i]; //v->iのエッジ
            //cout << "i = " << i << endl;
            //cout << "G[v][i].to = " << G[v][i].to<< endl;
            //cout << "G[v][i].cost = " << G[v][i].cost << endl;

            //cout << "v = " << v << endl; 
            //cout << "d[v] = " << d[v] << endl;
            //cout << "e.to = " << e.to << endl;
            //cout << "e.cost = " << e.to << endl;
            //cout << "d[e.to] = " << d[e.to] << endl;
            if( d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push( P(d[e.to], e.to) );
            }
        }
    }
}

vector<edge> costs[100];
vector<edge> times[100];

int main()
{
    int tmp = 0;

    int n,m;
    while(cin >> n >> m){
        if( n == 0 && m == 0 ) { break; }
        rep(i,100){
            costs[i].clear();
            times[i].clear();
        }
        
        rep(i,n){
            int a,b, cost_v,time_v;
            cin >> a >> b >> cost_v >> time_v;
            //edge ee = edge(b,cost_v);
            //cout << "ee.to = "  << ee.to << endl; 
            //cout << "ee.cost = " << ee.cost << endl;
            costs[a-1].push_back( edge(b-1, cost_v) );
            costs[b-1].push_back( edge(a-1, cost_v) );

            times[a-1].push_back( edge(b-1, time_v) );
            times[b-1].push_back( edge(a-1, time_v) );

            //cout << "_cost = " << cost_v << endl;
            //cout << "_time = " << time_v << endl;
            //cout << "a,b = " << a << " " << b << endl;
            //cout << endl;
        }

        int k;
        cin >> k;

        rep(i,k){
            int p,q,r;
            cin >> p >> q >> r;
            if( r == 0){
                dijkstra(p-1, costs);
            } else {
                dijkstra(p-1, times);
            }
            cout << d[q-1] << endl;
        }
    }
    return 0;


}

Measured memory_bytes: 1324
/*
** 
*/

# include <cstdio>
# include <iostream>
using namespace std;

const int maxn = 100000 + 10;
typedef long long LL;

int n, k;
LL w[maxn];

int getP(LL p) {
	int i = 0;
	for (int j = 0; j < k; j++) {
		LL s = 0;
		while (s + w[i] <= p) {
			s += w[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}
 
int main() {
	// freopen("infile", "r", stdin);
	// freopen("outfile", "w", stdout);
	
	while (scanf("%d%d", &n, &k) != EOF) {
		for (int i = 0; i < n; i++)
			scanf("%I64d", &w[i]);
		LL left = 0;
		LL right = 100000 * 10000;
		LL mid;
		while (right - left > 1) {
			mid = (left + right) / 2;
			if (getP(mid) >= n)
				right = mid;
			else
				left = mid;
		}
		cout << right << endl;
	}
	return 0;
}


Measured memory_bytes: 3980
#n本のマッチをピッタリ使い、mの数字の範囲で最大

waste = {
1 => 2,
2 => 5,
3 => 5,
4 => 4,
5 => 5,
6 => 6,
7 => 3,
8 => 7,
9 => 6,
}

n, m = gets.split.map &:to_i
as = gets.split.map &:to_i

$diff = {}

as.each{ |x|
	if $diff[waste[x]] == nil then
		$diff[waste[x]] = []
	end
	
	$diff[waste[x]] << x
}

$diff.each{ |k, v|
	$diff[k] = v.max
}

$diff_keys = $diff.keys.sort

$lcm = $diff_keys[0]

$diff_keys[1..-1].each{ |x|
	$lcm = $lcm.lcm(x)
} 

$count = Array.new($diff_keys.size, 0)

#p $diff
#p $diff_keys
#p $lcm

$result = []
$digit_count = nil

def ll(remain, idx)
#	puts "remain:" + remain.to_s
#	puts "key:" + $diff_keys[idx].to_s
	start = remain / $diff_keys[idx]
#	puts "start:" + remain.to_s
#	puts
	start.downto([start - $lcm / $diff_keys[idx], 0].max){ |i|
		$count[idx] = i
		next_remain = remain - i * $diff_keys[idx]

		if next_remain == 0 then
			output = []
			$count.each_with_index{ |d, k|
				output << $diff[$diff_keys[k]].to_s * d
			}

			val = output.sort.reverse.join("")

			if $digit_count == nil || $digit_count == val.size then
				$digit_count = val.size
				$result << val.to_i
			else
				puts $result.max
				exit
			end
		end

		if next_remain > 0 && idx < $diff_keys.size - 1 then
			ll(next_remain, idx + 1)
		end
	}
end

ll(n, 0)

puts $result.max


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

typedef long long ll;

const int INF = 101234567;

int main() {
    ll ans, cnt;
    string s, t;
    cin >> s;

    for (int i = 0; i < s.size()-1; i++) {
        if (s.substr(i, 2) == "BC") {
            t += 'D';
            i++;
        } else {
            t += s[i];
        }
    }

    ans = cnt = 0;
    for (int i = t.size(); i >= 0; i--) {
        if (t[i] == 'A') {
            ans += cnt;
        } else if (t[i] == 'D') {
            cnt++;
        } else {
            cnt = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 776
package main

import (
	"fmt"
)

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

func mm(x, y int) (int, int) {
	if x < y {
		return y, x
	}
	return x, y
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	var x, y, z int
	x, y = mm(c, d)
	z = c * d / gcd(x, y)
	var ans = b/c - (a-1)/c + b/d - (a-1)/d - b/z + (a-1)/z
	fmt.Println(b - a + 1 - ans)
}


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

int main() {
  int N;
  cin >> N;
  int a, d;
  cin >> a >> d;
  int M;
  cin >> M;
  vector<int> x(M), y(M), z(M);
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  int K;
  cin >> K;
  for (int i = M - 1; i >= 0; i--) {
    if (x[i] == 0) {
      if (K == y[i]) {
        K = z[i];
      } else if (K == z[i]) {
        K = y[i];
      }
    } else {
      if (K == y[i]) {
        K = z[i];
      }
    }
  }
  cout << a + (K - 1) * d << endl;
  return 0;
}



Measured memory_bytes: 3104
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int M = sc.nextInt();
		int ansL = 1;
		int ansR = N;

		for(int i = 0;i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}

		System.out.println(Math.max(0,ansR-ansL+1));
		sc.close();
	}
};


Measured memory_bytes: 65140
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    char a, b;
    cin >> a >> b;
    if(a == b) cout << "H" << endl;
    else cout << "D" << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int b=*max_element(a.begin(),a.end());
    int bidx=max_element(a.begin(),a.end())-a.begin();
    int l=*min_element(a.begin(),a.end());
    int lidx=min_element(a.begin(),a.end())-a.begin();
    cout << 2*n-2 << "\n";
    if(b+l>0){
        for(int i = 0; i < n; i++) {
            if(i!=bidx) cout << bidx+1 << " " << i+1 << "\n";
        }
        for(int i = 0; i < n-1; i++) {
            cout << i+1 << " " << i+2 << "\n";
        }
    }
    else{
        for(int i = 0; i < n; i++) {
            if(i!=lidx) cout << lidx+1 << " " << i+1 << "\n";
        }
        for(int i = 0; i < n-1; i++) {
            int j=n-i;
            cout << j << " " << j-1 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3628
N = int(input())

for i in range(N):
    x = input()
    y = x.split(' ')
    a = []
    b = []
    text='YES'
    for j in range(10):
        number = int(y[j])
        aNum = 0
        bNum = 0
        if a != [] :
            aNum = a[-1]
        if b != [] :
            bNum = b[-1]

        if(aNum > bNum):
            if(aNum < number):
                a.append(number)
            else:
                if(bNum < number):
                    b.append(number)
                else:
                    text = 'NO'
                    break
        else:
            if(bNum < number):
                b.append(number)
            else:
                if(aNum < number):
                    a.append(number)
                else:
                    text = 'NO'
                    break
#    print(a)
#    print(b)
    print(text)




Measured memory_bytes: 5592
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    
    vector<pair<string,pair<int, int>>> vec;
    for(int i=0;i<n;i++){
        string a;
        int b;
        cin>>a>>b;
        vec.push_back(make_pair(a,make_pair(b,i+1)));
    }
    
sort(vec.begin(), vec.end(), [](auto a, auto b){
   
   if(a.first < b.first)
        return true;
    else{
        if(a.first==b.first)
            {
                if(a.second.first > b.second.first)
                    return true;
            }
    }
    return false;
});
for(int i=0;i<n;++i){
    cout<<vec[i].second.second<<endl;
}
}


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

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

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

    int N, K;
    ll L,R;
    cin >> N >> K;
    cin >> L >> R;
    vector<ll> a(N);
    rep(i, N)cin >> a[i];
    sort(all(a));
    int l = N/2;
    int r = N - N/2;
    vector<pair<ll,ll>> v[2];
    map<pair<ll,ll>,ll> mp;
    for(int i = 0; i < bit(l);i++){
        ll sum = 0;
        ll cnt = __builtin_popcount(i);
        for(int j = 0; j < l; j++){
            if(i&bit(j))sum += a[j];
        }
        v[0].emplace_back(cnt, sum);
    }
    for(int i = 0; i < bit(r); i++){
        ll sum = 0;
        ll cnt = __builtin_popcount(i);
        for(int j = 0; j < r; j++){
            if(i&bit(j))sum += a[l+j];
        }
        v[1].emplace_back(cnt, sum);
        // mp[{sum,cnt}]++;
    }
    int sz = v[0].size();
    sort(all(v[1]));
    ll ans = 0;
    rep(i,sz){
        ll sum = v[0][i].second;
        ll cnt = v[0][i].first;
        ll add = upper_bound(all(v[1]), make_pair(K-cnt,R-sum))
                -lower_bound(all(v[1]), make_pair(K-cnt,L-sum));
        ans += add;
    }
    cout << ans << endl;
}



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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second

bool a[5050][5050];
int n;

bool inside(int x, int y)
{
    //cout << "y = " << x << ", x = " << y << endl;
    return 0 <= x && x <= 5000 && 0 <= y && y <= 5000;
}

signed main()
{
    while (cin >> n, n) {
        memset(a, 0, sizeof(a));
        static pair<int, int> arr[3010];

        rep(i, n) {
            int x, y; cin >> x >> y;
            a[y][x] = true;
            arr[i] = pair<int, int>(y, x);
        }

        int ma = 0;

        rep(i, n) rep(j, n) {
            if (i == j) continue;

            auto p1 = arr[i], p2 = arr[j];

            bool f = true;

            int dy = p2.fst - p1.fst, dx = p2.scd - p1.scd;

            auto p3 = pair<int, int>(p1.fst - dx, p1.scd + dy);
            auto p4 = pair<int, int>(p3.fst + dy, p3.scd + dx);

            f &= inside(p3.scd, p3.fst) && a[p3.fst][p3.scd];
            f &= inside(p4.scd, p4.fst) && a[p4.fst][p4.scd];

            if (f) {
                ma = max(ma, dy * dy + dx * dx);
            }
        }

        cout << ma << endl;
    }
}

Measured memory_bytes: 27980
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

#define rep(i,n) for(int i = 0;i < n;i++)
#define Rep(i,m,M) for(int i = m;i < M;i++)
#define print(var) cout<<#var" = "<<var<<endl;

typedef long long ll;

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int s = a + b + c;
	if (s >= 22)
	{
		cout << "bust";
	}
	else if (s <= 21)
	{
		cout << "win";
	}
}


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

using namespace std;
long long sum,r[40][100010];//a_jから2^i日で行ける最大距離がr[i][j]で位置を返す

int solve(int s, int t){
    int i,k;
    for(int i=0;i<40;i++){
        if(r[i][s]>=t){
            k = i;
            break;
        }
    }
    if(k==0){
        return sum;
    }else{
        sum += pow(2,k-1);
        solve(r[k-1][s],t);
    }
}

int main(){
    int i,j,n,q,s,t;
    vector<long long> a,b;
    long long x,l;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x;
        a.push_back(x);
    }
    cin >> l >> q;
    for(i=0;i<n;i++){
        int y = upper_bound(a.begin(),a.end(),a[i]+l)-a.begin()-1;
        b.push_back(y);
    }
    for(i=0;i<n;i++){
        //cout << b[i] << endl;
    }

    for(i=0;i<40;i++){
        for(j=0;j<n;j++){
            if(i==0){
                r[i][j] = b[j];
            }else{
            r[i][j] = r[i-1][r[i-1][j]];
            }
        }
    }
    
    for(i=0;i<q;i++){
        cin >> s >> t;
        if(s>t){
            int z = s;
            s = t;
            t = z;
        }
        s--; t--;
        sum = 1;
        solve(s,t);
        cout << sum << endl;
    }
}

Measured memory_bytes: 33780
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
vi sq;
vi sqa;
bool w[100100];
int main()
{
    while(1)
    {
        int n,k;
        int ans=0;
        cin >> n >> k;
        sqa.clear();
        sq.clear();
        memset(w,false,sizeof(w));
        if(n==0&&k==0)break;
        bool flag=false;
        for(int i=0;i<k;i++)
        {
            int c;
            cin >> c;
            if(c==0)
            {
                flag=true;
                continue;
            }
            w[c]=true;
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(w[i])
            {
                cnt++;
            }
            else
            {
                sq.pb(cnt);
                cnt=0;
            }
        }
        sq.pb(cnt);
        if(!(flag))
        {
            for(int i=0;i<sz(sq);i++)
            {
                ans=max(ans,sq[i]);
            }
            cout << ans << endl;
        }
        else
        {
            for(int i=0;i<sz(sq)-1;i++)
            {
                sqa.pb(sq[i]+sq[i+1]);
            }
            sort(sqa.begin(),sqa.end(),greater<int>());
            cout << sqa[0]+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10**6)

w=0;h=0;
def dfs(x,y,Map):
    #ending condition
    if not (0 <= x and x < h and 0 <= y and y < w):
        return
    if Map[x][y] == 0:
        return
    
    #operation
    Map[x][y] = 0

    #moving deep
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            dfs(x+i,y+j,Map)

def start_cnt():
    global w,h
    w,h = map(int,input().split())
    if w == 0 and h == 0:exit();
    cnt = 0
    Map = []
    for i in range(h):
            Map.append(list(map(int,input().split())))
    for i in range(h):
        for j in range(w):
            if Map[i][j] == 1:
                dfs(i,j,Map)
                cnt += 1
    print(cnt)
while True:
    start_cnt()



Measured memory_bytes: 8012
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
for i in range(N-1,-1,-1):
    if A[i+1]>=B[i]:
        a+=B[i]
    elif A[i]+A[i+1]>=B[i]:
        a+=B[i]
        A[i]-=B[i]-A[i+1]
    else:
        a+=A[i]+A[i+1]
        A[i]=0
print(a)

Measured memory_bytes: 18752
// -*- coding:utf-8-unix -*-
 
 
use proconio::input;
use std::collections::HashSet;
// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
 
fn main() {
/*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        a: isize,
        b: isize,
        c: isize,
        k: isize,
    }
 
    let res_num = k - a - b;
    if a > k {
        println!("{}", k);
    } else if res_num <= 0 {
        println!("{}",a);
    } else if c < res_num {
        println!("{}", a  - c);
    } else {
        println!("{}", a - res_num);
    }
 
}

Measured memory_bytes: 2096
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() { 
    int n;cin >> n;
    int ans = 1;
    while(ans*2<=n) ans*=2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
import numpy as np

n, k = list(map(int, input().split()))

ary = np.log2(k / (np.arange(n)+1))
ary = np.ceil(ary)

ary[ary < 0] = 0

prob = (1 / 2**ary).sum().astype(np.float64) / len(ary)
print(prob)


Measured memory_bytes: 21372
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    cin.tie(0);
    int n;
    double ans=0;
    cin >> n;
    vector<double> A(n);

    rep(i,n) cin >> A[i];

    cout << fixed;

    rep(i,n){
        ans+=1/A[i];
    }

    cout << setprecision(10) << 1/ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> c(N);
    rep(i, 1, N) {
        int a;
        cin >> a;
        c[a - 1]++;
    }
    rep(i, N) write(c[i]);
}

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

using namespace std;

int main(){
    char s1[101],s2[100],s3[100];
    deque<char> a;
    deque<char> b;
    deque<char> c;
    scanf("%s",s1);
    for (int i=0;i<strlen(s1);i++) a.push_back(s1[i]);
    scanf("%s",s2);
    for (int i=0;i<strlen(s2);i++) b.push_back(s2[i]);
    scanf("%s",s3);
    for (int i=0;i<strlen(s3);i++) c.push_back(s3[i]);
    int f=0;
    for(;;) {
        if (f==0) {
            if (a.empty()) {
                printf("A\n");
                break;
            }
            f=a.front()-'a';
            a.pop_front();
        } else if (f==1) {
            if (b.empty()) {
                printf("B\n");
                break;
            }
            f=b.front()-'a';
            b.pop_front();
        } else {
            if (c.empty()) {
                printf("C\n");
                break;
            }
            f=c.front()-'a';
            c.pop_front();
        }
    }
    return 0;
}


Measured memory_bytes: 256
import Data.List

main = do
  li <-getLine
  let n = read li
  li <- getLine
  let as = map read $ words li
  let ans = compute n as
  mapM_ print ans

compute :: Int -> [Int] -> [Int]
compute n as = format [1..n] $ map (\as -> (head as, length as)) $ group $ sort as

format (k:ks) icics@((i,c):ics)
  | k == i = c : format ks ics
  | True   = 0 : format ks icics
format (k:ks) [] = 0 : format ks []
format _ _ = []

Measured memory_bytes: 70252
# -*- coding: utf-8 -*-
import math
n = input()
numbers = list(map(int, input().split()))

unique_numbers = list(set(numbers))
if len(unique_numbers) == 1:
  print(0)
  exit(0)

min_num = min(numbers)
max_num = max(numbers)

results = []
for i in range(min_num, max_num):
  r = 0
  for num in numbers:
    r += abs((num - i) ** 2)
  results.append(r)

min_r = min(results)
print(min_r)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){ 
    ll n,a,b; cin>>n>>a>>b;

    ll ans = min(n*a,b);

    cout<<ans<<endl;
}

signed main(){

   FastRead;    

    ll t;
    t = 1; 
   // cin>>t;
    FOR(i,1,t){
        // cout<<"Case "<<i<<":\n";
        solve();
    }
}


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

int main(){
	//freopen("/home/byte001/Code/Input/1.txt","r",stdin);
	int a,b; cin>>a>>b;
	bool ansFound = false;
	for(int i=1;i<3000;i++ )
		if((int(i*0.08)==a)&&(int(i*0.1)==b)) {cout<<i<<endl; ansFound = true; break;}
	if(ansFound==false) cout<<-1<<endl;
	return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d, n, ans;
  cin >> d >> n;
  if (n == 100) n++;
  ans = pow(100, d) * n;
  cout << ans << endl;
}             


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N*A, B) << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int n;cin >> n;
  double sum;
  vector<double> pri(n);
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> pri[i] >> s[i];
  }


  for(int j=0;j<n;j++){
    if(s[j] == "JPY"){
      sum += pri[j];
    }else{
      sum += pri[j]*380000.0;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
# 入力
n = int(input())
f , p = [], []
for i in range(n):
    l = list(map(int, input().split()))
    f.append(l)
for i in range(n):
    l = list(map(int, input().split()))
    p.append(l)

# 営業するかどうかの組み合わせ 2^10個
max_profit = - 10 ** 9
for bit in range(1 << 10):
    if bit == 0: #営業しない場合を除く
        continue

    profit = 0
    c=[0] * n
    for i in range(10):
        if bit >> i & 1:
            # 営業する場合
            for j in range(n):
                c[j] += f[j][i]
    
    for i in range(n):
        profit += p[i][c[i]]
    max_profit = max(max_profit, profit)

print(max_profit)

Measured memory_bytes: 3188
s=input()
N=len(s)
L=[0]*N
g=0
p=0
for i in range(N):
    if g<=p:
        L[i]='g'
        g+=1
    else:
        L[i]='p'
        p+=1
point=0
for i in range(N):
    if s[i]=='g' and L[i]=='p':
        point+=1
    elif s[i]=='p' and L[i]=='g':
        point-=1
print(point)

Measured memory_bytes: 42480
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    int a, b, ans;
    cin >> a >> b;
    ans = (a * 3 + b) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))


from collections import deque
n,m = mp()
path = []
for i in range(n+1):
    path.append([])
for i in range(m):
    a,b = mp()
    path[a].append(b)
    path[b].append(a)

ans = [0]*(n+1)
q = deque([1])
used = set()
used.add(1)
while q:
    here = q.popleft()
    for i in path[here]:
        if i not in used:
            ans[i] = here
            q.append(i)
            used.add(i)
print("Yes")
for i in range(2, n+1):
    print(ans[i])




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

int main() {
int A,B,C,K;
  int result = 0;
  cin >> A >> B >> C >> K;
  if(A >= K){
    result = K;
  }else if(A + B >= K){
    result = A;
  }else{
    result = A - (K - A - B);
  }
  cout << result << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
vector<int> v;
void dfs(int x){
    int a=x%10;
    if(a!=0&&a!=9){
        v.push_back(x*10+a+1);
        v.push_back(x*10+a);
        v.push_back(x*10+a-1);
        if(x*10+a<=3234566667)dfs(x*10+a);
        if(x*10+a+1<=3234566667)dfs(x*10+a+1);
        if(x*10+a-1<=3234566667)dfs(x*10+a-1);
    }else if(a==0){
        v.push_back(x*10+a+1);
        v.push_back(x*10+a);
        if(x*10+a<=3234566667)dfs(x*10+a);
        if(x*10+a+1<=3234566667)dfs(x*10+a+1);
    }else{
        v.push_back(x*10+a);
        v.push_back(x*10+a-1);
        if(x*10+a+1<=3234566667)dfs(x*10+a);
        if(x*10+a-1<=3234566667)dfs(x*10+a-1);
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>k;
    for(int i=1;i<=9;i++){
        v.push_back(i);
        dfs(i);
    }
    sort(All(v));
    cout<<v[k-1]<<endl;
}


Measured memory_bytes: 6512
object Main extends App {
  val in   = new java.util.Scanner(System.in)
  val n, l = in.nextInt

  val apples         = for (i <- 1 to n) yield i + l - 1
  val idealApplePie  = math.abs(apples.sum)
  val eatenApplePies = for (i <- 1 to n) yield (apples.take(i - 1) ++ apples.drop(i)).sum

  val answer = eatenApplePies(
    eatenApplePies
      .map(idealApplePie - math.abs(_))
      .zipWithIndex
      .minBy(v => math.abs(v._1))
      ._2
  )

  println(answer)
}


Measured memory_bytes: 25664
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void inverse(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(mod-inv[mod%i]*(mod/i))%mod;
    }
}

void inverse_u(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%mod;
    }
}

void factorial(ll n,vector<ll> &fac){
    //要素数:n+1 (0~n)
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}

ll nCr(ll n,ll r,vector<ll> &inv,vector<ll> &fac){
    return fac[n]*inv[r]%mod*inv[n-r]%mod;
}

int main(){
    ll n,a,b,k,ans=0; cin>>n>>a>>b>>k;
    vector<ll> inv(n+1,0),fac(n+1,0);
    inverse(n,inv); inverse_u(n,inv);
    factorial(n,fac);
    for(ll i=0;i<=n;i++){
        ll l=k-i*a;
        if(l%b!=0) continue;
        l/=b;
        if(l<0 || l>n) continue;
        ans=(ans+nCr(n,i,inv,fac)*nCr(n,l,inv,fac)%mod)%mod;
    }
    cout<<(ans+mod)%mod<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  long long int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H.at(i) >= H.at(i + 1)) {
      answer += H.at(i) - H.at(i + 1);
      H.at(i + 1) = H.at(i);
    }
    else if (H.at(i) < H.at(i + 1)) {
      continue;
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 3996
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N := readInt()
	for i := 1; i <= 9; i++ {
		j := N / i
		if N%i == 0 && 0 <= j && j <= 9 {
			println("Yes")
			return
		}
	}
	println("No")
}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,c=0,d=0,m;
	cin>>n>>m;
	for(i=1; i<=100000; i++)
	{
		d = i*0.08;
		c = i*0.1;
		if(d==n && c==m)
        {
            cout<<i;
            return 0;
        }
	}
	cout<<-1;
}


Measured memory_bytes: 256
def tc():
    n = int(input())
    stones = list(map(int, input().split()))
    # dp[i]: min cost to get to stone i (0 based)
    dp = [0] * n
    dp[1] = abs(stones[1] - stones[0])

    for i in range(2, n):
        dp[i] = min(dp[i - 1] + abs(stones[i] - stones[i - 1]),
                    dp[i - 2] + abs(stones[i] - stones[i - 2]))

    print(dp[-1])


tc()


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
constexpr long long MOD(long long in) {
	return in % mod;
}

int n;
int d[100005];
int main() {
	std::cin >> n;

	for (int i = 0; i < n; ++i)
		std::cin >> d[i];

	std::sort(d, d + n);

	std::cout << d[n / 2] - d[n / 2 - 1] << std::endl;
	return 0;
}


Measured memory_bytes: 640
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = [SI() for _ in range(N)]
    B = defaultdict(list)
    for a in A:
        if a.count(".") != 1:
            B[int(a)].append(1)
            continue
        ba, bb = a.split(".")
        ba = int(ba+bb)
        bb = 10**len(bb)
        g = math.gcd(ba, bb)
        ba //= g
        bb //= g
        B[ba].append(bb)

    facts = defaultdict(int)
    for ba, bbs in B.items():
        tmp = ba
        ba_fac_2 = 0
        while True:
            if tmp % 2: break
            ba_fac_2 += 1
            tmp //= 2
        tmp = ba
        ba_fac_5 = 0
        while True:
            if tmp % 5: break
            ba_fac_5 += 1
            tmp //= 5

        for bb in bbs:
            tmp = bb
            bb_fac_2 = 0
            while True:
                if tmp % 2: break
                bb_fac_2 += 1
                tmp //= 2
            tmp = bb
            bb_fac_5 = 0
            while True:
                if tmp % 5: break
                bb_fac_5 += 1
                tmp //= 5
            facts[(ba_fac_2 - bb_fac_2, ba_fac_5 - bb_fac_5)] += 1

    ans = 0
    for fact, k in list(facts.items()):

        fac2, fac5 = fact
        for i in range(-fac2, 50):
            for j in range(-fac5, 20):
                if fac2 == i and fac5 == j:
                    ans += k * (k-1)
                else:
                    ans += k * facts[(i, j)]


    print(ans//2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 107508