akhauriyash/Code-Regression huggingface dataset:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ABC= []
for _ in range(N):
    a,b = map(int,input().split())
    ABC.append([a,b,a+b])

taka = 0
aoki = 0
ABC.sort(key=lambda x:x[2])
while ABC:
    
    taka += ABC.pop()[0]
    if len(ABC)==0:
        break
    aoki += ABC.pop()[1]
print(taka-aoki)


Measured memory_bytes: 30600
// coded by- mrNOBODY_

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// cin.sync();
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr, arr+n); 
	int sum =0;
	for(int i=0; i<k; i++)
	{
		sum += arr[i];
	}
	cout<<sum;


	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    int a;
    cin >> a;
    vector<ll> z(a);
    for (int i = 0; i < a; i++) {
        cin >> z.at(i);
    }
    if (a % 2 == 0) {
        string ans = "Yes";
        ll s = 0;
        for (int i = 0; i < a / 2; i++) {
            s = s ^ z.at(i * 2);
        }
        if (s != 0)ans = "No";
        for (int i = 0; i < a / 2; i++) {
            s = s ^ z.at(i * 2 + 1);
        }
        if (s != 0)ans = "No";
        cout << ans << endl;
    }
    else {
        string ans = "Yes";
        ll s = 0;
        for (int i = 0; i < a; i++) {
            s = s ^ z.at(i);
        }
        if (s != 0)ans = "No";
        cout << ans << endl;
    }
}

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

const int N = 100005;

int n, m;

priority_queue<int> pq;

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

	cin >> n >> m;

	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		pq.push(x);
	} 
	
	while(m--) {
		int x = pq.top(); pq.pop();
		pq.push(x/2);
	}

	long long ans = 0;

	while(pq.size()) {
		ans+=(long long)pq.top(); pq.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    int maxv = -1, ans;
    rrep(i, n) {
        int a = i, cnt = 0;
        while(a % 2 == 0) {
            a /= 2;
            cnt++;
        }
        if(maxv < cnt) {
            maxv = cnt;
            ans = i;
        }
    }
    
    cout << ans << endl;

    return 0;
}
/*
int main() {
    int n; cin >> n;
    rrep(i, 7) {
        if(n < (int)pow(2, i)) {
            cout << (int)pow(2, i - 1) << endl; 
            return 0;
        }
    }
    
    return 0;
}
*/

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

