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

const int N = 200005;
const int inf = 1e9;

int n, tot, MAX;
pair<int,int> z[N];
vector<int> G[N * 2];
int pos_seg[N];
int lst[N];

void add(int u, int v) {
	G[-v + N].push_back(u + N);
	G[-u + N].push_back(v + N);
}

// SEGMENT TREE
#define mid ((l + r) >> 1)
void build(int v, int l, int r) {
	if (l > r) return;
	if (l == r) {
		int pos = z[l].second;
		pos_seg[l] = v;
		if (lst[pos]) add(-v, -lst[pos]), add(v, lst[pos]); else lst[pos] = v;
		MAX = max(MAX, v);
		return;
	}
	build(v << 1, l, mid); build(v << 1 | 1, mid + 1, r);
	add(v, -(v << 1));
	add(v, -(v << 1 | 1));
}

void join(int pos, int v, int l, int r, int L, int R) {
	if (l > r || R < l || L > r) return;
	if (L <= l && r <= R) { add(-pos, -v); return; }
	join(pos, v << 1, l, mid, L, R); join(pos, v << 1 | 1, mid + 1, r, L, R);
}
#undef mid
// ------------------

// TWO-SAT
int color[N * 2];
int low[N * 2], num[N * 2], step;
bool invalid;

void setColor(int u, int c) { // FALSE = 1, TRUE = 2
	u -= N;
	if (color[u + N] == 3-c) invalid = true; else color[u + N] = c;
	if (color[-u + N] == c) invalid = true; else color[-u + N] = 3-c;
}

stack<int> st;
void dfs(int u) {
	low[u] = num[u] = ++step; st.push(u);
	for (int i = 0; i < G[u].size(); ++i) {
		int v = G[u][i];
		if (num[v]) low[u] = min(low[u], num[v]);
		else dfs(v), low[u] = min(low[u], low[v]);
		if (color[v] == 1) setColor(u, 1); // FALSE
	}

	if (low[u] == num[u]) {
		int v = 0;
		if (!color[u]) setColor(u, 2); // TRUE
		do {
			v = st.top(); st.pop();
			setColor(v, color[u]);
			low[v] = num[v] = inf;
		} while(v != u);
	}
}

bool check(int d) {
	// reset
	for (int i = 1; i <= n; ++i) lst[i] = 0;
	for (int i = 1; i <= MAX; ++i) G[i + N].clear(), color[i + N] = 0, low[i + N] = num[i + N] = 0;
	for (int i = 1; i <= MAX; ++i) G[-i + N].clear(), color[-i + N] = 0, low[-i + N] = num[-i + N] = 0;
	step = 0;
	invalid = false;
	build(1, 1, tot);

	// solve
	int ptr = 1;
	for (int i = 1; i <= tot; ++i) {
		while(ptr <= i && z[i].first - z[ptr].first >= d) ++ptr; 
		join(pos_seg[i], 1, 1, tot, ptr, i - 1);
		//cerr << i << " [" << ptr << "," << i-1 << "]" << endl;
	}
	ptr = tot;
	for (int i = tot; i >= 1; --i) {
		while(ptr >= i && z[ptr].first - z[i].first >= d) --ptr;
		join(pos_seg[i], 1, 1, tot, i + 1, ptr);
		//cerr << i << " [" << i+1 << "," << ptr << "]" << endl;
	}

	for (int i = 1; i <= MAX; ++i) if (!num[i + N]) dfs(i + N);
	for (int i = 1; i <= MAX; ++i) if (!num[-i + N]) dfs(-i + N);

	return !invalid;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x, y; cin >> x >> y;
		z[++tot] = make_pair(x, i);
		z[++tot] = make_pair(y, i);
	}
	sort(z + 1, z + tot + 1);
	build(1, 1, tot);
	
	int l = 0, r = 1e9;
	while(l < r) {
		int mid = ((l + r + 1) >> 1);
		if (check(mid)) l = mid; else r = mid - 1;
	}
	cout << l << endl;
}

Measured memory_bytes: 33068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
vector<ll> pl(210000,0);
ll pcnt(ll x){
    ll y = 0;
    while(x>0){
        y+=x%2;
        x/=2;
    }
    return y;
}

void makepl(){
    FOR(i,1,209999){
        ll x = i%(pcnt(i));
        pl[i]=pl[x]+1;
    }
}

