akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

/*int a[21], num, m, q;

bool dfs (int n, int sum)
{
    bool ret;
    if (n==num && sum!=m) return false;
    if (sum==m) return true;
    if (sum>m) return false;
    if (sum<m)
    {
        for (int i=n+1; i<=num; i++)
        {
            ret=dfs(i,sum+a[i]);
            if (ret) return true;
        }
        return false;
    }
}*/

int main()
{
    int n, q, a[25], m[210];
    bool dp[50000], ret[210], dpc[50000];
    /*cin>>num;
    for (int i=1; i<=num; i++) cin>>a[i];
    sort(a,a+num);
    cin>>q;
    bool ret[q];
    for (int i=0; i<q; i++)
    {
        cin>>m;
        ret[i]=dfs(0,0);
    }
    for (int i=0; i<q; i++) cout<<(ret[i] ? "yes\n" : "no\n");*/
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i];
    cin>>q;
    for (int i=0; i<q; i++) cin>>m[i];
    for (int i=0; i<q; i++) //for each query
    {
        for (int j=0; j<50000; j++) { dp[j]=false;  dpc[j]=false; } dp[0]=true; //initialization
        for (int j=1; j<=n; j++) //look through each element in the array
        {
            for (int k=0; k<=m[i]; k++)
            {
                if (dp[k]) dpc[k+a[j]]=true;
            }
            for (int k=0; k<=m[i]; k++) if (dpc[k]) dp[k]=true;
        }
        ret[i]=dp[m[i]];
    }
    for (int i=0; i<q; i++) cout<<(ret[i] ? "yes\n" : "no\n");
    return 0;
}



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

struct Card {char suit, value; };

void BubbleSort(struct Card c[], int n){
    Card a;
    for(int i = 0; i < n; i++){
        for(int j = n-1; j > i; j--){
            if(c[j].value < c[j-1].value){
                a = c[j];
                c[j] = c[j-1];
                c[j-1] = a;
            }
        }
    }
}

void SelectionSort(struct Card c[], int n){
    Card a;
    int minj;
    for(int i = 0; i < n; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(c[j].value < c[minj].value)
                minj = j;
        }
            a = c[i];
            c[i] = c[minj];
            c[minj] = a;
    }
}

int main(void){
    int n, cou = 0;
    Card c1[50], c2[50];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }
    BubbleSort(c1, n);
    SelectionSort(c2, n);
    
    for(int i = 0; i < n; i++){
        if(i == n-1)
        cout << c1[i].suit << c1[i].value << endl;
        else
        cout << c1[i].suit << c1[i].value << " ";
    }
    cout << "Stable" << endl;
    
    for(int i = 0; i < n; i++){
        if(i == n-1)
        cout << c2[i].suit << c2[i].value << endl;
        else
        cout << c2[i].suit << c2[i].value << " ";
        if(c1[i].suit != c2[i].suit)  cou++;
    }
    if(cou > 0)    
        cout << "Not stable" << endl;
    else    cout << "Stable" << endl;
    
    
    return 0;
}



Measured memory_bytes: 3104
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0
for i in range(2**h):
  for j in range(2**w):
    cnt=0
    for x in range(h):
      for y in range(w):
        if i>>x&1:continue
        if j>>y&1:continue
        if c[x][y]=="#":cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Measured memory_bytes: 68100
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;
int cnt[100000];
int main(){
  int N,M;
  cin >> N >> M;
  REP(i,M){
    int a,b;
    cin >> a >> b;
    cnt[a-1]++;
    cnt[b-1]++;
  }
  REP(i,N){
    if(cnt[i]%2 == 1){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i=0; i<N; i++) {
            B[i] = sc.nextInt();
        }

        int ans = solve4000334(N, A, B);

        System.out.println(ans);
    }

    private static int solve(int N, int[] A, int[] B) {

        List<Integer> pos = new ArrayList<>();
        List<Integer> neg = new ArrayList<>();

        for (int i=0; i<N; i++) {
            if (A[i] - B[i] >= 0) {
                pos.add(A[i] - B[i]);
            } else {
                neg.add(B[i] - A[i]);
            }
        }

        Collections.sort(pos, Collections.reverseOrder());
        Collections.sort(neg, Collections.reverseOrder());

        int count = 0;
        int possum = 0;
        while (neg.size() > 0) {
            count++;
            int value = neg.remove(0);

            // System.err.println("current negative = " + value);
            while (possum < value && pos.size() > 0) {
                possum += pos.remove(0);
                // System.err.println("current pos:" + possum);
                count++;
                if (value <= possum) break;
            }

            if (possum < value) return -1;

            possum -= value;
        }

        return count;
    }

    private static int solve4000334(int N, int[] A, int[] B) {
        long bal = 0;
        int[] C = new int[N];

        for (int i=0; i<N; i++) {
            bal += B[i];
            bal -= A[i];
            C[i] = A[i] - B[i];
        }

        if (bal > 0) return -1;

        int ch = 0;
        long f = 0;
        for (int i=0; i<N; i++) {
            if (C[i] < 0) {
                ch++;
                f -= C[i];
                C[i] = 0;
            }
        }

        Arrays.sort(C);
        for (int i=N-1; i>=0; i--) {
            long m = Math.min(f, C[i]);
            if (m > 0) {
                ch++;
                f -= m;
                C[i] -= m;
            }
        }

        return ch;
    }
}


