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

using namespace std;

typedef pair<int, int> P;

vector<int> G[100000];
int depth[100000];
bool ok[100000];
P depth_pair[100000];

void dfs_depth(int v, int d){
    depth[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(depth[G[v][i]] == -1) dfs_depth(G[v][i], d+1);
    }
}

void dfs_ok(int v){
    ok[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(depth[G[v][i]] > depth[v] && !ok[G[v][i]]) dfs_ok(G[v][i]);
    }
}

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 0; i < N; i++){
        depth[i] = -1;
        int a;
        cin >> a;
        a--;
        if(i == 0){
            if(a != 0) ans++;
        }else{
            G[a].push_back(i);
            G[i].push_back(a);
        }
    }
    //cout << ans << endl;
    dfs_depth(0, 0);
    for(int i = 0; i < N; i++) depth_pair[i] = P(depth[i], i);
    sort(depth_pair, depth_pair+N, greater<P>());
    for(int i = 0; i < N; i++){
        if(depth_pair[i].first <= K) break;
        if(!ok[depth_pair[i].second]){
            ans++;
            int cur = depth_pair[i].second;
            //cout << depth_pair[i].second << endl;
            //K-1個上まで
            for(int j = 0; j < K-1; j++){
                for(int k = 0; k < G[cur].size(); k++){
                    if(depth[G[cur][k]] < depth[cur]){
                        cur = G[cur][k];
                        break;
                    }
                }
            }
            dfs_ok(cur);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11648
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    ones = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                ones[i] += 1

    res_l = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                res_l[i] += (N-ones[i])
            else:
                res_l[i] += ones[i]
    res = 0
    for i in range(60):
        res += res_l[i] << i
        res %= MOD
    if res % 2 == 1:
        res += MOD
    print(res // 2)
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121800
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
int main(){
	int H, W, h, w;
	cin >> H >> W >> h >>w;
	cout << (H-h)*(W-w)<<endl;
}

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

using namespace std;

const int W = 1111;

char board[W][W];
int memo[W][W][3];

int main(){
	int h,w;
	int n;
	
	cin>>h>>w>>n;
	
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>board[i][j];
	
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			
			for(int k=0;k<3;k++){
				memo[i][j][k] = memo[i-1][j][k] + memo[i][j-1][k] - memo[i-1][j-1][k];
			}
			
			if(board[i][j] == 'J') memo[i][j][0]++;
			if(board[i][j] == 'O') memo[i][j][1]++;
			if(board[i][j] == 'I') memo[i][j][2]++;
		}
	}
	
	
	for(int i=0;i<n;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		
		for(int j=0;j<3;j++){
			int ans = memo[c][d][j] - memo[c][b-1][j] - memo[a-1][d][j] + memo[a-1][b-1][j];
			if(j!=0)printf(" ");
			printf("%d",ans);
		}puts("");
	}
}

Measured memory_bytes: 16552
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<string>
#include<stack>
#include<algorithm>

using namespace std;

void slove(){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

int main(){
    slove();
}

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

class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unit(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind UF(N);
  vector<int> V(N);
  for (int i = 0, a, b; i < M && cin >> a >> b; i++) {
    UF.unit(--a, --b);
    V.at(a)++;
    V.at(b)++;
  }
  vector<vector<int>> B(N);
  for (int i = 0, c, d; cin >> c >> d; i++) {
    if (UF.same(--c, --d)) {
      V.at(c)++;
      V.at(d)++;
    }
  }
  for (int i = 0; i < N; i++) {
    int ans = UF.size(i);
    ans--;
    ans -= V.at(i);
    cout << ans << "\n"; 
  }
}

Measured memory_bytes: 4352
n, m, q = map(int, input().split())
imos = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    imos[l-1][r-1] += 1

for i in range(n):
    for j in range(n-1):
        imos[i][j+1] += imos[i][j]

for j in range(n):
    for i in range(n-1):
        imos[i+1][j] += imos[i][j]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    if l == 0:
        print(imos[r][r])
    else:
        print(imos[r][r] - imos[l - 1][r] - imos[r][l - 1] + imos[l - 1][l - 1])


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

const int mxN = 205;
int a[mxN], b[mxN];

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; ++i)
		cin >> b[i];
	int tot = 0;
	b[0] = b[n] = 1e9 + 9;
	for(int i = 1; i <= n; ++i)
		tot += min(b[i], b[i - 1]);
	cout << tot;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		rep(i,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vvb adj(n,vb(n,false));
	
	rep(i,m){
		int a,b;
		cin>>a>>b;
		adj[a-1][b-1]=adj[b-1][a-1]=true;
	}
	vi stat(n);
	iota(all(stat),0);

	int ans=0;
	do{
		bool ok=stat[0]==0;
		rep(i,n-1){
			ok&=adj[stat[i]][stat[i+1]];
		}
		if(ok){
			ans++;
		}
	}while(next_permutation(all(stat)));
	puta(ans);

	return 0;
}

Measured memory_bytes: 256
n = input()
list_num = [int(num) for num in input().split()]
 
count = 0
condition = False 
 
while condition == False :
    for num in list_num:
        if int(num % 2) == 1:
            condition = True
            break
            
    if condition == False :
        count += 1
        list_num = list(map(lambda x: int(x / 2), list_num ))

print(count)

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x, y, ans;
    cin >> x >> y;
    if (x >= 0 && y >= 0) {
        if (x <= y) ans = y - x;
        else {
            if (y == 0) ans = x - y + 1;
            else ans = x - y + 2;
        }
    } else if (x < 0 && y < 0) {
        if (x <= y) ans = y - x;
        else ans = 2 + x - y;
    } else {
        if (y == 0) ans = x * (-1);
        else ans = 1 + abs(x * (-1) - y);
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int m; scanf("%d", &m);
	int n = 1 << m;
	std::vector<int> s(n);
	for(int i = 0; i < n; i++) scanf("%d", &s[i]);
	sort(begin(s), end(s)); reverse(begin(s), end(s));

	m++;
	std::vector<int> comp(m + 1), nxt(m + 1); comp[m] = 1;
	for(int i = 0, cnt = 1; i < s.size(); i++) {
		while(i + 1 < s.size() and s[i] == s[i + 1]) {
			cnt++;
			i++;
		}
		
		int cur = m;
		nxt.assign(m + 1, 0);
		while(cnt--) {
			while(cur > 0 and !comp[cur]) cur--;
			if(!cur) {
				printf("No\n");
				return 0;
			}
			
			comp[cur]--;
			nxt[1]++;
			nxt[cur]--;
		}

		for(int i = 0; i < m; i++) nxt[i + 1] += nxt[i];
		for(int i = 0; i <= m; i++) comp[i] += nxt[i];
		cnt = 1;
	}

	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <map>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;


typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


int main()
{
    int N, M;
    cin >> N >> M;

    vector <int> kimari(N, -1);
    REP(i,M)
    {
        int s,c;
        cin >> s >> c;
        --s;
        if(kimari[s] != -1 && kimari[s] != c)
        {
            cout << -1 << endl;
            return 0;
        }
        kimari[s] = c;
    }
    string res = "";

    if(N != 1)
    {
        if(kimari[0] == 0)
        {
            cout << -1 << endl;
            return 0; 
        }
    }

    REP(i,N)
    {
        if(kimari[i] != -1)
        {
            res += to_string(kimari[i]); 
        }
        else
        {
            char tmp;
            if(i != 0 || N == 1)tmp = '0';
            else tmp = '1';
            res += tmp; 
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pi 3.141592653
#define pb push_back
#define pp pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define mod 1000000007
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
void solve();
ll gc(ll a,ll b)
{
    if(b==0) return a;
    return gc(b,a%b);
}
signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}
void solve() 
{
    int h;
    int n;
    cin>>h>>n;
    int x;
    int s=0;
    for(int i=0;i<n;i++){
        cin>>x;
        s+=x;
    }
    if(s>=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
 int N;
  cin >> N;
  int a;
  vector <int> v1(200010,0);
  for(int i = 1;i < N;i++){
    cin >> a;
   v1.at(a-1)++;
    }
  for (int i = 0;i < N;i++){
    cout << v1.at(i) << endl;
  }
}

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

signed main(){
	int n,a[200010];
	cin >> n;
	map<int,int> counts;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		counts[a[i]]++;
	}
	sort(a,a + n,greater<int>());
	int ans = 0;
	for(int i = 0;i < n;i++){
		int v = (1 << (32 - __builtin_clz(a[i]))) - a[i];
		if((a[i] == v && counts[v] >= 2) || (a[i] != v && counts[v] && counts[a[i]])){
			counts[v]--; counts[a[i]]--;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 19712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			int d = scanner.nextInt();
			System.out.println(Math.max(a * b, c * d));
		}
	}
}


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

int multi(vector<int> a) {
  int result = 1;
  for (int x : a) {
    result *= x;
  }
  return result;
}

int main() {
  int H, W;
  cin >> H >> W;
  char wh = '.', bl = '#';
  vector<vector<char>> cell(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> cell.at(i).at(j);
    }
  }

  vector<bool> rm_row(H, true);
  vector<bool> rm_col(W, true);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (cell.at(i).at(j) == bl) {
        rm_row.at(i) = false;
        break;
      }
    }
  }
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if (cell.at(i).at(j) == bl) {
        rm_col.at(j) = false;
        break;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    if (rm_row.at(i)) continue;
    for (int j = 0; j < W; j++) {
      if (rm_col.at(j)) continue;
      cout << cell.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			s = in.next().toCharArray();
			if(s[0] == '.') break;
			count = 0;
			table = new int[3];
			dfs(0);
			System.out.println(count);
		}
	}
	public static int count;
	public static char[] s;
	public static int[] table;
	public static void dfs(int dep){
		if(dep == 3){
			idx = 0;
			if(formula() == 2) count++;
			return;
		}
		for(int i=0; i<3; i++){
			table[dep] = i;
			dfs(dep+1);
		}
	}
	
//	public static final String var = "012PQR";
	public static final int[] not = {2, 1, 0};
	public static final int[][] mult = {
		{0, 0, 0},
		{0, 1, 1},
		{0, 1, 2},
	};
	public static final int[][] add = {
		{0, 1, 2},
		{1, 1, 2},
		{2, 2, 2},
	};
	public static int idx;
	public static int formula(){
		if(s[idx] == '-'){
			idx++;
			return not[formula()];
		}
		if(s[idx] == '('){
			idx++;
			int val = formula();
			if(s[idx++] == '+'){
				val = add[val][formula()];
			}else{
				val = mult[val][formula()];
			}
			idx++;
			return val;
		}
		if('0' <= s[idx] && s[idx] <= '2'){
			return s[idx++] - '0';
		}
		return table[s[idx++]-'P'];
	}
}

Measured memory_bytes: 22548
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
  string s, t;
  cin >> s >> t;
  int slen = s.size();
  int tlen = t.size();
  int dp[1001][1001] = {};

  rep(i, slen + 1) dp[i][0] = i;
  rep(j, tlen + 1) dp[0][j] = j;

  loop(i, 1, slen + 1) {
    loop(j, 1, tlen + 1) {
      int cost = (s[i - 1] == t[j - 1] ? 0 : 1);
      dp[i][j] = min(min(dp[i - 1][j] + 1, dp[i][j - 1] + 1), dp[i - 1][j - 1] + cost);
    }
  }

  cout << dp[slen][tlen] << endl;

  return 0;
}



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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
using lint=mp::cpp_int;

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lint a;
    cin>>a;
    Yes(!(a%9));
}

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

