akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
        ll x;
        mint(ll x = 0):x((x % mod + mod) % mod) {}
        mint operator-() const { return mint(-x); }
        mint& operator+=(const mint a) {
            if ((x += a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator-=(const mint a) {
            if ((x += mod - a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator*=(const mint a) {
            (x *= a.x) %= mod;
            return *this;
        }
        mint operator+(const mint a) const {
            mint res(*this);
            return res += a;
        }
        mint operator-(const mint a) const {
            mint res(*this);
            return res -= a;
        }
        mint operator*(const mint a) const {
            mint res(*this);
            return res *= a;
        }
        mint pow(ll t) const {
            if (!t) return 1;
            mint a = pow(t >> 1);
            a *= a;
            if (t & 1) a *= *this;
            return a;
        }
        // for prime mod
        mint inv() const {
            return pow(mod - 2);
        }
        mint& operator/=(const mint a) { return (*this) *= a.inv(); }
        mint operator/(const mint a) const { mint res(*this); return res /= a; }
        bool operator<(const mint& a)const{ return x < a.x;}
        bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
void solve1() {
    int n;
    cin >> n;
    vector<vector<mint>> dp(4, vector<mint>(n+1, 0));

    // init;
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        dp[3][i+1] += dp[3][i] * 10;
        // 0, 9
        dp[3][i+1] += dp[1][i] + dp[2][i];
        // 0 -> 0, 9 -> 9
        dp[1][i+1] += dp[1][i] * 9;
        dp[2][i+1] += dp[2][i] * 9;
        // non -> 0, non -> 9
        dp[1][i+1] += dp[0][i];
        dp[2][i+1] += dp[0][i];
        // non -> non
        dp[0][i+1] += dp[0][i] * 8;
    }
    cout << dp[3][n] << '\n';
}

void solve2() {
    int n;
    cin >> n;
    // 包除原理
    // 全体 - (0を含まない順列) - (9を含まない順列) + (0, 9を含まない順列)
    // 10 ** n - 9 ** n - 9 ** n + 8 ** n
    mint ans = ex(10, n) - (mint)2 * ex(9, n) + ex(8, n);
    cout << ans << '\n';
}
/* main */
int main(){
    // solve1();
    solve2();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int n;
ll c[200001],rp4[200001];
int main(){
    cin>>n;
    rep(i,n) cin>>c[i];
    sort(c,c+n);reverse(c,c+n);
    ll cs=0,p2=1,p4=1,sp2=2,ans=0;
    rep(i,n-1) p4*=4,p4%=mod;
    rp4[0]=1;
    rep(i,n){
        ans+=((p4*sp2)%mod)*c[i];
        ++sp2;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int counter = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if (i * 500 + j * 100 + k * 50 == X)
                {
                    counter++;
                }
            }
        }
    }
    cout << counter << endl;
    return (0);
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,  *p = map(int, read().split())

i_min = float('inf')
ans = 0
for x in p:
    if x <= i_min:
        ans += 1
        i_min = x
print(ans)

Measured memory_bytes: 20408
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
int ma[5] = { -2,-1,0,1,2 };
int t[4] = { 1,0,-1,0 };
int y[4] = { 0,-1,0,1 };
const int INF = 1e9;


int main() {
	int H, W;
	int Ch, Cw, Dh, Dw;
	cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
	vector<string>s(H);
	vector<vector<int>>cn(H, vector<int>(W,INF));
	rep(i, H)cin >> s[i];
	Ch--; Cw--; Dh--, Dw--;
	cn[Ch][Cw] = 0;
	deque<P> q;
	P p = make_pair(Ch, Cw);
	q.push_back(p);
	while (!q.empty()) {
		//cout << q.size() << endl;
		P p=q.front(); q.pop_front();
		int i = p.first; int j = p.second;
		int d = cn[i][j];
		//cout << i << " " << j << " " << d << endl;
		rep(ai, 4) {
			int ii = i + t[ai]; int jj = j + y[ai];
			if (ii < 0 || ii >= H || jj<0 || jj>=W)continue;
			P pp = make_pair(ii, jj);
			if (cn[ii][jj] <= d)continue;
			if (s[ii][jj] == '.') {
				q.push_front(pp);
				cn[ii][jj] = d;
			}
		}
		rep(bi, 5) {
			rep(ci, 5) {
				int ii = i + ma[bi]; int jj = j + ma[ci];
				//cout << ii << " " << jj << endl;
				if (ii < 0 || ii >= H || jj < 0 || jj >= W)continue;
				if (cn[ii][jj] <= d)continue;
				P pp = make_pair(ii, jj);
				if (s[ii][jj] == '.') {
					cn[ii][jj] = d + 1;
					q.push_back(pp);
					//cout << "a" << endl;
				}

			}
		}
		//cout << i << " " << j << endl;
	}
	if (cn[Dh][Dw] == INF) {
		cout << -1;
		return 0;
	}
	cout << cn[Dh][Dw];

	return 0;
}

Measured memory_bytes: 10000
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	
	int sum = 0;
	int N;
	
	cin>>N;
	
	for(int i = 1; i <= N; i++){
		if(i%3 && i%5) sum += i;
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007

#define N_MAX 200001
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    std::vector<int> bucket(N_MAX);
    for (int i = 0; i < N; i++) {
        bucket[A[i]]++;
    }

    std::sort(bucket.begin(), bucket.end());

    int count = 0;
    for (int i = 0; i < N_MAX; i++) {
        if (bucket[i] != 0) {
            count++;
        }
    }

    int ans = 0;
    if (count <= K) {
        std::cout << ans << std::endl;
    } else {
        int temp = 0;
        for (int i = 0; i < N_MAX; i++) {
            if (bucket[i] != 0) {
                ans += bucket[i];
                temp++;
            }
            if (count - temp <= K) {
                break;
            }
        }
        std::cout << ans << std::endl;
    }

    return 0;
}

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


int main() {
  int X;
  cin >> X;
  
  if(X >=30){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define one(x) cout<<#x<<" : "<<x<<endl;
#define two(x,y) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;


signed main()
{
    int n , i;
    string s;
    cin >>n ;
    cin >> s;
    int cnt=0;
    for(i=0 ;i <n-1; i++)
    {
        if(s[i]!=s[i+1])
        {
            cnt++;
        }

    }
    cout<<cnt+1<<endl;


}




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

#define int long long int


int32_t main()
{
  int q;
  cin>>q;
 
    while(q--)
    {
         int a,b;
    cin>>a>>b;
    if(a==b)
    cout<<2*a-2<<endl;
    else
    {
      int max_score=a*b-1;
      int l=1,h=1<<30;
      while(abs(h-l)>1)
      {
        int mid=(l+h)/2;
        if(mid*mid>max_score)
        h=mid;
        else
        l=mid;
      }
      if(l*(l+1)<=max_score)
      cout<<2*l-1<<endl;
      else
      cout<<2*l-2<<endl;
    } 
    }
}

Measured memory_bytes: 3632
import math


def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i = i + 2

    return True


n = int(input())
numbers = [int(input()) for i in range(n)]


count = 0
for i in range(n):
    if is_prime(numbers[i]) is True:
        count += 1

print(count)



Measured memory_bytes: 6012
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    @lru_cache(None)
#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r
#
##    def comb2(n, r):
##        if n < 0 or r < 0 or n < r:
##            return 0
##        elif n == 0 or r == 0:
##            return 1
##        return comb2(n - 1, r - 1) + comb2(n - 1, r)
#
#    max = 0
#    comb_val1 = 0
#    comb_val2 = 0
#    for ele in itertools.combinations(A, 2):
#        buf_val1 = ele[0]
#        buf_val2 = ele[1]
#        if ele[1] > ele[0]:
#            buf_val1 = ele[1]
#            buf_val2 = ele[0]
##        print(buf_val1, buf_val2)
#        val = comb1(buf_val1, buf_val2)
#        if val >= max:
#            max = val
#            comb_val1 = buf_val1
#            comb_val2 = buf_val2
#    print(max)
#    print(str(comb_val1) + ' ' + str(comb_val2))

### n=10^5 * a=0~10^9の組み合わせがありうるので計算量は結局多いのでメモ化しても意味はない。

    N = max(A)
    A.remove(N)
    min_distance = 10 ** 10
    M = 0
    for a in A:
        if abs(N/2 - a) < min_distance:
            min_distance = abs(N/2 - a)
            M = a
    print("{} {}".format(N, M))

Measured memory_bytes: 14920
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  long long N, K, mmin = 3000000000;
  long long x[1000000];

  cin >> N >> K;

  for (int i = 0; i < N; i++) cin >> x[i];

  for (int i = 0; i < N - K + 1; i++) {
    long long l = abs(x[i]) + abs(x[i+K-1] - x[i]);
    long long r = abs(x[i+K-1]) + abs(x[i]- x[i+K-1]);
    long long m = min(l, r);
    mmin = min(m, mmin);
  }

  cout << mmin << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll k, a, b;
    cin >> k >> a >> b;

    // 単純に叩き続けた場合
    ll ans1 = 1+k;
    
    // 2回の操作で[ビスケットA枚をB枚にする]→2操作でB-A枚増やす
    // A>B+1じゃない場合、単純に叩き続けた場合で解決
    k -= (a-1);
    ll ans2 = a + (b-a)*(k/2) + (k%2 == 1 ? 1 : 0);

    // 大きい方を出力
    cout << max(ans1, ans2) << endl;
}

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

int main(void)
{
	int m, d;
	string s[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
	int mt[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

	while(cin >> m >> d){
		if(m == 0 && d == 0)
			break;

		int r;
		m--;
		int day = d;
		for(int i = 0; i < m; i++)
			day += mt[i];
		cout << s[(day - 1) % 7] << endl;
	}

	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int main() { 
    
    double r;
    const double PI  =3.141592653589793238463;
    cin >> r;
    double s = r*r*PI;
    double len = 2*PI*r;
   	cout << fixed << setprecision(6) << s << " " << fixed << setprecision(6) << len << endl;



    


    return 0;
}


Measured memory_bytes: 3276
A = int(input())
B = int(input())
C = int(input())
X = int(input())


def calc(val):
    pass
def main():
    cnt = 0
    ans = 0
    for i in range(C+1):
        ans_C = X - i*50
        if ans_C == 0:
            cnt+=1
            break
        elif ans_C < 0:
            break
        else:
            pass

        for j in range(B+1):
            ans_B = ans_C - j*100
            if ans_B == 0:
                cnt+=1
                break
            elif ans_B < 0:
                break
            else:
                pass

            for k in range(A+1):
                ans_A = ans_B - k*500
                if ans_A == 0:
                    cnt+=1
                    break
                elif ans_A < 0:
                    break
                else:
                    pass
    
    print(cnt)

                
if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String dat=br.readLine();
		int n=Integer.parseInt(br.readLine());
		for (int i=0;i<n;i++){
			String[] a=br.readLine().split(" ");
			dat=ans(a,dat);
			
		}
	
	}	
	public static String ans(String[] array,String src){
		if (array[0].equals("print")){
			int p=Integer.parseInt(array[1]);
			int q=Integer.parseInt(array[2]);
			System.out.println(src.substring(p,q+1));
		}else if(array[0].equals("reverse")){
			int p=Integer.parseInt(array[1]);
			int q=Integer.parseInt(array[2]);
			char temp;
			char[] csrc=src.toCharArray();
			while(q>p){
				temp=csrc[p];
				csrc[p]=csrc[q];
				csrc[q]=temp;
				p++;q--;
			}
			src=String.valueOf(csrc);
		}else{
			int p=Integer.parseInt(array[1]);
			int q=Integer.parseInt(array[2]);
			char[] csrc=src.toCharArray();
			char r;
			for(int i=0;i+p<=q;i++){
				r=array[3].charAt(i);
				csrc[i+p]=r;
			}
			src=String.valueOf(csrc);
		}
		return src;
	}
}

Measured memory_bytes: 22196
use proconio::{input,fastout};

#[fastout]
fn main() {
    input! {
        n:i32,
        m:i32,
        a:[i32;m],
    };
    let sum = a.iter().fold(0,|sum,i|sum+i);
    if sum<=n{
        println!("{}",n-sum);
    }
    else {
        println!("{}",-1);
    }
    


}



Measured memory_bytes: 2244
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main(){
    int n,ans;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(m[x]==0) v.push_back(x);
        ++m[x];
    }
    for(int i=0;i<v.size();++i) 
    if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5112
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

VInt EV[1 << 18];
VInt ES[1 << 18];
int PV[1 << 18];
int PS[1 << 18];
int B[1 << 18];
PII R[1 << 18];
int gMark;

int dfs(int s)
{
	if (B[s] == gMark) return 0;
	B[s] = gMark;
	for (auto it = ES[s].begin(); it != ES[s].end(); ++it)
	{
		if(PV[*it] == -1 || dfs(PV[*it]) != 0)
		{
			PV[*it] = s;
			PS[s] = *it;
			return 1;
		}
	}
	return 0;
}

int f(int n)
{
	gMark = 0;
	CLEAR(B, -1);
	CLEAR(PV, -1);
	CLEAR(PS, -1);
	int i, j;
	FOR(i, 0, n - 1)
		if(PS[i] == -1)
		{
			++gMark;
			if (dfs(i) == 0)
				return 0;
		}


	VInt bv(n, 0);
	VInt bs(n, 0);
	FOR(i, 0, n)
		if (PV[i] == -1)
			break;

	bv[i] = 1;
	queue<PII> q;
	for (auto it = EV[i].begin(); it != EV[i].end(); ++it) q.push(PII(i, *it));
	FOR(i, 1, n)
	{
		while (!q.empty() && bs[q.front().second] != 0) q.pop();
		if (q.empty()) return 0;
		int v = q.front().first;
		int s = q.front().second;
		int w = PS[s];
		bs[s] = 1;
		bv[w] = 1;
		R[s] = PII(v, w);
		for (auto it = EV[w].begin(); it != EV[w].end(); ++it) q.push(PII(w, *it));
	}

	return 1;
}

int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	FOR(i, 0, n - 1)
	{
		int m;
		scanf("%d", &m);
		FOR(j, 0, m)
		{
			int a;
			scanf("%d", &a);
			--a;
			EV[a].push_back(i);
			ES[i].push_back(a);
		}
	}

	if(f(n) == 0) printf("-1\n");
	else FOR(i, 0, n - 1) printf("%d %d\n", R[i].first + 1, R[i].second + 1);
	return 0;
};


Measured memory_bytes: 24696
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 50 + 5;
const int M = 100 + 5;
const ll OO = 1e18;
const int mod = 1e9 + 7;

int n,k,v[N],dp[N][N][M];

int solve(int s, int e, int g) {

    if(s>e) return 0;

    int &ret = dp[s][e][g];

    if(~ret) return ret;
    
    ret = 0;

    if(g>=1) {

        ret = max({ret, solve(s,e-1,g-1)+v[e],solve(s+1,e,g-1)+v[s]});

    }

    if(g>1) {

        ret = max({ret, solve(s,e-1,g-2),solve(s+1,e,g-2)});

    }

    return ret;

}

void init() {

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;

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

    memset(dp, -1, sizeof dp);

    cout << solve(0, n-1, k) << '\n';

    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define fod(i, r, l) for (int i = r; i >= l; i--)
#define pii pair<int, int>
#define vec vector<int>
#define vecl vector<long long>
#define umap unordered_map<int, int>
#define ll long long
#define yes cout << "Yes" \
                 << "\n";
#define no cout << "No" \
                << "\n";
#define en cout << "\n";
#define endl "\n";
#define inf 1000000001
#define mod 1000000007
#define pb push_back
#define mid(l, r) l + (r - l) / 2
#define all(arr) arr.begin(), arr.end()
#define mem(dp) memset(dp, 0, sizeof(dp));
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;
const int N = 100005;

inline int gcd(int a, int b)
{
    while (a != 0 && b != 0)
    {
        if (a > b)
        {
            a %= b;
        }
        else
        {
            b %= a;
        }
    }
    return max(a, b);
}

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

void solve()
{
    string a,b;
    cin>>a>>b;
    int j=0;
    for(int i=0;i<b.size();i++){
        if(a[j]!=b[i]){
            no
            return ;
        }
        j++;
        if(j==a.size()){
            yes
            return ;
        }
    }
    no
}

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

int main()
{
    fastio int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    int z = 0;
    int n = s.size();
    for(int i = 0; i < n; ++i) {
        if(s[i] == '0') ++z;

    }
    cout << min(n - z, z) * 2 << endl;
    return 0;
}



Measured memory_bytes: 512
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    for j in range(m):
        t=0
        for k in s[j][1:]:
            if(((i>>(k-1)))&1==1):
                t+=1
        if(t%2!=p[j]):
            break
    else:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

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

	cout << *mae(a) - *mie(a) << endl;
	ret 0;
}

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

typedef long long ll;

int main(void){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    vector<ll> dp(n, 1e18);
    dp[0] = 0;
    rep(i,n){
        rep1(j,k){
            if (i<j) break;
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 100 + 5;

int32_t main() {
    fastIO();
    
    int n, gcd = 0, lst, now;
    cin >> n >> lst;
    while (n--) cin >> now, gcd = __gcd(gcd, abs(lst - now)), lst = now;
    cout << gcd << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def mhd(x, y):
    return abs(x) + abs(y)

def calc(j, x, y):
    sx, sy = 1, 1
    if x < 0:
        x = -x
        sx = -1
    if y < 0:
        y = -y
        sy = -1
    
    if ((j*K) + K - y + x)%2 == 0:
        a = ((j*K) + K - y + x)//2
        b = j*K-a
        a *= sx
        b *= sy
        if mhd(a, b) == j*K:
            return (a, b)
    if ((j*K) - K - y + x)%2 == 0:
        a = ((j*K) - K - y + x)//2
        b = j*K-a
        a *= sx
        b *= sy
        if mhd(a, b) == j*K:
            return (a, b)
    return None

K = int(readline())
X, Y = map(int, readline().split())
ans = None
if mhd(X, Y) == K:
    print(1)
    print(X, Y)
elif (X+Y)&1 and K%2 == 0:
    print(-1)
else:
    ans = [(X, Y)]
    while True:
        px, py = ans[-1]
        md = mhd(px, py)
        if md == K:
            break
        j = -(-md//K)
        r1 = calc(j-1, px, py)
        if r1 is not None:
            ans.append(r1)
            continue
        r2 = calc(j, px, py)
        if r2 is not None:
            ans.append(r2)
            continue
        ans.append((px+K, py))
    ans.reverse()
    print(len(ans))
    print('\n'.join('{} {}'.format(*a) for a in ans))
        
            
            
            
            
    
    

Measured memory_bytes: 112324
from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
aka = x-1
midori = y-1
ps = p[:x]
qs = q[:y]
li = ps + qs
li.sort(reverse=True)
i = 0
z = d.popleft()
while li[x+y-1-i] < z:
  li[x+y-1-i] = z
  i += 1
  if not d:
    break
  z = d.popleft()
ans = 0
for i in range(x+y):
  ans += li[i]
print(ans)
  

Measured memory_bytes: 23480
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define p pair <int,int>
typedef long long ll;
using namespace std;
int main(int argc,char const* argv[])
{
  int n,count=1;
  cin >> n;
  vector<ll>a(n,0);
  bool tanpla=false;
  bool tanmi=false;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  for(int i=0;i<n-1;i++)
    {
      if(a[i+1]>a[i] && tanmi==false) 
	{
	  tanpla=true;
	}
      else if(a[i+1]<a[i] && tanpla==false) 
	{
	  tanmi=true;
	}
      if(a[i+1]<a[i] && tanpla==true) 
	{
	  count++;
	  tanpla=false;
	  tanmi=false;
	}
      else if(a[i+1]>a[i] && tanmi==true) 
	{
	  count++;
	  tanpla=false;
	  tanmi=false;
	} 
    }
  cout << count << endl;
	
  return 0;
    
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val L = listOfLong()
    val R = L.asReversed()
    val nk = Math.min(N, K)
    var ans = Long.MIN_VALUE
    for (l in 0 .. nk) {
        for (r in 0 .. nk - l) {
            val v = mutableListOf<Long>()
            v.addAll(L.subList(0, l))
            v.addAll(R.subList(0, r))
            v.sortDescending()
            val k = Math.min(K - (l + r), v.count { it < 0 })
            val d = v.subList(0, v.size - k).sum()!!
            if (ans < d) ans = d
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)

Measured memory_bytes: 41192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  string s;
  cin >> n >> s;
  a = n/2;
  if(n%2==1){
  cout << "No" << endl;
  }else{
    if(s.erase(a)==s.substr(a)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define pll  pair<ll,ll>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

void solve()
{
	ll n;
	cin>>n;
	vll a(n);
	ll m5=0,sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if(a[i]%10!=0)
			m5++;
	}
	if(sum%10==0)
	{
		if(m5==0)
		{
			cout<<0;
			return;
		}
		else
		{
			sort(all(a));
			for(ll i=0;i<n;i++)
			{
				if(a[i]%10!=0)
				{
					cout<<sum-a[i];
					return;
				}
			}
		}
	}
	else
		cout<<sum;
	return;
	
	
}            
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

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

void solve() {
    int N, K;
    cin >> N >> K;
    set<int> x;
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int a;
            cin >> a;
            x.insert(a);
        }
    }
    cout << N - x.size() << endl;
}

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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define pb push_back
#define pob pop_back
#define vi vt<long long>
#define vvi vt<vi>
#define vii vt<ii>
#define vvii vt<vii>
typedef long long ll;
#define For(i,a,b) for(int i = a; i < b; i++)
#define foR(i,a,b) for(int i = a; i <= b; i++)
#define roF(i,a,b) for(int i = a - 1; i >= b; i--)
#define Rof(i,a,b) for(int i = a; i >= b; i--)

vi sum;
long long a[1000];

signed main (){
	/*
	freopen(".inp","r",stdin);
	freopen(".out","w",stdout);
	*/
	long long n, k;
	cin >> n >> k;
	For(i,0,n){
		cin >> a[i];
	}
	long long temp;
	For(i,0,n){
		temp = 0;
		For(j,i,n){
			temp += a[j];
			sum.pb(temp);
//			cout << sum.back() << " ";
		}
	}
	long long ans = 0, coun;
	roF(i,41,0){
		coun = 0;
		For(j,0,sum.size()){
			if((sum[j] & (ans|(1LL<<i)))==(ans|(1LL<<i))){
				coun++;
			}
		}
		if (coun >= k){
			ans |= 1LL<<i;
//			cout << i << "\n";
		}
	}
	cout << ans;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    ll n; cin >> n;
    ll r = sqrt(static_cast<long double>(n));
    ll ans = 1e18;
    FOR(i,1,r+1){
        if(!(n % i == 0)) continue;
        ll s = n / i;
        if((s+i) < ans) ans = s+i;
    }
    ans -= 2;
    cout << ans << endl;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int INF = 10e8 + 5; 
typedef long long ll;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  multiset<int> m;
  for(int i = 1; i < n; i++){
    ll a;
    cin >> a;
    m.insert(a);
  }
  std::vector<int> v(n);
  for(int i = 0; i < n; i++){
    ll a = m.count(i+1);
    v[i] = a; 
  }
  for(auto i  : v) cout << i << endl;
  return 0;
}

/*
         ,--"""",--.__,---[],-------._         
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________
 
*/


Measured memory_bytes: 13496
#include<bits/stdc++.h>
using namespace std;
int n;
int a[110],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) 
	{
		int x;
		scanf("%d",&x);
		if(!a[x])
		{
			a[x]=1;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
local A, B, M = io.read("*n", "*n", "*n")
local a, b = {}, {}
for i = 1, A do
    a[i] = io.read("*n")
end
for i = 1, B do
    b[i] = io.read("*n")
end
local min_a = 10^5
local min_b = 10^5
for i = 1, A do
    min_a = math.min(min_a, a[i])
end
for i = 1, B do
    min_b = math.min(min_b, b[i])
end

local min_value = min_a + min_b
for i = 1, M do
    local x, y, c = io.read("*n", "*n", "*n")
    min_value = math.min(min_value, a[x] + b[y] - c)
end

print(min_value)

Measured memory_bytes: 4600
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

		static int[] mx = {1, 0, -1, 0};
		static int[] my = {1, 0, -1, 0};
		static int h;
		static int w;
		static char[][] map;

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

			String[] temp = scanner.nextLine().split(" ");
			int n  = Integer.parseInt(temp[0]);
			int m  = Integer.parseInt(temp[1]);

			String[] t = scanner.nextLine().split(" ");
			int[] sum  = new int[n];
			int[] lst  = new int[n];

			lst[0] = Integer.parseInt(t[0]);
			sum[0] = lst[0];
			for(int i = 1; i < n; i++) {

				lst[i] = Integer.parseInt(t[i]);
				sum[i] = lst[i] + sum[i - 1];
			}

			int max = 0;
			int num = 0;
			for(int i = 0; i < n - m; i++) {

				int te = sum[i + m] - sum[i];
				if(max < te) {
					max = te;
					num = i + 1;
				}
			}


			double ans = 0;

			for(int i = num; i < num + m; i ++) {

				for(int j = 1; j <= lst[i]; j++) {

					ans += ((double)j) / lst[i];
				}
			}

			System.out.println(ans);
		}
	}


Measured memory_bytes: 66028
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let n = v[0];
    let i = v[1];
    println!("{}", n - i + 1);
}


Measured memory_bytes: 4352
(function() {
    'use strict';

    var fs = require('fs');
    var contents = fs.readFileSync('/dev/stdin', 'utf-8');

    var printFrame = function(contents) {
        var lines = contents.trim().split("\n");
        for (var i = 0; i < lines.length; i++) {
            var b = lines[i].split(" ");
            var H = parseInt(b[0]);
            var W = parseInt(b[1]);

            if (H === 0 && W === 0) {
                break;
            }
            for (var h = 0; h < H; h++) {
                for (var w = 0; w < W; w++) {
                    if (h === 0 || h === H - 1 || w === 0 || w === W - 1) {
                        process.stdout.write("#");
                    } else {
                        process.stdout.write(".");
                    }
                }
                process.stdout.write("\n");
            }
            process.stdout.write("\n");
        }
    }
    printFrame(contents);
})();

Measured memory_bytes: 17684
n = int(input())
s = 'No'
if (n > 81) or (n < 1):
    print(s)
elif n < 10:
    print('Yes')
else:
    for i in range(1,10):
        if (n % i == 0) & (n // i <= 9):
            s = 'Yes'
            break
    print(s)

Measured memory_bytes: 3060
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

bool isSquare (ulong n) {
  ulong x = sqrt (n.to!double).roundTo!ulong;
  return x * x == n;
}

void main() {
  int n, d;
  readf (" %d %d", &n, &d);
  int[][] x;
  foreach (i; 0 .. n) {
    auto y = new int[d];
    foreach (j; 0 .. d) {
      readf (" %d", &y[j]);
    }
    x ~= y;
  }
  int res;
  foreach (i; 0 .. n) {
    foreach (j; i + 1 .. n) {
      if (isSquare (iota (0, d).map! (k => (x[i][k] - x[j][k]) ^^ 2).sum)) {
        ++res;
      }
    }
  }
  writeln (res);
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}


int main(void){
    int N;
    
    scanf("%d",&N);
    puts((N<1200)?"ABC":"ARC");
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

int main() {
	int H, W;
	cin >> H >> W;
	vs s(H);
	REP(i, H) {
		cin >> s[i];
	}

	REP(i, H) {
		REP(j, W) {
			if (s[i][j] == '#') {
				bool isolated = true;
				REP(d, 4) {
					int ni = i + dy[d], nj = j + dx[d];
					if (ni < 0 || H <= ni) {
						continue;
					}
					if (nj < 0 || W <= nj) {
						continue;
					}
					if (s[ni][nj] == '#') {
						isolated = false;
					}
				}
				if (isolated) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

//dp
int n, m;
vector<P> vp;
ll dp[510][1100];

int main() {
	cin >> n >> m;
	if (m == 0) {
		cout << n + 1 << endl;
		return 0;
	}
	rep(i, m) {
		ll c, d;
		cin >> c >> d;
		vp.push_back({ c,d });
	}
	sort(ALL(vp));
	vector<P> vp2;
	ll d = -1;
	rep(i, vp.size()) {
		//if (d < vp[i].second) {
		//	d = vp[i].second;
			vp2.push_back(vp[i]);
		//}
	}
	rep(i, 510)rep(j, 1010)dp[i][j] = INF;
	dp[0][0] = 0;
	int now = 0;
	rep(i, vp2.size()) {
		ll ci = vp2[i].first;
		ll di = vp2[i].second;
		FOR(j, di, n + 2) {//新しく経由する点
			FOR(k, now, n + 2) {//今までに経由した点
				if (k < j)dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + (j - now) + (j - ci));
				else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (ci - now));
			}
		}
		now = ci;
	}
	//FOR(i, 1, m + 1) {
	//	if (dp[i][5] == INF) {
	//		cout << i << endl;
	//		break;
	//	}
	//}
	//rep(i, vp2.size() + 1) {
	//	if (i != vp2.size())continue;
	//	rep(j, n + 1) {
	//		if (dp[i][j] != INF)printf("%4d", dp[i][j]);
	//		else cout << " INF";
	//	}
	//	cout << endl;
	//}
	ll ans = INF;
	rep(i, n + 2) {
		ans = min(dp[vp2.size()][i] + n + 1 - now, ans);
	}
	cout << ans << endl;
	//cout << dp[vp2.size()][d] + n + 1 - now << endl;
}

//int n, m;
//vector<P> vp;
//int sum[100100];
//
//int main() {
//	cin >> n >> m;
//	vp.resize(m);
//	rep(i, m) {
//		int a, b;
//		cin >> a >> b;
//		sum[a]++;
//		sum[b]--;
//	}
//	rep(i, n + 2)sum[i + 1] += sum[i];
//	ll ans = 0;
//	rep(i, n + 1) {
//		if (sum[i] > 0)ans += 3;
//		else ans++;
//	}
//	cout << ans << endl;
//}


Measured memory_bytes: 7532
# -*- coding: utf-8 -*-

n, m = gets.split.map(&:to_i)
a, b, c, d = Array.new, Array.new, Array.new, Array.new
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

distance = Array.new
number = Array.new
for i in 0...m do
  c, d = gets.split.map(&:to_i)
  for j in 0...n do
    distance[j] ||= 10**9
    tmp = (c-a[j]).abs + (d-b[j]).abs
    if tmp < distance[j]
      distance[j] = tmp
      number[j] = i+1
    end
  end
end

puts number


Measured memory_bytes: 1788
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int H,W;
	scanf("%d %d",&H,&W);
	int table[H][W];

	for(int k = 0; k < W; k++)scanf("%d",&table[0][k]);

	for(int i = 1; i < H; i++){
		for(int k = 0; k < W; k++){
			scanf("%d",&table[i][k]);
			table[i][k] = 1 - table[i][k];
		}
	}

	int ans = 0,left,right;

	for(int row = 0; row <= H-1; row++){
		left = 0;
		right = W-1;

		while(left <= right){
			if(table[row][left] == 1){
				ans++;
				left++;
				if(left <= right){
					table[row][left] = 1 - table[row][left];
				}
			}else if(table[row][right] == 1){
				ans++;
				right--;
				if(left <= right){
					table[row][right] = 1 - table[row][right];
				}
			}else{
				left++;
				if(left <= right){
					table[row][left] = 1 - table[row][left];
				}
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3248
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
xs = list(map(int,input().split()))

xs_arranged = sorted(xs)

ai = xs_arranged[-1]
xs_arranged.pop(-1)

aj = getNearestValue(xs_arranged, (ai/2))
    
print(ai,aj)

Measured memory_bytes: 31736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];
    auto solve=[&](ll x)->ll{
        ll ret=0;
        rep(i,n){
            if((x & a[i])==a[i]) ret+=b[i];
        }
        return ret;
    };
    ll ans=solve(k);
    rep(i,40){
        if((1ll<<i) & k){
            ll x=k^(1ll<<i);
            rep(j,i) x|=(1ll<<j);
            chmax(ans,solve(x));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4796