akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
}

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

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

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>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
    }

    let max_count = 26;
    let mut camn_calc = false;
    'outer: for i in 0..max_count {
        for j in 0..max_count {
            if n == 4*i + 7*j {
                camn_calc = true;
                break 'outer
            }
        }
    }
    if camn_calc {
        println!{"Yes"}
    } else {
        println!("No")
    }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MX 10e18
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
ll find(ll wt[],ll val[],ll w,ll n)
{
	ll dp[n+1][w+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(i==0||j==0)
			dp[i][j]=0;
			else
			if(wt[i-1]<=j)
			{
			 dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);	
			}
			else
			dp[i][j]=dp[i-1][j];
			
		}
	}
	
	return dp[n][w];
}
int main() {
	fastio();
	ll n,w,a,b;
	cin>>n>>w;
	ll wt[n],val[n];
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		wt[i]=a;
		val[i]=b;
	}
	cout<<find(wt,val,w,n);
	
	return 0;
}

Measured memory_bytes: 79104
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include <iomanip>

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;


typedef	unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef unsigned __int128 ulll;


template <class T>
int scan(T &n)
{
	bool negative = false;
	register int c;
	n = 0;
	c = getchar();
	while (!(c >= '0' && c <= '9') && c != -1 && c != '-')c = getchar();
	if (c == -1)return 0;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	for (; c >= '0' && c <= '9'; c = getchar())
		n = n * 10 + c - 48;
	if (negative)
		n *= -1;
	return 1;
}
template <class T>
void printrec(T n)
{
	if (n == 0) {
		return;
	}
	if (n < 0)
	{
		putchar('-');
		n *= -1;
	}
	printrec(n / 10);
	putchar_unlocked(n % 10 + 0x30);
}
template <class T>
void print(T n)
{
	if (n == 0)
	{
		putchar_unlocked('0');
		return;
	}
	else
	{
		printrec(n);
	}
}
template <class T>
T abs(T n)
{
	if (n < 0)n *= -1;
	return n;
}

long long pow(long long a, long long b, long long m)
{
	if(!b)return 1%m;
	long long p=pow(a,b>>1,m);
	long long q=(p*p)%m;
	if(b&1)return (q*a)%m;
	return q;
}

int arr[26]={0};
lll f()
{
	lll s=1;
	long long mod=1000000007;
	for(int i=0;i<26;i++)
	{
		s*=(arr[i]+1);
		s%=mod;
	}
	s--;
	if(s<0)s+=mod;
	return s;
}
int main(int argc, char const *argv[])
{
	int n;
	scan(n);
	string s;
	cin>>s;
	for(auto a:s)arr[a-'a']++;
		print(f());
	return 0;
}

Measured memory_bytes: 512
N,K = map(int,input().split())
if N==K:
    print(0)
elif N > K:
    if N%K == 0:
        print(0)
    else:
        print(min(N%K,K-(N%K)))
elif N < K:
    if 2*N<K:
        print(N)
    else:
        print(abs(N-K))

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

int main() {
    int N; cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    for (int i = 0; i < N-1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (int i = 0; i < N; i++) {
        ll t = 0;
        if (i == N-1) {
            cout << t << endl;
        }
        else {
            for (int j = i; j < N-1; j++) {
                if (j == i) {
                    t += S[j];
                    t += C[j];
                }
                else {
                    //tがSiより小さいときはSiまで待つ
                    if (t < S[j]) {
                        t = S[j];
                    }
                    //tがFiで割り切れるならCiかけて次の駅へ
                    //割り切れないなら割り切れるまで待つ
                    if (t%F[j] != 0) {
                        t += F[j]-(t%F[j]);
                    }
                    t += C[j];
                }
            }
            cout << t << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll m,d,cnt=0; cin>>m>>d;
    rep(i,m)rep(j,d){
        ll a=(j+1)%10,b=(j+1)/10;
        if(a>=2 && b>=2 && a*b==i+1) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double L;
  cin>>L;
  printf("%.10f\n",(double)pow(L/3.0,3));
  /*ll ans = 0;
  for(ll i = 1;i<L;i++){
    for(ll j = 1;j<L-i;j++){
      if(L-i-j > 0){
	ans = max(ans,i*j*(L-i-j));
      }
    }
  }
  cout<<ans<<endl;
  */
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#define MH 20
#define MW 20
using namespace std;
char f[MH][MW];
bool v[MH][MW];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int w, h;
int c = 0;

void search(int x, int y) {
	++c;
	v[y][x] = true;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i]; int ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && v[ny][nx] == false && f[ny][nx] != '#') {
			search(nx, ny);
		}
	}
	return;
}

int search2(int x, int y) {
	v[y][x] = true;
	int res = 1;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i]; int ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && v[ny][nx] == false && f[ny][nx] != '#') {
			res += search2(nx, ny);
		}
	}
	return res;
}