typedef long long ll;

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

int main() { 
    int H, W;
    string inp;
    vector<string> C;
    cin >> H >> W;
    rep(i, H){
        cin >> inp;
        C.push_back(inp);
    }
    rep(i, H) {
        cout << C.at(i) << "\n";
        cout << C.at(i) << "\n";
    }

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;

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

  vector<int> A(N);
  int all_attack = 0;
  REP(i, N) {
    cin >> A[i];
    all_attack += A[i];
  }

  if(all_attack >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int a = stoi(s + t);
  for (ll i = 1; i * i <= a; i++) {
    if (i * i == a) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


int main() {
	int n; std::cin >> n;
	std::vector<int> bars(n); for (auto& b : bars) std::cin >> b;
	std::sort(bars.begin(), bars.end());
	long long int result = 0;
	for (auto i = 0; i < n; ++i) for (auto j = 0; j < i; ++j) {
		auto max = bars[i] + bars[j] - 1;
		auto upper = std::upper_bound(std::next(bars.begin(), i + 1), bars.end(), max);
		result += std::distance(std::next(bars.begin(), i), upper) - 1;
	}
	std::cout << result << std::endl;
}

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

int main() {
  int M, N;
  cin >> N >> M;
  vector<int> A(N);
  long long votes = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    votes += A[i];
  }

  int selected = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] * 4 * M >= votes) selected++;
  }

  if (selected >= M) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

