akhauriyash/Code-Regression huggingface dataset:
x = int(input())
n = 100000
 
def binp(arr, val):
    left,right = 0,len(arr)-1
    while left <= right:
        mid = (left+right)//2
        if val==arr[mid]: return mid
        elif val>=arr[mid]: left = mid+1
        else: right = mid-1
    return 0
 
def binn(arr, val):
    left,right = 0,len(arr)-1
    while left >= right:
        mid = (left+right)//2
        if val==arr[mid]: return mid
        elif val>=arr[mid]: right = mid+1
        else: left = mid-1
    return 0
 
ap = [i**5 for i in range(n)]
an = [-(i**5) for i in range(n)]
 
for b in range(-n,n):
    val = x + b**5
    a = max(binp(ap, val), binn(an,val))
    if a: print(a,b) ; break

Measured memory_bytes: 97120
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int A[100000];
int B[100000];
int C[100000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll a = lower_bound(A, A + N, B[i]) - A;
		ll b = N - (upper_bound(C, C + N, B[i]) - C);
		ans += a * b;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
n, x = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()
count = 0

for i in range(n):
    if x >= A[i]:
        x -= A[i]
        count += 1

if len(A) == count and x > 0:
    count -= 1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int main()
{
    double a,b,h,m,angle,x,dis,pi,p;
    pi=acos(-1);
    cin>>a>>b>>h>>m;
    x=180.0-abs(180.0-abs((m*6.0)-((h*30.0)+(m*0.5))));
    angle=x*pi/180.0;
    dis=(a*a)+(b*b)-(2*a*b*cos(angle));
    p=sqrt(dis);
    cout<<showpoint;
    cout<<fixed;
    cout<<setprecision(15);
    cout<<p<<endl;
}


Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ll x, y;
    cin >> x >> y;
    if(abs(x-y) <= 1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double db;
const db eps=1e-12;
const db pi=acos(-1);
inline int sign(db k){if (k>eps) return 1; else if (k<-eps) return -1; return 0;}//判断k的正负
inline int cmp(db k1,db k2){return sign(k1-k2);}//比较大小
int main()
{
    db a,b,x;scanf("%lf%lf%lf",&a,&b,&x);
    db t=a*b*a/2;
    if(cmp(t,x)<0)
    {
        db cal=(2*b-2*x/a/a)/a;
        db c=atan(cal)/pi*180.0;
        printf("%.12lf\n",c);

    }
    else
    {
        db cal=b*b*a/(2*x);
        db c=atan(cal)*180.0/pi;
        printf("%.12lf\n",c);
    }
    return 0;
}


Measured memory_bytes: 512
/*
NAME:
 ___   _      _   ___  
/ __| /_\    /_\ |   \ 
\__ \/ _ \  / _ \| |) |
|___/_/ \_\/_/ \_\___/ 

lang: 
  ___   _      _   
 / __)_| |_  _| |_ 
( (__(_   _)(_   _)
 \___) |_|    |_|  

*/
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
 
using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef long l;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<l> vl;
typedef vector<ll> vll;

const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
 
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	int i=0,ans=0;
	if(n>=m){
		while(i<k){
			i+=n;
			ans++;
		}
	}
	else{
		while(i<k){
			i+=m;
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int main(){
  // 入力
  long int N;
  cin >> N;
  vector<long int> A(N);
  for (long int i=1; i<N; i++) {
    cin >> A[i];
  }

  vector<long int> count(N);
  for (long int i=0; i<N-1; i++) {
    count[A[i+1]]++;
  }

  for (long int i=1; i<N; i++) {
    cout << count[i] << endl;
  }
  cout << 0 << endl;
  return 0;
}

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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) __builtin_clzll(x)
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

ll N;

signed main() {
    LCIN(N);
    VL ans(N);
    REP(i, N) {
        LCIN(x);
        x--;
        ans[x] = i;
    }
    REP(i, N) { cout << ans[i]+1 << "\n"; }
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main{
    public static void main(String[]agrs){
        int a,b;
        String op;
        char op2;

        Scanner sc = new Scanner(System.in);

        while(true){
            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();
            op2 = op.charAt(0);
            if(op2 == '?') break;
        
            if(op2 == '+'){
                System.out.println(a+b);
            }else if(op2 == '-'){
                System.out.println(a-b);
            }else if(op2 == '*'){
                System.out.println(a*b);
            }else if(op2 == '/'){
                System.out.println(a/b);
            }
        }
    }    
}


Measured memory_bytes: 26376
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)


Measured memory_bytes: 33200
n = int(input())
s = input()
memoW = [0 for i in range(n)]
memoE = [0 for i in range(n)]
countW = 0
countE = 0
for i in range(1,n):
    if s[i-1]=='W':
        countW +=1
    memoW[i] = countW
for i in range(n-2,-1,-1):
    if s[i+1]=='E':
        countE +=1
    memoE[i] =countE
ans = n
for i in range(n):
   ans = min(memoW[i]+memoE[i],ans) 
print(ans)

Measured memory_bytes: 17872
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

if n == 1:
    print(k)
    exit(0)

ans = k
for i in range(n - 1):
    ans *= (k - 1)

print(ans)

Measured memory_bytes: 3064
h,w = (int(i) for i in input().split())
a = [input() for i in range(h)]
r,b = [["#"] for i in range(h)],[["."] for i in range(h)]
x = ["#","."]
for i in range(h):
	for j in range(1,w-1):
		if a[i][j]=="#":
			r[i].append("#")
			b[i].append("#")
		else:
			r[i].append(x[i%2])
			b[i].append(x[1-i%2])
	r[i].append(".")
	b[i].append("#")
for i in range(h): print("".join(r[i]))
print()
for i in range(h): print("".join(b[i]))

Measured memory_bytes: 8436
#include <iostream>
#include <string>

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

	int count = 0;
	//bool flg = true;
	//while (flg) {
	//	flg = false;
	int len = S.length() - 1;
	for (int i = 0; i < len; ) {
		if ((S[i] == '1' && S[i+1] == '0') ||
			(S[i] == '0' && S[i+1] == '1')) {
				//				flg = true;
				auto itr = S.begin() + i;
				S.erase(itr, itr + 2);
				len -= 2;
				count++;
				if (i > 0)i--;
		} else {
			i++;
		}
	//	}
	}

	std::cout << count * 2;
	return 0;
}


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

bool comp(pair<ll,ll> a, pair<ll,ll> b) {
	if(a.second != b.second) return a.second < b.second;
	else return a.first < b.first;
}

int main() {
	int n;
	cin >> n;
	vector<pair<ll,ll>> ab(n);
	for(int i=0;i<n;i++) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab.begin(),ab.end(), comp);
	ll now = 0;
	bool flag = true;
	for(int i=0;i<n;i++) {
		//cout << ab[i].first << " " << ab[i].second << endl;
		now += ab[i].first;
		if(now <= ab[i].second) {
			
		} else {
			flag = false;
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3328
S = list(input())
cnt = [0 for i in range(26)]
for i in range(len(S)):
    cnt[ord(S[i]) - 97] += 1
ans = -1
for i in range(26):
    if cnt[i] == 0:
        print(chr(i + 97))
        ans = 1
        break
if ans == -1:
    print("None")
    


Measured memory_bytes: 3956
import sys
s = input()
l = len(s)
if l == 2:
    if s[0] == s[1]:
        print(1, 2)
        sys.exit()
    else:
        print('-1 -1')
        sys.exit()
for i in range(l - 2):
    s1 = s[i]
    s2 = s[i + 1]
    s3 = s[i + 2]
    if s1 == s2 or s1 == s3 or s2 == s3:
        print(i + 1, i + 3)
        sys.exit()
print('-1 -1')

Measured memory_bytes: 9188
import sys
input = sys.stdin.readline

class segtree:
    x_unit=0 # 単位元
    x_func=sum  # 関数
    def __init__(self,n,seq):
        self.n=n
        self.x=[self.x_unit]*(2*n)
        for i,j in enumerate(seq, self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = self.x_func([self.x[i*2], self.x[i*2+1]])
    def update(self,i,j): # 1点更新
        i += self.n
        self.x[i]=j
        while i>1:
            i//=2 # 更新後、木の上へと登っていくついでに更新
            self.x[i]=self.x_func([self.x[i*2], self.x[i*2+1]])
    def fold(self,l,r): # 区間[l, r)の合計を取得 
        l+=self.n
        r+=self.n
        val_l=self.x_unit
        val_r=self.x_unit
        while l<r:
            if l & 1: # lが奇数
                val_l=self.x_func([val_l,self.x[l]])
                l+=1 # 偶数に調節
            if r & 1: # rが奇数
                r-=1 # 開区間なので1個前は偶数番目の要素
                val_r=self.x_func([val_r,self.x[r]])
            l //= 2
            r //= 2
        return self.x_func([val_l,val_r])

n,q=map(int,input().split())
*a,=map(int,input().split())
seg=segtree(n,a) 
for i in range(q):
    t,x,y=map(int,input().split())
    if t==0:
        old=seg.fold(x,x+1)
        seg.update(x, old+y)
    else:
        print(seg.fold(x, y))

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

using namespace std;

const int MOD = (int) (1e9 + 7);
const int H = 1000;
const int W = 1000;
char grid[H + 1][W + 1];
int h, w;
int dp[H + 1][W + 1];

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

    cin >> h >> w;

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> grid[i][j];
        }
    }

    if (grid[1][1] == '#') {
        cout << "0\n";
        return 0;
    }

    // dp[i][j]: number of paths from (1, 1) to (i, j)
    dp[1][1] = 1;

    for (int i = 2; i <= h; i++) {
        if (grid[i - 1][1] == '#') {
            dp[i][1] = 0;
        }
        else {
            dp[i][1] = dp[i - 1][1];
        }
    }

    for (int j = 2; j <= w; j++) {
        if (grid[1][j - 1] == '#') {
            dp[1][j] = 0;
        }
        else {
            dp[1][j] = dp[1][j - 1];
        }
    }

    auto Add = [&](int& a, int b) {
        a += b;
        if (a >= MOD) a -= MOD;
    };

    auto NumPaths = [&](int i, int j) {
        int res = 0;
        if (grid[i - 1][j] != '#') {
            Add(res, dp[i - 1][j]);
        }
        if (grid[i][j - 1] != '#') {
            Add(res, dp[i][j - 1]);
        }
        return res;
    };

    for (int i = 2; i <= h; i++) {
        for (int j = 2; j <= w; j++) {
            dp[i][j] = NumPaths(i, j);
        }
    }

    cout << dp[h][w] << '\n';

    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		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;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
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);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<P> b(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		b[i]=P(a[i],i);
	}
	sort(b.begin(),b.end());
	int cnt=0;
	rep(i,n){
		if(i%2!=b[i].second%2)cnt++;
	}
	cout<<cnt/2<<endl;
}
  

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
    long A, B;

    cin >> A >> B;

    long x = 0;
    if ( B-A < 256 ) {
        for ( long l = A; l <= B; l ++ ) {
        
            x ^= l;
        }
    } else {
        unsigned long l;
        l = A;
        if ( l & 0x03 ) {
//            cout << "A " << endl;
            for ( int i = (l&0x03); i <= 3; i ++ ) {
//                cout << l << endl;
                x ^= l;
                l ++;
            }
        }
        l = B;
        if ( (l & 0x03) != 0x03 ) {
//            cout << "B " << endl;
            int lm = (l&0x03);
            l -= lm;
            for ( int i = 0; i <= lm; i ++ ) {
//                cout << l << endl;
                x ^= l;
                l ++;
            }
        }
    }
//    cout << "x " ;    
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

a, b, c = na()

if a + b >= c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/05/20 00:39:46
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,k; cin>>n>>k;
  vector<int> A(n); for (auto& a:A) cin>>a;
  sort(A.begin(), A.end());

  using Bitset = bitset<5000>;
  vector<Bitset> dpl(n+1);
  dpl[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    auto a = A[i-1];
    dpl[i] = dpl[i-1] | dpl[i-1] << a;
  }
  vector<Bitset> dpr(n+1);
  dpr[n][0] = 1;
  for (int i = n-1; i >= 0; i--) {
    auto a = A[i];
    dpr[i] = dpr[i+1] | dpr[i+1] << a;
  }

  auto check = [&](int v) {
    auto a = A[v];
    auto& dl = dpl[v];
    auto& dr = dpr[v+1];
    for (int i = 0; i < k; i++) {
      if (!dl[i]) continue;
      for (int j = 0; j < k; j++) {
        if (!dr[j]) continue;
        if (i + j < k and i + j >= k-a)
          return true;
      }
    }
    return false;
  };
  int l = -1, r = n;
  while (l+1<r) {
    auto c = (l+r)/2;
    if (check(c)) {
      r = c;
    } else {
      l = c;
    }
  }
  cout << l+1 << endl;

  return 0;
}


