akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

constexpr int MOD = 1e9+7;

constexpr int COMB_MAX = 200010;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_MAX; i ++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    initComb();
    Cin(int, h, w, a, b);
    ll ans = 0;
    For(i, h-a){
        ans = (ans + comb(b-1+i, i) * comb(w-b-1+h-i-1, h-i-1)) % MOD;
        // Cout(b-1+i, "C", i, " * ", w-b-1+h-i-1, "C", h-i-1);
    }
    Cout(ans);
}


Measured memory_bytes: 4992
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main()
{
   int i,j,n;
   cin>>n;
   int dp[n][3],a[n][3];
   for(i=0;i<n;i++)
   {
    for(j=0;j<3;j++)
    {
	 cin>>a[i][j];
	}
   }
   dp[0][0]=a[0][0];
   dp[0][1]=a[0][1];
   dp[0][2]=a[0][2];
   for(i=1;i<n;i++)
   {
    
	 dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
	 dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
     dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
   }
   
   cout<<max( (max(dp[n-1][0],dp[n-1][1])),dp[n-1][2]);




}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, A[10], ans = 1, odd = 1;

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

	rep(i, N) ans *= 3;
	rep(i, N) {
		if (A[i] % 2 == 0) odd *= 2;
	}

	cout << ans - odd << endl;

	return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

while a >= b or b >= c:
    if a >= b:
        b *= 2
        k -= 1
    else:
        if b >= c:
            c *= 2
            k -= 1

if k >= 0:
    print("Yes")
else:
    print("No")


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