void bubble(vector<string> &a) {
    for (int i = 0; i < a.size(); i++) {
        for (int o = a.size() - 1; o > i; o--) {
            if (a[o][1] < a[o - 1][1]) swap (a[o], a[o - 1]);
        }
    }
}

void select(vector<string> &b) {
    for (int i = 0; i < b.size(); i++) {
        int mini = i;
        for (int j = i; j < b.size(); j++) {
            if (b[j][1] < b[mini][1]) mini = j;
        }
        if (i < mini) swap (b[i], b[mini]);
    }
}

int main() {
    int n; cin >> n;
	vector<string> a(n);
	vector<string> b(n);
	for (int i = 0; i < n; i++) {cin >> a[i]; b[i] = a[i];}
	bubble(a);
	for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
	cout << a[n - 1] << endl << "Stable" << endl;
	select(b);
	for (int i = 0; i < n; i++) {
	    cout << b[i];
	    if (i < n - 1) cout << " ";
	}
	cout << endl;
	bool hi = false;
	for (int i = 0; i < n; i++) {
	    if (b[i].at(0) != a[i].at(0)) hi = true;
	}
	if (hi) cout << "Not stable" << endl;
	else cout << "Stable" << endl;
}



Measured memory_bytes: 3220
#########################
# 
# ######

