akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, -1)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

int cnt;
int m;
Vi G;

void insertionSort(Vi &A, int n, int g) {
   REP(i, g, n) {
      int v = A[i];
      int j = i - g;
      while (j >= 0 && A[j] > v) {
         A[j+g] = A[j];
         j = j - g;
         cnt++;
      }
      A[j+g] = v;
   }
}

void shellSort(Vi &A, int n) {
   cnt = 0;
   rep(i, m) insertionSort(A, n, G[i]);
}

int main() {
   int n; cin >> n;
   Vi A = Vi(n); rep(i, n) cin >> A[i];

   rrep(i, 30) {
      int g = pow(2, i);
      if (g <= n) G.pb(g);
   }
   m = G.size();
   shellSort(A, n);

   cout << m << endl;
   cout << G[0]; REP(i, 1, m) cout << " " << G[i]; cout << endl;
   cout << cnt << endl;
   for(int a: A) cout << a << endl;

   return 0;
}



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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int n; cin >> n;
  vector<ll> a(n); REP(i,n) cin >> a[i];
  ll ans = 0;
  bool f = false;
  ll sum = 0;
  REP(i,n) {
    if (a[i] == 0) {
      ans += sum/2;
      sum = 0;
    } else {
      sum += a[i];
    }
  }
  ans += sum/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;

public class Main {
	enum marks {
		S, H, C, D;
	}

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			int n = Integer.parseInt(br.readLine());
			HashSet<String> strSet = new HashSet<String>();

			for (marks mark : marks.values()) {
				for (int i = 1; i <= 13; i++) {
					strSet.add(mark + " " + i);
				}
			}

			for (int i = 0; i < n; i++) {
				strSet.remove(br.readLine());
			}
			
			String[] strs = (String[]) strSet.toArray(new String[0]);
			
			Arrays.sort(strs, new Comparator<String>() {
				@Override
				public int compare(String o1, String o2) {
					int flg;
					flg = marks.valueOf(o1.split("\\s")[0]).compareTo(
							marks.valueOf(o2.split("\\s")[0]));
					if (flg == 0) {
						return Integer.parseInt(o1.split("\\s")[1])
								- Integer.parseInt(o2.split("\\s")[1]);
					} else {
						return flg;
					}
				}		
			});
			
			for (String str : strs){
				System.out.println(str);
			}
			
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 19872
#include <bits/stdc++.h>
#define maxn 10006
using namespace std;

typedef pair<int, int> P;

int main()
{
	int ans = 0;
	for (int i = 0; i < 6; i++)
	{
		char c;
		scanf(" %c", &c);
		if (c == '1')
			ans++;
	}
	printf("%d", ans);

	return 0;
}


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

vector<string> normals;

void solve(string s, int n){
  if(s.size()==n){
    normals.push_back(s);
    return;
  }
  
  set<char> sc;
  for(int i=0;i<s.size();++i){
    sc.insert(s[i]);
  }
  
  for(char i='a';i<='a'+sc.size();++i){
    string tmp{i};
    solve(s+tmp,n);
  }
}

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

  solve("a",N);
  
  sort(normals.begin(),normals.end());
  
  for(int i=0;i<normals.size();i++){
    cout << normals[i] << endl;
  }
}


Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":	" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

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

