akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
using namespace std;

struct Point {
    double x,y;
    Point(){}
    Point(double x, double y) : x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x, y+p.y);}
    Point operator-(Point p) {return Point(x-p.x, y-p.y);}
    Point operator*(double k){return Point(x*k,y*k);}
    Point operator/(double k){return Point(x/k,y/k);}
    double norm(){return x*x+y*y;}
    double abs(){sqrt(norm());}
    bool operator == (const Point &p) const {return equals(x,p.x)&&equals(y,p.y);}
};
typedef Point P;

double norm(P a){return a.x*a.x+a.y*a.y;}
double abs(P a){return sqrt(norm(a));}

// 線分
struct Segment {
    Point p1,p2;
    Segment(){}
    Segment(Point p1, Point p2):p1(p1),p2(p2){}
};

// 内積
double dot(Point a, Point b) {return a.x*b.x + a.y*b.y;}

// 外積
double cross(Point a, Point b) {return a.x*b.y-a.y*b.x;}
// 2直線の直行判定
bool is_orthogonal(Point a1, Point a2, Point b1, Point b2) {
    return equals(dot(a1-a2, b1-b2), 0.0);
}
// 2直線の平行判定
bool is_parallel(Point a1, Point a2, Point b1, Point b2) {
    return equals(cross(a1-a2, b1-b2), 0.0);
}