N, A, B = [int(_) for _ in input().split()]
if N < A + B - 1 or A * B < N:
    print(-1)
elif B == 1:
    print(*list(range(1, A + 1)))
else:
    M = N - A - B + 1
    count = [B] * (1 + M // (B - 1))
    count += [1] * (A - len(count))
    count[-1] += (N - A - B + 1) % (B - 1)
    f = 0
    ans = []
    for c in count:
        ans += list(range(f + c, f, -1))
        f += c
    print(*ans)


Measured memory_bytes: 23252
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
 int a,b;
 cin >> a >> b;
 int ans=-1;
 for(int i=1;i<=100000;i++){
   int x=(i*8)/100;
   int y=i/10;
   if(a==x && b==y){
     ans=i;
     break;
   }
 }
 cout << ans << endl;
} 
    

Measured memory_bytes: 3592
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 100005;
int a[MAXN], b[MAXN], ca[MAXN], cb[MAXN];
int n, m, k;

int main()
{
    cin >> n >> m >> k;
    int min1 = INF, min2 = INF;
    int min3 = INF;
    for (int i = 1; i <= n; i++) cin >> a[i], ca[i] = a[i], min1 = min(min1, a[i]);
    for (int i = 1; i <= m; i++) cin >> b[i], cb[i] = b[i], min2 = min(min2, b[i]);

    for (int i = 0; i < k; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        min3 = min(min3, ca[x] + cb[y] - z);
    }
    cout << min(min1 + min2, min3) << endl;
}

Measured memory_bytes: 1792
from heapq import heappop, heappush