int main(){
    makepl();
    ll n; cin >> n;
    string s; cin >> s;
    if (s=="0"){
        cout << 1 << endl;
        return 0;
    }
    if (s=="1"){
        cout << 0 << endl;
        return 0;
    }
    ll cnter = 0;
    REP(i,n) if (s[i]=='1') cnter++;
    if (cnter==0){
        REP(i,n) cout << 1 << endl;
        return 0;
    }
    ll m1 = cnter-1; ll m2 = cnter+1;
    vector<ll> d1(n,1);
    vector<ll> d2(n,1);
    FOR(i,1,n-1){
        if (m1!=0) d1[i]=(d1[i-1]*2)%m1;
        d2[i]=(d2[i-1]*2)%m2;
    }
    ll t1,t2;
    if (s[n-1]!='1') t1=t2=0;
    else t1=t2=1;
    FOR(i,1,n-1){
        if (s[n-1-i]=='1'){
            if (m1!=0) t1=(t1+d1[i])%m1;
            t2=(t2+d2[i])%m2;
        }
    }
    if (m1==0){
        FOR(i,0,n-1){
            ll x;
            if (s[i]=='1'){
                x=-1;
            }
            else{
                //cout << "t2 " << t2 << " " << d2[n-1-i] << " " << m2 << endl;
                x = (t2+d2[n-1-i])%m2;
            }
            cout << x+1 << endl;
        }
        return 0;
    }
    FOR(i,0,n-1){
        ll x;
        if (s[i]=='1'){
            //cout << "t1 " << t1 << " " << d1[n-1-i] << " " << m1 << endl;
            x = (t1+m1-d1[n-1-i])%m1;
        }
        else{
            //cout << "t2 " << t2 << " " << d2[n-1-i] << " " << m2 << endl;
            x = (t2+d2[n-1-i])%m2;
        }
        
        //cout << x << endl;
        cout << pl[x]+1 << endl;
    }
}

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

void Trace(int* a, int n){
	for(int i=0; i<n; i++){
		if(i!=n-1) printf("%d ", a[i]);
		else printf("%d\n", a[i]);
	}
}

int main(void){
	int n;
	int a[200];
	cin >> n;

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

	Trace(a, n);

	for(int i=1; i<n; i++){
		int key = a[i];
		int j=i-1;
		for(; j>=0 && a[j] > key; j--){
			a[j+1] = a[j];
		}
		a[j+1] = key;

		Trace(a, n);
	}


	return 0;
}

Measured memory_bytes: 1144
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident $($r:tt)*) => {
        let mut $var = $iter.next().unwrap().parse::<usize>().unwrap();
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, $var:ident $($r:tt)*) => {
        let $var = $iter.next().unwrap().parse::<usize>().unwrap();
        input_inner!{$iter $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().unwrap()
    };
}

use std::collections::BTreeSet;

fn main() {
    input! {n, a: [usize; n]};
    let nn = ((n + 1) * n / 2 + 1) / 2;
    let b: BTreeSet<_> = a.iter().cloned().collect();
    let b: Vec<_> = b.into_iter().collect();
    let (mut l, mut r) = (0, b.len());
    while r - l > 1 {
        let m = l + (r - l) / 2;
        let s: Vec<_> = a
            .iter()
            .scan(n as isize + 2, |acc, ai| {
                *acc += if *ai >= b[m] { 1 } else { -1 };
                Some(*acc)
            })
            .collect();
        let cap = *s.iter().max().unwrap() as usize + 1;
        let mut c = vec![0; cap];
        let mut p = 0;
        let mut i: isize = n as isize + 2;
        while i < cap as isize {
            c[i as usize] += 1;
            i += i & -i;
        }
        for si in s {
            let mut i: isize = si;
            while i > 0 {
                p += c[i as usize];
                i -= i & -i;
            }
            let mut i: isize = si;
            while (i as usize) < cap {
                c[i as usize] += 1;
                i += i & -i;
            }
        }
        if p >= nn {
            l = m
        } else {
            r = m
        }
    }
    println!("{}", b[l]);
}


Measured memory_bytes: 14508
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = 1
pre = abs(a * 1000 - (t * 1000 - h[0] * 6))
for i in range(1, n):
    tmp = (t * 1000 - h[i] * 6)
    tmp = abs(a * 1000 - tmp)
    if tmp < pre:
        pre = tmp
        ans = i + 1
print(ans)


