akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int N=2e5+5,YL=998244353;
inline int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}
int f[4005][4005],sr[4005],sb[4005],fac[4005],fnv[4005];
char s[20005];
inline void add(int &x,int y){if((x+=y)>=YL)x-=YL;}
inline int C(int x,int y){return y>x?0:1ll*fac[x]*fnv[y]%YL*fnv[x-y]%YL;}
int main()
{
	scanf("%s",s+1);int n=strlen(s+1);fac[0]=1;
	for(int i=1;i<=n+n;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[n+n]=ksm(fac[n+n],YL-2);
	for(int i=n+n;i>=1;--i)fnv[i-1]=1ll*fnv[i]*i%YL;
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		if(s[i]=='1')++sr[i],++sb[i];
		else if(s[i]=='2')sb[i]+=2;
		else sr[i]+=2;
	for(int i=1;i<=n;++i)sr[i]+=sr[i-1],sb[i]+=sb[i-1];
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i-1;++j)
		{
			int nr=j,nb=i-1-j;
			if(s[i]=='1')++nr,++nb;
			else if(s[i]=='2')nb+=2;
			else nr+=2;
			if(nb>0)add(f[i][nr],f[i-1][j]);
			if(nr>0)add(f[i][nr-1],f[i-1][j]);
		}
	int ans=0;
	for(int i=0;i<=n;++i)ans=(1ll*f[n][i]*C(n,i)+ans)%YL;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
char interesting[50][50];
int c,d,myfatherheheheinteresting[55][55];
int main(){
    cin>>c>>d;
    for(int GoAndFuckYourSelf=0;GoAndFuckYourSelf<c;GoAndFuckYourSelf++)
    cin>>interesting[GoAndFuckYourSelf];
    for(int GoAndFuckYourSelf=0;GoAndFuckYourSelf<c;GoAndFuckYourSelf++)
    for(int GoAndFuckYourSelfPlus=0;GoAndFuckYourSelfPlus<d;GoAndFuckYourSelfPlus++)
    if(interesting[GoAndFuckYourSelf][GoAndFuckYourSelfPlus]=='#')
    myfatherheheheinteresting[GoAndFuckYourSelf][GoAndFuckYourSelfPlus]++,myfatherheheheinteresting[GoAndFuckYourSelf][GoAndFuckYourSelfPlus+1]++,myfatherheheheinteresting[GoAndFuckYourSelf][GoAndFuckYourSelfPlus+2]++,
    myfatherheheheinteresting[GoAndFuckYourSelf+1][GoAndFuckYourSelfPlus]++,myfatherheheheinteresting[GoAndFuckYourSelf+1][GoAndFuckYourSelfPlus+1]++,myfatherheheheinteresting[GoAndFuckYourSelf+1][GoAndFuckYourSelfPlus+2]++,
    myfatherheheheinteresting[GoAndFuckYourSelf+2][GoAndFuckYourSelfPlus]++,myfatherheheheinteresting[GoAndFuckYourSelf+2][GoAndFuckYourSelfPlus+1]++,myfatherheheheinteresting[GoAndFuckYourSelf+2][GoAndFuckYourSelfPlus+2]++;
    for(int i=0;i<c;i++){
        for(int j=0;j<d;j++)
        if(interesting[i][j]=='#') cout<<'#';
        else cout<<myfatherheheheinteresting[i+1][j+1];
        cout<<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define PI 2*acos(0.0)
#define boost ios::sync_with_stdio(false);cin.tie(0)
int main()
{
 boost;
  ll x,y;
  cin>>x>>y;
  if(y%2) { cout<<"No"<<endl; return 0;}
  ll p=(y/2);
  ll k=abs(x-p);
  if(k*4 + 2*(abs(x-k))==y) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int q, h, s, d;
	int n;
	cin >> q >> h >> s >> d;
	cin >> n;
	int L1 = min({ q * 4,h * 2,s });
	int L2 = min({ L1 * 2,d });
	int L2n = n / 2;
	int L1n = n - L2n * 2;
	cout << (long)L2n * L2 + (long)L1n * L1;
}

Measured memory_bytes: 256
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")
    };
}

use rand::Rng;

fn position_max<T: Ord>(slice: &[T]) -> Option<usize> {
    slice.iter().enumerate().max_by(|(_, value0), (_, value1)| value0.cmp(value1)).map(|(idx, _)| idx)
}

fn main() {
    input! {
        D: usize,
        C: [i64; 26],
        S: [[i64; 26]; D],
    }

    let score = |sol: &Vec<i64>| -> i64 {
        let mut sat: i64 = 0;
        let mut last = vec![0; 26];
        for (d, v) in sol.iter().enumerate() {
            let j: usize = (v - 1) as usize;
            last[j] = d + 1;
            for i in 0..26 {
                sat -= (d + 1 - last[i]) as i64 * C[i];
            }
            sat += S[d][j];
        }

        return sat;
    };

    let mut ans:Vec<i64> = vec![];
    let mut last = vec![0; 26];
    for d in 0..D {
        let mut ma = 0;
        let mut mai = 0;
        for j in 0..26 {
            let a = (d + 1 - last[j]) as i64 * C[j] + S[d][j];
            if a > ma {
                ma = a;
                mai = j;
            }
        }
        last[mai] = d + 1;
        ans.push((mai+1) as i64);
    }

    let mut rng = rand::thread_rng();
    let mut s = score(&ans);
    for _ in 0..300000 {
        let c = rng.gen_range(1, 27);
        let d = rng.gen_range(0, D);
        let b = ans[d];
        ans[d] = c;
        let ss = score(&ans);
        if ss > s{
            // dbg!(ss);
            s = ss;
        }else{
            ans[d] = b;
        }
    }

    for c in ans {
        println!("{}", c);
    }
    // println!("{}", score(&ans));
}


Measured memory_bytes: 2752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a > 9 || b > 9) {
				System.out.println(-1);
			} else {
				System.out.println(a * b);
			}
		}
	}
}