ll f (ll n) {
  ll ret = 0;
  while (n > 0) {
    n %= pcnt(n);
    ret++;
  }
  return ret;
}

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

  ll t = 0;
  for (auto c:s) if (c=='1') t++;

  ll a = t-1;
  ll b = t;
  ll c = t+1;

  vector<ll> va(n, 1);
  vector<ll> vb(n, 1);
  vector<ll> vc(n, 1);

  rep(i, n-1) {
    if (a>0) va[n-i-2] = (va[n-i-1]*2) % a;
    if (b>0) vb[n-i-2] = (vb[n-i-1]*2) % b;
    if (c>0) vc[n-i-2] = (vc[n-i-1]*2) % c;
  }

  ll aa = 0;
  ll bb = 0;
  ll cc = 0;
  rep(i, n) {
    if (s[i]=='1') {
      aa += va[i];
      bb += vb[i];
      cc += vc[i];
    }
  }

  rep(i, n) {
    if (s[i]=='1') {
      if (a<=0) cout << 0 << endl;
      else cout << f((aa+a-va[i])%a)+1 << endl;
    } else {
      cout << f((cc+vc[i])%c)+1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 8428
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n, q; cin >> n >> q;

	multimap<int, int> st;
	multimap<int, int> tt;

	FOR_LT(i, 0, n) {
		int s, t, x; cin >> s >> t >> x;
		st.insert(make_pair(s - x, x));
		tt.insert(make_pair(t - x, x));
	}

	auto it_s = st.begin();
	auto it_t = tt.begin();
	multiset<int> ad;
	FOR_LT(i, 0, q) {
		int d; cin >> d;

		while (it_s != st.end() && (it_s->first <= d)) {
			ad.insert(it_s->second);
			it_s++;
		}
		while (it_t != tt.end() && (it_t->first <= d)) {
			ad.erase(ad.find(it_t->second));
			it_t++;
		}
		if (ad.empty()) {
			cout << -1 << endl;
		}
		else {
			cout << (*ad.begin()) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 29440
#include <stdio.h>

int main(){
int A,B,C;
scanf("%d %d %d",&A,&B,&C);
if (A==B && B==C){
printf("No\n");
}
else if(A != B && A != C && B != C) {
printf("No\n");
}
else {
printf("Yes\n");
}
return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
  N = int(input())
  A = []
  B = []
  for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
  ans = 0
  for i in range(N-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
      continue
    ans += B[i] - (A[i]+ans) % B[i]
  print(ans)

Measured memory_bytes: 11052
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        int[] p = new int[Q];
        int[] q = new int[Q];
        for (int i = 0; i < Q; ++i) {
            p[i] = sc.nextInt();
            q[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R, p, q));

        sc.close();
    }

    static String solve(int N, int[] L, int[] R, int[] p, int[] q) {
        @SuppressWarnings("unchecked")
        List<Integer>[] rightLists = new List[N + 1];
        for (int i = 0; i < rightLists.length; ++i) {
            rightLists[i] = new ArrayList<>();
        }

        for (int i = 0; i < L.length; ++i) {
            rightLists[L[i]].add(R[i]);
        }

        for (int i = 0; i < rightLists.length; ++i) {
            Collections.sort(rightLists[i]);
        }

        int[] result = new int[p.length];
        for (int i = 0; i < result.length; ++i) {
            for (int j = p[i]; j <= q[i]; ++j) {
                result[i] += findTrainNum(rightLists[j], q[i]);
            }
        }

        return Arrays.stream(result).mapToObj(String::valueOf).collect(Collectors.joining("\n"));
    }

    static int findTrainNum(List<Integer> rightList, int rightLimit) {
        int result = 0;
        int lower = 0;
        int upper = rightList.size() - 1;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            if (rightList.get(middle) <= rightLimit) {
                result = middle + 1;
                lower = middle + 1;
            } else {
                upper = middle - 1;
            }
        }

        return result;
    }
}

Measured memory_bytes: 64600
if __name__ == "__main__":
    s = list(input())
    t = list(input())

    s.sort()
    t.sort(reverse=True)

    index = 0
    while True:
        if index > len(s) - 1 or index > len(t) - 1:
            print('No')
            exit()
        if ord(s[index]) < ord(t[index]):
            print('Yes')
            exit()
        index += 1
        if index == min([len(s), len(t)]) and ord(s[index-1]) > ord(t[index-1]):
            print('No')
            exit()
        if index == min([len(s), len(t)]) and len(s) < len(t):
            print('Yes')
            exit()


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec B(N);
    REP(i,0,N-1) cin >> B[i];

    ll sum = B[0] + B[N-2];
    REP(i,1,N-1) sum += MIN(B[i-1],B[i]);
    PR(sum);

    return 0;
}

/*



*/

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int M = 20+5;
const int N = 50000+5;
const int inf = 1e9;

int n;
int m;
int d[M];
int memo[N];

int main(){
	ri2(n, m);
	for(int j = 0; j < m; j++) ri(d[j]);
	memo[0] = 0;
	for(int i = 1; i <= n; i++){
		memo[i] = inf;
		for(int j = 0; j < m; j++){
			if(i < d[j]) continue;
			memo[i] = min(memo[i], 1 + memo[i - d[j]]);
		}
	}
	printf("%d\n", memo[n]);
	return 0;
}


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

int main() {

  string N;
  cin >> N;

  if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 3596
'use strict'

class List {
    constructor()
    {
        const n = new Node;
        n.prev = n;
        n.next = n;
        this.nil = n;
    }

    insert(x)
    {
        const n = new Node(x);
        this.nil.next.prev = n;
        n.next = this.nil.next;
        this.nil.next = n;
        n.prev = this.nil
    }

    search(x)
    {
        let node = this.nil.next
        while(node.key !== null && node.key !== x){
            node = node.next;
        }
        return node
    }

    delete(x)
    {
        this.deleteNode(this.search(x))
    }
    
    deleteNode(node)
    {
        if(node.key === null){
            return
        }
        node.prev.next = node.next
        node.next.prev = node.prev
    }

    deleteFirst()
    {
        this.deleteNode(this.nil.next)
    }

    deleteLast()
    {
        this.deleteNode(this.nil.prev)
    }

    print()
    {
        let node = this.nil.next;
        let str = ''
        for(let i = 0; node.key !== null; i++){
            if(i > 0){
                str += ' '
            }
            str += node.key.toString()
            node = node.next
        }
        return str
    }
}

class Node {
    constructor(key = null, prev = null, next = null)
    {
        this.key = key;
        this.prev = prev;
        this.next = next;
    }
}


const main = (input) => {
    input = input.split('\n')
    const n = parseInt(input[0])
    const com = input.slice(1, n + 1)
    const list = new List;
    com.forEach(v => {
        if(v[0] === 'i'){
            const num = parseInt(v.split(' ')[1])
            list.insert(num)
        }else{
            if(v === 'deleteFirst'){
                list.deleteFirst()
            }else if(v === 'deleteLast'){
                list.deleteLast()
            }else{
                const num = parseInt(v.split(' ')[1])
                list.delete(num)
            }
        }
    })
    console.log(list.print())
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


Measured memory_bytes: 261652
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll X, ans;


void solve(){
    ans += 1000 * (X/500);
    X %= 500;
    ans += 5 * (X/5);

    cout << ans << endl;
}

int main(){
    cin >> X;

    solve();
}


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    solve();
}

#[allow(unused_variables)]
fn solve() {
    let n: u64 = input_ints()[0];

    let mut v = Vec::<Vec<u64>>::with_capacity(n as usize);
    
    for i in 0..n {
        v.push(input_ints());
    }

    let mut plus_num: u64 = 0;

    for v_i in v.iter().rev() {
        let b = v_i[1];
        let a = v_i[0] + plus_num;
        if a == 0 {
            continue;
        }
        if a < b {
            plus_num += b - a;
        } else {
            let m = a % b;
            if m != 0 {
                plus_num += b - m;
            }
        }
    }

    println!("{}", plus_num);

}

#[allow(dead_code)]
fn input_ints() -> Vec<u64> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => Vec::<u64>::new(),
    }
}

#[allow(dead_code)]
fn input_strs() -> Vec<String> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.to_string()).collect(),
        Err(_) => Vec::<String>::new(),
    }
}