Measured memory_bytes: 9508
N,M = (int(X) for X in input().split())
if N>=M: print(0)
else:
    P   = sorted(int(X) for X in input().split())
    Mov = sorted(P[X+1]-P[X] for X in range(0,M-1))
    if N==1: print(sum(Mov))
    else: print(sum(Mov[:1-N]))

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using ld = long double;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 n, m;
vector<int64> a;
vector<ld> p;
vector<int64> dp;

bool over(int64 a, int64 b, int64 c){
	return a > c/b;
}

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

int main(void){
	cin >> n >> m;
	a.resize(n); p.resize(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> p[i];
	dp.resize(1 << n, 0);
	FOR(i, 1, 1 << n){
		bool ok = true;
		int64 mul = 1, luz=a[__builtin_ctz(i)];
		REP(j, n){
			if(i >> j & 1 && !over(mul, a[j]/gcd(a[j], mul), m)) mul *= a[j]/gcd(a[j], mul);
			else if(i >> j & 1 && over(mul, a[j], m)) ok = false;
		}
		if(ok) dp[i] = m/mul;
		else dp[i] = 0;
	}

	REP(i, n){
		REP(j, 1 << n) if(j >> i & 1) dp[j] -= dp[j^(1 << i)];
	}
	ld res = 0;
	REP(i, 1 << n){
		dp[i] = abs(dp[i]);
		ld po = 1;
		REP(j, n){
			po *= (i >> j & 1 ? p[j] : 100-p[j])/100;
		}
		res += dp[i]*po;
	}
	cout << fixed << setprecision(10) << res << endl;
}



Measured memory_bytes: 11076
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;

int K,T;
int a[110];

int main() {
    while (scanf("%d%d",&K,&T) != EOF) {
        int maxs = 0;
        int sum = 0;
        for (int i = 0;i < T;i ++) {
            scanf("%d",&a[i]);
            maxs = max(maxs,a[i]);
            sum += a[i];
        }
        if (T == 1) {
            printf("%d\n",K - 1);
            continue;
        }

        if (maxs <= (sum + 1) / 2) {
            puts("0");
            continue;
        }
        printf("%d\n",maxs - (sum - maxs) - 1);
    }

}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
 
def code(a):
    pro = 1
    if 0 in a:
        print(0)
    else:
        for i in a:
            pro *= i
            if pro > (10 ** 18):
                print(-1)
                return
        print(pro)
 
code(l)

Measured memory_bytes: 21760
#include <iostream>
 
using namespace std;
 
long gcd(long a, long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
 
long lcm(long a, long b)
{
   return a * b / gcd(a, b);
}
 
int main()
{
   long a,b,c,d;
   cin >> a >> b >> c >> d;
 
   long num = b-a+1;
   long ans = (b/c) + (b/d) - (b/lcm(c,d)) + ((a-1)/lcm(c,d)) - ((a-1)/c) - ((a-1)/d);
   
   cout << num - ans << endl;
   return 0;
}

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

using ll = long long;

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n, 0);
    map<ll, ll> m;
    rep(i, n)
    {
        cin >> a[i];
        m[a[i]]++;
    }

    ll ans = 0;
    for (auto j = m.begin(); j != m.end(); ++j)
    {
        ans += j->second * (j->second - 1) / 2;
    }

    rep(i, n)
    {
        cout << ans - (m[a[i]] - 1) << endl;
    }

    return 0;
}


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