Measured memory_bytes: 23124
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr int gcd(int a, int b) {
  int c = 0;
  while (a) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}

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

void solve() {
  int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}

Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s, t;
	cin >> s >> t;
	vector<vector<int>> v(s.size()+1, vector<int>(27, -1));
	set<int> ss, st;
	for(int i = 0; i < s.size(); ++i){
		ss.insert(s[i]);
	}
	for(int i = 0; i < t.size(); ++i){
		st.insert(t[i]);
	}
	int a = 0;
	for(auto c : st){
		if(ss.count(c) == 0){
			a = 1;
		}
	}
	if(a == 1){
		cout << -1 << endl;
		return 0;
	}
	for(int i = s.size()-2; i>=0; --i){
		v[i] = v[i+1];
		v[i][s[i+1]- 'a'] = i+1;
	}
	long long ans = 0;
	int pos = -1;
	for(int i = 0; i < t.size(); ++i){
		if(pos == -1){
			if(s[0] == t[i]){
				pos = 0;
			}else{
				pos = v[0][t[i]-'a'];
			}
		}else{
			pos = v[pos][t[i]-'a'];
		}
		if(pos == -1){
			ans += s.size();
			i--;
		}
	}
	ans += pos + 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15360
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

void stndrtn() {
#ifdef accepted    
    freopen(".in", "r", stdin);
#endif
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int a, b;
    cin >> a >> b;
    int A = (100*a+7)/8;
    int B = (100*b+9)/10;
    if (A > B)
        swap(A, B);
    for (int i = A; i <= B; ++i) {
        if ((i*8)/100 == a && (i*10)/100 == b)
            cout << i, exit(0); 
    }
    cout << -1;
    return 0;
}



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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(2);
    cin >> s[0] >> s[1];
    vector<bool> v;
    for(int i=0;i<n;i++)
    {
        if(s[0][i]==s[1][i]) v.push_back(0);
        else
        {
            v.push_back(1);
            i++;
        }
    }
    n=v.size();
    vector<vector<vector<int>>> dp(n,vector<vector<int>>(3,vector<int>(3,0)));
    if(v[0]==0) for(int i=0;i<3;i++) dp[0][i][i]=1;
    else for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(i!=j) dp[0][i][j]=1;
    const int mod=1000000007;
    auto add=[&](int &a,int b){a=(a+b)%mod;};
    for(int o=1;o<n;o++)
    {
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(v[o]==0&&i!=j) continue;
                if(v[o]==1&&i==j) continue;
                for(int a=0;a<3;a++)
                {
                    for(int b=0;b<3;b++)
                    {
                        if(i==a||j==b) continue;
                        add(dp[o][i][j],dp[o-1][a][b]);
                    }
                }
            }
        }
    }
    int res=0;
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) add(res,dp[n-1][i][j]);
    cout << res << "\n";
    return 0;
}


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

int main(){
	
	int n;
	cin>>n;
	int arr[n],ans=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i]%2==0){
			int val=arr[i],idx=0;
			while(val%2==0){
				idx++;
				val=val/2;
			}
			ans+=idx;
		}
	}
	cout<<ans<<endl;
}




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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};


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

    int k, t;
    cin >> k >> t;
    vector<int> A(t);
    rep(i, t) {
        cin >> A[i];
    }

    cout << max(*max_element(all(A)) - 1 - (k - *max_element(all(A))), 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    if( a < c && c < b ) {
        cout << "Yes";
        return 0;
    }
    else if( b < c && c < a){
        cout << "Yes";
        return 0;
    }
    cout << "No";
}


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