int main() {
    int q;
    cin>>q;
    rep(i,q){
        double x0,y0,x1,y1,x2,y2,x3,y3;
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
        P p0(x0,y0),p1(x1,y1),p2(x2,y2),p3(x3,y3);
        if (is_parallel(p0,p1,p2,p3)) cout << 2 << endl;
        else if (is_orthogonal(p0,p1,p2,p3)) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int n;
    cin >> n;
    vector<int> p(n), s(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
        s[i] = p[i];
    }
    sort(p.begin(), p.end());
    int cnt = 0;
    for (int i = 0; i < n; i++){
        if(p[i] != s[i]){
            cnt++;
        }
    }

    if(cnt == 2 || cnt == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
LL n,sum,i;
inline LL read(){
	char ch=getchar(); LL x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	return x*f;}
int main()
{
	//freopen("Falling Stone Game.in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(i=1;;i++)
	{
		sum+=i;
		if(sum>=n) break;
	}
	LL tt=sum-n;
	for(LL j=1;j<=i;j++)
	{
		if(j==tt) continue;
		printf("%lld\n",j);
	}
	//fclose(stdin); fclose(stdout);
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int nmin = 1e9;
	int nmax = -1e9;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		nmin = min(nmin, A[i]);
		nmax = max(nmax, A[i]);
	}
	cout << 2 * N - 1 << endl;
	if (abs(nmin) >= abs(nmax)) {
		int i;
		for (i = 0; i < N; ++i) {
			if (nmin == A[i]) {
				break;
			}
		}
		for (int j = 0; j < N; ++j) {
			cout << i + 1 << " " << j + 1 << endl;
		}
		for (int j = 0; j < N - 1; ++j) {
			cout << N - j << " " << N - j - 1 << endl;
		}
	}
	else {
		int i;
		for (i = 0; i < N; ++i) {
			if (nmax == A[i]) {
				break;
			}
		}
		for (int j = 0; j < N; ++j) {
			cout << i + 1 << " " << j + 1 << endl;
		}
		for (int j = 0; j < N - 1; ++j) {
			cout << j + 1 << " " << j + 2 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3608
from collections import deque

n= int(input())

if n < 10:
    print(n);exit()

q=deque()
for i in range(1,10):
    q.append(i)

for _ in range(1,n):

    t = q.popleft()

    tt = t%10

    for j in range(-1,2):
        ttt = tt+j
        if ttt >= 0 and ttt <= 9:
            q.append(t * 10 + ttt)

print(q.popleft())


Measured memory_bytes: 12404
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];


int dp[100100][2];

void add(long long & a, long long b){
    a = (a+b) % MOD;
}

signed main() {
  string N;
  cin >> N;
  int l = N.size();
  vector<int> n;

  for (auto a : N) {
    n.push_back(a-'0');
  }

  dp[0][0] = 1;

  for (int i = 0; i < l; i++) {
    if (n[i] == 0) {
      add(dp[i + 1][1], 3 * dp[i][1]);
      add(dp[i + 1][0], dp[i][0]);
    }
    if (n[i] == 1) {
      add(dp[i + 1][1], 3 * dp[i][1]);
      add(dp[i + 1][1], dp[i][0]);
      add(dp[i + 1][0], 2 * dp[i][0]);
    }
  }

  cout << (dp[l][0] + dp[l][1]) % MOD<< endl;
}


Measured memory_bytes: 2932
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    N, X, M = [int(a) for a in input().split()]
    # D = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    h = {X: 0}

    totals = [X]

    t = X

    c = X
    counter = 0
    while True:
        c = (c * c) % M
        if c in h:
            counter += 1
            t += c
            last_index = h[c]
            diff = t - totals[last_index]
            width = counter - last_index
            amari = last_index
            break
        counter += 1
        h[c] = counter
        t += c
        totals.append(t)

    if N <= amari:
        print(totals[N - 1])
        return

    N -= amari + 1
    rep = N // width
    mod = N % width

    k = totals[amari + mod]

    T = rep * diff + k
    print(T)


if __name__ == "__main__":
    main()


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string s  , t ;
    cin>>s>>t;
    if(t.size() > s.size()){
        cout<<"UNRESTORABLE"<<endl;
    }else {
        int idx = -1;
        for(int i = s.size() - t.size() ; i >= 0 ; i--){
            bool is = true;
            for(int j = 0 , k = i ; j < t.size() ; j++ , k++){
                if(s[k] != '?' && s[k] != t[j]){
                    is = false;
                    break;
                }
            }
            if(is){
                idx = i;
                break;
            }
        }
        if(idx  == -1){
            cout<<"UNRESTORABLE"<<endl;
        }else {
            for(int i = 0 ; i < idx ; i++){
                if(s[i] == '?')
                    cout<<"a";
                else cout<<s[i];
            }
            cout<<t;
            for(int i = idx + t.size() ; i < s.size() ; i++){
                if(s[i] == '?')
                    cout<<"a";
                else cout<<s[i];
            }
        }
    }
}

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

Measured memory_bytes: 256
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=INF;

int main()
{
	string s;cin>>s;
	cout<<(s.back()=='s'?s+"es":s+"s");

	return 0;
}

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

int main()
{	
	long long x, y;

	cin >> x >> y;

	while (x > 0 || y > 0) {
		int i = 0;

		if (x < y)
			swap(x, y);

		while (y > 0) {
			x = x % y;
			swap(x, y);
			i++;
		}

		cout << x << " " << i << endl;

		cin >> x >> y;
	}
	
	return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll>X(N),Y(N);
	rep(i, N) {
		cin >> X[i];
		Y[i] = X[i];
	}
	sort(X.begin(), X.end());
	rep(i, N) {
		if (Y[i] <= X[N / 2 - 1])cout << X[N / 2] << endl;
		else cout << X[N / 2 - 1] << endl;
	}


	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
        long long int n,ans;
        cin >> n;
        ans = n - 1;
        for (int i = 1; i <= 1000000; i++)
                if (n % i == 0)
                        ans = min(ans, i + n/i - 2); 
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const size_t INF=1uLL<<57;

size_t binary_knapsack(vector<size_t> &w, vector<size_t> &v, size_t c) {
    // for small-capacity knapsack
    vector<size_t> dp(c+1);
    size_t n=w.size();
    for (size_t i=0; i<n; i++)
        for (size_t j=c; j>=w[i]; --j)
            if (dp[j] < dp[j-w[i]] + v[i])
                dp[j] = dp[j-w[i]] + v[i];

    return dp[c];
}

size_t nlimited_knapsack(
    vector<size_t> &w, vector<size_t> &v, vector<size_t> &m, size_t c
) {
    size_t n=w.size();
    vector<size_t> _w, _v;
    for (size_t i=0; i<n; ++i) {
        for (size_t j=1; m[i]>0; j<<=1) {
            size_t k=min(m[i], j);
            m[i] -= k;
            _w.push_back(w[i]*k);
            _v.push_back(v[i]*k);
        }
    }

    return binary_knapsack(_w, _v, c);
}

int main() {
    size_t N, W;
    scanf("%zu %zu", &N, &W);

    vector<size_t> v(N), w(N), m(N);
    for (size_t i=0; i<N; ++i) {
        scanf("%zu %zu %zu", &v[i], &w[i], &m[i]);
    }

    printf("%zu\n", nlimited_knapsack(w, v, m, W));
    return 0;
}

Measured memory_bytes: 2860
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t;
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  vector<vector<ll> > dp(n+1, vector<ll>(k + 1, 0));

  dp[0][0] = 1;
  for (i = 1; i <= n; i++)
  {
    ll cummulativeSum = 0;
    for (j = 0; j <= a[i - 1]; j++)
    {
      cummulativeSum = (cummulativeSum + dp[i - 1][j]) % mod;
      dp[i][j] = cummulativeSum;
      // cout << i << ' ' << j << ' ' << dp[i][j] << endl;
    }
    for (; j <= k;j++){
      cummulativeSum = (cummulativeSum + dp[i - 1][j]) % mod;
      cummulativeSum = (cummulativeSum - dp[i - 1][j - a[i - 1] - 1] + mod) % mod;
      dp[i][j] = cummulativeSum;
      // cout << i << ' ' << j << ' ' << dp[i][j] << endl;
    }
  }

  cout << dp[n][k] << endl;

  return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }

void _main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i, 0, N) cin >> A[i] >> B[i];

  ll ans = 0;
  rrep(i, N-1, 0) {
    ll a = A[i] + ans;
    if (a % B[i] == 0) continue;
    ans += B[i] - a % B[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      long x = sc.nextLong();
      long n = 0;
      while(n*(n+1)/2 < x){
      	n++;
      }
      System.out.println(n);
    }
}

Measured memory_bytes: 23764
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

	ll a, b, n;
	cin >> a >> b >> n;
	ll res = ((a*n)/b) - a*(n/b);
	if (b > 1e6) {
		for (ll k = 0; k*b-1 <= n; ++k) {
			ll x = k*b-1;
			res = max(res, ((a*x)/b) - a*(x/b));
		}
	} else {
		for (ll x = 0; x <= min(n, 3*b); ++x) {
			res = max(res, ((a*x)/b) - a*(x/b));
		}
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    string S;

    cin >> S;
    if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
    ||  (S[0] == S[2] && S[1] == S[3] && S[0] != S[1])
    ||  (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 256
# abc126_b.py
def mm(n):
    if 0 < n and n < 13:
        return True
    else:
        return False

S = input()

head = int(S[:2])
tail = int(S[2:])
head_mm = mm(head)
tail_mm = mm(tail)
if head_mm and tail_mm:
    print("AMBIGUOUS")
elif head_mm:
    print("MMYY")
elif tail_mm:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 9128
n,m = map(int,input().split())

edges = []
parity = [0]*n
di = {}
C = [[] for _ in range(n)]
for _ in range(m):
    a,b = [int(x)-1 for x in input().split()]
    C[a].append(b)
    C[b].append(a)
    edges.append((a,b))
    parity[b] ^= 1
    di[a,b] = 0 # a <- b

if sum(parity)%2 == 1:
    print(-1)
else:
    parent = [-1]*n
    parent[0] = 0
    Q = [0]

    order = []
    for cur in Q:
        for neigh in C[cur]:
            if parent[neigh] == -1:
                order.append(neigh)
                parent[neigh] = cur
                Q.append(neigh)
    
    for v in reversed(order):
        if parity[v] == 1:
            u = v
            p = parent[u]
            if (u,p) not in di:
                u,p = p,u
            di[u,p] ^= 1
            parity[v] ^= 1
            parity[parent[v]] ^= 1
    for a,b in edges:
        if di[a,b] == 0:
            print(b+1,a+1)
        else:
            print(a+1,b+1)




Measured memory_bytes: 98092
#include <stdio.h>
int main(void){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(0<=(x-r)&&x+r<=w&&0<=(y-r)&&y+r<=h){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2672
let calc a b s =
    let f v i c = v && (if i = a then c = '-' else c <> '-') in
    BatString.fold_lefti f true s

let main =
    let [a; b] = read_line () |> BatString.split_on_char ' ' |> List.map int_of_string in
    let s = read_line () in
    let v = (calc a b s) in
    print_endline (if v then "Yes" else "No")


Measured memory_bytes: 384
implicit none
character(26) :: s
integer :: i,j

read *,s
do i = 1, len_trim(s)-1
   do j = i+1, len_trim(s)
      if (s(i:i) .eq. s(j:j)) then
         write(*,'(a)') 'no'
         stop
      endif
   enddo
enddo
write(*,'(a)') 'yes'
end

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

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

int maze[MAX][MAX];

int H, W, ans;

bool range(int y, int x) {
    return (0 <= x && x < W && 0 <= y && y < H);
}

void dfs(int y, int x){
    maze[y][x] = 0;
    rep(8, d) {
        if (range(y+dy[d], x+dx[d]) && maze[y+dy[d]][x+dx[d]]) {
            dfs(y+dy[d], x+dx[d]);
        }
    }
    return;
}

void solve(void){
    while (1) {
        //input & init
        scanf("%d %d\n", &W, &H);
        if (W == 0 && H == 0) break;
        rep(H, y) rep(W, x) scanf("%d", &maze[y][x]);
        ans = 0;

        rep(H, y) rep(W, x) {
            if (maze[y][x]) {
                dfs(y, x);
                ans++;
            }
        }
        printf("%d\n", ans);
    }
}

int main(void){
  solve();
  return 0;
}



Measured memory_bytes: 3232
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {
	string S;
	char t[64];
	scanf("%s", t);
	S = t;

	if (S == "zyxwvutsrqponmlkjihgfedcba") {
		printf("-1\n");
		return 0;
	}
	else if (S.size() < 26) {
		bool f[26] = {};
		for (auto s : S) f[s - 'a'] = true;
		rep(i, 26) if (!f[i]) {
			S += 'a' + i;
			break;
		}
		printf("%s\n", S.c_str());
		return 0;
	}
	else {
		for (int i = 26 - 1; i > 0; --i) {
			if (S[i - 1] < S[i]) {
				bool f[26] = {};
				for (int t = 0; t < i; ++t) f[S[t] - 'a'] = true;
				for (int c = S[i - 1] - 'a'; c < 26; c++) if (!f[c]) {
					S[i - 1] = 'a' + c;
					S[i] = '\0';
					break;
				}
				break;
			}
		}

		printf("%s\n", S.c_str());
		return 0;
	}
}


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

// Range Update Query
// ???[s, t) ???????´???? x ??????????????¨???
// ???i ?????????????´????????????????????????¨???
const int INF = (1LL << 31) - 1;
const int sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<int> data;
  vector<bool> lazyFlag;
  vector<int> lazyUpdate;
  SqrtDecomposition(int n) : N(n) {
    // ?????±????????°??? N ??? sqrtN ??§?????£???????????????????????? ????????????
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, INF);
    lazyFlag.assign(K, false);
    lazyUpdate.assign(K, 0);
  }

  // ?????§??????????????±????????? lazyUpdate ???????????\??£???????????´??????
  // lazyUpdate ?????\??£?????????????????????????????? (?????¶??????)
  // ?????±??????????????????????????? update ?????¨?????????????????? find ?????¨???????????????
  // ????????????????????????????????????
  void eval(int k) {
    if (lazyFlag[k]) {
      lazyFlag[k] = false;
      for (int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
        data[i] = lazyUpdate[k];
      }
    }
  }

  // update [s, t)
  void update(int s, int t, int x) {
    for (int k = 0; k < K; ++k) {
      // ?????±?????????????????¨??????
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      // ?????????
      if (r <= s || t <= l)
        continue;
      // ?????±??????????¢????????????????
      // ??? ?????±????????¨????????????????????´????????§ lazeUpdate ????????¨??????
      if (s <= l && r <= t) {
        lazyFlag[k] = true;
        lazyUpdate[k] = x;
      }
      // ?????±????????????????????§?????? ??? ??????????????´?????? O(\sqrt N)
      else {
        eval(k);
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] = x;
        }
      }
    }
  }

  // find index i
  int find(int i) {
    // k <- ??????????????±????????????????????????
    int k = i / sqrtN;
    eval(k);
    return data[i];
  }
};

int main() {
  int n, q; cin >> n >> q;
  SqrtDecomposition R(n);
  for(int i=0; i<q; i++) {
    int num; cin >> num;
    if(num == 0) {
      int s, t, x; cin >> s >> t >> x;
      R.update(s, t+1, x);
    }
    else {
      int idx; cin >> idx;
      cout << R.find(idx) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int z=min(x,y);
  int ans=0;
  if(2*c<=a+b){
    ans+= z*2*c;
    x-=z;
    y-=z;
  }
  ans+= min(x*a+y*b,max(x,y)*2*c);
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3588
N = int(input())
s = list(input())
rot = 0
a = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(0, len(s)):
    rot = a.index(s[i])+N
    if rot > 25:
        rot -= 26        
    s[i] = a[rot]
print("".join(s))

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;


fn main() {
  let n = read::<i32>();
  let mut even = HashMap::new();
  let mut odd = HashMap::new();

  for i in 1..n + 1 {
    let item = read::<u32>();
    if i % 2 == 0 {
      *even.entry(item).or_insert(0) += 1;
    } else {
      *odd.entry(item).or_insert(0) += 1;
    }
  }
  let even_max = get_max_key_value(&even);
  let odd_max = get_max_key_value(&odd);

  if even_max.0 != odd_max.0 {
    println!("{}", n as u32 - even_max.1 - odd_max.1);
  } else {
    even.remove(&even_max.0);
    odd.remove(&odd_max.0);

    let even_2nd_max = get_max_key_value(&even);
    let odd_2nd_max = get_max_key_value(&odd);
    if even_2nd_max.1 > odd_2nd_max.1 {
      println!("{}", n as u32 - odd_max.1 - even_2nd_max.1);
    } else {
      println!("{}", n as u32 - even_max.1 - odd_2nd_max.1);
    }
  }
}

fn get_max_key_value(map: &HashMap<u32, u32>) -> (u32, u32) {
  let mut max = (0, 0);
  for (key, value) in map {
    if max.1 < *value {
      max = (*key, *value);
    }
  }
  max
}

Measured memory_bytes: 8444
def main():
    s = input()
    n = len(s) + 1
    ans = [-1] * (n)
    def right(i, ans):
        j = 1
        while True:
            ans[i + j] = max(ans[i + j], j)
            if i + j == n - 1:
                break
            if s[i + j] == '<':
                j += 1
            else:
                break
        return ans
    def left(i, ans):
        j = 1
        while True:
            ans[i - j] = max(ans[i - j], j)
            if i - j == 0:
                break
            if s[i - j - 1] == '>':
                j += 1
            else:
                break
        return ans
    for i in range(n):
        if i == 0:
            if s[i] == '<':
                ans[0] = 0
                ans = right(i, ans)
            else:
                pass
        elif i == n - 1:
            if s[i - 1] == '>':
                ans[n - 1] = 0
                ans = left(i, ans)
            else:
                pass
        else:
            if s[i] == '<' and s[i - 1] == '>':
                ans[i] = 0
                ans = right(i, ans)
                ans = left(i, ans)
            else:
                pass
    print(sum(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 49480
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    if (int(s.length()) != a + b + 1|| s[a] != '-') {
        printf("No\n");
        return 0;
    }
    for (int i = 0; i < int(s.length()); i++) {
       if ( i != a && s[i] == '-') {
            printf("No\n");
            return 0;
       }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<sys/time.h>
#define ck 26

unsigned long long seed;

unsigned long long xorshift(){
  seed=seed^(seed<<13);
  seed=seed^(seed>>7);
  seed=seed^(seed<<17);
  return seed;
}

int d;
int c[32];
int s[512][32];
int res[512];

int eval(){
  int i,j,lc[32],r=0;
  for(i=1;i<=ck;i++){lc[i]=-1;}
  for(i=0;i<d;i++){
    r+=s[i][res[i]];
    lc[res[i]]=i;
    for(j=1;j<=ck;j++){
      r-=c[j]*(i-lc[j]);
    }
  }
  return r;
}

int sum(int x){
  return (x*(x+1))/2;
}

int delq(int tg,int x){
  if(res[tg]==x){return 0;}
  int r,i;
  int bfb=-1,bff=d,afb=-1,aff=d;
  r=s[tg][x]-s[tg][res[tg]];

  for(i=tg-1;i>=0;i--){
    if(res[i]==res[tg]){bfb=i;break;}
  }
  for(i=tg+1;i<d;i++){
    if(res[i]==res[tg]){bff=i;break;}
  }

  for(i=tg-1;i>=0;i--){
    if(res[i]==x){afb=i;break;}
  }
  for(i=tg+1;i<d;i++){
    if(res[i]==x){aff=i;break;}
  }
  
  r+=c[res[tg]]*sum((tg-bfb)-1);
  r+=c[res[tg]]*sum((bff-tg)-1);
  r-=c[res[tg]]*sum((bff-bfb)-1);

  r-=c[x]*sum((tg-afb)-1);
  r-=c[x]*sum((aff-tg)-1);
  r+=c[x]*sum((aff-afb)-1);
  return r;
}

void getperm(int n,int p[]){
  int i,tg,mem;
  for(i=0;i<n;i++){
    p[i]=i;
  }
  for(i=n-1;i>=1;i--){
    tg=(xorshift()%(i+1));
    mem=p[tg];
    p[tg]=p[i];
    p[i]=mem;
  }
}

int main(){
  long long stt,nt;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  seed=(tv.tv_sec*1000000+tv.tv_usec);
  stt=seed;
  int i,j,q,r,tg,x,p[32],dv[32];
  int tgpm[512];
  scanf("%d",&d);
  for(i=1;i<=ck;i++){scanf("%d",&c[i]);}
  for(i=0;i<d;i++){
    for(j=1;j<=ck;j++){
      scanf("%d",&s[i][j]);
    }
  }
  for(i=0;i<d;i++){
    res[i]=(i%ck)+1;
  }
  r=eval();
  q=0;
  getperm(d,tgpm);
  while(1){
    tg=tgpm[q];
    for(i=1;i<=ck;i++){dv[i]=delq(tg,i);}
    getperm(ck,p);
    for(i=0;i<ck;i++){
      if(dv[res[tg]]<=dv[p[i]+1]){res[tg]=p[i]+1;}
    }
    q++;
    if(q==d){
      getperm(d,tgpm);
      q=0;
      gettimeofday(&tv, NULL);
      nt=(tv.tv_sec*1000000+tv.tv_usec);
      if((nt-stt)>=1988000){break;}
    }
  }
  for(tg=0;tg<d;tg++){
    for(i=1;i<=ck;i++){dv[i]=delq(tg,i);}
    getperm(ck,p);
    for(i=0;i<ck;i++){
      if(dv[res[tg]]<=dv[p[i]+1]){res[tg]=p[i]+1;}
    }
  }
  for(i=0;i<d;i++){
    printf("%d\n",res[i]);
  }
  return 0;
}


Measured memory_bytes: 1764
s = list(map(int, list(input())))

mod = 2019

mods = [0 for i in range(2019)]
mods[0] += 1

num = 0

pow10mod = 1

for i in range(len(s)):
    num = (num + s[-(i+1)] * pow10mod) % mod
    mods[num] += 1
    pow10mod = pow10mod * 10 % mod

ans = 0

for i in range(2019):
    m = mods[i]
    ans += (m * (m-1) // 2)


print(int(ans))


Measured memory_bytes: 12024
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_factorize(n):
    a = Counter()
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a


def com(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    r = min(r, n - r)
    numer = denom = 1
    for i in range(n - r + 1, n + 1):
        numer = numer * i
    for i in range(1, r + 1):
        denom = denom * i
    return numer // denom


def main():
    N = int(readline())

    prime = Counter()
    for n in range(1, N + 1):
        prime.update(prime_factorize(n))

    C = [0] * 101
    for v in prime.values():
        C[v] += 1

    for i in range(99, -1, -1):
        C[i] += C[i + 1]

    ans = 0
    ans += (C[2] - 2) * com(C[4], 2)
    ans += (C[2] - 1) * C[24]
    ans += (C[4] - 1) * C[14]
    ans += C[74]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9464
let rec range a b = if a > b then [] else a :: range (a+1) b
let (>>=) x f = List.map f x |> List.concat

let () =
  let h, w = Scanf.scanf "%d %d\n" (fun h w -> h, w) in
  let ss = Array.init h (fun _ ->
               Scanf.scanf "%s\n" (fun x -> x)) in
             
  (range 0 (h-1) >>= fun i ->
   range 0 (w-1) >>= fun j -> [(i, j)])
  |> List.for_all (fun (i, j) ->
         ss.(i).[j] = '.'
         || List.exists (fun (x, y) ->
                try ss.(x).[y] = '#' with _ -> false)
              [(i-1, j); (i+1, j); (i, j-1); (i, j+1)])
  |> function
    | true -> print_endline "Yes"
    | false -> print_endline "No"
  



Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
const int maxn = 1<<18;
int arr[maxn], best[maxn];
int main(){
  int n;
  scanf("%d", &n);
  for(int e = 0; e < 1<<n; e++) scanf("%d", arr + e);
  int now = 0;
  for(int e = 1; e < 1<<n; e++){
    int un[2] = {};
    auto add = [&](int v){
      if(v > un[0]){
        un[1] = un[0];
        un[0] = v;
      } else if(v > un[1]){
        un[1] = v;
      }
    };
    for(int msk = e; msk ; msk = (msk - 1) & e){
      add(arr[msk]);
    }
    add(arr[0]);
    now = max(now, un[0] + un[1]);
    printf("%d\n", now);
  }
  return 0;
}


Measured memory_bytes: 4096
#include <iostream>

int main(void)
{
    int n;
    std::cin >> n;
    for(int i = 1; i <= n; i++) {
        int x = i;
        if(x % 3 == 0) {
            std::cout << " " << i;
            continue;
        }
        do {
            if(x % 10 == 3) {
                std::cout << " " << i;
                break;
            } else {
                x /= 10;
            }
        }while(x);
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n, m, p;
    while(cin >> n >> m >> p, n|m|p){
        vector<int> vec(n);
        int sum = 0;
        for(auto &v: vec){
            cin >> v;
            sum += v;
        }
        int v = vec[--m];
        cout << (v ? (100-p)*sum/v : 0) << endl;
    }
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c=MI()
    N=b*10+c
    if N%4==0:
        print("YES")
    else:
        print("NO")

main()


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a[1000], n, m, h, k, r[1000], H1[100000], H2[100000], b[1000]; vector<pair<int, int>>x;
int main() {
	while (true) {
		cin >> n >> m >> h >> k; x.clear(); if (n == 0)break; for (int i = 0; i < n; i++) { cin >> a[i]; r[i] = i; }
		for (int i = 0; i < m; i++) { int p1, p2; scanf("%d%d", &p2, &p1); p2--; x.push_back(make_pair(p1, p2)); }
		sort(x.begin(), x.end());
		for (int i = 0; i < x.size(); i++) { H1[i] = r[x[i].second]; H2[i] = r[x[i].second + 1]; swap(r[x[i].second], r[x[i].second + 1]); }
		int sum = 0, minx = 0; for (int i = 0; i < n; i++) { if (r[i] < k)sum += a[i]; b[r[i]] = a[i]; }
		for (int i = 0; i < x.size(); i++) { if (H1[i] < k && H2[i] >= k)minx = min(minx, b[H2[i]] - b[H1[i]]); if (H1[i] >= k && H2[i] < k)minx = min(minx, b[H1[i]] - b[H2[i]]); }
		cout << sum + minx << endl;
	}
	return 0;
}

Measured memory_bytes: 4436
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	ans := ""
	for i := 0; i < len(S); i++ {
		diff := S[i] + byte(N) - 'A'
		diff %= 26
		ans += string(diff + 'A')
	}
	fmt.Println(ans)
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    int n, m;
    cin >> n >> m;

    int a;
    priority_queue<ll> pq;
    for(int i = 0; i < n; i++){
        cin >> a;
        pq.push(a);
    }

    while(m){
        ll u = pq.top(); pq.pop();

        pq.push(u / 2);
        m--;
    }

    ll ans = 0;
    while(!pq.empty()){
        ans += pq.top(); pq.pop();
    }
    cout << ans;
}








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

int a[2001];

int dfs(int n,int i,int sum,int m){
  if(i>n||sum>m)return 0;
  if(sum==m)return 1;
  int b = dfs(n,i+1,sum+a[i],m) || dfs(n,i+1,sum,m);
  return b;
}

int main(){
  int n,q,m;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>m;
    if(dfs(n,0,0,m))cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int h, w;
    std::cin >> h >> w;
    std::vector<std::vector<char>> s(h, std::vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            std::cin >> s[i][j];
        }
    }
    bool ans = true;
    rep(i, h) {
        rep(j, w) {
            if(s[i][j] != '#') continue;
            bool flag = false;
            if(i < h - 1 and s[i + 1][j] == '#')
                flag = true;
            else if(i > 0 and s[i - 1][j] == '#')
                flag = true;
            else if(j < w - 1 and s[i][j + 1] == '#')
                flag = true;
            else if(j > 0 and s[i][j - 1] == '#')
                flag = true;

            if(!flag) {
                ans = false;
                break;
            }
        }
    }
    std::cout << (ans ? "Yes" : "No") << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=2147483647;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=2e5+5;
int n,m,h[maxn],x,y,ans,maxx[maxn];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) h[i]=read();
	while(m--){
		x=read(),y=read();
		maxx[x]=max(maxx[x],h[y]);
		maxx[y]=max(maxx[y],h[x]);
	}
	for(int i=1;i<=n;i++) 
		if(h[i]>maxx[i]) ++ans;
	printf("%d\n",ans);
	return 0;
}


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

bool rec(int a,int b,int c,int d){  
  if(a==5&&b==5)return false;
  
  if(a<5&&c<5&&!rec(min(5,c+a),d,a,b))return true;
  if(b<5&&c<5&&!rec(min(5,c+b),d,a,b))return true;
  if(a<5&&d<5&&!rec(c,min(5,d+a),a,b))return true;
  if(b<5&&d<5&&!rec(c,min(5,d+b),a,b))return true;
  return false;
}

int main(){
  int a,b,c,d;
  while(cin>>a>>b>>c>>d){    
    cout<<( !rec(a,b,c,d)?"NAKAJIMA":"ISONO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import math

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
R=[]
#print(A)
for i in range(N-1):
    for j in range(i+1,N):
        #print(i,j)
        x=A[i][0]
        y=A[i][1]
        a=A[j][0]
        b=A[j][1]
        tmp=((x-a)**2+(y-b)**2)**0.5
        R.append(tmp)

x=math.factorial(N)
a=(N-1)*x/(len(R))
c=sum(R)
print(c*a/x)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ha 1000000007
#define inv2 500000004
using namespace std;

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=200010;
const int M=8000;
int fac[M+10],ifac[M+10];
int f[M/2+10][M/2+10],base=M/4+2;
int n,A[N],B[N];

int Pow(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=1ll*a*a%ha)
        if(b&1) ans=1ll*ans*a%ha;
    return ans;
}

void Init()
{
    fac[0]=1;
    for(int i=1;i<=M;i++)
        fac[i]=1ll*fac[i-1]*i%ha;
    ifac[M]=Pow(fac[M],ha-2);
    for(int i=M-1;i>=0;i--)
        ifac[i]=1ll*ifac[i+1]*(i+1)%ha;
}

int C(int n,int m){return 1ll*fac[n]*ifac[m]%ha*ifac[n-m]%ha;}

int main()
{
    Init(); n=read();
    for(int i=1;i<=n;i++)
    {
        A[i]=read(),B[i]=read();
        f[base-A[i]][base-B[i]]++;
    }
    for(int i=1;i<=M/2+2;i++)
        for(int j=1;j<=M/2+2;j++)
            f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%ha)%ha;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+f[A[i]+base][B[i]+base])%ha;
        ans=(ans-C(2*A[i]+2*B[i],2*A[i]))%ha;
    }
    ans=(ans+ha)%ha;
    ans=1ll*inv2*ans%ha;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int n; cin>>n;
	double p[n+1];
	for(int i=1; i<=n; i++) cin>>p[i];
	double dp[n+1][n+1]; //p of j heads among first i coins
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1.0;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=n; j++){
			dp[i][j] = dp[i-1][j] * (1.0-p[i]);
			if(j!=0) dp[i][j] += (dp[i-1][j-1]*p[i]);
		}
	}
	double sm=0.0;
	for(int j=(n/2)+1; j<=n; j++){
		sm += dp[n][j];
	}
	cout<<fixed;
	cout<<setprecision(12)<<sm;
}

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

int main(void) {
int a, b , x;
std::cin >> a >> b >> x;

if (a <= x && a + b >= x) {
  std::cout << "YES" << '\n';
  return 0;
}

std::cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    int a, b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" <<endl;
    }
	if(a > b){
        cout << "a > b" <<endl;
    }
    if(a == b){
        cout << "a == b" <<endl;
    }
	return 0;
}



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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>=0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=ma>sum?ma:sum;
      for(tmp=sum;i<n && a[i]<0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=ma>sum?ma:sum;

    cout << (flg?m:ma) << endl;
  }
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
const long long int MOD = 1000000007;
long long int dp[MAXN][MAXN][MAXN];
int main()
{
	int n,m;
	cin>>n>>m;
	dp[0][1][1] = 1;
	for (int i = 0; i <= m; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			for (int k = 0; k <= n; ++k)
			{
				dp[i+1][j][j] = (dp[i+1][j][j] + dp[i][j][k]*k)%MOD;
				dp[i+1][j+1][k] = (dp[i+1][j+1][k] + dp[i][j][k]*(n-j))%MOD;
				dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k]*(j-k))%MOD;
			}
		}
	}
	cout<<dp[m][n][n]<<"\n";
	return 0;
}

Measured memory_bytes: 217984
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_lines n "%s" id

let () =
  let h = Hashtbl.create n in
  ListL.iter ls ~f:(fun s ->
      Hashtbl.replace h s true);
  Printf.printf "%d\n" @@ Hashtbl.length h


Measured memory_bytes: 26420