int main() {
	int sx, sy;

	while (cin >> w >> h, !(w == 0 && h == 0)) {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				cin >> f[i][j];
				if (f[i][j] == '@') {
					sx = j;
					sy = i;
				}
			}
		}
		c = 0;
		fill(v[0], v[MH], false);
		//search(sx, sy);
		//cout << c << endl;
		cout << search2(sx, sy) << endl;
		
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int w, h;
int yoko[31][31], tate[31][31], d[31][31];
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        cin >> w >> h;
        if(w + h == 0) break;
        for(int i = 0; i < 2 * h - 1; i++){
            if(i % 2 == 0){
                rep(j, 0, w - 1){
                    cin >> yoko[i / 2][j];
                }
            }else{
                rep(j, 0, w){
                    cin >> tate[i / 2][j];
                }
            }
        }
        rep(i, 0, 31) rep(j, 0, 31) d[i][j] = INF;        
        queue<P> q;
        q.push(P(0, 0));
        d[0][0] = 1;
        while(!q.empty()){
            P p = q.front(); q.pop();
            int y = p.first;
            int x = p.second;
            if(y == h - 1 && x == w - 1){
                break;
            }
            rep(i, 0, 4){
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(!contain(ny, nx)) continue;
                if(d[ny][nx] != INF) continue;
                if(i == 0){
                    if(tate[y][x]) continue;
                }else if(i == 1){
                    if(tate[y - 1][x]) continue;
                }else if(i == 2){
                    if(yoko[y][x]) continue;
                }else if(i == 3){
                    if(yoko[y][x - 1]) continue;
                }
                d[ny][nx] = d[y][x] + 1;
                q.push(P(ny, nx));
            }
        }
        int ans = d[h - 1][w - 1];
        if(ans == INF) cout << 0 << endl;
        else cout << ans << endl;
    }    
}


Measured memory_bytes: 3144
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define		vii 			vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll NcR(ll n, int r)
{
    ll res = 1;
    if ( r > n - r )
        r = n - r;
    loop(r,i,0){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
int main() {
	ll l;cin>>l;
	double d=(1.0*l/3);
	cout<<fixed<<setprecision(12)<<d*d*d<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
/*考察
主となる部分がある。
例3だったら
6 3 1 2 7 4 8 5
の6 7 8をメインとして適切に他のを前と後ろに持ってくるだけ
このメインとなる部分は連続する数で前後関係が変わらないやつ
 */
int main(){
    int n;cin>>n;
    int p[n];
    unordered_map<int,int> m;
    rep(i,n){
        cin>>p[i];p[i]--;
        m[p[i]]=i;
    }
    bool check[n]={};
    int ren=0;
    rep(i,n){
        //iについて調べる。checkつけてけばO(n)
        if(check[i]) continue;
        int j=i+1,index=m[i];
        for(;j<n;j++){
            if(m[j]<=index) break;
            index=m[j];
            check[j]=true;
        }
        ren=max(ren,j-i);
    }
    
    cout<<n-ren<<endl;
    return 0;
}

Measured memory_bytes: 9416
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#pragma warning (disable: 4996)
using namespace std;

long long N;
long long X[1 << 18], Y[1 << 18];
long long lx = (1LL << 30), rx = -(1LL << 30);
long long ly = (1LL << 30), ry = -(1LL << 30);

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i];
		lx = min(lx, X[i] + Y[i]);
		rx = max(rx, X[i] + Y[i]);
		ly = min(ly, X[i] - Y[i]);
		ry = max(ry, X[i] - Y[i]);
	}
	cout << max(ry - ly, rx - lx) << endl;
	return 0;
}

Measured memory_bytes: 6748
# 2019-11-18 17:34:23(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, k, q, *a = [int(x) for x in sys.stdin.read().split()]

    c = collections.Counter(a)
    for i in range(1, n+1):
        if not i in c:
            print('No' if k - q <= 0 else 'Yes')
        else:
            print('No' if k - (q - c[i]) <= 0 else 'Yes')
    