typedef long long ll;
typedef long int lint;

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

    ll n;
    cin >> n;
    string s;
    cin >> s;
    
    ll ans = 0;
    ll i = 0, j = n-1;
    while(i < j)
    {
        if(s[i] == 'W' && s[j] == 'R') 
        {
            ans++;
            i++;
            j--;
        }
        else if(s[i] == 'R') i++;
        else if(s[j] == 'W') j--;
    }

    cout << ans << '\n';
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,t;
cin >> n >> t;
int c,time;
int ans = INF;
REP(i,n) {
  cin >> c >> time;
  if(time<=t) {
    ans = min(ans,c);
  }
}
if(ans!=INF) {
  cout << ans << endl;
} else {
  cout << "TLE" << endl;
}
return 0;
}


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

using namespace std;

int main()
{
	
	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n, sum = 0;

	cin >> n;

	int d[n];

	for(int i = 0; i < n; i++)
	{

	   cin >> d[i];

	}

	for(int i = 0; i< n - 1; i++)
	{

	   for(int j = i + 1; j< n; j++)
	   {

	       sum += (d[i] * d[j]);

	   }

	}

	cout << sum;
}

Measured memory_bytes: 256
import bisect
S=input()

A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N=[0 for i in range(26)]
n=[i for i in range(26)]
a=[]

if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)<26:
    for i in range(len(S)):
        for j in range(26):
            if S[i]==A[j]:
                N[j]=1
    for i in range(26):
        if N[i]==0:
            S=S+A[i]
            print(S)
            exit()
else:
    S=list(S)
    for i in range(len(S)):
        for j in range(26):
            if S[i]==A[j]:
                S[i]=n[j]
    for i in range(25):
        if S[25-i]>S[24-i]:
            break
    L=S[25-i:]
    L.sort()
    X=S[:24-i]
    Y=L[bisect.bisect_left(L,S[24-i])]
    X.append(Y)
   
    for i in range(len(X)):
        for j in range(26):
            if X[i]==n[j]:
                X[i]=A[j]
    print("".join(X))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int MAX_N = 200000;

ll nums[MAX_N + 10];

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        nums[a[i]]++;
    }
    ll sum = 0;
    for (int i = 0; i <= MAX_N; i++) {
        if (nums[i] < 2) continue;
        sum += (nums[i] * (nums[i] - 1) / 2);
    }
    for (int i = 0; i < n; i++) {
        ll v = nums[a[i]];
        if (v < 2) {
            cout << sum << endl;
            continue;
        }
        ll t = v * (v - 1) / 2;
        ll t2 = (v - 1) * (v - 2) / 2;
        ll ans = sum - (t - t2);
        cout << max(0LL, ans) << endl;
    }
}

Measured memory_bytes: 4736
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;

ll par[N];
ll sz[N];

ll find(ll x){
  while(par[x]!=x)x=par[x];
  return x;
}

void unio(ll a,ll b){
a=find(a),b=find(b);
if(a==b)return;
if(sz[a]<sz[b])swap(a,b);
sz[a]+=sz[b];
par[b]=a;
}


int main()
{ 

IOS;


ll n,m;cin>>n>>m;

vl p(n+1);

for(int i=1;i<=n;i++){
  par[i]=i;
  sz[i]=1;
  cin>>p[i];
}


while(m--){
  ll a,b;cin>>a>>b;
  unio(a,b);
}

ll ans=0;


for(int i=1;i<=n;i++){
  if(find(i)==find(p[i]))++ans;
}

cout<<ans<<endl;


return 0;
 
}


Measured memory_bytes: 5552
#B問題
n = int(input())
p = input().split()
p = [int(i) for i in p]
count = 0
for i in range(n-2):
    if p[i+1] <max(p[i:i+3]) and p[i+1]>min(p[i:i+3]):
      count +=1
print(count)

Measured memory_bytes: 3060
from sys import *
N = int(stdin.readline())
a,b = [],[]
for i in range(N):
    tmp = list(map(int, stdin.readline().split()))
    a.append(tmp[0] + tmp[1])
    b.append(tmp[0] - tmp[1])

a.sort()
b.sort()
print(max(a[-1]-a[0], b[-1]-b[0]))


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MAX=105;
const ll LIM=10000  ;
const ll INF=0x3f3f3f3f3f3f3f;
const ll MOD=1e9+7;
ll N,W,w[MAX],v[MAX],ans,opt[5],b_idx=0;