N, M = map(int, input().split())
price = list(map(int, input().split()))
he = []
for i in price:
  heappush(he, -i)
for i in range(M):
  max = heappop(he)
  heappush(he, -(-max//2))
print(-sum(he))

Measured memory_bytes: 14380
#include <iostream>
#include <array>
#include <string>

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

    bool varied = true;
    std::array<bool, 26> count = {false};
    for (const auto c : s)
    {
        if (count[c - 'a'])
        {
            varied = false;
            break;
        }
        count[c - 'a'] = true;
    }

    if (varied)
    {
        std::cout << "yes";
    }
    else
    {
        std::cout << "no";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3628
from bisect import bisect as bisect
def LIS(l):
    seq = []
    for a in l:
        i = bisect(seq,a)
        if len(seq)==i:
            seq.append(a)
        else:
            seq[i]=a
    return len(seq)

N = int(input())
A = [-int(input()) for _ in range(N)]
print(LIS(A))

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

using namespace std;

const long long inf = 1e15;
const int mod = 1e9+7;

int main(void){
    string s;
    cin >> s;
    if(s.length() < 4){
        cout << "No" << endl;
        return 0;
    }
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' & s[3] == 'I'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
	char b;
	cin >> b;

	char ans;
	if (b == 'A') {
		ans = 'T';
	}
	if (b == 'C') {
		ans = 'G';
	}
	if (b == 'G') {
		ans = 'C';
	}
	if (b == 'T') {
		ans = 'A';
	}

	cout << ans << endl;

}

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

int a[3];

int main() {
    rep(i, 3) {
        cin >> a[i]; 
    }
    sort(a, a + 3);

    string ans = "No";
    if (a[0] + a[1] == a[2]) {
        ans = "Yes";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
#define WHITE 0
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
typedef priority_queue<ll> PQ;

int main(void) {
    ll H, W, N, i, j;
    cin >> H >> W;
    cin >> N;
    ll a[10010];
    ll m[H+1][W+1];
    for(i=1; i<=N; i++) {
        cin >> a[i];
    }
    
    for(i=0; i<=H; i++) {
        for(j=0; j<=W; j++) {
            m[i][j]=0;
        }
    }
    
    ll k=1, l=1;
    ll dire=0;
    for(i=1; i<=N; i++) {
        for(j=1; j<=a[i]; j++) {
            m[k][l]=i;
            if(dire==0 && l<W) {
                l++;
            }else if(dire==0 && l==W) {
                k++;
                dire=1;
            }else if(dire==1 && 1<l) {
                l--;
            }else if(dire==1 && l==1) {
                k++;
                dire=0;
            }
        }
    }
    
    for(i=1; i<=H; i++) {
        for(j=1; j<=W; j++) {
            cout << m[i][j] << " ";
        }
        cout << endl;
    }
    
}


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

int main() {
  string s;
  cin >> s;
  string yaki = "YAKI";
  if (s.size() >= 4) {
    bool y = true;
    rep(i, 4) if (s[i] != yaki[i]) y = false;
    if (y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) cout << "YES\n";
  else if (A == 5 && B == 7 && C == 5) cout << "YES\n";
  else if (A == 7 && B == 5 && C == 5) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

const int N = 100010;
ll pw[N];

int main(){
    pw[0] = 1;
    rep(i,N-1) pw[i+1] = (pw[i]*2)%mod;

    int n,m;
    while(scanf(" %d %d", &n, &m),n){
        UF uf(n);

        rep(i,m){
            int a,b;
            scanf(" %d %d", &a, &b);
            --a;
            --b;
            uf.unite(a,b);
        }

        int ct = 0;
        int add = 0;
        vector<bool> vis(n);

        rep(i,n){
            int v = uf.root(i);
            if(vis[v]) continue;

            int sz = uf.size(v);
            if(sz>1) add = 1;
            ++ct;
            vis[v] = true;
        }

        ll ans = pw[ct];
        (ans += add) %= mod;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 4420
package main

import "fmt"

var (
	N, W  int
	items []Item
	dp    [][]int
)

type Item struct {
	w, v int
}

func main() {
	fmt.Scan(&N, &W)
	items = make([]Item, N)
	var w_, v int
	for i := range items {
		fmt.Scan(&w_, &v)
		items[i] = Item{w: w_, v: v}
	}

	dp = make([][]int, N+1)
	for i := range dp {
		dp[i] = make([]int, W+10001)
	}
	for i := range items {
		for w := 0; w <= W; w++ {
			if w - items[i].w >= 0 {
				chmax(&dp[i+1][w], dp[i][w-items[i].w] + items[i].v)
			}
			chmax(&dp[i+1][w], dp[i][w])
		}
	}

	fmt.Println(dp[N][W])
}

func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> V(N), C(N), cost(N);
    int ans = 0;
    rep(i, 0, N)
    {
        cin >> V.at(i);
    }
    rep(i, 0, N)
    {
        cin >> C.at(i);
        cost.at(i) = V.at(i) - C.at(i);
        if (cost.at(i) > 0)
        {
            ans += cost.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fore(i, init, n) for(long long i = init; i < n; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
 
const int MAXN = 1e4+5;
int sn, tn, dp[MAXN][MAXN];
string s, t;

int main() {
    FIN;
 
    cin >> s >> t;
    
    sn = s.size(); 
    tn = t.size();

    for(int i = sn-1; i >= 0; i--) {
        for(int j = tn-1; j >= 0; j--) {
            if (s[i] == t[j]) {
                dp[i][j] = 1 + dp[i+1][j+1];           
            }
            dp[i][j] = max({dp[i][j], dp[i+1][j], dp[i][j+1]});
        }
    }
 
    int i = 0, j = 0;
    string res;

    while(i < sn && j < tn) {
        if (s[i] == t[j]) {
            res += s[i];
            i++;j++;
        } else { 
            if (dp[i+1][j] > dp[i][j+1]) i++;
            else j++;
        }
    }
 
    cout << res << endl;

}

Measured memory_bytes: 117888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long x = sc.nextInt();
		long y = sc.nextInt();
		
		if(c+c > a+b){
			System.out.println(a*x+y*b);
		}else{
			if(x < y){
				
				if(c+c < b){
					System.out.println(2* c * y);
				}else{
					System.out.println(2*c*x+ b * (y-x));
				}
			}else{
				
				if(c+c < a){
					System.out.println(2*c*x);
				}else{
					System.out.println(2*c*y + a *(x- y)  );
				}
			}
		}
	}
}


Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    long long cnt = 0;
    for (int a = 1; a <= n; ++a) {
        if ((a % k) == 0) {
            cnt++;
        }
    }
    long long ans = cnt * cnt * cnt;
    cnt = 0;
    if (k % 2 == 0) {
        for (int a = 1; a <= n; ++a) {
            if (a % k == k / 2) {
                cnt++;
            }
        }
        ans += cnt * cnt * cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    s = input()

    print(resolve(s))

def resolve(s):
    # count total
    total_east = 0
    total_west = 0

    for c in s:
        if c == 'E':
            total_east += 1
        else:
            total_west += 1
    
    ww = 0
    ee = total_east
    
    m = len(s) - 1
    for i, c in enumerate(s):
        if c == 'E':
            ee -= 1

        x = ee + ww
        m = min(m, x)

        if c == 'W':
            ww += 1
    
    return m


main()


Measured memory_bytes: 3828
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

kouho = [0] * (2 * 10 ** 5 + 1)
ans = 0

for i in range(n):
    kouho[a[i]] += 1

num = 0
kouho.sort()

for i in range(len(kouho)):
    if kouho[i] != 0:
        #print(kouho[i],i)
        num += 1
#print(num)
if num <= k:
    print(0)
    exit()

cnt = 0

for i in range(len(kouho)):
    if cnt >= num-k:
        break
    if kouho[i] != 0:
        #print(kouho[i],i)
        ans += kouho[i]
        cnt += 1

print(ans)


Measured memory_bytes: 25768
#include<iostream>
using namespace std;
int main(){
    long long N,Y;
    int i,j;
    cin>>N>>Y;
    for(i=0;i<=N;i++ ){
    for(j=0;j<=N;j++ ){
    if(Y==10000*i+5000*j+1000*(N-i-j)&&i+j<=N)
    {cout<<i<<" "<<j<<" "<<N-i-j<<endl;
     goto A;
    }
    }}
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    A:;
    }


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const ll MOD = 1e18;


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
  ll x; cin>>x;
  ll N = 1000;
  rep(i,N){
    rep(j,N){
      ll a = modpow(i , 5 , MOD);
      ll b = modpow(j , 5 , MOD);
      if(a + b == x){
        cout<<i<<" "<<-j<<endl;
        return 0;
      }
      else if(a - b == x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3644
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		Set<Long> set = new HashSet<Long>();
		int n = scan.nextInt();
		
		for(int i = 0; i < n ; i++){
			set.add(scan.nextLong());
		}
		System.out.println( set.size() == n ? "YES":"NO");
		
	}
}

Measured memory_bytes: 104888
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 1000;

int N; ll V;
ll A[MAX_N], B[MAX_N], C[MAX_N], D[MAX_N];
ll a2[MAX_N * MAX_N];

int main(){
	cin >> N >> V;
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	for(int i = 0; i < N; i++) cin >> C[i];
	for(int i = 0; i < N; i++) cin >> D[i];
	int i1 = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			a2[i1] = C[i] + D[j];
			i1++;
		}
	}
	sort(a2, a2 + N * N);
	ll ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			ans += upper_bound(a2, a2 + N * N, V - (A[i] + B[j])) - lower_bound(a2, a2 + N * N, V - (A[i] + B[j]));
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 10984
<?php
    $tmp_line = array();
    while($line = trim(fgets(STDIN))){
        $tmp_line[] = $line;
    }
    foreach($tmp_line as $val){
        $math = explode(" ",$val);
        $koyaku;
        $kobaisu;
        if($math[0]>$math[1]){
            $tmp = $math[0] - $math[1];
            $tmp2 = $math[1];
            while($tmp != $tmp2){
                if($tmp > $tmp2){
                    $tmp = $tmp - $tmp2;
                }else{
                    $tmp2 = $tmp2 - $tmp;
                }
            }
            $koyaku = $tmp;
        }else if($math[0]<$math[1]){
            $tmp = $math[1] - $math[0];
            $tmp2 = $math[0];
            while($tmp != $tmp2){
                if($tmp > $tmp2){
                    $tmp = $tmp - $tmp2;
                }else{
                    $tmp2 = $tmp2 - $tmp;
                }
            }
            $koyaku = $tmp;
        }else{
            $koyaku = $math[0];
        }
        $kobaisu = ($math[0] * $math[1]) / $koyaku;
        echo $koyaku." ".$kobaisu."\n";
    }



Measured memory_bytes: 9280
h,w = map(int, raw_input().split())
P = []
for i in range(h):
    p = list(raw_input())
    P.append(p)

result = True
for i in range(h):
    for j in range(w):
        if P[i][j] == '#':
            try:
                up = P[i-1][j]
            except:
                up = ''
            try:
                down = P[i+1][j]
            except:
                down = '.'
            try:
                right = P[i][j+1]
            except:
                right = '.'
            try:
                left = P[i][j-1]
            except:
                left = '.'

            if up == '.' and down == '.' and right == '.' and left == '.':
                result = False

if result:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,x;
    cin>>N>>x;
    ll a[N];
    rep(i,0,N) cin>>a[i];
    sort(a,a+N);
    int i=0;
    while(i<N&&a[i]<=x){
        x-=a[i];
        i++;
    }
    if(i==N&&x>0) cout <<N-1<<"\n";
    else cout <<i<<"\n";
}

Measured memory_bytes: 256
N=int(input())
W = list(map(int, input().split()))
S = sum(W)
min = 100*101;
for i in range(N-1):
  S1 = sum(W[0:i+2])
  S2 = S - S1
  dif = abs(S1-S2)
  if (min>dif) :
    min = dif
print(min)
      

Measured memory_bytes: 3060
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define NumberOfOnes __builtin_popcount
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twoll pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
const int N = 100100;
two a[N];
two b[N];
int p[N];
int n;
int main(){FAST;xRand;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
	scanf("%d", &a[i].f);
	a[i].s = i;
}
for (int i = 0; i < n; i++) {
	scanf("%d", &b[i].f);
	b[i].s = i;
}
sort(a, a + n);
sort(b, b + n);
for (int i = 0; i < n; i++)
	if (a[i].f > b[i].f) {
		printf("No\n");
		return 0;
	}
for (int i = 0; i < n - 1; i++) {
	if (a[i + 1].f <= b[i].f) {
		printf("Yes\n");
		return 0;
	}
}
for (int i = 0; i < n; i++) {
	p[a[i].s] = b[i].s;
}
int x = 0;
int len = 0;
do {
	x = p[x];
	len++;
} while(x != 0);
if (len == n)
	printf("No\n");
else
	printf("Yes\n");
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/



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

int main(){
  int x, y;
  cin>>x >>y;
  
  if(y%2!=0 || y<2*x || 4*x<y){
    cout<<"No"<<endl;
    return 0;
  }
  
  cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long


bool is(string s){

	for(int i = 0, j = s.size() - 1; i < j; i++, j--){
		if(s[i] != s[j]) return false;
	}

	return true;
}


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

	int n = s.size();

	if(n == 1){
		cout << "Yes" << endl; return 0;
	}

	cout << (is(s) and is(s.substr(0, n / 2)) and is(s.substr(n / 2 + 1, n)) ? "Yes" : "No") << endl;
	
	return 0;
}

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

#define MN 1001000

using namespace std;
typedef long long ll;

ll n, a[MN];
vector<pair<int, int> > adj;
char s[MN]; string str;

void cant() {
    puts("-1");
    exit(0);
}

int main() {
    scanf("%s", s); str = s;
    n = str.size();

    for(int i = 1; i <= n; i++) {
        a[i] = (str[i-1] - '0');
    }

    for(int i = 0; i <= n; i++)
        if(a[i] && !a[n-i]) cant();

    if(!a[1]) cant();
    int last = 1;
    for(int i = 2; i <= n; i++) {
        adj.emplace_back(last, i);
        if(a[i-1]) last = i;
    }

    for(auto t : adj) {
        printf("%d %d\n", t.first, t.second);
    }
    return 0;
}


Measured memory_bytes: 3316
import std;

// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
alias sread=()=>readln.chomp();enum MOD =10^^9+7;
alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less);
// dfmt on

void main()
{
    long A, B, C, K;
    scan(A, B, C, K);
    long ans;
    ans += min(K, A);
    K -= min(K, A);
    K -= min(K, B);
    ans -= min(K, C);
    writeln(ans);
}


Measured memory_bytes: 3684
#include<stdio.h>
int main()
{
  char x;
  int n=0;
  while(1)
    {
      scanf("%c",&x);
      switch(x)
	{
	  case '9':
	    n++;
	  case '8':
	    n++;
	  case '7':
	    n++;
	  case '6':
	    n++;
	  case '5':
	    n++;
	  case '4':
	    n++;
	  case '3':
	    n++;
	  case '2':
	    n++;
	  case '1':
	    n++;
	    break;
	}
      if(x=='\n')
	{
	  if(n!=0)
	    {
	      printf("%d\n",n);
	      n=0;
	      continue;
	    }
	  else break;
	}
    }
  return 0;
}

Measured memory_bytes: 536
from fractions import gcd
a,b,c,d = map(int,input().split())
lcm=int(c*d/gcd(c,d))
#1~Nに何個kの倍数があるか
def counter(n):
    return n-(n//c + n//d - n//lcm)
countA=counter(a-1)
countB=counter(b)
#print(countA,countB)
print(-countA+countB)


Measured memory_bytes: 5372