Measured memory_bytes: 4348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        CP sc = new CP();
        long a= sc.nextLong(), b= sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = a*c;
        long y = a*d;
        long z = b*c;
        long v = b*d;
        System.out.println(Math.max(x,Math.max(y,Math.max(z,v))));
    }

    /*****************************************************************************/
    static class CP {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        public CP() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextInt() {
            return Integer.parseInt(NNNN());
        }

        long nextLong() {
            return Long.parseLong(NNNN());
        }

        double nextDouble() {
            return Double.parseDouble(NNNN());
        }

        String NNNN() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        String nextLine() {
            String spl = "";
            try {
                spl = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return spl;
        }
    }
    /*****************************************************************************/
}

Measured memory_bytes: 32584
import sys

readline = sys.stdin.readline

MOD = pow(10,9)+7

def combinations(n,k):
    global fac, finv
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

def main():
    global fac, finv
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A.sort()

    MAX_NUM = N + 1

    fac  = [0 for _ in range(MAX_NUM)]
    finv = [0 for _ in range(MAX_NUM)]
    inv  = [0 for _ in range(MAX_NUM)]

    fac[0]  = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,MAX_NUM):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

    summax = 0
    summin = 0
    for i in range(N-K+1):
        j = N-i
        tmp = combinations(j-1, K-1)
        summax += A[j-1] * tmp
        summin += A[i] * tmp
        #print('max:{}, min:{}'.format(A[j-1] * tmp, A[i] * tmp))
    ans = (summax - summin) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18996