Measured memory_bytes: 9268
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  bool out = true;
  REP(i,s.length()){
    if(i % 2 == 1 && s.substr(i,1) == "R"){
      out = false;
      break;
    }
    if(i % 2 == 0 && s.substr(i,1) == "L") {
      out = false;
      break;
    }
  }
  if(out){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

struct Solver{
  int n, k;
  ll sum;
  vector<ll> data;
  priority_queue<ll> possible_ans;
  explicit Solver(int N, int K): n(N), k(K){
    data.resize(n);
    sum = 0;
  }
  
  void init(){
    for(int i=0; i<n; i++){
      auto dmy=scanf("%lld", &data[i]);
      sum += data[i];
    }
    for(int i=1; i<=sqrt(sum); i++){
      if(sum%i==0){
        possible_ans.push(i);
        possible_ans.push(sum/i);
      }
    }
  }
  
  void solve(){
    this->init(); 
    ll ans=0;
    while(!possible_ans.empty()){
      ll p = possible_ans.top(); possible_ans.pop();
      ll sum_r=0;
      vector<ll> rest(n);
      for(int j=0; j<n; j++){
        rest[j] = this->data[j]%p;
        sum_r += rest[j];
      }
      sort(rest.begin(), rest.end());
      
      ll count = 0;
      for(int j=0; j<n-sum_r/p; j++){
        count += rest[j];
      }
      if(count<=k){ans=p; break;}
    }
    printf("%lld\n", ans);
  }
};

int main(){
  int N,K;
  auto dmy=scanf("%d %d", &N, &K);
  Solver solver(N,K);
  solver.solve();  
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> xys(n);
    for (auto& e : xys) {
        int a;
        cin >> a;
        vector<pair<int, int>> xy(a);
        for (auto& f : xy) cin >> f.first >> f.second, f.first--;
        e = move(xy);
    }

    int ans = 0;
    // 1: honest, 0: not
    for (int s = 0; s < (1 << n); s++) {
        vector<int> h(n, -1);
        bool discard = false;
        for (int i = 0; i < n; i++) {
            if (!((s >> i) & 1)) continue;
            for (auto& e : xys[i]) {
                if (h[e.first] != -1 && h[e.first] != e.second) discard = true;
                if (e.second != (s >> e.first & 1)) discard = true;
                h[e.first] = e.second;
            }
        }
        if (discard) continue;
        ans = max(ans, (int) bitset<15>(s).count());
    }
    cout << ans << endl;
}


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

int main() {
  double l[10];
  char c;
  
  while(cin >> l[0] >> c) {
    // 区間全体を1に変換
    int sum = l[0];
    for(int i=1; i<10; i++) cin >> l[i] >> c, sum += l[i];
    for(int i=0; i<10; i++) l[i] = l[i]/sum;
    
    // 速さの和を1に変換
    double a, b;
    double left;
    cin >> a >> c >> b;
    left = a/(a+b);
    
    int t = 0;
    double L = 0.0;
    while( L < left ) {
      L += l[t++];
    }
    cout << t << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N;
  ll a[110];
  cin >> N;
  rep(i,N){
    cin >> a[i];
  }
  
  ll cnt = 0;
  rep(i,N){
    if(i%2==0){
      if(a[i]%2==1) cnt++;
    }
  }
  
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 3620
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define REPN(i,a,b) for(ll i = a; i <= b; ++i)
#define REPV(i,a,b) for(ll i = a; i >= b; --i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define with_tests int t; cin>>t; while(t--){ solve(); }
#define without_tests solve();
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 100000000
#define ff first
#define ss second
const int M=1e9+7;


void solve()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a) < abs(x-b))
	cout<<"A";
	else
	cout<<"B";
}

int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  //with_tests;
  without_tests;
  return 0;
}

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