ll main(){
    scanf("%lld%lld",&N,&W);
    for(ll i=0;i<n;i++){
        scanf("%lld%lld",&w[i],&v[i]);
        opt[w[i]-w[0]]=max(v[i],opt[w[i]-w[0]]);
    }
    for(ll i=1;i<=3;i++) if(opt[i]*(b_idx+w[0])>opt[b_idx]*(i+w[0])){
        b_idx=i;
    }

    return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MAX=400005;
const ll INF=(1ll<<63)-1;
const ll MOD=1e9+7;

ll N;
ll conn[MAX],chk[MAX],min_B,max_B,min_R,max_R,ans=INF;
char flag[MAX];
pll val[MAX];
void eval(){
    ans=min(ans,(val[max_R].first-val[min_R].first)*(val[max_B].first-val[min_B].first));
    //printf("%lld %lld %lld %lld %lld\n",val[min_R].first,val[max_R].first,val[min_B].first,val[max_B].first,(val[max_R].first-val[min_R].first)*(val[max_B].first-val[min_B].first));
    return;
}
ll setflag(ll x,char u){
    if(u=='R'){
        flag[x]='R';
        flag[conn[x]]='B';
    }
    else{
        flag[x]='B';
        flag[conn[x]]='R';
    }
    return conn[x];
}
int main(){
    scanf("%lld",&N);
    for(ll i=0;i<N;i++){
        ll t1,t2;
        scanf("%lld%lld",&t1,&t2);
        val[i*2]=make_pair(t1,i),val[i*2+1]=make_pair(t2,i);
        chk[i*2]=-1,chk[i*2+1]=-1;
    }
    sort(val,val+2*N);
    for(ll i=0;i<2*N;i++){
        if(chk[val[i].second]==-1){
            chk[val[i].second]=i;
        }
        else{
            conn[chk[val[i].second]]=i;
            conn[i]=chk[val[i].second];
            chk[val[i].second]=-1;
        }
    }
    if(N==1){
        printf("0\n");
        return 0;
    }
    if(conn[0]!=2*N-1){
        min_R=0,max_R=2*N-1;
        ll k1=setflag(min_R,'R');
        ll k2=setflag(max_R,'R');
        ll lim=max(k1,k2);
        min_B=INF,max_B=-INF;
        for(ll i=1;i<2*N-1;i++){
            if(flag[i]==0) setflag(i,'R');
            if(flag[i]=='B'){
                min_B=min(min_B,i);
                max_B=max(max_B,i);
            }
        }
        eval();
        for(ll i=max_B;i>lim;){
            ll t=setflag(i,'R');
            lim=max(lim,t);
            min_B=min(min_B,t);
            do{i--;}while(i>max(k1,k2)&&flag[i]=='R');
            max_B=i;
            eval();
        }
    }
    for(ll i=0;i<2*N;i++) flag[i]=0;
    min_R=0,max_B=2*N-1;
    min_B=INF,max_R=-INF;
    setflag(min_R,'R'),setflag(max_B,'B');
    for(ll i=1;i<2*N-1;i++){
        if(flag[i]==0) setflag(i,'R');
        if(flag[i]=='R') max_R=max(max_R,i);
        else min_B=min(min_B,i);
    }
    eval();
    printf("%lld\n",ans);
}


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

bool vis[11];
bool valid(int cur){
    while(cur){
        if(vis[cur % 10]) return 0;
        cur /= 10;
    }
    return true;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i=0; i<k; i++){
        int cur;
        scanf("%d", &cur);
        vis[cur] = 1;
    }
    for(int i=n; ;i++){
        if(valid(i)){
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
using namespace std;

int main() {
  int N, K, i = 0, ans = 1;
  cin >> N >> K;
  while(i < N){
    if(ans * 2 > ans + K){
      ans += K;
      i++;
    }else if(ans * 2 <= ans + K){
      ans += ans;
      i++;
    }
  }
  cout << ans << endl;
      
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    //解説AC
  int main(){      
      lint n,k;
      string s;
      cin>>n>>k>>s;
      lint x=0;
      rep(i,n-1){
          if(s[i]==s[i+1])x++;
      }
      cout<<min(n-1,x+2*k);
      }
      
    

  
          
  

Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        s: [chars; n]
    }

    let mut counts = vec![];
    for i in 0..n {
        counts.push(
            count(&s[i])
        );
    }

    let mut mins = std::collections::HashMap::new();
    for c in b'a'..b'z'+1 {
        let mut min = usize::max_value();
        for i in 0..n {
            if let Some(&x) = counts[i].get(&(c as char)) {
                min = std::cmp::min(min, x);
            } else {
                min = 0;
            }
        }
        mins.insert(c as char, min);
    }

    let mut ret = vec![];
    for c in b'a'..b'z'+1 {
        for _ in 0..mins[&(c as char)] {
            ret.push(c as char);
        }
    }
    println!("{}", ret.into_iter().collect::<String>());
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main () {
    int n;
    vector<int> sticks;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int l; cin >> l;
        sticks.push_back(l);
    }

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

    int count = 0;

    for(int i = n - 1; i >= 0; i--) {
        for(int j = i - 1; j >= 0; j--) {
            if (sticks[j] * 2 < sticks[i]) break;
            for (int k = j - 1; k >=0; k--) {
                if (sticks[k] + sticks[j] > sticks[i]) count++;
                else break;
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int length(char*str){
  int i=0;
  while(str[i]){
    i++;
  }
  return i;
}

int main()
{
  char str[100];
  cin >> str;
  int t;
  t = length(str);
  for (int i = 0; i < t; i++){
    cout << "x";
  }
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string ans = "No";
        if (s[0] == s[1] && s[1] == s[2]) ans = "Yes";
        else if (s[3] == s[2] && s[1] == s[2]) ans = "Yes";
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int> pqi;
#define ttttyyyy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fo(i,n,m) for(int i=n,i<m;i++)
#define endll "\n"
#define ci(x) int x;cin>>x
#define pb(x) push_back(a)
#define mk(a,b) make_pair(a,b)
int gcd(int a,int b){
    int t;
    while(a%b!=0){
        t=a%b;
        a=b;
        b=t;
    }
    return b;
}
int main(){
    ttttyyyy
    ci(n);
    int sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=gcd(gcd(i,j),k);
            }
        }
    }

    cout<<sum<<endl;
    return 0;
}



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

int main(){
	string s;
	cin >> s;
	
	bool res = true;
	rep(i, s.size()){
		if(i%2 == 0 && s.at(i) == 'L'){
			res = false;
		}else if(i%2 == 1 && s.at(i) == 'R'){
			res = false;
		}
	}

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

	return 0;
}


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

using namespace std;

int n,t,i,j,a[200005];

int main(){
	scanf("%d%d", &n, &t);
	
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	int res = t;
	int now = t;
	
	for(i = 1; i < n; i++){
		if(a[i] <= now)
		res += a[i] + t - now;
		else
		res += t;
		
		now = a[i] + t;
	}
	
	printf("%d\n", res);
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		int sum=0;
		int c;
		c=a+b;
		while (c/10!=0)
		{
			c=c/10;
			sum++;
		}
		sum++;
		printf("%d\n",sum);
	}
	return 0;
} 

Measured memory_bytes: 600
#include<cstdio>

int main(){
    int n;
    scanf("%d", &n);
    int x,y;
    int p = 0;
    int ans = 0;
    for(int i=0;i<n;i++){
        scanf("%d %d", &x, &y);
        if(x == y) p++;
        else p = 0;
        if(p == 3){
            ans = 1;
        }
    }
    if(ans == 1) printf("Yes");
    else printf("No");
    return 0;
}

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

int main() {

  string s;
  cin >> s;
  int count = 0;
  if(s[0] == 'o') ++count;
  if(s[1] == 'o') ++count;
  if(s[2] == 'o') ++count;
  cout << 700+count*100 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,m,s;

class V
{
	public: ll to,cost,time;
	public: V(ll to,ll cost,ll time)
	{
		this->to = to;
		this->cost = cost;
		this->time = time;
	}
};
vector<V> G[50];
ll C[50],D[50];
ll DIS[50][2501];
const ll INF = 1e18;

class P
{
	public: ll v,time,gin;
	public: P(ll v,ll time,ll gin)
	{
		this->v = v;
		this->time = time;
		this->gin = gin;
	}
	
};
bool operator<(const P &a,const P &b)
{
	return a.time>b.time;
}

void dijkstra(ll gin)
{
	
	priority_queue<P> PQ;
	PQ.emplace(0,0,min(0LL+2500,gin));
	DIS[0][min(0LL+2500,gin)]=0;
	/*
	for(ll i = 0 ;;i++)
	{
		if(gin+i*C[0]>2500)
		{
			DIS[0][2500] = i*D[0];
			PQ.emplace(0,DIS[0][2500],2500);
			break; 
		}
			DIS[0][gin+i*C[0]] = i*D[0];
			PQ.emplace(0,DIS[0][gin+i*C[0]],gin+i*C[0]);
	}
	*/
	while(!PQ.empty())
	{
		//cout<<PQ.size()<<endl;
		auto now = PQ.top();
		ll v = now.v;
		PQ.pop();
		
		//cout<<v<<endl;
		//今交換できる分交換する；
		if(DIS[v][now.gin]<now.time)continue;
		for(ll i = 1;;++i)
		{
			if(now.gin+i*C[v]>2500)
			{
				
				if(DIS[v][2500]>now.time+i*D[v])
				{
					DIS[v][2500] = now.time+ i*D[v];
					PQ.emplace(v,DIS[v][2500],2500);
				}
				break;
			}
			if(DIS[v][now.gin+i*C[v]]>now.time+i*D[v])
			{
				DIS[v][now.gin+i*C[v]] = now.time + i*D[v];
				PQ.emplace(v,DIS[v][now.gin+i*C[v]],now.gin+i*C[v]);
			}
		}
		for(auto &next:G[v])
		{
			//	if(v==0&&now.time==10)cout<<';'<<next.to<<' '<<now.time+next.time<<' '<<gin<<endl
			//	<<DIS[next.to][now.gin-next.cost]<<endl;
			if(now.gin-next.cost<0)continue;
			if(DIS[next.to][now.gin-next.cost]>now.time+next.time)
			{
				DIS[next.to][now.gin-next.cost]=now.time+next.time;
				PQ.emplace(next.to,DIS[next.to][now.gin-next.cost],now.gin-next.cost);
			}
		}
		
	}
}

int main()
{
	for(ll i = 0;i<50;i++)
	{
		for(ll j = 0;j<2501;j++)
		{
			DIS[i][j] = INF;
		}
	}
	cin >> n >> m >> s;
	for(ll i = 0;i<m;i++)
	{
		ll u,v,a,b;
		cin >> u >> v >> a >> b;
		u--;
		v--;
		G[u].emplace_back(v,a,b);
		G[v].emplace_back(u,a,b);
	}

	for(ll i = 0;i<n;++i)
	{
		cin >> C[i] >> D[i];
	}
	dijkstra(s);
	for (ll i = 1; i < n; i++)
	{
		ll ans = INF;
		for (ll j = 0; j < 2501; j++)
		{
			ans = min(ans,DIS[i][j]);
			//if(DIS[i][j]==15)cout<<';'<<j<<endl;
		}
		cout<<ans<<endl;
	}
	//cout<<DIS[2][0]<<endl;

	
}

Measured memory_bytes: 102672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


struct UnionFind
{
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		rep(i, n) par[i] = i;
	}

	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) return;

		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return sizes[find(x)];
	}
};

int N, M;
int A[2500][2];

bool check(int ex){
	UnionFind U(N);
	rep(i, M) {
		if(i != ex) U.unite(A[i][0], A[i][1]);
	}

	rep(i, N){
		if(!U.same(0, i)) return true;
	}
	return false;
}

int main() {
	cin >> N >> M;
	rep(i, M){
		cin >> A[i][0] >> A[i][1];
		A[i][0]--;
		A[i][1]--;
	}

	int ret = 0;
	rep(i, M) if(check(i)) ret++;
	cout << ret << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$lineInput = trim(fgets(STDIN));
$A = explode(" ", $lineInput);
if(in_array(0,$A)){
    echo 0;
}else if(array_product($A) <= pow(10,18)){
    echo (int)array_product($A);
}else{
    echo -1;
}
 
 
?>

Measured memory_bytes: 25412
def main():
	import sys
	input=sys.stdin.readline
	l=[[0,0,0]];r=[[0,0,0]]
	n,c=map(int,input().split())
	for i in range(n):
		x,v=map(int,input().split())
		r.append([x,v])
		l.append([c-x,v])
	r.sort()
	l.sort()
	for x in (l,r):
		now=0
		for i in range(n):
			now+=x[i+1][1]
			x[i+1].append(max(now-x[i+1][0],x[i][2]))
			if x[i+1][2]==x[i][2]:
				x[i+1][0]=x[i][0]
	ans=0
	for i in range(n+1):
		a=l[i][0]
		b=r[n-i][0]
		ans=max(l[i][2]+r[n-i][2]-min(a,b),ans)
	print(ans)
if __name__ == '__main__':
	main()

Measured memory_bytes: 45624
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string x;
  	cin >> x;	
  	int N = 4;
	vector<int> A(N);
	rep(i,N){
    	A[i] = x[i] - '0';
    }
  
	// vector<vector<int>> sign = {{1,1,1,1}, {1,1,1,-1}, {1,1,-1,1}, {1,1,-1,-1},...}  	
	int pn = 1<<(N-1); // 2^3 のこと
  	vector<vector<int>> sign(pn, vector<int>(N));
  	for (int bit = 0; bit < pn; ++bit) {
  		sign[bit][0] = 1;
      	rep3(j,1,N-1){
      		if (bit & (1<<(j-1))){
  				sign[bit][N-j] = -1;
            }
          	else { 
          		sign[bit][N-j] = 1;
            }
        }      
    } 
	/*  	
  	rep(i,pn){
		rep(j,N){    
        	cout << sign[i][j] << " ";
        }
      	cout << endl;
	}
  	*/
  	int sum;
  	rep(i,pn){
    	sum = 0;
		rep(j,N){
      		sum += (A[j] * sign[i][j]);
        }
        //cout << "i = " << i << ", sum = " << sum << endl;
      	if(sum == 7){
          	cout << A[0];
          	rep3(k,1,N-1){
          		if(sign[i][k] == -1){ cout << '-';}
              	else{ cout << '+';}
        		cout << A[k];
            }
          	cout << "=7" << endl;
            break;
        }
    }
  
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 200005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,num_rows,num_cols;
pii blocks[MAXN];
ll dp[MAXN],f[MAXN],inv[MAXN];

ll cnk(ll n, ll k){
    if(k > n) return 0;
    ll q = (inv[k]*inv[n - k])%MOD;
    return (f[n]*q)%MOD;
}

int main(){
    scanf("%d %d %d",&num_rows,&num_cols,&len);
    for(int i=1; i<=len; i++)
        scanf(" %d %d",&blocks[i].first,&blocks[i].second);
    f[0] = 1, inv[0] = 1;
    for(int i=1; i<=2e5; i++){
        f[i] = (f[i-1]*i)%MOD;
        inv[i] = fpow(f[i],MOD-2,MOD);
    }
    sort(blocks+1,blocks+len+1);
    blocks[++len] = mp(num_rows,num_cols);
    for(int i=1; i<=len; i++){
        dp[i] = cnk(blocks[i].first+blocks[i].second-2,blocks[i].first-1);
        for(int k=1; k<i; k++){
            if(blocks[k].first <= blocks[i].first && blocks[k].second <= blocks[i].second){
                ll rem = cnk(blocks[i].first-blocks[k].first+blocks[i].second-blocks[k].second,blocks[i].first-blocks[k].first);
                rem = (rem*dp[k])%MOD;
                dp[i] = (dp[i]-rem+MOD)%MOD;
            }
        }
    }
    printf("%lld\n",dp[len]);
}

Measured memory_bytes: 6400
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int normal[1001000];
int odd[1001000];

int main() {
  MEMSET(normal, 0x0f);
  MEMSET(odd, 0x0f);
  normal[0] = odd[0] = 0;
  REP(i, 1000001) {
    REP(j, 10000) {
      int plus = j * (j + 1) * (j + 2) / 6;
      if (i + plus > 1000000) { break; }
      normal[i + plus] = min(normal[i + plus], normal[i] + 1);
      if (plus & 1) {
        odd[i + plus] = min(odd[i + plus], odd[i] + 1);
      }
    }
  }
  int n;
  while (scanf("%d", &n), n) {
    printf("%d %d\n", normal[n], odd[n]);
  }
}

Measured memory_bytes: 8572
#include<iostream>
#include <cmath>
#include<vector>
using namespace std;

int main(){
  long N;
  int min = 1000;
  cin >> N;
  for(int i=1;i<=sqrt(N);i++){
    if(int(N%i) == 0){
      int M = max(int(log10(i) + 1), int(log10(N/i)+ 1));
      if(M<min){
        min = M;
      }
    }
  }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 512
N=int(input())
w=0
for h in range(1,3501):
    for n in range(h,3501):
        if 4*h*n>N*(h+n) and N*h*n%(4*h*n-N*(h+n))==0:
            w=N*h*n//(4*h*n-N*(h+n))
            break
    if w>0:
        break

print(h,n,w)

Measured memory_bytes: 9092
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N, K = 0; cin >>N;
  vector<int> ds(N);
  for(int& d : ds){ cin >>d; }
  sort(ds.begin(), ds.end());
  for(int k = ds[0]; k <= ds[N - 1]; k++){
    int i = lower_bound(ds.begin(), ds.end(), k) - ds.begin();
    if(N / 2 == i) K++;
  }
  cout <<K <<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n ;
  vector<int> num(n) ;
  vector<int> count(n) ;
  REP(i,n){
    cin >> num.at(i) ;
  }
  REP(i,n){
    while(true){
      if(num.at(i)%2==0){
      num.at(i) = num.at(i)/2 ;
      count.at(i)++ ;
      }
      else{
      break ;
      }
    }
  }

  sort(ALL(count)) ;
  
  cout << count.at(0) <<endl ;

  return 0 ;
}




Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    if((a-b)%2==0) cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  double A=0;
  for(int i=0;i<N;i++){
    double S;
    string T;
    cin >> S >> T;
    if(T=="JPY"){
      A+=S;
    }
    else{
      A+=S*380000;
    }
  }
  cout << A << endl;
}   

Measured memory_bytes: 3764
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	int A,B,C,X,Y;
	ll ans=0;
	scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
	if(A>2*C && B>2*C){
		ans=2*C*max(X,Y);
	}else if(A>2*C){
		ans=2*C*X;
		if(Y>X)ans+=(Y-X)*B;
	}else if(B>2*C){
		ans=2*C*Y;
		if(X>Y)ans+=(X-Y)*A;
	}else if(A+B<2*C){
		ans=A*X+B*Y;
	}else{
		int small=min(X,Y);//後でX,Yは変わるので，ここで記録しないといけない
		ans=small*2*C;
		X-=small;
		Y-=small;
		ans+=X*A+Y*B;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b)(((a)<(b))?(a):(b))
#define max(a,b)(((a)>(b))?(a):(b))
int LargestSquare(int size);
int w[1001][1001];
char str[1001][1001];
int main(void) {
	int n,ans=0;
	int i;
	while (1) {
		scanf("%d",&n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%s",str[i]);
		}
		ans = LargestSquare(n);
		printf("%d\n",ans);
	}
	return 0;
}

int LargestSquare(int size) {
	int  maxW=0;
	int i, j;
	for (i = 0; i < size; i++) {
			if (str[0][i] == '*')
				w[0][i] = 0;
			else
				w[0][i] = 1;
			if (str[i][0] == '*')
				w[i][0] = 0;
			else
				w[i][0] = 1;
	}
	for (i = 1; i < size; i++) {
		for (j = 1; j < size; j++) {
			if (str[i][j] == '*') {
				w[i][j] = 0;
			}else{
				w[i][j] = min(w[i - 1][j-1], min(w[i - 1][j], w[i][j - 1])) + 1;
				maxW = max(maxW,w[i][j]);
			}
		}
	}
	return maxW;
}

Measured memory_bytes: 5492
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int N, M;
vector<int> L, R;



int main()
{

	int ans = 0;
	cin >> N;
	cin >> M;

	int l_max = 0;
	int r_min = N + 1;

	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l;
		cin >> r;

		l_max = max(l_max, l);
		r_min = min(r_min, r);
	}

	ans = max(0, r_min - l_max + 1);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define min(A,B) ((A<B)?(A):(B))
#define max(A,B) ((A>B)?(A):(B))

typedef long long ll;

int main(){
  ll N,A,B, edge;
  scanf("%lld%lld%lld",&N,&A,&B);
  if((B-A)%2 == 0) {
    printf("%lld",(B-A)/2);
  }else{
    if(A-1 < N - B){
      edge = A-1 + 1;
      printf("%lld",edge + (B-edge-1)/2);
    }
    else{
      edge = N-B + 1;
      printf("%lld",edge + (N-(A+edge))/2);
    }
  }
}

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

using namespace std;

/*
//1
int main() {
	int ans = 0;
	for (int i = 0; i < 10; i++) {
		int a;
		cin >> a;
		ans += a;
	}
	cout << ans << endl;

	return 0;
}
*/


//2
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 1 && b == 1) || c == 1) {
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}