#include <bits/stdc++.h>
using namespace std;
vector<int>vecx;
vector<int>vecy;
int main(){
    int n,m,a,b,x=0,y=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(a==1){
            vecx.push_back(b);
            x++;
        }
        if(b==n){
            vecy.push_back(a);
            y++;
        }
    }
    if(x==0||y==0){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    sort(vecx.begin(),vecx.end());
    sort(vecy.begin(),vecy.end());
    x=0,y=0;
    while(x<=vecx.size()&&y<=vecy.size()){
        if(vecx[x]==vecy[y]){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
        if(vecx[x]<vecy[y])x++;
        else y++;
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int n, k;
string s;

int main() {
    cin >> n >> k;
    cin >> s;
    int ret = 0;
    for(int i = 1; i < n; i++)
        if (s[i] == s[i - 1]) ret++;
    cout << min(ret + 2 * k, n - 1) << endl; 
}

Measured memory_bytes: 512
// 2020-08-31 14:20:12
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int h, w;
  cin >> h >> w;
  vector<vector<int> > a(h, vector<int>(w, 0));
  rep(i, h) rep(j, w) cin >> a[i][j];
  vector<P> ans1, ans2;
  rep(i, h) rep(j, w - 1) {
    if (a[i][j] % 2) {
      a[i][j]--;
      a[i][j + 1]++;
      ans1.emplace_back(i + 1, j + 1);
    }
  }
  rep(i, h - 1) {
    if (a[i][w - 1] % 2) {
      a[i][w - 1]--;
      a[i + 1][w - 1]--;
      ans2.emplace_back(i + 1, w);
    }
  }
  cout << int(ans1.size()) + ans2.size() << '\n';
  for (auto [i, j] : ans1) {
    cout << i << ' ' << j << ' ' << i << ' ' << j + 1 << '\n';
  }
  for (auto [i, j] : ans2) {
    cout << i << ' ' << j << ' ' << i + 1 << ' ' << j << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 5252
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
def fight(k):
    c = k
    for i in h:
        hp = i - B * k
        if hp > 0:
            c -= -(-hp // (A - B))
        if c < 0:
            return False
    return True

lo = 0
hi = 10 ** 9
while hi - lo > 1:
    mid = (lo + hi) // 2
    if fight(mid):
        hi = mid
    else:
        lo = mid
print(hi)

Measured memory_bytes: 7072
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int main(){
	ll a,b,c,r,n;
	while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&r),n){
		int cnt=0;
		while(n--){
			ll t;
			scanf("%ld",&t);
			while(cnt<=10010&&r!=t){
				r=(a*r+b)%c;
				cnt++;
			}
			r=(a*r+b)%c;
			cnt++;
		}
		printf("%d\n",cnt<=10001?cnt-1:-1);
	}
}


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


int main () {
  int A, B, C, D, cost = 0;
  cin >> A >> B >> C >> D;
  if (A < B) cost += A;
  else cost += B;
  if (C < D) cost += C;
  else cost += D;
  cout << cost << endl;
}

Measured memory_bytes: 3536
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] nums = new int[n];
      
      int maxNum = -1;
      for(int i = 0; i < n; i++) {
        nums[i] = sc.nextInt();
        maxNum = Math.max(maxNum, nums[i]);
      }
      
      int halfNum = maxNum / 2;
      
      int maxIdx = -1;
      for(int i = 0; i < n; i++) {
        int a = nums[i];
        if(a == maxNum) continue;
        if(a > halfNum) {
          a = maxNum - a;
        }
        if(maxIdx == -1 || a > Math.min(nums[maxIdx], maxNum - nums[maxIdx])){
          maxIdx = i;
        }
      }
      System.out.println(maxNum + " " + nums[maxIdx]);
  }
}

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

int main () {
  int N , M ;
  cin >> N >> M ;
  int nul[M] = {} ;
  for(int i = 0 ; i < N ; i++ ){
    int k = 0 ;
    cin >> k ;
    for(int j = 0 ; j < k ; j++ ){
      int a ;
      cin >> a ;
      nul[a-1]++ ;
    }
  }
  int ans = 0 ;
  for(int i = 0 ; i < M ; i++ ){
    if(nul[i]==N) ans ++ ;
  }
  cout << ans << endl ;
  //for(int i = 0 ; i < M ; i++ ) cout << nul[i] << endl ;
}

Measured memory_bytes: 256
from sys import stdin
from math import floor,ceil