int main(void)
{
    long long N, K;
    cin >> N >> K;
    vector<long long> vec(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    long long ans = 0;
    for (long long i = 0; i < K; i++)
    {
        ans += vec[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int a, b, c;
  char s;
  cin >> a >> b >> s >> c;

  cout << a*(b*100+c)/100 << "\n";

  return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n, x, y = [int(x) for x in input().split()]
    
    ans = defaultdict(int)

    for i in range(1, n):
        for j in range(i + 1, n+1):
            d = min(j - i, min(abs(i - x) + 1 + abs(j - y), abs(i - y) + 1 + abs(j - x)))
            ans[d] += 1

    for i in range(1, n):
        print(ans[i])

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Measured memory_bytes: 10228
function Main(input) {

	input = input.split("\n");
	
	var ques = input[0].split(" ");
	var N = parseInt(ques[0]);
	var X = parseInt(ques[1]);
	
	var L = input[1].split(" ");
	var d = [];
	d[0] = 0;
	var i = 0;

	var leng = 0;
	var count = 0;
	
	while(leng <= X){
	    d[i+1] = d[i] + parseInt(L[i]);
	    count++;
	    leng = d[i+1];
	    i++;
	}
	
	console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    int n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    	cin>>a[i]>>b[i]>>c[i];

    ll dp1[n],dp2[n],dp3[n];
    dp1[0]=a[0];dp2[0]=b[0];dp3[0]=c[0];

    for(int i=1;i<n;i++)
    {
    	dp1[i]=max(dp2[i-1],dp3[i-1])+a[i];
    	dp2[i]=max(dp1[i-1],dp3[i-1])+b[i];
    	dp3[i]=max(dp1[i-1],dp2[i-1])+c[i];
    }

    ll ans=max({dp1[n-1],dp2[n-1],dp3[n-1]});
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4992
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;



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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	M = 99000;
	vector<int>ans;
	while (M>0) {
		if (v.front() < v.back() && v.front()) {
			M--;
			ans.push_back(N - 1);
			swap(v.back(), v.front());
		}
		M--;
		ans.push_back(1);
		auto w = v;
		for (int i = 0; i < N; i++) {
			v[i] = w[(i + 1) % N];
		}
	}
	while (v.front()) {
		ans.push_back(1);
		auto w = v;
		for (int i = 0; i < N; i++) {
			v[i] = w[(i + 1) % N];
		}
	}
	cout << ans.size() << endl;
	for (auto i : ans)cout << i << endl;
}

Measured memory_bytes: 1016
from itertools import combinations

N, K = map(int, input().split())

K_max = (N - 1) * (N - 2) // 2
if K > K_max:
    print(-1)
else:
    surplus = K_max - K
    edges = [(i + 1, N) for i in range(N - 1)] + \
        list(combinations(list(range(1, N)), 2))[:surplus]
    print(len(edges))
    for edge in edges:
        print(edge[0], edge[1])


Measured memory_bytes: 4000
N, T = gets.split.map(&:to_i)

min_c = Float::INFINITY
N.times do
  c, t = gets.split.map(&:to_i)
  min_c = c if t <= T && (min_c.nil? || min_c > c)
end

if min_c < Float::INFINITY
  puts min_c
else
  puts 'TLE'
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
typedef long long int llint;

typedef std::set<int, std::greater<int>()> set;

llint counts(const std::vector<int>& A, int k){
  llint count = 0;
  for(const auto& elem: A){
    //std::cout << elem << std::endl;
    auto lb = std::lower_bound(A.begin(), A.end(), k-elem);
    //std::cout << (*lb) << std::endl;
    //std::cout << A.size() - std::distance(A.begin(), lb) << std::endl;
    count += A.size() - std::distance(A.begin(), lb);
  }
  //std::cout << std::endl;

  return count;
}

llint total(const std::vector<int>& A, int k){
  std::vector<llint> acc(A.size());
  acc[A.size()-1] = A[A.size()-1];
  for(int i=A.size()-2; i>=0; i--){
    acc[i] = acc[i+1] + A[i];
    //std::cout << acc[i] << " ";
  }
  //std::cout << std::endl;

  llint ret = 0;
  for(const auto& elem: A){
    //std::cout << elem << std::endl;
    auto lb = std::lower_bound(A.begin(), A.end(), k-elem);
    //std::cout << (*lb) << std::endl;
    //std::cout << std::distance(A.begin(), lb) << std::endl;
    int dist = std::distance(A.begin(), lb);
    if(dist == A.size()) continue;
    ret += acc[dist] + elem * (A.size()-dist);
  }
  return ret; 
  
}


int main(void){
  llint n, m;
  std::cin >> n >> m;

  std::vector<int> A(n);
  for(int i=0; i<n; i++){
    std::cin >> A[i];
  }
  std::sort(A.begin(), A.end());

  int st = 0;
  int ed = A[A.size()-1] * 2 + 1;

  while(ed-st > 1){
    int mid = (ed+st)/2;
    if(counts(A, mid) < m) ed = mid;
    else                   st = mid;
  }
  //std::cout << st << " " << ed << std::endl;

  // st ha OK
  // ed ha dame

  llint result = total(A, ed);
  m -= counts(A, ed);
  result += st * m;

  //std::cout << total(A, ed) << std::endl;
  std::cout << result << std::endl;
  

  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
	int N,a[10000],SUNADA=0,HIGASHINO=0,q=0,w=0,e=0,r=0,t=0,y=0,u=0,o=0,BaKa=0;
	cin>>N;
	for(int i=0;i<N;i++){
		a[i]=0;
		cin>>a[i];
	}
	for(int i=0;i<N;i++){
		if(a[i]<=399&&q==0){
			SUNADA+=1;
			HIGASHINO+=1;
			q+=1;
		}
		else if(a[i]/400==1&&w==0){
			HIGASHINO+=1;
			SUNADA+=1;
			w+=1;
		}
		else if(a[i]/400==2&&e==0){
			SUNADA+=1;
			HIGASHINO+=1;
			e+=1;
		}
		else if(a[i]/400==3&&r==0){
			SUNADA+=1;
			HIGASHINO+=1;
			r+=1;
		}
		else if(a[i]/400==4&&t==0){
			SUNADA+=1;
			HIGASHINO+=1;
			t+=1;
		}
		else if(a[i]/400==5&&y==0){
			SUNADA+=1;
			HIGASHINO+=1;
			y+=1;
		}
		else if(a[i]/400==6&&u==0){
			SUNADA+=1;
			HIGASHINO+=1;
			u+=1;
		}
		else if(a[i]/400==7&&o==0){
			SUNADA+=1;
			HIGASHINO+=1;
			o+=1;
		}
		else if(a[i]>=3200){
			SUNADA+=1;
			BaKa++;
		}
	}
	if(BaKa==N){
		cout<<1<<" "<<N<<endl;
	}
	else{
		cout<<HIGASHINO<<" "<<SUNADA<<endl;
	}
}


Measured memory_bytes: 256
/**
 *    author:  Sarfaraz
 *    created: 19.04.2020 17:51:34
**/

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

void solve(){

long long days,as,sum=0,result;

cin>>days>>as;

deque<int>de(as);

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

for(int i=0;i<as;i++){
   sum+=de[i];

}

result=days-sum;

if(result>=0){
    cout<<result<<endl;
}else{

    cout<< "-1"<<endl;

}

}

int main(){


    solve();

return 0;
}



Measured memory_bytes: 3668
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if 10000 * i + 5000 * j + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print('-1 -1 -1')

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n, k, m; cin >> n >> k >> m&&n;) {
		vector<int> v(n);
		rep(i, 0, n)v[i] = i + 1;
		m--;
		rep(i, 0, n - 1) {
			v.erase(v.begin() + m);
			m = m + k - 1;
			m %= v.size();
		}
		cout << v[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

int n, d = 0;
int o[1000][1000];
int cp[1000];
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    memset(o, -1, sizeof(o));
    F0R(i, n) 
    {
        F0R(j, n - 1) 
        {
            cin >> o[i][j];
            o[i][j]--;
        }
    }
    // for(auto i : o) 
    // {
    //     for(auto j : i) cout << j << " ";
    //     cout << "\n";
    // }
    bool c = true;
    cc_hash_table<ll, int> m;
    stack<int> tc;
    F0R(i, n) tc.push(i);
    int tot = 0;
    while(c)
    {
        c = false;
        tot += sz(tc);
        vector<pair<int, int>> e;
        while(!tc.empty())
        {
            int j = tc.top();
            tc.pop();
            if(cp[j] < n - 1)
            {
                int a = o[j][cp[j]], b = j;
                if(a > b) swap(a, b);
                m[1005 * (a + 1) + (b + 1)]++;
                if(m[1005 * (a + 1) + (b + 1)] == 2) 
                {
                    // cout << a << " " << b << "\n";
                    c = true;
                    e.pb({a, b});
                }
            }
        }
        for(auto i : e) 
        {
            cp[i.f]++;
            cp[i.s]++;
            tc.push(i.f);
            tc.push(i.s);
            m.erase((i.f + 1) * 1005 + (i.s + 1));
        }
        // cout << "\n";
        d++;
        if(!c) break;
    }
    bool pos = true;
    F0R(i, n) if(cp[i] != n - 1) pos = false;
    cout << (pos ? d - 1 : -1);
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
vector<int>G[100000];
queue<int>Q;
int col[100000],n,id=1;
void bfs(int u,int c){
	Q.push(u);
	col[u]=c;
	while(!Q.empty()){
		u=Q.front();Q.pop();
		r(i,0,G[u].size()){
			int w=G[u][i];
			if(col[w]==-1){
				Q.push(w);
				col[w]=c;
			}
		}
	}
}
void Color(){
	r(i,0,100000)col[i]=-1;
	r(i,0,n)if(col[i]==-1)bfs(i,id++);
}
int main(){
	int s,t,m,q;
	cin>>n>>m;
	r(i,0,m){
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	Color();
	cin>>q;
	while(q--){
		cin>>s>>t;
		if(col[s]==col[t])cout<<"yes";
		else cout<<"no";
		cout<<endl;
	}
}

Measured memory_bytes: 8988
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

int main(void) {
	char S[3][101];
	size_t nextIdx[3] = { 0,0,0 };

	scanf("%s\n%s\n%s", S[0], S[1], S[2]);

	size_t nextPos = 0;
	while (1) {
		if (S[nextPos][nextIdx[nextPos]] == '\0') {
			break;
		}
		else {
			nextIdx[nextPos]++;
			nextPos = S[nextPos][nextIdx[nextPos] - 1] - 'a';
		}
	}

	putchar('A' + (char)nextPos);
	putchar('\n');

	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,pos;
ll a[200010],b[200010];
vector<pll >s;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;for(int i=0;i<n;i++)cin>>a[i]>>b[i],s.pb(m_p(b[i],a[i]));sort(s.begin(),s.end());
	vector<pll >::iterator it=s.begin();
	for(;it!=s.end();it++){
		pll p=*it;
		pos+=p.sec;
		if(pos>p.fir){
			cout<<"No";
			return 0;
		}
//		cout<<pos-p.sec<<"-->"<<pos<<"   "; 
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 8560
#include <iostream>
using namespace std;
int main (){
    int n, m;
    cin>>n;
    long long int N[n];
    N[0]=2;
    N[1]=1;
    m=2;
    while (m<n+1){
        N[m]=N[m-2]+N[m-1];
        m++;
    }
    cout<<N[m-1]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    VVI ru(n+1,VI(3));
    REP(i,0,n) {
        REP(j,0,3) ru[i+1][j] = ru[i][j];
        if (s[i] == 'R') ru[i+1][0]++;
        if (s[i] == 'G') ru[i+1][1]++;
        if (s[i] == 'B') ru[i+1][2]++;
    }
    LL ans = 0;
    REP(i,0,n) {
        LL sum = 0;
        if (s[i] == 'R') {
            sum += 1LL * ru[i][1] * (ru[n][2] - ru[i+1][2]);
            sum += 1LL * ru[i][2] * (ru[n][1] - ru[i+1][1]);
        }
        if (s[i] == 'G') {
            sum += 1LL * ru[i][0] * (ru[n][2] - ru[i+1][2]);
            sum += 1LL * ru[i][2] * (ru[n][0] - ru[i+1][0]);
        }
        if (s[i] == 'B') {
            sum += 1LL * ru[i][1] * (ru[n][0] - ru[i+1][0]);
            sum += 1LL * ru[i][0] * (ru[n][1] - ru[i+1][1]);
        }
        REP(j,1,n) {
            if (i - j < 0 || i + j >= n) break;
            if (s[i-j] == s[i + j]) continue;
            if (s[i-j] == s[i]) continue;
            if (s[i] == s[i + j]) continue;
            --sum;
        }
        ans += sum;
    }
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

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

	if (S.size() <= K) { cout << S << endl; }
	else {
		cout << S.substr(0, K) << "..." << endl;
	}
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

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

int main() {
    ull N;
    cin >> N;
    ull A[N], next_gcd[N], back_gcd[N];
    ull max_gcd=0, gcd_n, prev_gcd_n, gcd_b, prev_gcd_b;
    for (int i=0; i<N; i++)  cin >> A[i]; 

    for (int i=0; i<N; i++) {
        if (i==0) gcd_n = A[0];
        gcd_n = gcd(gcd_n, A[i]);
        next_gcd[i] = gcd_n;
    };

    for (int i=N-1; i>=0; i--) {
        if (i==N-1) gcd_b = A[N-1];
        gcd_b = gcd(gcd_b, A[i]);
        back_gcd[i] = gcd_b;
    };

    for (int i=0; i<N; i++) {            
        if (i==0) gcd_n = back_gcd[N-1];
        else  gcd_n = next_gcd[i-1];
        if (i==N-1) gcd_b = next_gcd[0];
        else gcd_b = back_gcd[i+1];

        max_gcd = max(max_gcd, gcd(gcd_n ,gcd_b));
    }

    cout << max_gcd << endl;

    return 0;
}


Measured memory_bytes: 2560
while True:
    n, x = input().split(" ")
    n, x = int(n), int(x)
    if n == 0 and x == 0:
        break
    cnt = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    cnt += 1
    print(cnt)


Measured memory_bytes: 5600
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    // std::string S;
    // std::cin >> S;

    int64_t prev = 0;
    int dir = 0;
    int64_t count = 0;

    for (decltype(N) i = 0; i < N; ++i) {
        int64_t a;
        std::cin >> a;

        if (i == 0) {
            // nop
        }
        else if (dir == 0) {
            if (prev < a) {
                dir = 1;
            }
            else if (prev > a) {
                dir = -1;
            }
        }
        else if (dir > 0) {
            if (prev > a) {
                count++;
                dir = 0;
            }
        }
        else if (dir < 0) {
            if (prev < a) {
                count++;
                dir = 0;
            }
        }
        prev = a;
    }

    count++;

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
  
    int w,a,b ;
    cin>>w>>a>>b ;

    int tmp = a+w ;

    if(tmp>=b && b>=a)
     cout << 0 << endl ;
    else if(b>tmp)
     cout << b-tmp << endl ;         
    else 
     cout << a-(b+w) << endl ;         
    
  return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};


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


int main() {
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    for (int i = 2; i < n; i++)
    {
        if (s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C') ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  map<int,int> A;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a]++;
  }
  int ans=0;
  while(A.size()){
    int j=(*prev(A.end())).first,k=1;
    for(;k<j;k*=2);
    if(k==j){
      ans+=A[j]/2;
      A.erase(j);
      continue;
    }
    if(A.count(k-j)){
      A[k-j]--;
      if(!A[k-j])A.erase(k-j);
      ans++;
    }
    A[j]--;
    if(!A[j])A.erase(j);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 16056
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  int n = in(), t = in();

  int mini = INF;
  int dis = 0;
  int ans = 0;
  REP(_, n) {
    int a = in();
    mini = min(mini, a);
    if (a - mini > dis) {
      ans = 0;
      dis = a - mini;
    }
    if (dis == a - mini) ans++;
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
#include <cstdio>

long long n;

inline bool check(long long k) {
    if (k == 1) return 0;
    long long t = n;
    while (t && !(t % k)) t /= k;
    if (!t) return 0;
    return !((t - 1) % k);
}

int main() {
    scanf("%lld", &n);
    int ans = 0;
    for (int i = 1; (long long)i * i < n; ++i)
        if (!((n - 1) % i)) {
            ++ans;
            if ((long long)i * i < n - 1) ++ans;
        }
    for (int i = 1; (long long)i * i <= n; ++i)
        if (!(n % i)) {
            if (check(i)) ++ans;
            if ((long long)i * i < n && check(n / i)) ++ans;
        }
    printf("%d\n", ans - 1);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,start,end;
  int group_cnt;
  int person_cnt;
  cin >> N;
  // ここにプログラムを追記
  while(group_cnt < N){
    cin >> start >> end;
    person_cnt += end -start +1; 
    group_cnt++;
  }
  cout << person_cnt << endl;
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
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)*}
    };
}

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

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,
        M: usize,
        sc: [(usize, usize); M],
    }

    if N == 1 {
        if sc.iter().all(|&(s, c)| c == 0) {
            println!("0");
            return;
        }
    }

    for d in 10usize.pow(N as u32 - 1)..10usize.pow(N as u32) {
        let ds = d.to_string().chars().map(|c| (c as u32 - '0' as u32) as usize).collect::<Vec<_>>();
        if sc.iter().all(|&(s, c)| ds[s-1] == c) {
            println!("{}", d);
            return;
        }
    }

    println!("-1");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
	
using namespace std;
inline void FAST_IO(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

template<class F, class S> ostream& operator<<(ostream& os, pair<F, S> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template<class T, class S> ostream& operator<<(ostream& os, map<T, S> &v) {
	os << "{";
	for(auto &i : v) cout << "{" << i.first << "," << i.second << "}";
	os << "}";
	return os;
}

template<class T> ostream& operator<<(ostream& os, set<T> &v) {
	os << "{";
	for(auto &i : v) cout << i << ",";
	os << "}";
	return os;
}
 
template<class T> ostream& operator<<(ostream& os, vector<T> &v) {
	os << "[";
	if(v.size()) os << v[0];
	for(int i = 1; i < v.size(); ++i) os << "," << v[i];
	os << "]";
	return os;
}

/*----------------------------------------------------------------------------*/

int main (){
	// FAST_IO();

	int n,x;
	cin >> n >> x;

	priority_queue<int> pq;
	int resp = 0;

	while(n-->0) {
		int in;
		cin >> in;
		pq.push(-in);
		if (x >= in)  {
			x -= in;
			resp++;
		}
	}

	while(x > 0 && !pq.empty()) {
		int v = -pq.top();
		if (x >= v) {
			resp += x/v;
			x -= (x/v)*v;
		}
		pq.pop();
	}

	cout << resp << endl;

	return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  long long r = 0, g = 0, b = 0;
  for(int i = n-1; i >= 0; --i){
    if(s.at(i) == 'R') ++r;
    if(s.at(i) == 'G') ++g;
    if(s.at(i) == 'B') ++b;
  }
      
  long long ans = r * g * b;
  for(int i = 0; i < n; ++i){
    char c = s.at(i);
    for(int j = i+1; j < n; ++j){
      char d = s.at(j);
      if(c == d) continue;
      int k = j + j - i;
      if(k >= n) continue;
      if(s.at(k) != c && s.at(k) != d) --ans;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=600005;
map<pair<int,int>,int>mp;
vector<pair<int,int>>e[N];
int n,m,cnt,vis[N];
priority_queue<pair<int,int>>q;
void add(int p,int q,int c,int d)
{
	e[p].push_back({q,c});
	e[q].push_back({p,d});
}
int solve(int u,int v)
{
	if(mp.count({u,v}))
		return mp[{u,v}];
	int ret=cnt++;
	add(u,ret,1,0);
	return mp[{u,v}]=ret;
}
int main()
{
	scanf("%d%d",&n,&m);
	cnt=n+1;
	for(int i=1;i<=m;i++)
	{
		int p,q,c;
		scanf("%d%d%d",&p,&q,&c);
		int a=solve(p,c),b=solve(q,c);
		add(a,b,0,0);
	}
	q.push({0,1});
	while(!q.empty())
	{
		pair<int,int> tmp=q.top();
		q.pop();
		int cost=-tmp.first,pt=tmp.second;
		if(vis[pt])
			continue;
		vis[pt]=1;
		if(pt==n)
		{
			printf("%d\n",cost);
			return 0;
		}
		for(auto it:e[pt])
			q.push({-(cost+it.second),it.first});
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 61816
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        long ans = 0L;
        for (int i=0;i<N;i++) {
            ans += A[i]/2;
            if (i<N-1 && A[i]%2==1) {
                if (A[i+1]>0) {
                    A[i]--;
                    A[i+1]--;
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 48984
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let s: String = scan(tokens);
    let s = s.as_bytes();
    let n = s.len();
    if palindrome(&s) && palindrome(&s[..(n - 1) / 2]) && palindrome(&s[(n + 1) / 2..]) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn palindrome(s: &[u8]) -> bool {
    for i in 0..s.len() / 2 {
        if s[i] != s[s.len() - 1 - i] {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,k;
  cin >> a >> b >> k;
  if(b-a+1 < 2*k) {
    for(int i=a; i<=b; i++)
      cout << i << endl;
  } else {
    for(int i=a; i<=a+k-1; i++) {
      cout << i << endl;
    }
    for(int i=b-k+1; i<=b; i++) {
      cout << i << endl;
    }
  }
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int h,w;
	cin>>h>>w;
	char str[h+2][w+2];
	for(int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			str[i][j]=',';
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>str[i][j];
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(str[i][j]=='#'){
				if(str[i][j-1]!='#'&&str[i][j+1]!='#'&&str[i-1][j]!='#'&&str[i+1][j]!='#'){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100010

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    ll n, a[MAXN], b[MAXN];

    ll ans;
    cin >> n;

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

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

    for(int i=0; i<n; i++) {
        if (a[i] >= b[i]) {
            ans += b[i];
            a[i] -= b[i];
            b[i] = 0;
        } else {
            ans += a[i];
            b[i] -= a[i];
            a[i] = 0;
        }

        if (a[i+1] >= b[i]) {
            ans += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        } else {
            ans += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> prefw(n + 1, 0), sufr(n + 2, 0);
    prefw[0] = 0;
    for (int i = 1; i <= n; ++i) {
        prefw[i] = prefw[i - 1] + (s[i - 1] == 'W');
    }
    sufr[n + 1] = 0;
    for (int i = n; i > 0; --i) {
        sufr[i] = sufr[i + 1] + (s[i - 1] == 'R');
    }
    int ans = n;
    for (int i = 0; i <= n; ++i) {
        int now, w = prefw[i], r = sufr[i + 1], x = min(r, w);
        now = r + w - x;
        ans = min(ans, now);
    }
    cout << ans << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 5236
import sys
input = sys.stdin.readline
def print_ans(N, M):
    """Test Case
    >>> print_ans(3, 3)
    Yes
    >>> print_ans(3, 2)
    No
    """
    if N > M:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    print_ans(N, M)




Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;

    int cnt = 0;
    for(int i = 3; i <= N; i += 2) {
        int cnt_div = 0;
        repi(j, 1, i + 1) {
            if(i % j == 0) cnt_div++;
        }
        if(cnt_div == 8) cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n, A[50];

int solve(int i, int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    cin >>n;
    for(int i = 0; i < n; i++){
        cin >>A[i];
    }
    int q, temp;
    cin >>q;
    for(int i = 0; i < q; i++){
        cin >>temp;
        if(solve(0, temp)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = int(1e2 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

ll n, W, w[MAX_N], v[MAX_N], dp[MAX_N][100005]; // dp[i][j] i番目までみて重量jにしたときの価値の最大値

int main() {
    cin >> n >> W;
    REP(i,n) cin >> w[i] >> v[i];
    REP(i,n){
        REP(j,W+1){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            if(j>=w[i]) dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;}
const db eps=1e-8,PI=acos(-1.0);
const int N=1e5+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
int x,y,a,b,c,p[N],q[N],r[N],now,nex;
ll suma,sumb,ans;
priority_queue<int,vector<int>,greater<int> >s;
int main(){
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	rep(i,1,a)sci(p[i]);
	rep(j,1,b)sci(q[j]);
	rep(k,1,c)sci(r[k]);
	sort(p+1,p+a+1,greater<int>());
	sort(q+1,q+b+1,greater<int>());
	rep(j,1,y){
		s.push(q[j]);
		sumb+=q[j];
	}
	sort(r+1,r+c+1,greater<int>());
	rep(k,1,x){
		suma+=r[k];
	}
	rep(k,x+1,c){
		now=s.top();s.pop();
		sumb-=now;
		now=max(now,r[k]);
		sumb+=now;
		s.push(now);
	}
	ans=suma+sumb;
	rep(i,1,x){
		suma-=r[x+1-i];suma+=p[i];
		now=s.top();s.pop();
		sumb-=now;
		now=max(now,r[x+1-i]);
		sumb+=now;
		s.push(now);
		ans=max(ans,suma+sumb);
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2044
#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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 COM(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() { int S;
    cin >> S;
    long long temp=1;
    if(S<3){
        cout << 0 << endl;
        return (0);
    }
    if(S<=5){
        cout << 1 << endl;
        return (0);
    }
    COMinit();
    for (int i = 1; i < S/3;i++){
        temp += COM((S - 2 * i - 3), i);
        temp = temp % 1000000007;
    } cout << temp << endl;
}

Measured memory_bytes: 15496
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    S = input()[:-1]
    T = input()[:-1]

    n = len(S)
    m = len(T)
    ans = INF
    for i in range(n-m+1):
        tmp = 0
        for j in range(m):
            if S[i+j] != T[j]:
                tmp += 1
        ans = min(ans, tmp)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72884