return 0;
}


/*
//3
int main() {


return 0;
}
*/

/*
//4
int main() {


return 0;
}
*/

/*
//5
int main() {


return 0;
}
*/

/*
//6
int main() {


return 0;
}
*/

/*
//7
int main() {


return 0;
}
*/

/*
//8
int main() {


return 0;
}
*/

/*
//9
int main() {


return 0;
}
*/

/*
//10
int main() {


return 0;
}
*/




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

bool check(int mask, int pos){
    //cout << "check:" << (mask & (1 << (pos-1))) << endl;
    if((mask & (1 << (pos-1))) != 0){
        return true;
    }else{
        return false;
    }
}

int main(){
    string s;
    cin >> s;
    int n;
    n = s.size() -1;

    long sum=0,tmp;
    int l,r;

    for(int i=0; i<(1 << n); i++){
        tmp = 0;
        l = 0;
        for(r=0; r<n; r++){
            if(check(i,n-r)){
                string t = s.substr(l,r-l+1);
                tmp += stol(t);
                //cout << "tmp:" << tmp << endl;
                l = r+1;
            }
        }
        string u = s.substr(l,r-l+1);
        sum += tmp + stol(u);
        //cout << tmp+stol(u) << endl;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
# A - Simple Calculator
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
x,y=nm()
cnt=0
ans=0
ans=abs(y-x)
if x>=0 and y>=0:
    if y<x:
        if y==0:
            cnt+=1
        else:
            cnt+=2
elif x>=0 and y<0:
    if abs(x)==abs(y):
        print(1)
        exit()
    cnt+=1
    ans=abs(x+y)
elif x<0 and y>=0:
    if y==0:
        print(abs(x))
        exit()
    if abs(x)==abs(y):
        print(1)
        exit()
    cnt+=1
    ans=abs(y+x)
elif x<0 and y<0:
    if x>y:
        cnt+=2
ans+=cnt
print(ans)


Measured memory_bytes: 3064