if __name__ == "__main__":
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i ++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int a, b;
  a = 0;
  b = 0;
  
  for(int i = 0; i < N; i ++){
    if (i%2 == 0){
      a += vec.at(i);
    }
    
    else{
      b += vec.at(i);
    }
    
  }
  
  cout << a-b << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int main () {
    int n;
    cin >> n;
    if (n > 5) {
        cout << "yes" << endl;
        return 0;
    }
    int rots[5][3];
    for(int i = 0; i < n; i++) {
        int m;
        cin >> m;
        for(int j = 0; j < 3; j++) rots[i][j] = j;
        for(int j = 0; j < m; j++) {
            int b;
            cin >> b;
            if (b == 0) {
                swap(rots[i][0], rots[i][1]);
            } else {
                swap(rots[i][1], rots[i][2]);
            }
        }
    }
    int par[n];
    for(int i = 0; i < n; i++) par[i] = i;
    int ans[3] = {0, 1, 2};
    do {
        for(int i = 0; i < 3; i++) ans[i] = i;
        for(int i = 0; i < n; i++) {
            int tmp[3];
            for(int j = 0; j < 3; j++) tmp[j] = ans[j];
            for(int j = 0; j < 3; j++) ans[j] = tmp[rots[par[i]][j]];
            if (ans[0] == 0 && ans[1] == 1 && ans[2] == 2) {
                cout << "yes" << endl;
                return 0;
            }
        }
    } while(next_permutation(par, par + n));
    cout << "no" << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
int main(void) {
	int a, b, div, count, i;
	count = 0;
	scanf("%d %d %d", &a, &b, &div);
	for (i = a; i <= b; i ++) if (div % i == 0) count ++;
	printf("%d\n", count);
	return 0;
}

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

#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(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	int N, D;
	int Dw;
	cin >> N >> D;
	Dw = D * 2 + 1;
	if (N % Dw == 0)cout << N / Dw << endl;
	else cout << int(N / Dw) + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
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;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    long double n,m,d; cin >> n >> m >> d;

    long double ans;

    if(d == 0){
        ans = n * (m-1) / n / n;
        cout << ans << endl;
        return 0;
    }

//    ans = 2 * (n-d) * (m-1) / n / n;
    //ans = 2.0 * (n-d) / n / n * (m-1);
    ans = 2.0L * (n-d) * (m-1) / (n*n);
    printf("%.12Lf\n", ans);

    //cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


#define mk make_pair
#define pb push_back

typedef long long lld;
typedef pair<lld,lld> pr;
typedef priority_queue <lld> max_heap;
typedef priority_queue <lld, vector<lld>, greater<lld> > min_heap;
lld const mod = 1e9+7;
lld const N = 1e5+5;
#define ordered_set tree<lld, null_type,less<lld>, rb_tree_tag,tree_order_statistics_node_update>

lld fact[N], ifact[N];

lld power(lld x, lld y)
{
    lld res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

lld power_mod(lld base, lld y)
{
    lld t = 1;
    while (y > 0)
    {

        if (y % 2 != 0)
            t = (t * base) % mod;
        base = (base * base) % mod;
        y /= 2;
    }
    return t % mod;
}

void findFact() {
    fact[0] = 1;
    for(lld i = 1; i <= N; i++)
        fact[i] = 1ll * fact[i - 1] * i % mod;
    ifact[N] = power_mod(fact[N], mod - 2);
    for(lld i = N - 1; i >= 0; i--)
        ifact[i] = 1ll * ifact[i + 1] * (i + 1) % mod;
}

lld comb(lld n, lld r) {
    return 1ll * fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld n;
  cin>>n;
  lld a;
  lld max_ht=-1;
  lld sum = 0;
  for(lld i=0;i<n;i++)
  {
    cin>>a;
    if(max_ht==-1)
    {
      max_ht=a;
    }
    else if(a>=max_ht)
    {
      max_ht=a;
    }
    else
    {
      sum += max_ht-a;
    }
  }
  cout<<sum<<endl;

}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define mp	make_pair
#define pb	push_back
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

typedef long long	ll;

using namespace std;

vector<ll> a, b, vec, a1, b1;
ll n;

void testgen() {
	n = rand() % 11 + 2;
	vec.resize(0);
	a.resize(0);
	b.resize(0);
	a1.resize(0);
	b1.resize(0);
	for (int i = 0; i < n; i++)
	{
		vec.pb(rand() % 20);
	}
}

ll minim() {
	ll l = 1, r = n - 3;
	bool e = true;
	a.pb(vec[0]);
	a.pb(vec[n - 1]);
	b.pb(vec[n - 2]);
	while (l <= r)
	{
		ll y = vec[r];
		ll q, w;
		bool aa, bb;
		if (abs(a[a.size() - 1] - y) > abs(b[b.size() - 1] - y))
		{
			q = abs(a[a.size() - 1] - y);
			aa = true;
		}
		else
		{
			q = abs(b[b.size() - 1] - y);
			aa = false;
		}

		ll u = vec[l];
		if (abs(a[a.size() - 1] - u) > abs(b[b.size() - 1] - u))
		{
			w = abs(a[a.size() - 1] - u);
			bb = true;
		}
		else
		{
			w = abs(b[b.size() - 1] - u);
			bb = false;
		}
		if (w > q)
		{
			l++;
			if (bb)
			{
				a.pb(u);
			}
			else
			{
				b.pb(u);
			}
		}
		else
		{
			r--;
			if (aa)
			{
				a.pb(y);
			}
			else
			{
				b.pb(y);
			}
		}
	}
	ll rr = 0;
	for (ll i = a.size() - 1; i > 0; i--)
	{
		rr += abs(a[i] - a[i - 1]);
	}
	rr += abs(a[0] - b[0]);
	for (ll i = 1; i < b.size(); i++)
	{
		rr += abs(b[i] - b[i - 1]);
	}
	return rr;
}

ll maxim() {
	ll l = 2, r = n - 2;
	bool e = true;
	a1.pb(vec[n - 1]);
	a1.pb(vec[0]);
	b1.pb(vec[1]);
	while (l <= r)
	{
		ll y = vec[r];
		ll q, w;
		bool aa, bb;
		if (abs(a1[a1.size() - 1] - y) > abs(b1[b1.size() - 1] - y))
		{
			q = abs(a1[a1.size() - 1] - y);
			aa = true;
		}
		else
		{
			q = abs(b1[b1.size() - 1] - y);
			aa = false;
		}

		ll u = vec[l];
		if (abs(a1[a1.size() - 1] - u) > abs(b1[b1.size() - 1] - u))
		{
			w = abs(a1[a1.size() - 1] - u);
			bb = true;
		}
		else
		{
			w = abs(b1[b1.size() - 1] - u);
			bb = false;
		}
		if (w > q)
		{
			l++;
			if (bb)
			{
				a1.pb(u);
			}
			else
			{
				b1.pb(u);
			}
		}
		else
		{
			r--;
			if (aa)
			{
				a1.pb(y);
			}
			else
			{
				b1.pb(y);
			}
		}
	}
	ll rr = 0;
	for (ll i = a1.size() - 1; i > 0; i--)
	{
		rr += abs(a1[i] - a1[i - 1]);
	}
	rr += abs(a1[0] - b1[0]);
	for (ll i = 1; i < b1.size(); i++)
	{
		rr += abs(b1[i] - b1[i - 1]);
	}
	return rr;
}

int main()
{
	cin >> n;
	vec.resize(n);
	for (ll i = 0; i < n; i++)
	{ 
		cin >> vec[i];
	}
	//for (int qqq = 0; qqq < 30; qqq++) {
			//testgen();
		if (n == 2)
		{
			int yy = vec[0], tt = vec[1];
			cout << abs(yy-tt);
			return 0;
		}
		sort(vec.begin(), vec.end());
		ll r1 = maxim();
		ll r2 = minim();
		cout << max(r1, r2);
			//cout << '\n';
			//for (int i = 0; i < n; i++)
			//{
			//	cout << vec[i] << ' ';
			//}
			//cout << '\n' << r1 << ' ' << r2 << '\n';
	//}
	return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
cout<<(a*b)-a-b+1<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>

typedef long long ll;
typedef long long int lli;

#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)

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

using namespace std;

int v[200000],a[200000]={0},b[200000]={0};
int main() {
    int N,T,c[101],t[101],min=10000;
    cin>> N>>T;
    for(int i=0; i<N;i++){
        cin>>c[i];
        cin>>t[i];
    }
    rep(i,N){
        if(t[i]<=T){
            if(min>c[i]){
                min=c[i];
            }
        }
    }

    if(min>=5000){
        printf("TLE");
    }else{
        printf("%d",min);
    }
    return 0;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        int length = c.nextInt();
        c.nextLine();
        String s = c.nextLine();
        if(s.length() <= length){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0,length)+"...");
        }
    }
}