int gcd(int x, int y){
	if(y==0) return x;
	return gcd(y, x%y);
}
int main(){
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

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


void solve()
{
    int n;
    cin>>n;
    vl a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    vl POW(1000001,0);
    for(int i=0;i<n;i++) {
        int x=a[i];
        for(int j=2;j*j<=x;j++) {
            if(x%j==0) {
                ll cnt=0;
                while(x%j==0) {
                    cnt++;
                    x/=j;
                }
                POW[j]=max(cnt,POW[j]);
            }
        }
        if(x>1) POW[x]=max(POW[x],(ll)1);
    }
    ll lcm=1;
    for(ll i=2;i<=1000000;i++) {
        while(POW[i]--) {
            lcm=mul(lcm,i,mod);
        }
    }
    ll sum=0;
    for(int i=0;i<n;i++) {
        sum=(sum+lcm*power(a[i],mod-2,mod))%mod;
    }
    cout<<sum;

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

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

int main() {
	int n,w;
	cin >> n >> w;
	long long int dp[w+1];
	memset(dp,0,sizeof(dp));
	for(int i = 0;i < n;i++)
	{
		int we,val;
		cin >> we >> val;
		for(int i = 0; i <= w-we;i++)
		dp[i] = max(dp[i],dp[i+we] + val); 
	}
	long long int ans = 0;
	for(int i = 0;i <= w;i++)
	ans = max(ans,dp[i]);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
    def search_left(self,f,L,R):
      if not f(self.fold(L,R)): return R
      while R-L>1:
        M = (R+L)//2
        if f(self.fold(L,M)): R = M
        else: L = M
      return L

N,Q=map(int,input().split())
*A,=map(int,input().split())
seg = SegTree(N,max,0)
seg.build(A)
for i in range(Q):
  t,a,b = map(int,input().split())
  if t==1:
    seg.set_val(a-1,b)
  elif t == 2:
    print(seg.fold(a-1,b))
  else:
    print(seg.search_left(lambda x: x >= b,a-1,N)+1)

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for(int i = 0; i < h; i++){
        cin >> a[i];
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }

    //結果を出力
    for(int i = 0; i < h; i++) {
        if(row[i]){
            for(int j = 0; j < w; j++){
                if(col[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }


}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

int main() {
  int number_n, number_of_gates, i, under = 0, top = INT_MAX, temp_under, temp_top;
  scanf("%d %d", &number_n, &number_of_gates);
  for(i = 0; i < number_of_gates; i++) {
    scanf("%d %d", &temp_under, &temp_top);
    if(temp_top < top) {
      top = temp_top;
    }
    if(temp_under > under) {
      under = temp_under;
    }
  }
  if(top >= under) {
    printf("%d\n", top - under + 1);
  } else {
    printf("0\n");
  }

  return 0;
}


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


int cnt[50][26];

int main(void){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string S;
        cin >> S;
        for(int j=0;j<S.length();j++){
            cnt[i][S[j]-'a'] ++;
        }
    }

    for(int i=0;i<26;i++){
        int m = 100000000;
        for(int j=0;j<n;j++){
            m = min(m, cnt[j][i]);
        }

        for(int k=0;k<m;k++) cout << (char)(i+'a');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll        = long long;
using ld        = long double;
using vl        = vector<ll>;
using vd        = vector<ld>;
using vs        = vector<string>;
using vb        = vector<bool>;
using vvl       = vector<vector<ll>>;
using vvd       = vector<vector<ld>>;
using vvs       = vector<vector<string>>;
using vvb       = vector<vector<bool>>;
using pll       = pair<ll, ll>;
constexpr ll mod= 998244353;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

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

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

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N,K;
    cin >> N >> K;
    vl A(N*2+100);
    vl P(K);
    vl Q(K);
    REP(i,K)cin >> P[i] >> Q[i];
    A[0] = 1;
    A[1] = -1;
    ll S = 0;
    REP(i,N){
        S += A[i];
        S = modu(S);
        REP(l,K){
            A[i+P[l]] = modu(A[i+P[l]] +  S);
            A[i+Q[l]+1] = modu(A[i+Q[l]+1]-S);
        }
    }
    cout << modu(S) << "\n";
}

Measured memory_bytes: 6344
#include<iostream>

using namespace std;

int main(void){
  int a,b,c,count;
  cin >> a>>b>>c;
    if(a==b) count++;
    if(a==c) count++;
    if(b==c) count++;
    if(count == 3){
      cout<<"No"<<endl;
    }else if(count == 0)
    {
      cout<<"No"<<endl;
    }else
    {
      cout<<"Yes"<<endl;
    }
    
    
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=="Y"){
      cout << "Four\n";
      exit(0);
    }
  }
  cout << "Three\n";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,s[100000],q,t,c,l,m,r,i,j;
main(){
  cin.sync_with_stdio(false);
  for(cin>>n;i<n;cin>>s[i++]);
  for(cin>>q;j++<q;){
    l=0,r=n,cin>>t;
    while(m=(l+r)/2,l<r){
      t-s[m]||(l=r,c++);
      if(t<s[m])r=m;
      else if(t>s[m])l=m+1;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3392
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main()
{
    string n;
    cin >> n;
    if (n[n.size() - 1] == '3')
    {
        cout << "bon" << endl;
    }
    else if (n[n.size() - 1] == '0' || n[n.size() - 1] == '1' || n[n.size() - 1] == '6' || n[n.size() - 1] == '8')
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3628
A, B, C, X, Y = map(int, input().split())

ans = 0
if (A + B) / 2 >= C:
    #AB = C
    ans += min(X, Y) * C * 2
    X, Y =X - min(X, Y), Y - min(X, Y)

if A >= 2 * C:
    A = 2 * C
if B >= 2 * C:
    B = 2 * C

while X != 0:
    ans += A
    X -= 1
while Y != 0:
    ans += B
    Y -= 1

print(ans)

Measured memory_bytes: 3064
n = input()
L = map(int, raw_input().split())
dp = [[0] * 21 for _ in xrange(n)]
dp[0][L[0]] = 1
for i in xrange(1, n):
    for j in xrange(21):
        if j - L[i] >= 0:
            dp[i][j - L[i]] += dp[i - 1][j]
        if j + L[i] <= 20:
            dp[i][j + L[i]] += dp[i - 1][j]
print dp[n - 1][0]

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

int main(){
	string Number;
	cin >> Number;
	while(Number[0] != '0' || Number.size() > 1){
		int Count = 0;
		vector<int> number;
		for(int i = 0; i < Number.size(); i++){
			for(int j = 0; j < 10; j++){
				if(Number[i] == '0' + j) number.push_back(j);
			}
			Count += number[i];
		}
		cout << Count << endl;
		cin >> Number;
	}
	return 0;
}

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

int main(){

  int d;
  int x,y;
  int e;

  double cost;

  while(cin >> d >> e ,d&&e){

    cost = 1000000;
    
    for(x=0; x<=d; x++){
      y = d-x;

      if(fabs(e - sqrt(x*x+y*y) ) < cost)
	cost = fabs(e - sqrt(x*x+y*y));
    }

    printf("%.8f\n",cost);
  }


  return 0;
}

Measured memory_bytes: 1196
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)


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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll a[2][n];
	rep(i,0,2){
		rep(j,0,n){
			cin >> a[i][j];
		}
	}
	ll ans=0;
	ll sum=0;
	for(ll i=0; i<n; i++){
		sum+=a[0][i];
		ll someone=0;
		for(ll j=i; j<n; j++){
			someone+=a[1][j];
		}
		ans=max(ans,sum+someone);
	}
	cout << ans << "\n";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

const vector<int> dx4 = {-1,  0,  1,  0};
const vector<int> dy4 = { 0,  1,  0, -1};
const vector<int> dx8 = {-1, -1, -1,  0,  1,  1,  1,  0};
const vector<int> dy8 = {-1,  0,  1,  1,  1,  0, -1, -1};

int main(){
    int h, w;
    vector<string> s;
    string temp;

    cin >> h >> w;

    s.push_back(string(w + 2, '.'));
    for(int i = 0; i < h; i++){
        cin >> temp;
        s.push_back("." + temp + ".");
    }
    s.push_back(string(w + 2, '.'));

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '#'){
                bool isNG = true;
                for(int k = 0; k < dx4.size(); k++){
                    if(s[i + dx4[k]][j + dy4[k]] == '#'){
                        isNG = false; break;
                    }
                }
                if(isNG){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A,B,N;
    cin >> N >> A >> B;
    int out;
    if (A+B-N < 0){
        out = 0;
    }
    else{
        out = A+B-N;
    }
    cout << min(A,B)<< " " <<  out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

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

int M[1005][1005];
const int INF = 100000000;

int main(){
    int h, w;
    cin >> h >> w;

    #define mp make_pair    
    queue<pair<int, int> > q;
    for(int i=0;i<h;i++){
        string s;
        cin >> s;
        for(int j=0;j<w;j++){
            if(s[j] == '.')M[i][j] = INF;
            else{
                q.push(mp(i, j));
            }
        }
    }

    while(!q.empty()){
        queue<pair<int, int>> newq;
        while(!q.empty()){
            auto f = q.front(); q.pop();
            int curi = f.first, curj = f.second;
            if(curi + 1 < h && M[curi][curj] + 1 < M[curi + 1][curj]){
                M[curi + 1][curj] = M[curi][curj] + 1;
                newq.push(mp(curi + 1, curj));
            }
            if(curj + 1 < w && M[curi][curj] + 1 < M[curi][curj + 1]){
                M[curi][curj + 1] = M[curi][curj] + 1;
                newq.push(mp(curi, curj + 1));
            }
            if(curi - 1 >= 0 && M[curi][curj] + 1 < M[curi - 1][curj]){
                M[curi - 1][curj] = M[curi][curj] + 1;
                newq.push(mp(curi - 1, curj));
            }
            if(curj - 1 >= 0 && M[curi][curj] + 1 < M[curi][curj - 1]){
                M[curi][curj - 1] = M[curi][curj] + 1;
                newq.push(mp(curi, curj - 1));
            }
        }
        q = newq;
    }
    int ret = -1;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)ret = max(ret, M[i][j]);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int n, m;
int field[10][10];
ll ans = 0;
int win[10];

void f(int person) {
    //cerr << "F: " << person << " " << win[person] << endl;
    if(person == n) {
        if(win[person] == 0) ans++;
        return;
    }
    int rest = n - person;
    if(win[person] < 0 || win[person] > rest) return;
    vector<int> bit(rest);
    for(int i = 0; i < win[person]; i++) bit[rest - 1 - i] = 1;
    do {
        //cerr << "A" << endl;
        bool out = false;
        for(int j = 1; j <= rest; j++) {
            if(field[person][person+j] == 0) continue;
            if((field[person][person+j] == 1) ^ (bit[j-1] == 1)) out = true;
        }
        if(out) continue;
        /*
        cerr << "BIT: ";
        for(int j = 0; j < bit.size(); j++) cerr << bit[j] << " ";
        cerr << endl;
        */
        for(int j = 1; j <= rest; j++) {
            if(!bit[j-1]) win[person+j]--;
        }
        f(person + 1);
        for(int j = 1; j <= rest; j++) {
            if(!bit[j-1]) win[person+j]++;
        }
    } while(next_permutation(bit.begin(), bit.end()));
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        ans = 0;
        cin >> n;
        if(n == 0) break;
        for(int i = 1; i <= n; i++) win[i] = n / 2;
        cin >> m;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) field[i][j] = 0;
        }
        while(m--) {
            int x, y;
            cin >> x >> y;
            if(x > y) field[y][x] = -1;
            else field[x][y] = 1;
        }
        f(1);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define N 100001
#define MAX_W 1000000010
typedef long long int LL;
LL dp[N];
int main(){
	int t=1,nt=0;
	//cin>>t;
	while(t--){
		LL exp,prob[100],mnprob=1,n,money[100],mi,sum=0;
		scanf("%lld%lld",&n,&exp);
		for(int i=0;i<n;i++){
			scanf("%lld%lld",prob+i,money+i);
			sum+=money[i];
		}
		for(int i=1;i<=sum;i++) dp[i]=MAX_W;
		for(int j=0;j<n;j++){
			for(int i=sum;i>0;i--){ 
				if(i-money[j]>-1)
					dp[i]=min(dp[i],prob[j]+dp[i-money[j]]);
			}
		}
		for(int i=sum;i>-1;i--) if(dp[i]<=exp){ 
		cout<<i<<"\n";
		break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n,i;
	char a[202];
	scanf("%d",&n);
	for(i=0;i<=2*n+2;i++)
		scanf("%c",&a[i]);
	for(i=1;i<=n;i++)
	{	
		printf("%c%c",a[i],a[i+1+n]);		
	}
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict

def main():
    N = int(input())
    A = input().split()
    counts = defaultdict(int)
    ans = 0
    for a in A:
        counts[a] += 1
        ans += int(a)
    Q = int(input())
    BC = []
    for _ in range(Q):
        BC.append(input().split())
    for b,c in BC:
        ans += (int(c)-int(b)) * counts[b]
        print(ans)
        counts[c] += counts[b]
        counts[b] = 0

if __name__ == '__main__':
    main()

Measured memory_bytes: 118464