int main() {
    uint n, d; cin >> n >> d;
    int a[n][d];
    int count = 0;

    for (int i=0;i<n;i++) {
        for (int j=0;j<d;j++){
            cin >> a[i][j];
        }
    }

    // i行とj行を比較する
    for (int i=0;i<n;i++) for(int j=i+1;j<n;j++){
        int dist = 0;
        for (int k=0;k<d;k++){
            dist += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
        }

        if ((int) sqrt(dist) * (int) sqrt(dist) == dist) {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// longest path in undirected graph
// dp conteset g
#include <bits/stdc++.h>
 
# define C continue;
# define R return
 
# define D double
# define I insert
# define ll long long
# define ld long double
 
# define ull unsigned long long
# define ui unsigned int
 
# define pb push_back
# define pf push_front
 
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue
 
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >
 
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp
 
# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >
# define pipii pair<int, pii >
# define pcpii pair<char,pii>
 
# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >
 
# define vvpii vector < vector < pii > >
# define vpipii vector< pipii >
 
# define F first
# define S second
# define mp make_pair
 
# define unm unordered_map
# define unmii unm< int , int >
# define unmll unm< ll , ll >
# define unms unm<string,int>
# define unmci unm<char,int>
 
# define sortvia sort(a.begin(),a.end());
# define sortvib sort(b.begin(),b.end());
# define revsorta sort(a.begin(), a.end(), greater <int>());
# define revsortb sort(b.begin(), b.end(), greater <>());
# define loop(q,n) for(int i=q;i<n;i++)
# define test int t;cin >> t;while(t--)
# define nextline "\n"
# define tab "\t"
# define space " "
//vector<vector<int> > vec( n , vector<int> (m, 0));
//YES
//NO
//cout
//true
//false
//yes
//no
 
const ll mod9=1e9+7;
const ll maxsize=2e9+1;
// const ll mod =998244353;
const ll mod2=1073741824;
const ll INF=1e18L+5;
const int two_pow_fiv=200008;
using namespace std;

int n,m;
vector<vector <int>> adj;
vector <pair <bool,int>> dp;
void max_self(int& a,int b){
    a=max(a,b);
}


void dfs(int a){
    int curr_max=0;
    for(auto x:adj[a]){
        if(!dp[x].first)dfs(x);
        max_self(curr_max,dp[x].second+1);
    }
    dp[a]={true,curr_max};
}


int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    cin>>n>>m;
    // making directed graph
    adj.resize(n+1);
    dp.resize(n+1,{false,0});
    int a,b;
    loop(0,m){
        cin>>a>>b;
        adj[a].push_back(b);
    }
    //perform dfs and find the longest path
    int ans=0;
    for(int i=1;i<=n;i++){
        if(!dp[i].first)dfs(i);
        max_self(ans,dp[i].second);
    }
    // loop(0,n+1){
    //     cout<<dp[i].first<<','<<dp[i].second<<nextline;
    // }
    cout<<ans<<nextline;
return 0;
}

Measured memory_bytes: 11496
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int a[N];
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        sum ^=a[i];
    }
    for (int i = 0; i < N; i++)
    {
        int tmp = a[i];
        int ans = sum^tmp;
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 4400
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val P = List.fill(N)(sc.nextInt())

    def count(P: List[Int]): Int = {
      def loop(lst: List[Int], min: Int, acm: Int): Int =
        lst match {
          case Nil => acm
          case h :: t if h <= min => loop(t, h, acm + 1)
          case h :: t => loop(t, min, acm)
        }
      loop(P, N, 0)
    }

    println(count(P))
  }

}


Measured memory_bytes: 81124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double, int> P;

struct edge {
	int to;
	double cost;
};

double x[1010];
double y[1010];
double r[1010];
double d[1010];

vector<edge> G[1010];