Measured memory_bytes: 38712
/*
https://atcoder.jp/contests/dp/tasks/dp_c
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 1;
int n;
ll f[N][3];

void Init ()
{
    cin >> n;
    for (int i = 0; i < n ; ++i)
    {
        cin >> f[i][0] >> f[i][1] >> f[i][2];
    }
}

ll GetResult ()
{
    for (int i = 1; i < n; ++i)
    {
        f[i][0] += max (f[i - 1][1], f[i - 1][2]);
        f[i][1] += max (f[i - 1][0], f[i - 1][2]);
        f[i][2] += max (f[i - 1][0], f[i - 1][1]);
    }
    return max (f[n - 1][0], max (f[n - 1][1], f[n - 1][2]));
}

int main ()
{
    Init();
    cout << GetResult();
    return 0;
}

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

using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;

	vector<vector<int>> map;
	for(int i = 0; i < H; i++)
	{
		vector<int> line;
		for(int j = 0; j < W  + 1; j++)
		{
			if(j == W)
			{
				line.push_back(0);
				continue;
			}
			int state;
			cin >> state;
			line.push_back(state == 0 ? 1 : 0);
		}
		map.push_back(line);
	}

	for(int i = 0; i < H-1; i++)
	{
		for(int j = 0; j < W; j++)
		{
			if(map[i + 1][j] != 0)
			{
				map[i + 1][j] += map[i][j];
			}
		}
	}
	int maxValue = 0;
	for(int i = 0; i < H; i++)
	{
		for(int j = 0; j < W; j++)
		{
			int minHight = map[i][j];
			if(minHight == 0)
			{
				continue;
			}
			for(int k = j + 1; k < W + 1; k++)
			{
				
				if(map[i][k] == 0)
				{
					int buf = (k-j) * minHight;
					maxValue = maxValue > buf ? maxValue : buf;
					break;
				}
				maxValue = maxValue > (k - j) * minHight ? maxValue : (k - j) * minHight;
				minHight = minHight < map[i][k] ? minHight : map[i][k];
				
			}
		}
	}
	cout << maxValue << endl;
}

Measured memory_bytes: 10412
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 4000+5;

char s1[N], s2[N];
int n, m;
ull p[30], h1[N][N], h2[N][N];

void calc(int n, ull hx[][N], char *s){
    for(int i=1; i<=n; i++){
        ull h = 0;
        for(int j=i; j<=n; j++)h += p[s[j]-'a'], hx[j-i+1][i] = h;
    }
}

void go(){
    int ans = 0;
    calc(n, h1, s1);
    calc(m, h2, s2);
    int len = min(n, m);
    for(int i=1; i<=n; i++)sort(h1[i]+1, h1[i]+2+n-i);
    for(int i=1; i<=m; i++)sort(h2[i]+1, h2[i]+2+m-i);
    for(int i=1; i<=len; i++){
        for(int j=1; j+i-1<=n; j++){
            int pos = lower_bound(h2[i]+1, h2[i]+2+m-i, h1[i][j])-h2[i];
            if(h2[i][pos] == h1[i][j])ans = max(ans, i);
        }
    }
    printf("%d\n", ans);
}

int  main(){
    scanf("%s%s", s1+1, s2+1);
    n = strlen(s1+1), m = strlen(s2+1);
    p[0] = 1;
    for(int i=1; i<30; i++)p[i] = p[i-1]*2333;
    go();
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")

Measured memory_bytes: 158228
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <set> 
using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	string s;
	cin >> s;
	for (int i = 0 ; i < 4; ++i) {
		cout << s[i];
	}
	cout << " ";
	for (int i = 4; i < (int) s.size(); ++i) {
		cout << s[i];
	}
	cout << endl;


	return 0;
}

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

namespace AGC010a
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long sum = a.Sum();
            if(sum % 2 == 0)
            { Console.WriteLine("YES"); }
            else
            { Console.WriteLine("NO"); }
        }
    }
}


Measured memory_bytes: 21088
# -*- coding: utf-8 -*-
n = int(input())
aa = [0]
s = 0
for x in input().split():
    a = int(x)
    aa.append(aa[-1]+a)
    s += a

ret = abs(2*aa[1]-s)
for i in range(1,n):
    if abs(aa[i]-(s-aa[i]))<ret:
        ret = abs(aa[i]-(s-aa[i]))

print(ret)


Measured memory_bytes: 26648
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,p;	cin>>n>>m>>p;
	vector<int> d(m);
	for(int i=0;i<m;i++){
		cin>>d[i];
		d[i]=(d[i]+n-p)%n;
	}
	sort(d.begin(),d.end());
	for(int i=0;i<m;i++)	d.push_back(d[i]);
	int ans=min(n-d[0],d[m-1]);
	for(int i=1;i+1<2*m;i++){
		int tmp1=2*d[i]+n-d[i+1];
		int tmp2=2*(n-d[i])+d[i-1];
		ans=min(ans,min(tmp1,tmp2));
	}
	cout<<ans*100<<endl;
	return 0;
}

Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		String[] ss = new String[s.length()];
		ss = s.split("");
		String result = "";
		for(String f : ss){
			result+="x";
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 23636
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let m = scan.read::<usize>();
    let ab = arr(m, |_| (scan.read::<usize>()-1, scan.read::<usize>()-1));
    let mut cnt = vec![0;n];
    for (a, b) in ab {
        cnt[a] += 1;
        cnt[b] += 1;
    }
    println!("{}", if cnt.iter().any(|&x| x % 2 != 0) {"NO"} else {"YES"});
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 6396
#include <stdio.h>

void print(int a[8][8]){
    int i,j;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(a[i][j]==0){
                printf(".");
            }else{
                printf("Q");
            }
        }
        printf("\n");
    }
}


int existT(int j,int a[8][8]){
    int i;
    for(i=0;i<8;i++){
        if(a[i][j]==1){
            return 1;
        }
    }
    return 0;
}

int existN1(int i,int j,int a[8][8]){
    if(i>j){
        i-=j;j=0;
    }else{
        j-=i;i=0;
    }
    while(i<8&&j<8){
        if(a[i][j]==1){
            return 1;
        }
        i++;j++;
    }
    return 0;
}

int existN2(int i,int j,int a[8][8]){
    if(i>7-j){
        i-=(7-j);j=7;
    }else{
        j+=i;i=0;
    }
    while(i<8&&j>=0){
        if(a[i][j]==1){
            return 1;
        }
        i++;j--;
    }
    return 0;
}

int exist(int i,int j,int a[8][8]){
    if(existT(j,a)==1){return 1;}
    if(existN1(i,j,a)==1){return 1;}
    if(existN2(i,j,a)==1){return 1;}
    return 0;
}

int search(int i,int a[8][8]){
    int j,flg=0;
    for(j=0;j<8;j++){
        if(a[i][j]==1){
            flg=1;break;
        }
    }
    if(flg==1){
        if(i==7){
          //print(a);

          int h,j;
          for(h=0;h<8;h++){
              for(j=0;j<8;j++){
                  if(a[h][j]==0){
                      printf(".");
                  }else{
                      printf("Q");
                  }
              }
              printf("\n");
          }

          return 1;
        }
        return search(i+1,a);
    }else{
        flg=0;
        for(j=0;j<8;j++){
            if(exist(i,j,a)==1){continue;}
            a[i][j]=1;
            if(i==7){print(a);return 1;}
            if(search(i+1,a)==1){return 1;}
            a[i][j]=0;
        }
    }
    return 0;
}


int main(){
    int a[8][8];
    int n,i,j,k;
    scanf("%d",&n);
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            a[i][j]=0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d",&j);
        scanf("%d",&k);
        a[j][k]=1;
    }
    search(0,a);
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int s;
	cin >> s;
	if(s < 3){
		cout << 0 << newl;
		return;
	}
	vector <vector <int>> dp(s + 1);
	dp[0] = vector <int>(1,1);
	for(int i = 1;i <= s;++i){
		if(i == 1){
			dp[1] = vector <int>(2,1);
			continue;
		}
		dp[i] = vector <int> (i + 1,1);
		for(int j = 1;j < i;++j){
			dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) %mod;
		}
	}
	lli ans = 0;
	for(int i = 1;i <= (s / 3);++i){
		ans = (ans + dp[s - 2 * i - 1][s - 3 * i]) % mod;
	}
	cout << ans << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 11044
#include <iostream>

using namespace std;


int main()
{
	long long int n,d;
	cin >> n >> d;
	d=d*d;
	int ans = 0;
	while(n--)
	{
		long long int x,y;
		cin >> x >> y;
		long long int dist = x*x+y*y;
		if(dist<=d)
		{
			ans++;
		}

	}
	cout << ans;
}

Measured memory_bytes: 3628
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.length() != 26) {
            int a[] = new int[26];
            for (int i = 0; i < s.length(); i++) {
                a[s.charAt(i) - 'a'] = 1;
            }
            for (int i = 0; i < 26; i++) {
                if (a[i] == 0) {
                    char tmp = (char) ('a' + i);
                    System.out.println(s + tmp);
                    break;
                }
            }
        } else {
            boolean bre = false;
            for (int i = s.length() - 1; i > 0; i--) {
                if (s.charAt(i) > s.charAt(i - 1)) {
                    int min = s.charAt(i);
                    for (int j = i; j < s.length(); j++) {
                        if (s.charAt(j) > s.charAt(i - 1)) {
                            min = Math.min(min, s.charAt(j));
                        }
                    }
                    char mi = (char)min;
                    System.out.println(s.substring(0, i - 1) + mi);
                    bre = true;
                    break;
                }
            }
            if (!bre) {
                System.out.println(-1);
            }
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;


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

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

  ll sum=0;
  for(ll bit=0; bit<(1<<(S.size()-1)); bit++)
    {
      ll tmp=0;
      for(int i=S.size()-1; i>-1; i--)
	{
	  //	  if(sum <1000)
	  // cout << int(S[S.size()-1-i])-int('0')<< " " << sum << " " << tmp << endl;
	  if(bit&(1<<i))
	    {
	      sum += tmp;
	      tmp = int(S[S.size()-1-i])-int('0');
	    }
	  else
	    {
	      tmp = tmp*10 +int(S[S.size()-1-i])-int('0') ;
	    }
	}
      if(tmp!=0)
	{
	  sum+=tmp;
	  tmp=0;
	}
    }

  cout << sum << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    
    int a = scan.nextInt();
    int b = scan.nextInt();
    
    if (a <= b){
      for (int i = 0; i < b; i++){
        System.out.print(a);
      }
    } else {
      for (int i = 0; i < a; i++){
        System.out.print(b);
      }
    }
    System.out.println();
  }
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code here;
	int n,i,j,count=0;
	cin>>n;
	vector<int> ar(n);
	for(i=0;i<n;i++) cin>>ar[i];
	sort(ar.begin(),ar.end());
	for(i=0;i<n-2;i++) {
		int k=i+2;
		for(j=i+1;j<n;j++) {
			while(k<n && ar[i]+ar[j]>ar[k]) k++;
			if(k>j) count+=k-j-1;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//repetition
//------------------------------------------
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;

int main() {
    int N, cnt = 0;
    int a[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    cin >> N;
    int n = N;
    int i = 0;
    REP(i, 9) {
            a[i] = n % 10;
        if (n < 10) {
            break;
        }
        n = n / 10;
    }

    i = 0;
    int total = 0;
    REP(i, 9) {
        total += a[i];
    }

    if (N % total == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int const NMAX = 1e5;
int freq[1 + NMAX];

int main() {

  long long n, m, k = 1000000000000000001, p;
  cin >> n >> m >> k;
  //n = n % m;
  for(int i = 1;i <= k;i++){
    cin >> p;
    freq[p]++;
  }
  for(int i =1;i <= n;i++){
    if(m + freq[i] - k > 0){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }
  return 0;
}


Measured memory_bytes: 4008
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


//auto mod int
//https://github.com/atcoder-live/library/blob/master/mint.cpp

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://github.com/atcoder-live/library/blob/master/comb.cpp

struct combination {
    vector<mint> frac, ifrac;
    combination(int n):frac(n+1), ifrac(n+1) {
        assert(n < mod);
        frac[0] = 1;
        for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
        ifrac[n] = frac[n].inv();
        for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return frac[n]*ifrac[k]*ifrac[n-k];
    }
} c(100000);

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

    if(abs(n-m)>1) {
        cout << 0 << endl;
        return 0;
    }

    mint ans = 1;
    if(m == n) {
        ans = 2;
    }

    ans *= c.frac[n];
    ans *= c.frac[m];

    cout << ans << endl;
}

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

int main()
{
  string s,t;
  int mi=10000000,mx=-1;
  cin>>s>>t;
  for(int i=0; s[i]; i++)
    mi=min(mi,(int)s[i]);
  for(int i=0; t[i]; i++)
    mx=max(mx,(int)t[i]);
  if(mi<mx)
  {
    printf("Yes");
  }
  else if(mi==mx)
  {
    int i=0;
    for(; s[i]&&t[i]&&s[i]==t[i]; i++);
    if(s[i]||t[i]=='\0')
    {
      printf("No");
    }
    else
    {
      printf("Yes");
    }
  }
  else
  {
    printf("No");
  }
  return 0;
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  
  if (N == 1) cout << 0 << endl;
  
  else {
    int X = 0, Y = 0;
    for (int i = 1; i < N; i++) {
      if (S.at(i - 1) == 'R' && S.at(i) == 'L') X++;
    }
    if (S.at(0) == 'L') Y++;
    if (S.at(N - 1) == 'R') Y++;
    
    int U = 2 * X + Y;
    if (X > K) U = U - 2 * K;
    else if (X + Y > K) U = U - X - K;
    else U = 1;
    
    cout << N - U << endl;
  }
}

Measured memory_bytes: 3752
#include<cstdio>
long long n;
int w[100], cnt, R[200], cc, RC;
int main(){
    scanf("%lld",&n);
    n++;
    while(n){
        w[cnt++] = n%2;
        n/=2;
    }
    int p1 = 50, p2 = 51, p3 = 101, i;
    for(i=cnt-2;i>=0;i--){
        cc++;
        R[p2] = cc;
        R[p3] = R[p2];
        if(w[i]){
            R[++p3] = ++cc;
            R[p1--] = cc;
        }
        p2++,p3++;
    }
    for(i=1;i<200;i++)if(R[i])RC++;
    printf("%d\n",RC);
    for(i=1;i<200;i++)if(R[i])printf("%d ",R[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n); for (int i = 1; i <= n ;++i )
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
  int h,w;
  cin >> h >> w;
  char s[55][55];
  bool flag = false;
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#' && s[i][j-1] != '#' && s[i-1][j] != '#' && s[i+1][j] != '#' && s[i][j+1] != '#'){
        flag = true;
        break;
      }
    }
  }
  if(flag) puts("No");
  else puts("Yes");
  return 0;
}


Measured memory_bytes: 256
R, C,K = map(int, input().split())
dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]
import random
for i in range(K):
    r, c, v = map(int,input().split())
    D[r][c] = v

for i in range(R+1):
    for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])

        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]

ans = 0
for i in range(4):
    ans = max(ans, dp[i][-1][-1])
print(ans)


Measured memory_bytes: 447888
def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_nodes, num_regions = tuple(input_ints())
    regions = [tuple(input_ints()) for _ in range(num_regions)]
    regions.sort(key=lambda r: r[1])

    edges = []
    for r in regions:
        if not edges or edges[-1] < r[0]:
            edges.append(r[1] - 1)

    print(len(edges))


main()


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

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=1e6+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int t,n,m,k;
int arr[N];
int mem[N];

int solve(int rem){
    if(rem==0) return 1;
    if(rem<0) return 0;
    int &ret=mem[rem];
    if(~ret) return ret;
    ret=0;
    for(int i=3;i<=n;++i)
        ret=(ret%M+solve(rem-i)%M)%M;
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d",&n);
    memset(mem,-1,sizeof mem);
    printf("%d",solve(n));
    return 0;
}


Measured memory_bytes: 7744
// Beginner162.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

bool has7(int n)
{
	while (n > 0)
	{
		int c = n % 10;
		if (c == 7) return true;
		n /= 10;
	}
	return false;
}

int main()
{
	//A
	/*int n;
	cin >> n;
	bool has = has7(n);
	cout << (has ? "Yes" : "No");*/

	//B
	int n;
	cin >> n;

	ll result = 0;
	for (int i = 1; i <=n; ++i)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			result += i;
		}
	}
	cout << result;

	

	
	//C

	//D

	//E

	//F
}



Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, K;
ll patterns[101010];

ll ppow(ll a, ll b)
{
    a %= MOD;
    ll res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = (res * a) % MOD;
        }
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

map<ll, ll> prime_factor(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n]++;
    }
    return res;
}

int main()
{
    cin >> N >> K;
    for (ll i = K; i >= 1; i--)
    {
        ll p = K / i;
        ll p_cnt = ppow(p, N) % MOD;
        ll j = i + i;
        while (true)
        {
            if (j > K)
            {
                break;
            }
            p_cnt -= patterns[j];
            p_cnt += MOD;
            p_cnt %= MOD;
            j += i;
        }
        patterns[i] = p_cnt;
    }

    ll ans = 0;
    for (ll i = 1; i <= K; i++)
    {
        ans += (i * patterns[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4376