int main()
{
 int a;
 string s;
 cin >> a >> s;
 if(a >= 3200)
 {
	 cout << s << endl;
 }
 else
 {
	 cout << "red"<< endl;
 }

 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, m, a[1001], b[1001], c[1001];

    int dist[110][110];

    REP(i, 110)
    REP(j, 110)
    {
        dist[i][j] = 1e8;

        if (i == j)
            dist[i][j] = 0;
    }

    cin >> n >> m;
    REP(i, m)
    {
        cin >> a[i] >> b[i] >> c[i];

        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int res = m;

    for (int i = 0; i < m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (dist[j][a[i]] + c[i] == dist[j][b[i]] ||
                dist[j][b[i]] + c[i] == dist[j][a[i]])
            {
                res--;
                break;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
long long MOD = 1000000007;
const int MAX = 200001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

int BIT_SIZE = 64;
long long power(long long m, long long n){
    long long ans = 1;
    long long tmp = m;
    for(int i = 0; i < BIT_SIZE; i++){
        //cout << ans << endl;
        if(((n >> i) & 1) == 1){
            ans = (ans * tmp) % MOD;
        }
        tmp = (tmp * tmp) % MOD;
    }
    return ans;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}


void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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 comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    long long N;
    long long A;
    long long B;
    long long C;
    cin >> N >> A >> B >> C;
    comb_init();

    long long ans = 0;
    for(int match_num = N; match_num < 2 * N; match_num ++){
        long long a_tmp = (((power(A, N) * power(B, match_num - N)) % MOD) * inverse(power(A + B, match_num))) % MOD;
        long long a_win = (a_tmp * comb(match_num - 1, N - 1)) % MOD;
        long long b_tmp = (((power(B, N) * power(A, match_num - N)) % MOD) * inverse(power(A + B, match_num))) % MOD;
        long long b_win = (b_tmp * comb(match_num - 1, N - 1)) % MOD;
        long long expectation = ((((long long)100 * inverse(A + B)) % MOD) * match_num) % MOD;
        ans = (ans +  (((a_win + b_win) % MOD) * expectation) % MOD) % MOD;
        //cout << comb(match_num, N) << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=1e5+5;
const int MOD=1e9+7;
const int INF=1e9;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define pow2(a) a*a
#define pow3(a) a*a*a
#define lcm(a,b) (a*b)/__gcd(a,b)

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

vector<int> movy={0,0,1,-1};
vector<int> movx={1,-1,0,0};

bool mark[10];

bool check(lld x){
    while(x>0){
        if(mark[x%10])return false;
        x/=10;
    }
    return true;
}

void solve(){
    lld n, k, x;
    cin>>n>>k;
    for(lld i=0;i<k;i++){
        cin>>x;
        mark[x]=true;
    }
    for(lld i=n;;i++){
        if(check(i)){
            cout<<i<<endl;
            return;
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("IN.txt","r",stdin);
        //freopen("OUT.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	int x = 0;
	for (int i =0; i < 3; i++) {
		if (s.at(i) == '1') {
			x++;
			}
	}
	cout << x << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    if(x==1){
        cout<<b-a+1<<endl;
        return 0;
    }
    ll A,B;
    if(a%x==0) A=a/x;
    else A=a/x+1;
    B=b/x;
    cout<<B-A+1<<endl;
}

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

using ll = long long;
using namespace std;

int N, K, h[100010];
ll dp[100010];

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; ++i) cin >> h[i];

	for(int i = 0; i < N; ++i) dp[i] = LONG_MAX;
	dp[0] = 0;
	for(int i = 0; i < N; ++i){
		for(int j = 1; j <= K; ++j){
			if(i - j >= 0){
				dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
// #include <bits/stdc++.h>
#include <iostream>
#include <ctime>
#include <vector>
#include <algorithm>

#define all(x) x.begin(), x.end()
#define pi 3.14159

using namespace std;
using ll = long long;


void solve() {
    int r;
    cin >> r;
    printf("%.5lf\n", (2 * pi * r));
}   

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

#ifndef ONLINE_JUDGE
    double st = clock();
    // freopen("input.txt", "r", stdin);
#endif

    solve();

#ifndef ONLINE_JUDGE
    // cerr <<"\ntime = " <<  (clock() - st)/CLOCKS_PER_SEC << endl;
#endif 
    return 0;
}

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

using namespace std;
typedef long long int ll;

void solve()
{
	string s, t;
	cin  >> s >> t;
	int n = s.size(), n1 = t.size();
	int minn = INT_MAX;
	for(int i = 0; i <= n-n1; i++)
	{
		int cnt = 0;
		string s1 = s.substr(i,n1);
		if(s1.size() == t.size())
		{
			for(int j = 0; j < n1; j++)
			{
				cnt += (s[j+i] != t[j]);
			}
		}
		minn = min(minn,cnt);
	}
	cout << minn << "\n";
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  int flag = 0;
  for (int i = 0; i <= x; i++){
    if ((y-2*i)%4 == 0 && (y - 2 * i)/4 == x-i){
      flag++;
      cout << "Yes" << endl;
      break;
      }
    }
  if (flag == 0){
    cout << "No" << endl;
  }
}

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

#define double long double
     
int main() {
  int N;
  cin >> N;
      
  vector<int>vec(N);
  int count = 0;
      
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
    count+=vec.at(i);
  }        
        
  double ave;
  ave = (double)count/N;
  int number =0;
      
  for(int i=0;i<N-1;i++){
    double a= min(abs((double)vec.at(number)-ave),abs((double)vec.at(i+1)-ave));
    if(a != abs((double)vec.at(number)-ave)){
      number = i+1;
    }
  }
  cout << number <<endl;
      
}


Measured memory_bytes: 3600
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = read_vec::<i64>().iter().map(|&x| -x).collect::<Vec<_>>();
    s.sort();
    let mut slimes = vec![s[0]];
    let mut map = BTreeMap::new();
    for num in s.iter().skip(1) {
        *map.entry(num).or_insert(0) += 1;
    }

    for i in 0..n {
        let mut added = vec![];
        for j in 0..slimes.len() {
            let mut after = map.range((Excluded(slimes[j]), Unbounded));
            let key;
            if let Some(x) = after.next() {
                key = **x.0;
            } else {
                println!("No");
                return;
            }
            *map.get_mut(&key).unwrap() -= 1;
            if map[&key] == 0 {
                map.remove(&key);
            }
            added.push(key);
        }
        slimes.append(&mut added);
    }
    println!("Yes");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11600
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n,k,x; cin>>n>>k>>x;
    cout<<(n+k)*x/2<<endl;
}

Measured memory_bytes: 256
/*input
5
1 2 3 4 5
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  cout << (n - k) + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int H, W;
	cin >> H >> W;
	
	vector<string> table(H);
	for (int i = 0; i < H; i++)
		cin >> table[i];

	// カウント用配列
	vector<vector<int>> cnt(H, vector<int>(W));

	// ヨコ方向	
	for (int i = 0; i < H; i++)
	{
		// 計算済みの判定用
		vector<int> done(W);
		for (int j = 0; j < W; j++)
		{
			if (table[i][j] == '#')
				continue ;
			if (done[j])
				continue ;
			int length = 0;
			// lengthを計って
			while (j + length < W)
			{
				if (table[i][j+length] == '#')
					break ;
				length++;
			}
			// cnt += length
			for (int k = 0; k < length; k++)
			{
				cnt[i][j+k] += length;
				done[j+k] = 1;
			}
		}
	}

	// タテ方向
	for (int j = 0; j < W; j++)
	{
		vector<int> done(H);
		for (int i = 0; i < H; i++)
		{
			if (table[i][j] == '#')
				continue ;
			if (done[i])
				continue ;
			int length = 0;
			while (i + length < H)
			{
				if (table[i+length][j] == '#')
					break ;
				length++;
			}
			for (int k = 0; k < length; k++)
			{
				cnt[i+k][j] += length;
				done[i+k] = 1;
			}
		}
	}

	// O(HW)で最大値を取得
	int ans = 0;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
			ans = max(ans, cnt[i][j]-1);
	}
	cout << ans << endl;
}



Measured memory_bytes: 20116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		int ans = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				ans++;
			}
		}
		System.out.println(ans / 2);
	}
}


Measured memory_bytes: 23764
//Circle Pond
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    float R;
    cin >> R;
    //cout << (float)((float)R * 3.14159265359f * 2f) << endl;
    printf("%.10f", (double)R * 3.14159265359f * 2.0f);
    return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#define inf 1000000007
using namespace std;

int main(void){
    int n;
    cin >> n;
    string s[n];
    int count = 0;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    char a[26]; a[0]='a';
    int ans = 0;
    for(int i = 1; i < 26; i++)
        a[i] = a[i-1]+1;
    //for(int i = 0; i < n; i++)
      //  cout << s[i] << endl;
    for(int i = 0; i < 26; i++){
        ans = inf;
        for(int j = 0; j < n; j++){
            count = 0;
            for(int k = 0; k < s[j].length(); k++){
                if(a[i]==s[j][k]) 
                count++;
            }
            ans = min(ans, count);
        }
        for(int b = 0; b < ans; b++)
            cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

const int MAXN = 300300;
typedef long long LL;
LL sum[MAXN],f[MAXN],g[MAXN],pre[MAXN],suf[MAXN],val[MAXN],y[MAXN],temp[MAXN],x;
int q[MAXN],top,m,n,pos;

template<typename T>
void read(T &x)
{
	x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0',ch = getchar(); 
}

void DP(LL *f)
{
	q[top = 1] = 0;
	for(int i = 1;i <= n;i++)
	{
		sum[i] = sum[i-1] + val[i];
		while(top > 1 && (y[q[top]] - y[q[top-1]]) <= 1LL * i * (q[top] - q[top-1])) top--;
		f[i] = max(f[i-1],f[q[top]] + sum[q[top]] - sum[i] + 1LL * (i-q[top]) * (i-q[top]+1) / 2LL);
		y[i] = f[i] + sum[i] + 1LL * i * (i - 1LL) / 2LL;
		while(top > 1 && (y[q[top]] - y[q[top-1]]) * (i - q[top]) <= (y[i] - y[q[top]]) * (q[top] - q[top-1])) top--;
		q[++top] = i;
	}
}

void Solve(int l,int r,LL *pre,LL *suf,LL *f)
{
	if(l == r)
	{
		f[l] = 1 - val[l];
		return ;
	}
	int mid = (l + r) >> 1;
	Solve(l,mid,pre,suf,f),Solve(mid+1,r,pre,suf,f);top = 0;
	for(int i = l;i <= mid;i++)
	{
		y[i] = pre[i] + sum[i] + 1LL * i * (i-1) / 2LL;
		while(top > 1 && (y[q[top]] - y[q[top-1]]) * (i - q[top]) <= (y[i] - y[q[top]]) * (q[top] - q[top-1])) top--;
		q[++top] = i;
	}
	for(int i = mid+1;i <= r;i++)
	{
		while(top > 1 && (y[q[top]] - y[q[top-1]]) <= 1LL * i * (q[top] - q[top-1])) top--;
		temp[i] = pre[q[top]] + sum[q[top]] - sum[i] + 1LL * (i - q[top]) * (i - q[top] + 1LL) / 2LL + suf[i+1];
	}
	for(int i = r-1;i > mid;i--) temp[i] = max(temp[i],temp[i+1]);
	for(int i = mid+1;i <= r;i++) f[i] = max(f[i],temp[i]);
}

int main()
{
	read(n);
	for(int i = 1;i <= n;i++) read(val[i]);
	DP(f),reverse(val+1,val+n+1);
	DP(g),reverse(val+1,val+n+1),reverse(g+1,g+n+1);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + val[i];
	Solve(0,n,f,g,pre);
	reverse(f+1,f+n+1),reverse(g+1,g+n+1),reverse(val+1,val+n+1);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + val[i];
	Solve(0,n,g,f,suf);
	reverse(suf+1,suf+n+1),reverse(f+1,f+n+1),reverse(g+1,g+n+1),reverse(val+1,val+n+1);
//	for(int i = 1;i <= n;i++) printf("pre[%d]:%lld suf[%d]:%lld\n",i,pre[i],i,suf[i]);
	read(m);
	while(m--)
	{
		read(pos),read(x);
		printf("%lld\n",max(f[pos-1]+g[pos+1],max(pre[pos],suf[pos])-x+val[pos]));
	}
	return 0;
}

Measured memory_bytes: 21376
n, a, b = gets.chomp.split.map(&:to_i)
arr = []
n.times{arr << gets.to_i}

l, r = 0, 10**9+1
while r-l >= 1 do # r-l>1にしてたんだけどダメなのか
  mid = (l+r)/2
  # mid回と仮定して計算
  count = 0
  temp_arr = arr.map{|x|x-mid*b}
  # 体力が残っているやつをA-Bで何回で倒せるかカウント
  # （A>BかつBで叩き済みなので差で殴る）
  temp_arr.each do |x|
    next if x<=0  # 死んでいる
    # ちょうどmid*(a-b)回で倒せない場合はもっかいたたけば倒せる
    count += x%(a-b)>0 ? x/(a-b) + 1 : x/(a-b)
  end
  if mid < count
    # まだ叩けるので増やす
    l = mid +1
  else
    # 叩きすぎたので減らす
    r = mid
  end
end
puts (r+l)/2

Measured memory_bytes: 26548
#include<bits/stdc++.h>
using namespace std;
int n,now;
struct node{
	int a,b;
}job[200002];
bool cmp(node w,node l){
	return w.b<l.b;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%d%d",&job[i].a,&job[i].b);
	}
	sort(job+1,job+n+1,cmp);
	for(int i=1;i<=n;i++){
		now+=job[i].a;
		if(now>job[i].b){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 1792
input =  gets.chomp
input = input.split(" ")
array = []
input.each do |v|
  if v =~ /[0-9]/
    array.push(v.to_i)
  elsif v =~ /\+|\-|\*/
    v2 = array.pop
    v1 = array.pop
    case v
    when "+"
      array.push(v1 + v2)
    when "-"
      array.push(v1 - v2)
    when "*"
      array.push(v1 * v2)
    end
  end
end
puts array


Measured memory_bytes: 6880
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0; i<n; i++)

int N, Q;
long long int T;
pair<long long int,int> P[100000];

int main(){
	scanf("%d %lld %d", &N, &T, &Q);
	rep(i, N){
		long long int A;
		int D;
		scanf("%lld %d", &A, &D);
		P[i].first = A;
		P[i].second = D;
	}
	rep(i, Q){
		int X;
		scanf("%d", &X);
		X = X - 1;
		int a,b;
		int flaga=0;
		int flagb = 0;
		if (P[X].second == 1){
			for (int j = X + 1; j < N; j++){
				if (P[j].second != P[X].second){
					b = j;
					flagb = 1;
					break;
				}
			}
		}
		else{
			for (int j = X - 1; j >= 0; j--){
				if (P[j].second != P[X].second){
					b = j;
					flagb = 1;
					break;
				}
			}
		}
		if (flagb == 0){
			printf("%lld\n", P[X].first + (P[X].second == 1 ? 1 : -1)*T);
			continue;
		}
		if (P[X].second == 1){
			for (int j = b - 1; j > X; j--){
				if (P[j].second == P[X].second){
					a = j;
					flaga = 1;
					break;
				}
			}
		}
		else{
			for (int j = b + 1; j < X; j++){
				if (P[j].second == P[X].second){
					a = j;
					flaga = 1;
					break;
				}
			}
		}
		if (flaga == 0&&flagb==1){
			//A????????????????????
			long long bxt = abs(P[X].first - P[b].first) / 2;
			if (T < bxt)printf("%lld\n", P[X].first + (P[X].second == 1 ? 1 : -1)*T);
			else printf("%lld\n", P[X].first + (P[X].second == 1 ? 1 : -1)*bxt);
			continue;
		}
		if(flaga==1&&flagb==1){
			long long abt = abs(P[a].first - P[b].first) / 2;
			long long abxd = abs(P[X].first - P[a].first) + abt;
			if (T < abxd)printf("%lld\n", P[X].first + (P[X].second == 1 ? 1 : -1)*T);
			else printf("%lld\n", P[X].first + (P[X].second == 1 ? 1 : -1)*abxd);
			continue;
		}
	}
	return 0;
}


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

int main(){
    while(1){
        int H,W;
        cin>>H>>W;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0||i==H-1)cout<<'#';
                else if(j==0||j==W-1)cout<<'#';
                else cout<<'.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 3;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;


void walk (int u, vector<ll> & dist, 
	vector<vector<int>> & adj, vector<int> & inDeg) {

	for (auto v : adj[u]) {
		inDeg[v]--;
		dist[v] = max(dist[u] + 1l, dist[v]);
		if (inDeg[v] == 0) {
			walk(v, dist, adj, inDeg);
		}
	}
}

void solve () {
	int n, m; cin >> n >> m;
	vector<vector<int>> adj(n + 2);
	vector<int> inDeg(n + 2);

	for (auto i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		inDeg[v]++;
	}

	vector<ll> dist(n + 2, -1);
	for (auto i = 1; i <= n; ++i) {
		if (inDeg[i] == 0 and dist[i] == -1) {
			dist[i] = max(dist[i], 0ll);
			walk(i, dist, adj, inDeg);
		}
	}

	ll ret = 0;
	for (auto it : dist) {
		ret = max(ret, it);
	}
	cout << ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}



Measured memory_bytes: 13184
a, b, c, k = map(int, input().split())
if a >= k:
    sum = 1 * k
else:
    if b >= k - a:
        sum = 1 * a + 0 * (k-a)
    else:
        if c >= k - a - b:
            sum = 1 * a + 0 * b - 1 * (k-a-b)
        else:
            sum = 1 * a + 0 * b - 1 * c
print(sum)

Measured memory_bytes: 78832
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    unordered_map<char, int> hist;
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H * W; i++) {
        char c;
        cin >> c;
        hist[c] += 1;
    }
    int one = (H % 2 == 1 && W % 2 == 1) ? 1 : 0;
    int two = 0;
    if (H % 2 == 1) {
        two += W / 2;
    }
    if (W % 2 == 1) {
        two += H / 2;
    }
    int one_cnt = 0;
    int two_cnt = 0;
    for (int i = 0; i <= 'z' - 'a'; i++) {
        char c = 'a' + i;
        if (hist[c] % 2 == 1) {
            one_cnt++;
            hist[c]--;
        }
        if (hist[c] % 4 == 2) {
            two_cnt++;
        }
    }
    if (one < one_cnt) {
        cout << "No" << endl;
        return 0;
    }
    if ((one - one_cnt) % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    one -= one_cnt;
    one /= 2;
    two += one;
    if (two < two_cnt) {
        cout << "No" << endl;
        return 0;
    }
    if ((two - two_cnt) % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  
  if (A+B+C > 21)
  {
    cout << "bust" << endl;
  }
  else
  {
    cout << "win" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>

using namespace std;

struct Card {
    char suit;
    int value;
};

void BubbleSort(Card C[], int N) {
    for(int i = 0; i < N; i++) {
        for(int j = N - 1; j > 0; j--) {
            if(C[j].value < C[j-1].value) {
                swap(C[j], C[j-1]);
            }
        }
    }
}

void SelectionSort(Card C[], int N) {
    for(int i = 0; i < N; i++) {
        int mini = i;
        for (int j = i; j < N; j++) {
            if(C[mini].value > C[j].value) mini = j;
        }
        if(i != mini) {
            swap(C[i], C[mini]);
        }
    }
}

bool isStable(Card C1[], Card C2[], int N) {
    bool stable = true;
    for(int i = 0; i < N && stable; i++) {
        if(C1[i].suit != C2[i].suit) stable = false;
    }
    return stable;
}

int main() {
    int N;
    cin >> N;
    Card C1[N], C2[N];
    for(int i = 0; i < N; i++) cin >> C1[i].suit >> C1[i].value;
    for(int i = 0; i < N; i++) C2[i] = C1[i];

    BubbleSort(C1, N);
    SelectionSort(C2, N);

    for(int i = 0; i < N; i++) {
        if(i != 0) cout << " ";
        cout << C1[i].suit << C1[i].value;
    }
    cout << endl;
    cout << "Stable" << endl;

    for(int i = 0; i < N; i++) {
        if(i != 0) cout << " ";
        cout << C2[i].suit << C2[i].value;
    }
    cout << endl;
    if(isStable(C1, C2, N)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll smallest_prime[10000001];
void seive()
{
     ll i,j,k,l,m,n,o,p;
     for(i=1;i<=10000000;i++)
     {
         smallest_prime[i]=1;
     }
     smallest_prime[0]=smallest_prime[1]=1;
     for(i=2;i<=10000000;i++)
     {
         if(smallest_prime[i]==1)
         {
             for(j=2*i;j<=10000000;j+=i)
             {
                 if(smallest_prime[j]==1)
                 smallest_prime[j]=i;
             }
             smallest_prime[i]=i;
         }
     }
}
 
ll prime_divisors(ll n)
    {
     ll i,j,k,l,m,o,p,q,r,s,t;
     ll ans=1;
     if(n<=1)
     return ans;
 
     while(n!=1)
     {
        p=0;
        k=smallest_prime[n];
        while(n%k==0)
        {
            n/=k;
            p++;
        }
        ans*=(p+1);
     }
     if(n>1)
     {
         ans*=2;
     }
     return ans;
    } 
    ll an[10000001];
int main()
{
    memset(an,0,sizeof(an));
    seive();
    ll i,j,k,l,m,n,o,p,q,r;
    ll ans=1;
    cin>>n;
    an[1]=1;
    for(i=2;i<=n;i++)
    {
       o=smallest_prime[i];
       k=i/o;
       if(k%o!=0)
       {
            an[i]=an[k]*2;
       }
       else
       {
           p=1;
           while(k%o==0)
           {
             k/=o;
             p++;
           }
           an[i]=an[k]*(p+1);
       }
       ans+=an[i]*i; 
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 159848
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n & 1){
            (res *= a) %= mod;
        }else{
            (a *= a) %= mod;
        }
        n >>= 1;
    }
    return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    ll sum = 0;
    for(ll i=0;i<n;++i){
        if(a[i] == sum + 1){
            sum++;
        }
    }

    ll ans = -1;
    if(sum != 0){
        ans = n - sum;
    }
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};


int main()
{
  int N, M;
  map< pair< int, int >, int > g;

  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(a > b) swap(a, b);
    g[{a, b}] ^= 1;
  }

  UnionFind tree(N);
  vector< int > las(N, 0);
  for(auto &p : g) {
    if(p.second == 0) continue;
    las[p.first.first]++;
    las[p.first.second]++;
  }

  for(int i = 0; i < N; i++) {
    if(las[i] & 1) {
      cout << "NO" << endl;
      return (0);
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,n;cin >> h >> w >> n;
	int y,x;cin >> y >> x;
	string s,t;cin >> s >> t;
	vector<vector<int>> a(n+1,vector<int>(4)),b(n+1,vector<int>(4));
	int curx=x,cury=y;
	bool flg=false;
	rep(i,n){
		if(s.at(i)=='L') curx--;
		if(curx<=0) flg=true;
		if(t.at(i)=='R' && curx<w) curx++;
	}
	curx=x;
	rep(i,n){
		if(s.at(i)=='R') curx++;
		if(curx>w) flg=true;
		if(t.at(i)=='L' && curx>1) curx--;
	}
	rep(i,n){
		if(s.at(i)=='U') cury--;
		if(cury<=0) flg=true;
		if(t.at(i)=='D' && cury<h) cury++;
	}
	cury=y;
	rep(i,n){
		if(s.at(i)=='D') cury++;
		if(cury>h) flg=true;
		if(t.at(i)=='U' && cury>1) cury--;
	}
	if(flg) cout << "NO" << endl;
	else cout << "YES" << endl;
}


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

int main(void){
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

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


/*************************************************************************/
//多次元配列の確保及び初期化用マクロ
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
/*************************************************************************/


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;



int main() {

	int n;
	cin >> n;
	vector<int> t, x, y;
	t.push_back(0);
	x.push_back(0);
	y.push_back(0);

	for (int i = 0; i < n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		t.push_back(a);
		x.push_back(b);
		y.push_back(c);
	}

	for (int i = 0; i < n; i++)
	{
		if (((t[i + 1] - t[i]) % 2) != ((abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])) % 2) || t[i + 1] - t[i] < (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])))
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;



	return 0;
}


Measured memory_bytes: 1644
#include<bits/stdc++.h>
#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;

int modExp(int a, int b) {
	if (!b) return 1;
	if (b & 1) return (a * modExp(a, b - 1)) % mod;

	int ans = modExp(a, b / 2) % mod;
	return (ans * ans) % mod;
}

int x, y;
void ExtEuclid(int a, int b) {
	if (!a) {
		x = 0, y = 1;
		return;
	}

	ExtEuclid(b % a, a);
	int tx = y - (b / a) * x, ty = x;
	x = tx, y = ty;
}

int ncr(int n, int r) {

	int num = 1, den = 1;

	for (int i = 1; i <= r; i++) {
		num *= (n - i + 1) % mod, num %= mod;
		den *= i, den %= mod;
	}

	ExtEuclid(den, mod);
	int modInv = (x + mod) % mod;
	int ans = (num * modInv) % mod;

	return ans;
}

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

	int one = modExp(2, n);
	int two =  1 + ncr(n, a) + ncr(n, b);
	int ans = (one - two % mod + mod) % mod;
	// dbg(one, two);

	cout << ans << endl;

}

// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

// COME ON DUDE .... GIVING UP NOT GONNA HELP
// JUST GET YOUR ASS TO WORK ALREADY ..
// AND FOR FUCKING SAKE ... DONT PANIC !!


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,l;cin>>n>>l;
  vs s(n);
  rep(i,n)cin>>s[i];
  vsort(s);
  string ans="";
  rep(i,n){
    ans+=s[i];
  }
  cout(ans);
  return 0;
}

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

main(){
	int n; cin>>n;
	vector<int> v, v1;
	for(int i=0; i<n; i++){
		int a,b; cin>>a>>b;
		v.push_back(a+b);
		v1.push_back(a-b);
	}
	int maxv = *max_element(v.begin(), v.end());
	int minv = *min_element(v.begin(), v.end());
	int maxv1 = *max_element(v1.begin(), v1.end());
	int minv1 = *min_element(v1.begin(), v1.end());
	
	cout<<max(abs(maxv-minv), abs(maxv1-minv1));
}

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

int main(){
  int n,m;
  cin>>n>>m;
  int c[m];
  int t[n+1];
  memset(t,50001,sizeof(t));
  t[0]=0;
  for(int i=0;i<m;i++){
    cin>>c[i];
  }
  for(int i=0;i<m;i++){
    for(int j=c[i];j<=n;j++){
      t[j]=min(t[j],t[j-c[i]]+1);
    }
  }
  cout<<t[n]<<endl;
}

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

int main(){
  string n;
  cin>>n;
  if(n.size()==1){
      cout<<n<<endl;
  }
  else{
      bool nine=true;
      for(int i=1;i<n.size();i++){
          if(n[i]!='9') nine=false;
      }
      int top=n[0]-'0';
      if(nine){
          cout<<top+9*(n.size()-1)<<endl;
      }
      else{
          cout<<top-1+9*(n.size()-1)<<endl;
      }
  }

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

MONSTERS = A[:]
BRAVERS = B[:]

sum_monster = sum(MONSTERS)
#print(sum_monster)

for i, b in reversed(list(enumerate(BRAVERS))):
    if MONSTERS[i+1] >= b:
        MONSTERS[i+1] -= b
    else:
        b -= MONSTERS[i+1]
        MONSTERS[i+1] = 0
        if MONSTERS[i] >= b:
            MONSTERS[i] -= b
        else:
            MONSTERS[i] = 0
            
ans = sum_monster - sum(MONSTERS)
print(ans)

Measured memory_bytes: 23932
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,k;
            cin>>n;
            ll ans=0;
            for(i=1;i<=n;++i)
            {
                for(j=1;j<=n;++j)
                {
                    for(k=1;k<=n;++k)
                    {
                        ans=ans+__gcd(i,__gcd(j,k));
                    }
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n,k;cin>>n>>k;
  vi v(n);
  rep(i,n)cin>>v[i];
  vector<ll> dp(n,9999999999);
  dp[0]=0;
  dp[1]=abs(v[1]-v[0]);
  for(int i=2;i<n;i++){
    rep(j,k){
      if(i-j-1>=0)chmin(dp[i],dp[i-j-1]+abs(v[i]-v[i-j-1]));
    }
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;

  int i,j,k;
  int count=0;

for(i=1;i<n;i++){
  if(s[i] == 'E') count++;
}
int ans = count;

for(i=1;i<n;i++){
  if(s[i-1] == 'W') count++;
  if(s[i] == 'E') count--;
  if(ans>count) ans = count;
}
cout << ans << endl;

}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int a, b;
 	cin >> a >> b;
 	cout << max(max(a+b, a-b), a*b);
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll num(n, -1);
  ll m;
  cin >> m;
  vll s(m), c(m);
  rep(i, 0, m) cin >> s.at(i) >> c.at(i);
  rep(i, 0, m){
    if(num.at(s.at(i) - 1) == -1){
      num.at(s.at(i) - 1) = c.at(i);
    }
    else{
      if(num.at(s.at(i) - 1) != c.at(i)){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  rep(i, 0, n){
    if(num.at(i) == -1){
      if(i == 0 && n > 1) num.at(i) = 1;
      else num.at(i) = 0;
    }
    if(i == 0 && num.at(i) == 0 && n > 1){
      cout << -1 << endl;
      return 0;
    }
    cout << num.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
h1,m1,h2,m2,k=map(int,input().split())
h_d=h2-h1
m_d=m2-m1
if m_d<0:
    h_d-=1
    m_d=60+m2-m1
    
sum=60*h_d+m_d
sum-=k
 
if sum<0:
    print(0)
else:
    print(sum)

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

table = [[0]*n for i in range(3)]

for _ in range(k):
	x,y=map(int,input().split())
	for i in range(3):
		table[i][x-1] = 0 if i == y-1 else -1

for i in range(3):
	if table[i][0] != -1:
		table[i][0] = 1

for i in range(1,n):
	s = 0
	for j in range(3):
		s += table[j][i-1] if table[j][i-1] != -1 else 0

	for j in range(3):
		if table[j][i] == -1:
			continue

		table[j][i] = s%10000

		if table[j][i-1] != -1 and table[j][i-2] != -1:
			if i == 1:
				continue
			table[j][i-1] -= table[j][i-2]
			table[j][i] -= table[j][i-2]

total = 0
for i in range(3):
	total += table[i][n-1] if table[i][n-1] != -1 else 0
total = total % 10000
print(total)


Measured memory_bytes: 5616
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] xy = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int x = xy[0];
        int y = xy[1];
        for (int i = 0; i <= x; i++)
        {
            if (2 * i + 4 * (x - i) == y)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}

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

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)
#define sz(x) (int)(x).size()

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;
using ld = long double;

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

	ll N, K;

	cin >> N >> K;

	ll m = (N + 1) / 2;

	if (K <= m) cout << "YES\n";
	else cout << "NO\n";

}


Measured memory_bytes: 256