Measured memory_bytes: 77212
#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>
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)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	while(cin >> n, n) {
		vs field(n);
		REP(i, n) {
			cin >> field[i];
		}

		vvi dp(n, vi(n));
		REP(i, n) {
			REP(j, n) {
				if(i == 0 || j == 0) {
					if(field[i][j] == '.') {
						dp[i][j] = 1;
					}
				} else {
					if(field[i][j] == '.') {
						dp[i][j] = min(dp[i-1][j], min(dp[i][j-1], dp[i-1][j-1]))+1;
					}
				}
			}
		}

		int ans = 0;
		REP(i, n) {
			REP(j, n) {
				ans = max(ans, dp[i][j]);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 6096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main()
{
    int N;
    cin >> N;
    if (N % 2 == 0)
    {
        double ans = 1. / 2;
        cout << fixed << setprecision(15) << ans << endl;
    }
    else
    {
        double ans = (N / 2 + 1) / (double)N;
        cout << fixed << setprecision(15) << ans << endl;
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    ll n; cin >> n;
    vll a(5);
    rep(i, 5) cin >> a[i];
    
    sort(all(a));
    ll c = a[0];
    
    ll tot = (n + c - 1) / c;
    
    cout << tot + 4 << endl;    
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
using pii = pair<int, int>;

int f(int n, int x) {
  int res = 0;
  int p = x;
  while (p <= n) {
    res += n / p;
    p *= x;
  }
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;

  vector<int> ps;
  for (int i = 2; i <= N; i++) {
    int no = 0;
    for (int j = 2; j*j <= i; j++) {
      if (i % j == 0) no = 1;
    }
    if (!no) ps.emplace_back(i);
  }
  int ans = 0;
  rep(i, 0, ps.size()) {
    if (f(N, ps[i]) >= 74) ans++;
  }
  rep(i, 0, ps.size()) {
    rep(j, 0, ps.size()) {
      if (i == j) continue;
      if (f(N, ps[i]) >= 2 && f(N, ps[j]) >= 24) ans++;
      if (f(N, ps[i]) >= 4 && f(N, ps[j]) >= 14) ans++;
    }
  }
  rep(i, 0, ps.size()) {
    rep(j, 0, ps.size()) {
      rep(k, 0, ps.size()) {
        if (i == j || i == k || j == k || k < j) continue;
        if (f(N, ps[i]) >= 2 && f(N, ps[j]) >= 4 && f(N, ps[k]) >= 4) ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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

#define MOD 1000000007

int main()
{
    long long N;
    cin >> N;
    long long ans = 1;
    while (N)
    {
        ans *= N;
        ans %= MOD;
        N--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
string str;
int K;
cin>>str>>K;
vector<pair<char,int> > vp;
vp.emplace_back(str[0],1);
for (int i = 1; i < str.size(); i++)
{
  if(vp.back().first == str[i]) vp.back().second++;
  else vp.emplace_back(str[i],1);
}
if(vp.size() == 1)
{
  cout<<(K*vp[0].second)/2<<endl;
  return;
}
int ANS = 0,T = 0;
ANS += vp[0].second/2;
for (int i = 1; i+1 < vp.size(); i++)T += vp[i].second/2;
ANS += T*K;
// DEBUG(ANS);
ANS += vp.back().second/2;

if(vp[0].first == vp.back().first)
{
  ANS += (K-1)*((vp[0].second + vp.back().second)/2);
}
else
{
  ANS += (K-1)*(vp[0].second/2 + vp.back().second/2);
}
cout<<ANS<<endl;

return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    cout << (N<=999 ? "ABC":"ABD") << endl;
    
    return 0;
}

Measured memory_bytes: 256
S = input()

# S = 'dreameraser'

words = ['dream', 'dreamer', 'erase', 'eraser']

while True:
    flag = False

    for word in words:
        # word=words[3]
        length = len(word)
        if S[-length:] == word:
            S = S[:len(S) - length]
            flag = True
            break

    if flag:
        if S == '':
            print('YES')
            break
        else:
            continue
    else:
        print('NO')
        break


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

#define ll long long
#define INF 99999999
void swap( vector<int>& target)
{
    int tmp;
    for(int i = 0;i < target.size()/2;i++)
    {
        tmp = target[i];
        target[i] = target[target.size()-i - 1];
        target[target.size()-i - 1] = tmp;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int>ans;
    for(int i = 0;i < n;i++) cin >> a[i];
    for(int i = 0;i < n;i++)
    {
        if(i%2==0)
        {
            ans.push_back(a[i]);
        }
        else
        {
            ans.insert(ans.begin(),a[i]);
        }
    }
    if(n%2==1) reverse(ans.begin(),ans.end());
    for(int j = 0;j < ans.size();j++) cout << ans[j] << " ";
    cout << endl;
}


Measured memory_bytes: 3828
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long n = input.nextInt();
        long d = input.nextInt();

        long remain = (long)(2 * Math.pow(10,9)) * 2;
        for (long i = n; i < d; i++) {
            for (long j = i + 1; j <= d; j++) {
                if((i*j)%2019 < remain)
                    remain = (i*j)%2019;
                if(remain == 0)
                    break;
            }
            if(remain == 0)
                break;
        }
        System.out.println(remain);
    }
}


Measured memory_bytes: 23764
using System;

namespace B___Power_Socket
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var c = 1;
            var ans = 0;
            while (c < b)
            {
                --c;
                c += a;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
    fast_io();

    int a, b;
    cin >> a >> b;

    if(b<=1) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;

    int counts = 1;

    while(counts< b) {
        ans++;
        counts += a-1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >>N;
  int sum = 0;
  vector<int> V(N);
  vector<int> C(N);
  for(int i=0;i<N;i++){
    cin >> V[i];
  }
  for(int i=0;i<N;i++){
    cin >> C[i];
  }
  for(int i=0;i<N;i++){
    if(V[i] > C[i]) sum+= V[i]-C[i];
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
s = input()
t = input()

alphas = [chr(i) for i in range(97,97+26)]

dics = {}
for a in alphas:
    dics[a] = s.count(a)
    s = s.replace(a, str(dics[a]))

dic_t = {}
for a in alphas:
    dic_t[a] = t.count(a)
    t = t.replace(a, str(dic_t[a]))

if s == t:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 7588
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long a, b, k, t;
	scanf("%lld %lld %lld", &a, &b, &k );
	t = k;
	k -= a;
	a = a-t;
	if( a < 0 ) b = b-k;
	printf("%lld %lld\n", max( a, 0ll ), max(b,0ll) );
	return 0;
}


Measured memory_bytes: 256
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from copy import copy
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inar():
    return [int(k) for k in input().split()]


def main():
    n,k=map(int,input().split())
    ar=list(map(int,input().split()))
    fr=[0]*(n+1)
    while(k):
        for i in range(n):
            mn=max(0,i-ar[i])
            mx=min(n-1,i+ar[i])
            fr[mn]+=1
            fr[mx+1]-=1
        k-=1
        for i in range(1,n):
            fr[i]=fr[i]+fr[i-1]
        ok=True
        for i in range(n):
            if(ar[i]!=fr[i]):
                ok=False
                break
        if(ok):
            break
        ar=copy(fr)
        fr = [0] * (n + 1)
    for i in range(n):
        print(ar[i],end=' ')
    print()












BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


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

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

    int zeros = 0, ones = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == '0') zeros++;
        else ones++;
    }

    cout << min(zeros,ones)*2;
}


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

using namespace std;

typedef long long LL;

const LL MAX_N = 2000 + 5;

struct Node {
    LL id;
    Node *nex;
    Node(LL id_ = 0, Node *nex_ = NULL)
        : id(id_), nex(nex_) {}
} *head[MAX_N];

void init() {
    for (LL i = 0; i < MAX_N; ++i) head[i] = new Node(-1, NULL);
}

void addEdge(LL u, LL v) {
    Node *e = new Node(v, head[u]->nex); head[u]->nex = e;
    Node *r = new Node(u, head[v]->nex); head[v]->nex = r;
}

LL n, k, A[MAX_N], B[MAX_N];

LL cal(LL u, LL fa, LL step) {
    LL ret = 0;
    if (step > k / 2) ++ret;
    for (Node *it = head[u]->nex; it != NULL; it = it->nex) {
        if (it->id != fa) {
            ret += cal(it->id, u, step + 1);
        }
    }
    // printf("Call cal(u = %lld, fa = %lld, step = %lld), ", u, fa, step);
    // printf("return (ret = %lld)\n", ret);
    return ret;
}

int main() {
    scanf("%lld%lld", &n, &k);
    LL u, v;
    init();
    for (LL i = 1; i <= n - 1; ++i) {
        scanf("%lld%lld", &u, &v);
        addEdge(u, v);
        A[i] = u; B[i] = v;
    }
    LL ans = INT_MAX;
    if (k % 2 == 0) {
        for (LL i = 1; i <= n; ++i) ans = min(ans, cal(i, -1, 0));
    } else {
        for (LL i = 1; i <= n - 1; ++i) ans = min(ans, cal(A[i], B[i], 0) + cal(B[i], A[i], 0));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main () {
    int N,M;
    cin>>N>>M;
    int x=N;
    for(int i=0;i<M;i++)
    {int A;
        cin>>A;
        x-=A;
    }
    if(x>=0)
        cout<<x;
    else
        cout<<"-1";
return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct weightedUnionFind{

    vector<int> par, rank, wei;

    void init(int n){
        par.resize(n);
        rank.resize(n, 0);
        wei.resize(n, 0);
        rep(i, n){
            par[i] = i;
        }
        return;
    }

    int root(int x){
        if(par[x] == x){
            return x;
        }else{
            int r = root(par[x]);
            wei[x] += wei[par[x]];
            return par[x] = r;
        }
    }

    bool unite(int x, int y, int w){
        w = -w;
        w += weight(x);
        w -= weight(y);
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return false;
        }
        if(rank[rx] < rank[ry]){
            swap(rx, ry);
            w = -w;
        }
        if(rank[rx] == rank[ry]){
            rank[rx]++;
        }
        par[ry] = rx;
        wei[ry] = w;
        return true;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int weight(int x){
        root(x);
        return wei[x];
    }

    int diff(int x, int y){
        return weight(x) - weight(y);
    }

};

int main(){
    int n, m;
    cin >> n >> m;
    weightedUnionFind uf;
    uf.init(n);
    bool flag = true;
    rep(i, m){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        if(uf.same(l, r)){
            if(uf.diff(l, r) != d){
                flag = false;
                break;
            }
        }else{
            uf.unite(l, r, d);
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
N, M = map(int, input().split())
D = [[float("inf")]*(N+1) for i in range(N+1)]
E = []
for i in range(M):
    a, b, c = map(int, input().split())
    E.append([a, b, c])
    D[a][b] = D[b][a] = c
for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])
cnt = 0
for e in E:
    a, b, c = e
    if D[a][b] != c:
        cnt += 1
print(cnt)


Measured memory_bytes: 3444
a, b, c, x, y = map(int,input().split())
p = (a + b) / 2

if x == y:
    ans = min(a * x + b * y, c * x * 2)
elif x > y:
    ans = min(a * x + b * y, c * x * 2, c * y * 2 + a *(x-y))
else:
    ans = min(a * x + b * y, c * y * 2, c * x * 2 + b *(y-x))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    string ss[3] = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    rep(i, 3){
        if(s==ss[i]){
            cout << ss[(i+1)%3] << endl;
        }
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N,Q=map(int,input().split())
G=[[] for _ in range(N)]
count=[0]*N
for i in range(N-1):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for i in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q=deque([0])
flag=[False]*N
while q:
    v=q.pop()
    flag[v]=True
    for e in G[v]:
        if flag[e]:
            continue
        count[e]+=count[v]
        q.append(e)
print(*count)

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void dijkstra(vector<vector<tuple<i64,i64,i64>>> &graph, vector<i64>& dist1,vector<i64>& dist2,i64 s){
    dist1[s]=dist2[s]=0;
    {
        priority_queue<pair<i64,i64>,vector<pair<i64,i64>>,greater<pair<i64,i64>>> que;
        que.push(make_pair(0,s));
        while(!que.empty()){
            auto p=que.top();
            que.pop();
            i64 u=p.second,d=p.first;
            if(d>dist1[u]) continue;
            for(auto &edge:graph[u]){
                i64 c=get<1>(edge),v=get<0>(edge);
                if(d+c>=dist1[v]) continue;
                dist1[v]=d+c;
                que.push(make_pair(d+c,v));
            }
        }
    }
    {
        priority_queue<pair<i64,i64>,vector<pair<i64,i64>>,greater<pair<i64,i64>>> que;
        que.push(make_pair(0,s));
        while(!que.empty()){
            auto p=que.top();
            que.pop();
            i64 u=p.second,d=p.first;
            if(d>dist2[u]) continue;
            for(auto &edge:graph[u]){
                i64 c=get<2>(edge),v=get<0>(edge);
                if(d+c>=dist2[v]) continue;
                dist2[v]=d+c;
                que.push(make_pair(d+c,v));
            }
        }
    }
}

void solve(){
    i64 n,m,s,t;
    cin >> n >> m >> s >> t;
    
    vector<vector<tuple<i64,i64,i64>>> graph(n+1);
    rep(i,0,m){
        i64 u,v,a,b;
        cin >> u >> v >> a >> b;
        graph[u].push_back(make_tuple(v,a,b));
        graph[v].push_back(make_tuple(u,a,b));
    }

    vector<i64> dist_s1(n+1,inf64),dist_s2(n+1,inf64),dist_t1(n+1,inf64),dist_t2(n+1,inf64);
    dijkstra(graph,dist_s1,dist_s2,s);
    dijkstra(graph,dist_t1,dist_t2,t);



    vector<i64> ans;
    i64 tmp=0,k=1000000000000000;
    for(i64 i=n; i>=1; --i){
        tmp=max(tmp,k-dist_s1[i]-dist_t2[i]);
        ans.push_back(tmp);
    }

    reverse(begin(ans),end(ans));
    rep(i,0,ans.size()) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 15496
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	lint N, K, Q;
	cin >> N >> K >> Q;
	vector<lint>P(N,K-Q);
	vector<lint>A(Q);
	for (int i = 0; i < Q; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < Q; i++) {
		P[A[i] - 1]++;
	}
	for (int i = 0; i < N; i++) {
		if (P[i] <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>

using namespace std;

int main()
{
    map<char,char> b;
    b['A'] = 'T';
    b['T'] = 'A';
    b['G'] = 'C';
    b['C'] = 'G';
    
    char s;
    cin >> s;
    cout << b[s] << endl;
}


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

using namespace std;

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

    int *d = new int[N];

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

    unsigned long long sum = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;

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


int main() {
int n,a,b,x,y,xmax,ymax,ymin,xmin;
while(cin>>n && n){
xmax=0,ymax=0,ymin=0,xmin=0;
vector<pair<int,int> > v;
v.push_back(make_pair(0,0));
for(int i=0;i<n-1;i++){
cin>>a>>b;
x=v[a].first;
y=v[a].second;
if(b==0) x--;
if(b==1) y--;
if(b==2) x++;
if(b==3) y++;
v.push_back(make_pair(x,y));
if(x>xmax) xmax=x;
if(y>ymax) ymax=y;
if(x<xmin) xmin=x;
if(y<ymin) ymin=y;
}

cout<<xmax-xmin+1<<" "<<ymax-ymin+1<<endl;


}


	return 0;
}

Measured memory_bytes: 1204
use proconio::input;
use std::collections::HashMap;

const MOD: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
    }

    let mut map = HashMap::new();

    for i in 2..=n {
        for (key, val) in factors(i) {
            *map.entry(key).or_insert(0) += val;
        }
    }

    let mut ans = 1;

    for (_, val) in map.into_iter() {
        ans *= val+1;
        ans %= MOD;
    }

    println!("{}", ans);
}

fn factors(n: usize) -> HashMap<usize, usize> {
    let mut x = n;
    let mut ret = HashMap::new();
    for i in 2..n {
        if i * i > n {
            break;
        }
        if x % i != 0 {
            continue;
        }
        while x > 0 && x % i == 0 {
            x /= i;
            *ret.entry(i).or_insert(0) += 1;
        }
    }
    if x > 1 {
        *ret.entry(x).or_insert(0) += 1;
    }
    ret
}


Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef unsigned long long ll;
int ans,n;
char s[100005];
vector<int>x;
int main(void){
   cin>>s;
   n=strlen(s);
   char p=s[0];
   x.push_back(1);
   for(int i=1;i<n;i++){
       if(s[i]==p){
           x.back()++;
       }else{
           x.push_back(1);
           p=s[i];
       }
   }
   int s=0,t=x.size()-1;
   ans=n;
   while(s<t){
       if(x[s]<x[t]){
           ans=min(ans,n-x[s]);
           s++;
           x[s]+=x[s-1];
       }else{
           ans=min(ans,n-x[t]);
           t--;
           x[t]+=x[t+1];
       }
   }
   cout<<ans<<endl;
}


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

using Graph = std::vector<std::vector<uint32_t>>;

uint32_t dfs(const Graph& G, std::vector<std::pair<uint32_t, uint32_t>>& ts,
             uint32_t node, uint32_t t) {
  ts[node].first = t;
  for (auto&& g : G[node]) {
    if (ts[g].first == 0) t = dfs(G, ts, g, t + 1);
  }
  t++;
  ts[node].second = t;
  return t;
}

int main() {
  uint32_t n = 0;
  std::cin >> n;
  Graph G(n + 1);
  for (size_t i = 1; i < n + 1; i++) {
    uint32_t k = 0;
    std::cin >> i >> k;
    if (k > 0) G[i] = std::vector<uint32_t>(k);
    for (auto&& g : G[i]) std::cin >> g;
  }

  uint32_t time = 0;
  std::vector<std::pair<uint32_t, uint32_t>> timestamp(n + 1, {0, 0});
  for (size_t i = 1; i < timestamp.size(); i++) {
    if (timestamp[i].first == 0) time = dfs(G, timestamp, i, time + 1);
  }

  for (size_t i = 1; i < timestamp.size(); i++) {
    std::cout << i << " " << timestamp[i].first << " " << timestamp[i].second
              << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	if(N == 7 || N == 5 || N == 3){
    		System.out.println("YES");
    	}else{
    		System.out.println("NO");
    	}
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,C;
    cin >> N >> C;
    vec<vec<int>> D(C,vec<int>(C));
    rep(i,C)rep(j,C) cin >> D[i][j];
    vec<vec<int>> c(N,vec<int>(N));
    rep(i,N)rep(j,N) cin >> c[i][j],--c[i][j];

    vec<vec<int>> cost(3,vec<int>(C));
    rep(i,N)rep(j,N)rep(k,C){
        if(c[i][j] == k) continue;
        cost[(i+j+2)%3][k]+=D[c[i][j]][k];
    }
    
    int ans = 1e9;
    rep(i,C)rep(j,C)rep(k,C){
        if(i==j||i==k||j==k) continue;
        ans = min(ans,cost[0][i]+cost[1][j]+cost[2][k]);
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    string s1, s2;
    int a=0,b=0;
    cin >>n;
    
    for(int i=0;i< n;i++){
        cin >>s1>>s2;
        if(s1 > s2) a+=3;
        else if (s1 <s2) b+=3;
        else{
            a++; 
            b++;
        }
    }
    
    cout<<a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 3156
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;

	writeln(max(0, A-B*2));
	stdout.flush();
	debug readln();
}

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

int main(int argc, char* argv[]) {
  double r;
  cin >> r;
  cout << fixed << setprecision(6) << r*r*M_PI << " " << 2*r*M_PI << endl;

  return 0;
}

Measured memory_bytes: 1292
#include <stdio.h>
int main(void)
{
    int x,a,h,m,s;
    scanf("%d",&x);
  
  h = x / 3600;
  a = x % 3600;
  m = a / 60;
  s = a % 60;
  
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 505;

int n, c, best = INF, cur, D[MAXN][MAXN], P[MAXN][MAXN], DP[3][MAXN];

int main() {
    scanf("%d%d", &n, &c);

    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) {
            scanf("%d", &D[i][j]);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &P[i][j]);
            DP[(i + j) % 3][P[i][j] - 1]++;
        }
    }

    for (int c0 = 0; c0 < c; c0++) {
        for (int c1 = 0; c1 < c; c1++) {
            for (int c2 = 0; c2 < c; c2++) {
                if (c0 != c1 && c0 != c2 && c1 != c2) {
                    cur = 0;

                    for (int s = 0; s < c; s++) {
                        cur += D[s][c0] * DP[0][s];
                        cur += D[s][c1] * DP[1][s];
                        cur += D[s][c2] * DP[2][s];
                    }

                    best = min(best, cur);
                }
            }
        }
    }

    printf("%d\n", best);

    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
	int N, A, B, count = 0, countB = 0;
	char S[100000] = { 0 };
	scanf("%d%d%d", &N, &A, &B);
	scanf("%s", S);
	for (int i = 0; i < N; i++) {
		if (S[i] == 'c')puts("No");
		else if (S[i] == 'a') {
			if (count < A + B) {
				count++;
				puts("Yes");
			}
			else puts("No");
		}
		else if (S[i] == 'b') {
			if (count < A + B&&countB < B) {
				count++;
				countB++;
				puts("Yes");
			}
			else puts("No");
		}
		else puts("No");
	}

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
using namespace std;

template <typename T_char>
T_char ToUpper(T_char cX) { return toupper(cX); }

int main()
{
	string w;
	cin >> w;
	transform(w.begin(), w.end(), w.begin(), ToUpper<char>);

	int cnt = 0;
	while (true) 
	{
		string t;
		cin >> t;
		if (t == "END_OF_TEXT") break;
		transform(t.begin(), t.end(), t.begin(), ToUpper<char>);
		if (t == w) cnt++;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' '; cout << endl;
#define OUTP(a) cout << a.f << ' ' << a.s << endl;
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);
#define get_lind(vec, val) (int)(lower_bound(all(vec), val) - vec.begin())
#define get_rind(vec, val) (int)(upper_bound(all(vec), val) - vec.begin())


using  namespace std;
const int N = 2e5 + 5;

int main()
{
    ll x; cin >> x;
    ll f = x / 500;
    ll s = x % 500;
    cout << f * 1000 + (s / 5) * 5 << endl;
    return 0;
}


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

using namespace std;
int main(void) {
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i = 0;i<h;i++){
        string a;
        cin >> a;
        for(int j = 0;j<w;j++){
            if(a.at(j) == '#'){
                s[i][j] = '#';
            }else{
                s[i][j] = '.';
            }
        }
    }
     int x[4] = {0,-1,1,0};
    int y[4] = {-1,0,0,1};
    string frag = "Yes";
    for(int i = 0; i<h;i++){
        for(int j = 0;j<w;j++){
            bool frag1 = false;
            if(s[i][j] == '#'){
                for(int k =0;k<4;k++){
                    if(s[i +x[k]][j + y[k]] == '#'){
                        frag1 = true;
                    }
                }
                if(frag1 == false){
                    frag = "No";
                }
            }
        }
    }
    cout << frag << endl;
}

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

uint xor128(){
	static uint x=1,y=3,z=5,w=8;
	uint t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct node{
	node*l,*r;
	uint pri;
	int cnt,val,Min;
};
node pool[400000];
int p;

inline int cnt(node*t){return t?t->cnt:0;}
inline int Min(node*t){return t?t->Min:INF;}

inline node*update(node*t){
	t->cnt=cnt(t->l)+cnt(t->r)+1;
	t->Min=min({t->val,Min(t->l),Min(t->r)});
	return t;
}
inline node*merge(node*l,node*r){
	if(!l)return r;
	if(!r)return l;
	if(l->pri>r->pri){
		l->r=merge(l->r,r);
		return update(l);
	}
	else{
		r->l=merge(l,r->l);
		return update(r);
	}
}
inline pair<node*,node*>split(node*t,int k){
	if(!t)return make_pair((node*)NULL,(node*)NULL);
	if(k<=cnt(t->l)){
		auto p=split(t->l,k);
		t->l=p.second;
		return make_pair(p.first,update(t));
	}
	else{
		auto p=split(t->r,k-cnt(t->l)-1);
		t->r=p.first;
		return make_pair(update(t),p.second);
	}
}

int main(){
	int n,q;scanf("%d%d",&n,&q);
	node*root=NULL;
	rep(i,n){
		int a;scanf("%d",&a);
		node*t=&pool[p++];
		*t={NULL,NULL,xor128(),1,a,a};
		root=merge(root,t);
	}
	rep(i,q){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y-1);
			auto c=split(b.second,1);
			root=merge(merge(merge(a.first,c.first),b.first),c.second);
		}
		else if(x==1){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y);
			printf("%d\n",Min(b.first));
			root=merge(merge(a.first,b.first),b.second);
		}
		else{
			auto a=split(root,y);
			auto b=split(a.second,1);
			b.first->val=b.first->Min=z;
			root=merge(merge(a.first,b.first),b.second);
		}
	}
}


Measured memory_bytes: 9492
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll power(ll a, ll n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 0) {
    ll x = power(a, n/2);
    return x * x;
  } else {
    return power(a, n-1) * a;
  }
}

ll N, A;

int main () {
  cin >> N >> A;
  ll ub = sqrt(N)+1;
  ll lb = 2;
  ll ans = N;
  for (auto i = 2; i < 1000; ++i) {
    if (power(2, i) > N) break;
    if (i == 2) {
      while (ub - lb > 1) {
        ll t = (ub + lb)/2;
        if (power(t, i) > N) {
          ub = t;
        } else {
          lb = t;
        }
      }      
    } else {
      for (auto j = 1; j < 12000; ++j) {
        if (power(j, i) < N) {
          lb = j;
        } else {
          break;
        }
      }
    }
    // cerr << "i = " << i << ", lb = " << lb << endl;
    for (auto j = 0; j <= i; ++j) {
      if (power(lb, i-j) * power(lb+1, j) >= N) {
        ans = min(ans, lb * (i-j) + (lb+1) * j + A * (i-1));
        break;
      }
    }
    ub = lb;
    lb = 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from operator import itemgetter
from scipy.sparse import csr_matrix
import numpy as np

N = int(input())

XY = [[i] + [int(x) for x in input().split()] for i in range(N)]

edge = set()
for key in [itemgetter(1),itemgetter(2)]:
  XY.sort(key = key)
  for i in range(N-1):
    i1,x1,y1 = XY[i]
    i2,x2,y2 = XY[i+1]
    d = min(abs(x1-x2),abs(y1-y2))
    edge.add((i1,i2,d))
    
# csr形式に直す
row,col,value = zip(*edge)
value = np.array(value,dtype=int)
graph = csr_matrix((value,(row,col)),shape=(N,N))

# 最小全域木
from scipy.sparse.csgraph import minimum_spanning_tree
tree = minimum_spanning_tree(graph, overwrite = True).astype(int)
answer = tree.sum()
print(answer)

Measured memory_bytes: 85136
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

long long h[100000];
int main(){
	int n;
	cin >> n;
	REP(i,n){
		cin >> h[i];
	}
	
	for(int i = n-1; i>=1; i--){
		if(h[i-1]-h[i] == 1){
			h[i-1]--;
		}else if(h[i-1] > h[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<utility>
#include<set>
#include<stack>
#include<string>
#include<vector>
#define ll long long
#define llu unsigned long long
using namespace std;
const int maxn = 101000;
pair<int,int> p[maxn];
int t[maxn],s[maxn],n;
void solve()
{
    for(int i=0;i<n;i++){
        p[i].first = t[i];
        p[i].second = s[i];
    }
    sort(p,p+n);
    int ans = 0,tt = -1;
    for(int i=0;i<n;i++){

        if(tt<=p[i].second){
            ans++;
            tt = p[i].first;
        }
    }
    printf("%d\n",ans);
}
int main(void)
{
    int a,b;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        s[i] = a - b;
        if(s[i]<0)  s[i] = 0;
        t[i] = a + b;
    }
    solve();
    return 0;
}


Measured memory_bytes: 1792