N, K = map(int, input().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def is_max_len_less_than_input(x,K,A):
  count = 0
  if x==0:
    return False
  for ln in A:
    count += ceil(ln/x)-1
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = (begin+end)//2
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return end

print(binary_search(0,max(A),K,A))

Measured memory_bytes: 104452
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int a[3][3];
   f(i,0,3){
      f(j,0,3){
         cin >> a[i][j];
      }
   }
   int n;
   cin >> n;
   map<int,int> cnt;
   f(i,0,n){
      int x;
      cin >> x;
      cnt[x] = 1;
   }
   // Row;
   f(i,0,3){
      int s = 0;
      int r = 0;
      f(j,0,3){
         s += cnt[a[i][j]];
         r += cnt[a[j][i]];
      }
      if(s == 3 or r == 3){
         cout << "Yes\n";
         return 0;
      }
   }
   if(cnt[a[0][0]] + cnt[a[1][1]] + cnt[a[2][2]] == 3 or cnt[a[0][2]] + cnt[a[1][1]] + cnt[a[2][0]] == 3){
      cout << "Yes";
   }else{
      cout << "No\n";
   }
   return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, sum, i;

	while(scanf("%d%d", &a, &b) != EOF)
	{
		sum = a + b;
		for(i=0;sum!=0;i++)
		{
			sum /= 10;
		}
		printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 596
using System;

namespace Vanila
{
    public class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();

            Console.WriteLine((int.Parse(N) + 1) * int.Parse(N) / 2);
        }
        public static long Max(long a, long b)
        {
            if (a <= b) return b;
            else return a;
        }
        public static long Min(long a, long b)
        {
            if (a == Max(a, b)) return b;
            else return a;
        }
        public static long GCD(long a, long b)
        {
            while (Max(a, b) % Min(a, b) != 0)
            {
                if (a < b) b %= a;
                else a %= b;
            }
            return Min(a, b);
        }
        public static long LCM(long a, long b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

int selection_sort(int a[], int n){
    int cnt = 0;
    for(int i=0; i<n; i++){
        int minj = i;
        for(int j=i; j<n; j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(i != minj){
            swap(a[i], a[minj]);
            cnt++;
        }
    }
    return cnt;
}

int main(){
    int n, a[100];
    cin >> n;
    for(int m=0; m<n; m++){
        cin >> a[m];
    }
    int cnt = selection_sort(a, n);
    for(int i=0; i<n; i++){
        if(i == 0){
            cout << a[i];
            continue;
        }
        cout << ' ' << a[i];
    } 
    cout << '\n';
    cout << cnt << endl;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>
int month[10] = {20,19,20,19,20,19,20,19,20,19};
int daycount(int *y,int *m,int *d);
int main(void){
	int *y, *m, *d;
	int n, i, mir;
	int Y = 1000, M = 1, D = 1;
	scanf("%d",&n);
	mir = daycount(&Y,&M,&D);
	y = (int *)malloc(sizeof(int) * n);
	m = (int *)malloc(sizeof(int) * n);
	d = (int *)malloc(sizeof(int) * n);
	for(i = 0;i < n;i++)
		scanf("%d %d %d",y + i,m + i,d + i);
	for(i = 0;i < n;i++)
		printf("%d\n",mir - daycount(y + i,m + i,d + i));
	return 0;
}
int daycount(int *y,int *m,int *d){
	int sum = 0,i , j;
	for(i = 0;i < *y - 1;i++){
		if((i + 1) % 3 == 0)
			sum += 200;
		else{
			for(j = 0;j < 10;j++)
				sum += month[j];
		}
	}
	for(i = 0;i < *m - 1;i++){
		if(*y % 3 == 0)
			sum += 20;
		else
			sum += month[i];
	}
	sum += *d;
	return sum;
}

Measured memory_bytes: 596
def main():
    N = int(input())
    h = [0] + [int(i) for i in input().split()]
    memo = [float('inf')] * (N+1)

    memo[1] = 0
    for j in range(2, N+1):
        for i in range(j-2, j):
            memo[j] = min(memo[j], memo[i] + abs(h[j] - h[i]))

    print(memo[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 52464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define endl '\n'

const long long M = 998244353;

template<typename T>
struct seg_tree{
    int n;
    vector<T> tree, start, lazy;

    seg_tree(vector<T> start_) : start(start_){
        n = start_.size();
        tree.resize(n * 4);
        lazy.resize(n * 4);
        build(1, 1, n);
    }

    seg_tree(int n_) : n(n_){
        seg_tree(vector<T>(n_));
        tree.resize(n * 4);
        lazy.resize(n * 4);
    }

    T identity(){
        return 0;
    }

    T merge(T a, T b){
        return (a + b)%M;
    }
    
    void build(int id, int l, int r){
        if (l == r) tree[id] = start[l-1];
        else{
            int m = (l+r)>>1;
            build(id<<1, l, m);
            build(id<<1|1, m+1, r);
            tree[id] = merge(tree[id<<1], tree[id<<1|1]);
        }
    }

    void prop(int id, int l, int r){
        if (lazy[id]){
            tree[id] += lazy[id] * (r - l + 1) % M; // merge / set
            if (l != r){
                lazy[id<<1] += lazy[id];
                lazy[id<<1|1] += lazy[id];
            }
            lazy[id] = 0;
        }
    }

    void upd(int id, int l, int r, int lq, int rq, T val){
        if (l > rq || r < lq) prop(id, l, r);
        else if (lq <= l && r <= rq){
            lazy[id] += val;
            prop(id, l, r);
        } else{
            prop(id, l, r);
            int m = (l+r)>>1;
            upd(id<<1, l, m, lq, rq, val);
            upd(id<<1|1, m+1, r, lq, rq, val);
            tree[id] = merge(tree[id<<1], tree[id<<1|1]);
        }
    }

    T qry(int id, int l, int r, int lq, int rq){
        prop(id, l, r);
        if (l > rq || r < lq) return identity();
        if (lq <= l && r <= rq) return tree[id];
        int m = (l+r)>>1;
        return merge(qry(id<<1, l, m, lq, rq), qry(id<<1|1, m+1, r, lq, rq));
    }

    void upd(int pos, T val){upd(1, 1, n, pos, pos, val);}
    void upd(int l, int r, T val){upd(1, 1, n, l, r, val);}
    T qry(int l, int r){return qry(1, 1, n ,l, r);}
    T qry(int pos){return qry(1, 1, n , pos, pos);}
};

void solvetask(){
    int n, m; cin >> n >> m;
    seg_tree<long long> stree(n+1);
    vector<array<long long, 2>> a(m);
    for (int i=0; i<m; i++) cin >> a[i][0] >> a[i][1];
    stree.upd(1, 1);
    for (int i=1; i<n; i++){
        long long cur = stree.qry(i);
        for (int j=0; j<m; j++){
            int l = i + a[j][0], r = min((long long)n, i + a[j][1]);
            if (l > n) continue;
            stree.upd(l, r, cur);
        }
    }
    cout << stree.qry(n) << endl;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}

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

int main()
{
	int n,k,cnt=0;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; ++i) cin >> h[i];
	
	for (int i = 0; i < n; ++i)
	{
		if (h[i] >= k)
		{
			cnt++;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

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

using namespace std;

int arr[101][101]={0,};
int dp[101][101]={0,};

vector <int> prime;

void eratos(void)
{
	bool isprime[101];

	memset(isprime,true,sizeof(isprime));

	for(int i=2;i<=100;i++)
	{
		if(isprime[i])
		{
			isprime[i]=false;
			prime.push_back(i);
			for(int j=2*i;j<=100;j+=i)
			{
				isprime[j]=false;
			}
		}
	}
}

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

	int n;

	eratos();

	cin >> n;

	for(int i=2;i<=100;i++)
	{
		int x = i;
		for(int j=0;j<prime.size();j++)
		{
			if(x==1 || x<prime[j])
			{
				break;
			}
			if(x%prime[j]==0)
			{
				while(1)
				{
					if(x%prime[j]!=0)
					{
						break;
					}
					arr[i][prime[j]]++;
					x/=prime[j];
				}
			}
		}
	}

	for(int i=2;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			dp[i][j] = dp[i-1][j] + arr[i][j];
		}
	}

	int res = 0;

	for(int i=0;i<prime.size();i++)
	{
		if(dp[n][prime[i]]>=74)
		{
			res++;
		}
		for(int j=i+1;j<prime.size();j++)
		{
			if(dp[n][prime[i]]>=24 && dp[n][prime[j]]>=2)
			{
				res++;
			}
			if(dp[n][prime[i]]>=2 && dp[n][prime[j]]>=24)
			{
				res++;
			}			
			if(dp[n][prime[i]]>=14 && dp[n][prime[j]]>=4)
			{
				res++;
			}
			if(dp[n][prime[i]]>=4 && dp[n][prime[j]]>=14)
			{
				res++;
			}						
			for(int k=j+1;k<prime.size();k++)
			{
				if(dp[n][prime[i]]>=4 && dp[n][prime[j]]>=4 && dp[n][prime[k]]>=2)
				{
					res++;
				}
				if(dp[n][prime[i]]>=4 && dp[n][prime[j]]>=2 && dp[n][prime[k]]>=4)
				{
					res++;
				}
				if(dp[n][prime[i]]>=2 && dp[n][prime[j]]>=4 && dp[n][prime[k]]>=4)
				{
					res++;
				}								
			}
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 384
N = int(input())
D = [list(map(int,input().split())) for _ in range(N)]
i = 0
judge=False
for a,b in D:
  if a==b:
    i+=1
  else:
    i=0
  if i>=3:
    judge=True
    break
    
if judge:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 62356
import Control.Monad

solve :: String -> [(String,Int)] -> Int
solve _ [] = 0
solve x ((s,t):xs) 
    | x == s = sum $ map snd xs
    | otherwise = solve x xs

main = do
    n <- readLn :: IO Int
    xs <- replicateM n $ do
        [s,t] <- words <$> getLine
        return (s, read t :: Int) 
    x <- getLine :: IO String
    print $ solve x xs


Measured memory_bytes: 1020
#include <stdio.h>

int main(void){
  int num;
  float h,w;

  while(1){
    scanf("%d,%f,%f",&num,&w,&h);
    if(feof(stdin))break;

    if(25.0<=w/(h*h)){
      printf("%d\n",num);
    }
  }
  return(0);
}

Measured memory_bytes: 628
a,b=map(int,input().split())
c=[int(i) for i in input().split()]
c.sort()
d=c[-1]-c[0]
for i in range(b-1):
    c[-i-1]=c[-i-1]-c[-i-2]
c[0]=0
c.sort()
print([sum(c[:b-a+1]),0][a >=b])

Measured memory_bytes: 13840
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    s=input()
    ans=0
    for c1,c2 in zip(s,s[::-1]):
        if c1!=c2:ans+=1
    print(ans//2)
main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int N=100000+10;
typedef long long LL;
int n,s[N];
map<int,LL> sum[N],sum2[N];
vector<int> divs[N];
int gcd(int x,int y){
    return y==0?x:gcd(y,x%y); 
}
LL pre[N];
int main() {
    for(int i=1;i<N;i++)for(int j=i;j<N;j+=i) divs[j].push_back(i); 
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&s[i]); 
    for(int i=n-1;i>=0;i--){
        int d=n-1-i;
        for(auto x: divs[d]){
            if(x>=i) continue;
            sum[i][x] = sum[i+x][x] + s[i];
            int r = d / x;
            sum2[i][x] = sum2[i+x][x] + s[x*r];
        }
    }
    LL ans=0;
    for(int a=1;a<n-1;a++) {
        int d=n-1-a;
        for(auto x: divs[d]) {
            //x=a-b
            if(x>=a) continue;
            int b=a-x;
            int g=gcd(a,b);
            LL aa=a/g, bb=b/g;
            if(aa - bb == 1 && aa * a - (aa - 1)*b < n-1) continue;
            LL tmp=sum2[a][a-b]+sum[a][a-b];
            // printf("tmp=%lld, a=%d, b=%d [%d, %d]\n", tmp,a,b,sum2[a][a-b],sum[a][a-b]);
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;
}
/*
a a-b 2a-b 2a-2b 3a-2b 3a-3b
ka-kb = (t+1)a-tb
(k-t-1)a=(k-t)b
k-t-1=b/g
k-t=a/g
a=10, b=9
8 2 10
6 2 8 4 10
*/

Measured memory_bytes: 159744
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(i+1<s.length() && s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
		if(i+2<s.length() && s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    X, A = LI()
    if X < A: print(0)
    else: print(10)
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int H, W;
	cin >> H >> W;

	vector<vector<char>> v(H + 2, vector<char>(W + 2));
	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			v.at(i).at(j) = '.';
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> v.at(i).at(j);
		}
	}

	//for (int i = 0; i < H + 2; i++) {
	//	for (int j = 0; j < W + 2; j++) {
	//		cout << v.at(i).at(j);
	//	}
	//	cout << endl;
	//}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			char ch = v.at(i).at(j);
			if (ch == '#') {
				bool b = false;
				if (v.at(i - 1).at(j) == '#') b = true;
				if (v.at(i + 1).at(j) == '#') b = true;
				if (v.at(i).at(j - 1) == '#') b = true;
				if (v.at(i).at(j + 1) == '#') b = true;
				
				if (!b) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;
}

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

int main() {
    int N;
    cin >> N;
    
    vector<int> a(N+1);
    rep(i,N+1) {
        cin >> a[i];
    }
    
    vector<long int> d_max(N+1), d_min(N+1), max(N+1);
    bool tf = true;
    
    reverse(a.begin(), a.end());
    
    rep(i,N+1) {
        if(i == 0) {
            d_min[i] = a[0];
            d_max[i] = a[0];
        }
        else {
            d_min[i] = (d_min[i-1] + 1) / 2 + a[i];
            d_max[i] = d_max[i-1] + a[i];
        }
    }
    
    if(d_min[N] > 1)
        tf = false;
    
    reverse(d_max.begin(), d_max.end());
    reverse(a.begin(), a.end());
    
    if(a[N] < 1)
        tf = false;
    
    rep(i,N+1) {
        if(i == 0)
            max[i] = 1;
        else {
            max[i] = min((max[i-1] - a[i-1]) * 2, d_max[i]);
            if(max[i] < max[i-1] - a[i-1])
                tf = false;
        }
    }
    
    long int sum = 0;
    if(tf) {
        rep(i,N+1) {
            sum += max[i];
        }
    }
    else
        sum = -1;
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 5868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

void solve(){

}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,n;
	ll ans=0;
	char c;
	cin>>h>>w>>n;
	vl sx(n+1),sy(n+1);
	int tx,ty;
	vvl vv(h+2,vl(w+2,-1));
	rep(i,h){
		rep(j,w){
			cin>>c;
			vv[i+1][j+1]=(c!='X'?INF:-1);
			if(c=='S'){sx[0]=i+1,sy[0]=j+1;}
			if(1<=c-'0'&&c-'0'<=9){sx[c-'0']=i+1;sy[c-'0']=j+1;}
		}
	}
	rep(i,n){

		queue<pll> q;
		vv[sx[i]][sy[i]]=0;
		q.push(pll(sx[i],sy[i]));
		while(!q.empty()){
			tie(tx,ty)=q.front();q.pop();
			rep(i,4){
				if(vv[tx+dx[i]][ty+dy[i]]==INF){
					vv[tx+dx[i]][ty+dy[i]]=vv[tx][ty]+1;
					q.push(pll(tx+dx[i],ty+dy[i]));
				}
			}
		}
		ans+=(vv[sx[i+1]][sy[i+1]]-vv[sx[i]][sy[i]]);
		rep(i,h){
			rep(j,w){
				if(vv[i+1][j+1]!=-1)vv[i+1][j+1]=INF;
			}
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;

int n, m;
int nxt[N];

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        nxt[i] = n + 1;

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        nxt[a] = min(nxt[a], b);
    }

    int cutoff = n + 1, ans = 0;
    for (int i = 1; i <= n; i++) {
        if (cutoff == i) {
            ans++;
            cutoff = n + 1;
        }
        cutoff = min(cutoff, nxt[i]);
    }
    cout << ans;
}


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

using namespace std;
using ll = long long;

int main() {
  int x;
  cin >> x;
  if (x) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

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

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

  for(int i=0; i<n; i++){
    int count=0;
    for(int j=0;j<=i; j++){
      if(v[j]<=v[i]) count++;
      if(count == i+1) honmei++;
    }
  }
    cout << honmei << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main() {
  int H,N;
  cin>>H>>N;
  vector<int>A(N),B(N);
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  vector<int>dp(H+1,INF);
  dp[0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<=H;j++){
      if(dp[j]==INF){continue;}
      chmin(dp[min(H,j+A[i])],dp[j]+B[i]);
    }
  }
  cout<<dp[H]<<endl;
  return 0;  
}

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


int main()
{
	int a,b,c;
  	cin>>a>>b>>c;
  	int k=0;
  	for(int i=min(a,b) ; i>=0 ; --i)
    {
    	if(a%i==0 && b%i==0)
        ++k;
        if(k==c)
        {
            cout<<i<<endl;
            return 0;
        }
    }
	return 0;
}


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


using namespace std;


int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<int> p(a); for (int i=0; i<a; i++) cin >> p[i];
    vector<int> q(b); for (int i=0; i<b; i++) cin >> q[i];
    vector<int> r(c); for (int i=0; i<c; i++) cin >> r[i];

    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());

    vector<int> s;
    for (int i=0; i<x; i++) s.push_back(p[i]);
    for (int i=0; i<y; i++) s.push_back(q[i]);
    for (int i=0; i<c; i++) s.push_back(r[i]);
    sort(s.begin(), s.end(), greater<int>());

    long long ans = 0;
    for (int i=0; i<x+y; i++) {
        ans += s[i];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572