double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	double d = sqrt(dx * dx + dy * dy);
	if(d < r[i] + r[j]) return 0;
	return d - (r[i] + r[j]);
}

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

	double xs, ys, xt, yt;
	int N;
	cin >> xs >> ys >> xt >> yt >> N;

	for(int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	x[N] = xs, y[N] = ys, r[N] = 0;
	x[N + 1] = xt, y[N + 1] = yt, r[N + 1] = 0;

	for(int i = 0; i < N + 2; i++) {
		for(int j = 0; j < N + 2; j++) {
			if(i == j) continue;
			G[i].push_back(edge{ j, dist(i, j) });
		}
	}

	fill(d, d + N + 2, 1e20);
	d[N] = 0;
	priority_queue <P, vector<P>, greater<P>> q;
	q.push(P(0, N));
	while(q.size()) {
		int v = q.top().second;
		double c = q.top().first;
		q.pop();
		if(d[v] < c) continue;
		for(auto e : G[v]) {
			if(d[e.to] >  c + e.cost) {
				d[e.to] = c + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
	cout << fixed << setprecision(15) << d[N + 1] << endl;
}

Measured memory_bytes: 20592
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define MOD 2019

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>>s;

    ll n=s.length();
    ll suf=0;
    ll pot=1;
    ll ans=0;

    vector<ll>cnt_suf(2019,0);
    cnt_suf[0]=1;

    for(ll i=n-1;i>-1;i--)
    {
        ll digit=s[i]-'0';
        suf=(digit*pot+suf)%MOD;
        pot=(pot*10)%MOD;
        ans+=cnt_suf[suf];
        cnt_suf[suf]++;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>>data;
  for(int i=0;i<n;i++){
      int a,b;
      cin >> a >> b;
      data.push_back(make_pair(b,a));
    }
    sort(data.begin(),data.end());
    int time =0;
    for(int i=0;i<n;i++){
        int a,b;
        tie(b,a)=data[i];
        time += a;
        if(time > b){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    int n;string  s;
    cin>>n>>s;
    int ok=0;
    ll ans =0;
    for(int i=0;i<10;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++)
    {
        for(int u=0;u<s.size();u++)
        {
            if(s[u]==char(i+'0')&&ok==0) ok++;
            else if(s[u]==char(j+'0')&&ok==1) ok++;
            else if(s[u]==char(k+'0')&&ok==2) ok++;
        }
        if(ok==3) ans++;
        ok=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

def DFS(adj, start):
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n
    S = []
    time = 1

    S.append(start)
    flag[start] = 1
    d[start] = time
    time = time + 1
    
    while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§
        if len(S) != 0:
            u = S.pop()
            v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] # v <= ??£??\???????????????????????¢?´¢??????????????????
            if len(v) != 0:
                S.append(u)
                S.append(v[0])
                flag[v[0]] = 1
                d[v[0]] = time
                time = time + 1
            else:
            #??£??\??????????????¨????¨??????????
                flag[u] = 2
                f[u] = time
                time = time + 1

        else:
            u = flag.index(0)
            S.append(u)
            flag[u] = 1
            d[u] = time
            time = time + 1            

    return d, f    

def main():
    
    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1
    
    d, f = DFS(adj, 0)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == "__main__":
    main()    

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

bool comp(P a, P b) {
	return a.second < b.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	vector<ll> a(n * 3);
	rep(i, n * 3) cin >> a[i];

	vector<ll> s(2 * n + 1, 0);
	priority_queue<ll, vector<ll>, greater<ll>> que1;
	rep(i, n) {
		s[i + 1] = s[i] + a[i];
		que1.push(a[i]);
	}
	for (int i = n; i < 2 * n; i++) {
		ll mi = que1.top();
		if (a[i] > mi) {
			s[i + 1] = s[i] - mi + a[i];
			que1.pop();
			que1.push(a[i]);
		}
		else s[i + 1] = s[i];
	}

	vector<ll> t(2 * n + 1, 0);
	priority_queue<ll> que2;
	rep(i, n) {
		t[i + 1] = t[i] + a[3 * n - 1 - i];
		que2.push(a[3 * n - 1 - i]);
	}
	for (int i = n; i < 2 * n; i++) {
		ll ma = que2.top();
		if (a[3 * n - 1 - i] < ma) {
			t[i + 1] = t[i] - ma + a[3 * n - 1 - i];
			que2.pop();
			que2.push(a[3 * n - 1 - i]);
		}
		else t[i + 1] = t[i];
	}

	ll res = -inf;
	for (int i = n; i <= 2 * n; i++) {
		chmax(res, s[i] - t[3 * n - i]);
	}

	out(res);

	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  
  vector<ll> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  
  vector<ll> res;
  res.push_back(p[0]);
  ll index = 0;
  for(int i=1; i<n; i++){
    if(res[index]>p[i]){
      res.push_back(p[i]);
      index++;
    }
  }
  
  cout << index+1 << endl;
  
  return 0;
}

Measured memory_bytes: 6720
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n, m; cin >> n >> m;
	ll x[114514];
	for (int i = 0; i < n; i++)cin >> x[i];
	sort(x, x + n);
	ll xs = 0;
	for (int i = 0; i < n; i++) {
		xs += x[i] * ((n - i - 1) - i);
		xs %= 1000000007;
	}
	ll y[114514];
	for (int i = 0; i < m; i++)cin >> y[i];
	sort(y, y + m);
	ll ys = 0;
	for (int i = 0; i < m; i++) {
		ys += y[i] * ((m - i - 1) - i);
		ys %= 1000000007;
	}
	cout << xs*ys % 1000000007;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int u=1,v=(n-1)/2;u<v&&m;++u,--v){
        cout<<u<<" "<<v<<"\n";
        m--;
    }
    for(int u=(n-1)/2+1,v=u+(n-1)/2;u<v&&m;++u,--v){
        cout<<u<<" "<<v<<"\n";
        m--;
    }
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3628
main(){
  int w,n,i,t[32],y,z,a;
  scanf("%d %d",&w,&n);
  for(i=1;i<=w;i++)
    t[i]=i;
  for(i=0;i<n;i++)
    {
      scanf("%d,%d",&y,&z);
      a=t[y];
      t[y]=t[z];
      t[z]=a;
    }
  for(i=1;i<=w;i++)
    printf("%d\n",t[i]);
  return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())

B = input()
happy = 0
for i in range(n):
  if B[i]=="L" and i != 0 :
    if B[i-1] == "L":
      happy +=1
  if B[i]=="R" and i != n-1 :
    if B[i+1] == "R":
      happy +=1
print(min(happy+2*k, n-1))


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

int main() {
  int n, m; cin >> n;
  vector<string> ss(n);
  rep(i, n){
    cin >> ss.at(i);
  }

  cin >> m; 
  vector<string> ts(m);
  rep(j, m) {
    cin >> ts.at(j);
  }

  sort(ss.begin(), ss.end());

  int i, j, count, ans;
  ans = 0;
  count = 1;
  for(i = 0; i < ss.size(); i++){
    if (i == ss.size()-1) {
      for (j = 0; j < ts.size(); j++) {
        if (ss[i] == ts[j]) {
          count = max({0, count-1});
        }
      }
      ans = max({ans, count});

      break;
    } else if(ss[i] == ss[i+1]) {
      count++;
    } else {  
      for (j = 0; j < ts.size(); j++) {
        if (ss[i] == ts[j]) {
          count = max({0, count-1});
        }
      }
      ans = max({ans, count});
      count = 1;
    }
  }

  p(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COM_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

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

int main(){
  ll N;
  cin>>N;
  ll A[N],sum=0,ssum=0;
  REP(i,N){
    cin>>A[i];
    sum+=A[i];
    sum%=MOD;
    ssum+=A[i]*A[i];
    ssum%=MOD;
  }
  COM_init();
  
  ll ans=(sum*sum%MOD-ssum)%MOD;
  ans*=inv[2];
  ans=(ans%MOD+MOD)%MOD;
  co(ans);
  return 0;
}

Measured memory_bytes: 52244
#include <stdio.h>
#define SWAP(type,a,b) { type temp = a; a = b; b = temp; }
#define N 36

typedef struct element{
  char mark;
  int num;
}card;
 

int main(){
  int i, j, n, minj, judge=0;
  card ca[N], cb[N];
  char s;

  scanf("%d%c",&n,&s);
  for(i=0;i<n;i++){
    scanf("%c%d%c",&ca[i].mark,&ca[i].num,&s);
    cb[i] = ca[i];
  }

  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(ca[j].num < ca[j-1].num){
	SWAP(card,ca[j],ca[j-1]);
      }
    }
  }


  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(cb[minj].num > cb[j].num){
	minj = j;
      }
    }
    SWAP(card,cb[minj],cb[i]);
  }

  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d\n",ca[i].mark,ca[i].num);
    else printf("%c%d ",ca[i].mark,ca[i].num);
  }

  
  printf("Stable\n");

  
  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d\n",cb[i].mark,cb[i].num);
    else printf("%c%d ",cb[i].mark,cb[i].num);
  }


  
  for(i=0;i<n;i++){
    if(ca[i].mark != cb[i].mark) judge=1;
  }
  if(judge==1) printf("Not stable\n");
  else printf("Stable\n");


  
  return 0;
}



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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define ff              first
#define ss              second
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define NL           "\n"
#define pb           push_back
#define mk              make_pair
#define pi           acos(-1.0)
#define prec(n)      fixed << setprecision(n)
#define sq(a)          (a)*(a)
#define asi          cout<<"check"<<" ";
#define all_set(arr,val) memset(arr,val,sizeof(arr))

int main()
{
    fast;
    LL i,j,k,ans=0,n,temp;
    string s;
    vector<LL>vec;
    cin>>s;
    n=s.size();
    FLR(i,n){
        if(s[i]=='W')vec.pb(i);
    }
    FLR(i,n-1){
        if(s[i]=='B'){
            auto it=upper_bound(all(vec),i);
            temp=vec.end()-it;
            //cout<<temp<<NL;
            //asi
            ans+=temp;
        }

    }
    cout<<ans;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h)
  {
    vector<int> done(w);
    rep(j, w)
    {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w)
      {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      rep(k, l)
      {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  rep(j, w)
  {
    vector<int> done(h);
    rep(i, h)
    {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h)
      {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      rep(k, l)
      {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;
}


Measured memory_bytes: 20096
import math
import numpy as np

N = int(input())
a = np.array([int(input()) for _ in range(N)])
s = np.sum(a)

# Counts of (R >= s / 2)
dp0 = np.zeros((N + 1, s + 1))
dp0[0, 0] = 1
# Counts of (R == s / 2 and G == s / 2)
dp1 = np.zeros((N + 1, s // 2 + 1))
dp1[0, 0] = 1

mod = 998244353
for i, x in enumerate(a):
    dp0[i + 1, :] += dp0[i, :] * 2 % mod
    dp0[i + 1, x:] += dp0[i, :-x] % mod
    dp1[i + 1, :] += dp1[i, :] % mod
    dp1[i + 1, x:] += dp1[i, :-x] % mod

c0 = int(np.sum(dp0[N][math.ceil(s / 2):]))
c1 = int(dp1[N][s // 2]) if s % 2 == 0 else 0

ans = (3 ** N - 3 * c0 + 3 * c1) % mod
print(ans)

Measured memory_bytes: 328896
$line = <>;
chomp($line);
($a, $b) = split(/ /, $line);

if($a == 1){
	print $b;
}
else{
	$n = $a - 1;
	foreach $i (-$n .. 0){
		push(@r, $b + $i);
	}
	foreach $i (1 .. $n){
		push(@r, $b + $i);
	}
	print join(" ",@r);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b;
  cin >> a >> b;
  cout << a / __gcd(a, b) * b << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
  var N int
  var K int
  var X int
  var Y int
  var sum int = 0
  fmt.Scan(&N)
  fmt.Scan(&K)
  fmt.Scan(&X)
  fmt.Scan(&Y)
  
  if N <= K {
    sum = X * N
  } else if N > K {
    sum = X * K + Y * (N-K)
  }
  fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
const int mod=998244353;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,f[N],ans=0,bin[N];
char s[N];

int main() {
	cin>>n;scanf("%s",s+1);reverse(s+1,s+n+1);
	bin[0]=1;for(int i=1;i<=n;i++) bin[i]=(bin[i-1]<<1)%mod;
	for(int i=1;i<=n;i++)
		if(n%i==0&&((n/i)&1)) {
			int sum=0;
			for(int j=n;j>=n-i+1;j--)
				if(s[j]=='1') sum=(sum+bin[j-(n-i)-1])%mod;
			int fl=0,fl2=0;
			for(int j=n-i;j&&!fl2;j-=i) {
				fl^=1;
				for(int k=j,l=n;k>=j-i+1;k--,l--) {
					int b=(s[l]-'0')^fl;
					if(b<s[k]-'0') { sum=(sum+1)%mod;fl2=1;break; }
					else if(b>s[k]-'0') { fl2=1;break; }
				}
			}
			if(!fl2) sum=(sum+1)%mod;
			f[i]=sum;
		}
	for(int i=1;i<=n;i++)
		if(n%i==0&&((n/i)&1)) 
			for(int j=i+i;j<=n;j+=i)
				if(n%j==0&&((n/i)&1)) f[j]=(f[j]-f[i]+mod)%mod;
	for(int i=1;i<=n;i++)
		if(n%i==0&&((n/i)&1)) ans=(ans+2ll*f[i]*i)%mod;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 998244353;

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

	int n, d;
	cin >> n;
	ll* num = new ll[n];
	memset(num, 0, sizeof(ll)*n);
	int maxNum = 0;

	rep(i, n) {
		cin >> d;
		++num[d];
		if (i == 0 and d != 0) {
			cout << 0 << "\n";
			return 0;
		}
		maxNum = max(maxNum, d);
	}

	if (num[0] != 1) {
		cout << 0 << "\n";
		return 0;
	}

	ll ans = 1;
	REP(i, 2, maxNum + 1) rep(j, num[i]) ans = (ans * num[i - 1]) % MOD;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		while(true){
			String line = sc.nextLine();
			if(line.equals("0")){
				break;
			}
			int sum=0;
			for(int i=0;i<line.length();i++){
				sum+=Integer.parseInt(line.substring(i,i+1));
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 26652
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n, m;
    cin >> n >> m;
    LL w = (1<<10);
    vector<vector<LL>> mat(w, vector<LL>(w));
    for(LL i = 0; i < 10; ++i){
        for(LL y = 0; y < (1<<i); ++y){
            for(LL x = 0; x < (1<<i); ++x){
                LL b = (1<<i);
                mat[b+y][x] = mat[y][x];
                mat[y][b+x] = mat[y][x];
                mat[b+y][b+x] = 1 - mat[y][x];
            }
        }
    }
    LL n2 = (1<<n)-1;
    LL m2 = (1<<m)-1;
    vector<vector<LL>> ans(n2, vector<LL>(m2));
    for(LL y = 0; y < n2; ++y){
        for(LL x = 0; x < m2; ++x){
            ans[y][x] = (mat[y+1][x+1] + mat[y][x+1] + mat[y+1][x] + mat[y][x]) % 2;
        }
    }
    for(LL y = 0; y < n2; ++y){
        for(LL x = 0; x < m2; ++x){
            cout << ans[y][x];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 17792
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;


void virus(){
    ll len;
    cin >> len;
    bool in = false;
    ll cnt = 0;
    for(auto i=0; i<len; i++){
        ll a, b;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt == 3){
            in = true;
        }
    }
    (!in)? cout<<"No\n" : cout<<"Yes\n";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t = 1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
           //cerr << "\n Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 20
struct Ele{
    int l,r,c1,c2;
    Ele(int r_l=0,int r_r=0,int r_c1=0,int r_c2=0)
    {
	l=r_l,r=r_r,c1=r_c1,c2=r_c2;
    }
};
bool operator < (Ele a1,Ele a2) {
    if(a1.l!=a2.l) return a1.l<a2.l;
    if(a1.r!=a2.r) return a1.r<a2.r;
    if(a1.c1!=a2.c1) return a1.c1<a2.c1;
    return a1.c2<a2.c2;
}
int n;
ll val[M];
map<Ele,ll> f;
ll f2[M][M][605][605];
ll dfs(int l,int r,int c1,int c2) {
    if(l+1==r) return 0;
    ll x;
    if(c1<=600&&c2<=600) x=f2[l][r][c1][c2];
    else x=f[Ele(l,r,c1,c2)];
    if(x!=0) return x;
    x=1e18;
    for(int i=l+1;i<=r-1;i++)
	x=min(x,dfs(l,i,c1,c1+c2)+dfs(i,r,c1+c2,c2)+(c1+c2)*val[i]);
    if(c1<=600&&c2<=600) f2[l][r][c1][c2]=x;
    else f[Ele(l,r,c1,c2)]=x;
    return x;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>val[i];
    cout<<(dfs(1,n,1,1)+val[1]+val[n])<<'\n';
    return 0;
}

Measured memory_bytes: 318976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

bool dp[105][10005];

int main() {
    int n; cin >> n;
    vint s(n);
    rep(i,n) cin >> s[i];
    dp[0][0] = true;
    rep(i,n)rep(j,10005) {
        if (dp[i][j]) {
            dp[i+1][j] = true;
            dp[i+1][j+s[i]] = true;
        }
    }
    for (int i = 10000; i >= 0; i--) {
        if (i % 10 == 0) continue;
        if (dp[n][i]) {
            cout << i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

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

using namespace std;

int a,b,c,ans;

int main(){
	scanf("%d%d%d",&a,&b,&c);
	ans=b; a+=b;
	ans+=min(c,a+1);
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,d,e,ans=0;
	double c;
	cin>>n>>d;
	ll arr[n][d];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<d;j++)
			cin>>arr[i][j];
	}
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			c=0.0;e=0;
			for(ll k=0;k<d;k++)
			{
				e+=(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
			}
			c=sqrt(e);
			if(c==floor(c))
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}





Measured memory_bytes: 256
# -*- coding: utf-8 -*-
A, B, C, D, E, F = map(int, input().split(' '))

watars = []
import math
for i in range(int(math.floor(F/ (A*100)))+1):
    rest = F - A * 100 * i
    for j in range(int(math.floor(rest/ (B*100)))+1):
        watars.append(A*100*i + B*100*j)

salts = []
lim_salt = int(F * E // 100)
for i in range(int(math.floor(lim_salt/ C))+1):
    rest = lim_salt - C * i
    for j in range(int(math.floor(rest/ D))+1):
        salts.append(C*i + D*j)

watars = set(watars)
salts = set(salts)

# print(len(watars), len(salts))

max_ratio = 0
ans = [0, 0]
for watar in watars:
    if watar == 0:
        continue

    for salt in salts:
        amount = watar + salt
        ratio = salt / amount
        if amount <= F and salt <= watar * E / 100:
            if ratio > max_ratio:
                max_ratio = ratio
                ans = [watar, salt]

if max_ratio == 0:
    water = min([water for water in watars
                 if 0 < water <= F])
    print(water, 0)

else:
    print(sum(ans), ans[1])

Measured memory_bytes: 52736
s = input()
 
ans = ''
for i in range(len(s)):
	if s[i:i+1]=='0':
		ans += '0'
	elif s[i:i+1]=='1':
		ans += '1'
	elif s[i:i+1]=='B':
		ans = ans[:-1]
 
print(ans)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    deque<int> d;
    rep(i, N) {
        int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (p == 0) {
            d.push_front(a[i]);
        } else {
            d[p - 1] = a[i];
        }
    }
    int ans = d.size();
    cout << ans << endl;
}


Measured memory_bytes: 1024