akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int f[102][102];

bool dfs(int ys,int xs,int yg,int xg,int c){
  if(f[ys][xs]!=c)return 0;

  if(ys==yg && xs==xg)return 1;;

  f[ys][xs]=0;

  bool flag=0;
  flag += dfs(ys+1,xs,yg,xg,c);
  flag += dfs(ys-1,xs,yg,xg,c);
  flag += dfs(ys,xs+1,yg,xg,c);
  flag += dfs(ys,xs-1,yg,xg,c);
  return flag;
}

void set(int c,bool d,int x,int y){
  if(d==0){
    for(int i=0; i<4; i++){
      f[y][x+i]=c;
      f[y+1][x+i]=c;
    }
  }else if(d==1){
    for(int i=0; i<4; i++){
      f[y+i][x]=c;
      f[y+i][x+1]=c;
    }
  }
}

int main(){
  while(1){

  int w,h;
  cin >> w >> h;
  if(w==0 && h==0)break;

  int xs,ys;
  cin >> xs >> ys;
  int xg,yg;
  cin >> xg >> yg;
  int n;
  cin >> n;

  for(int i=0; i<n; i++){
    bool d;
    int c,x,y;
    cin >> c >> d >> x >> y;
    set(c,d,x,y);
  }

  if(dfs(ys,xs,yg,xg,f[ys][xs])){
    cout << "OK\n";
  }else{
    cout << "NG\n";
  }
  }

  return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int n, x, cnt=0, a[100]={0};
    long long sum=0;

    scanf("%d%d", &n, &x);
    for(int i=0; i<n; i++){ scanf("%d", &a[i]); sum+=a[i]; }

  	//お菓子の方が多い -> 1人犠牲になってもらう
    if( x > sum ){ printf("%d\n", n-1); return 0; }
  	
  	//お菓子の方が少ない -> 少ない人から順に配る
    qsort( a, n, sizeof(int), compare_int );
  	for(int i=0; i<n; i++){
     	x -= a[i];
      	if	   ( x >  0 ){ cnt++; }
      	else if( x == 0 ){ printf("%d\n", i+1);	return 0; }	//ぴったり配りきった
      	else			 { printf("%d\n", cnt); return 0; }	//お菓子が足りなかった
    }
  	return 0;
}

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

# input
A, B = map(int, input().split())

# solve
def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, b)

def divisor(n):
    i = 1
    l = list()
    while i * i <= n:
        if n % i == 0:
            l.append(i)
            l.append(n // i)
        i += 1
    l = list(set(l))
    return l

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

ans = list()
a = divisor(A)
b = divisor(B)
d = a + b
l = list()
for i in set(d):
    if d.count(i) > 1:
        l.append(i)

if len(l) > 1:
    ans.append(l[0])
    for i in range(1, len(l)):
        if is_prime(l[i]):
            ans.append(l[i])
else:
    ans = l

# output
print(len(ans))

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

int main(){

    int h,w;
    cin >> h >> w;

    vector<string> a(h);

    rep(i,h){
        cin >> a[i];
    }

    queue<pair<int,int>> q;

    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#'){
                q.push({i,j});
            }
        }
    }

    int ans=0;

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

    while(q.size()!=0){
        ans++;
        queue<pair<int,int>> t;
        while(q.size()!=0){
            pair<int,int> tp=q.front();
            q.pop();
            rep(i,4){
                int nx=tp.second+dx[i];
                int ny=tp.first+dy[i];
                if(nx>=0&&nx<w&&ny>=0&&ny<h&&a[ny][nx]=='.'){
                    a[ny][nx]='#';
                    t.push({ny,nx});
                }
            }
        }
        q=t;
    }

    cout << ans-1 << endl;

    return 0;
}

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

int main() 
{
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i=0; i<n; i++)
        cin >> v[i];
    bool y = true;
    ll sum = 0;
    while (y)
    {
        for (int i=0; i<n; i++)
            if (v[i]%2==0) v[i] = v[i] / 2;
            else y = false;
        sum++;
    }
    cout << sum-1;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
string N;
int ans = 1000000;

int main(){
    cin >> N;
    rep(i, 0, N.length()-2){
        string tmpn = N.substr(i, 3);
        int tmp = stoi(tmpn);
        ans = min(ans, abs(753-tmp));
    }
    cout << ans << endl;
    return 0;
}




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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 5000000 + 7;
const ll linf  = 1ll * inf * inf;
const int N = 100000 + 7;
const int M = 10000 + 7;
const int multipleTest = 0;
const double pi = acos(-1);

int n;
int a[N];
int b[N];
vector<int> uniq;

class FenWickTree{
public:
	static const int MAXN = 200000 + 7;
	static const int MID = MAXN / 2;
	int L[MAXN];
	
	void update(int x, int val) {
		x += MID;
		for (int t = x; t < MAXN; t += t & -t) L[t] += val;
	}
	
	int get(int x) {
		x += MID;
		int res = 0;
		for (int t = x; t > 0; t -= t & -t) {
			res += L[t];
		}
		return res;
	}
} fenwickTree;


ll check(int x) {
	for (int i = 0; i < n; ++i) b[i] = (a[i] >= x) ? 1 : -1;
	for (int i = 1; i < n; ++i) b[i] += b[i - 1];
	
	fenwickTree.update(0, 1);
	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		cnt += fenwickTree.get(-b[i] - 1);
		fenwickTree.update(-b[i], 1);
	}
	
	fenwickTree.update(0, -1);
	for (int i = 0; i < n; ++i) fenwickTree.update(-b[i], -1);
	
	return cnt;
}

void solve() {
	cin >> n;
	uniq.resize(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		uniq[i] = a[i];
	}
	sort(uniq.begin(), uniq.end());
	unique(uniq.begin(), uniq.end());
	
	int lo = 0, hi = uniq.size() - 1, res = uniq[0];
	const ll M = 1ll * n * (n + 1) / 2;
	const ll cnt = (M + 2) / 2;
	
	while (lo <= hi) {
		int mid = (lo + hi) >> 1;
		if (check(uniq[mid]) < cnt) {
			res = uniq[mid];
			lo = mid + 1;
		} else hi = mid - 1;
	}
	
	cout << res << '\n';
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i, N) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  int ans = 2e9;
  REP(i, N - K + 1) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [2, 4, 3])
    3
    >>> print_ans(12, [100, 104, 102, 105, 103, 103, 101, 105, 104, 102, 104, 101])
    0
    """
    ar = np.array(ar)
    sum_ar = np.sum(ar)
    br = np.add.accumulate(ar)
    cr = br - sum_ar / 2
    dr = abs(cr)
    # er = np.where(dr == dr.min())
    er = np.argmin(dr)
    if dr[er] == 0:
        print("0")
    else:
        left = np.sum(ar[:er + 1])
        right = np.sum(ar[er + 1:])
        print(abs(left - right))

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = list(map(int, input().rstrip().split()))
    print_ans(N, ar)




Measured memory_bytes: 36168
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (a = 0; a < b; a++)

int main(){
  
  string str1, str2, str3;
  cin >> str1;
  cin >> str2;
  int N1, N2;
  cin >> N1 >> N2;	
  cin >> str3;
  
  if (str3 == str1){
    
    cout << N1 - 1 << " " << N2 << endl; 
    
  } else if (str3 == str2){
    
    cout << N1 << " " << N2 - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        a: i64,
        b: i64,
        _c: i64,
        k: i64,
    }

    if k < a {
        println!("{}", k);
    } else if k < a + b {
        println!("{}", a);
    } else {
        println!("{}", a - (k - b - a));
    }
}


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

int main(){
  
  string S,T;
  cin >> S >> T;
  
  int count = 0;
  for( int i=0; i<(int)S.size(); i++){
    if( S[i] != T[i] ) count++;
  }
  
  printf("%d\n",count);
  return 0;
  
}
  

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l,r,d;
	int c = 0;
	cin >> l >> r >> d;
	for(int i=l; i<=r ; i++){
		if(i%d==0){
			c++;
		}
	}
		cout << c << endl;
		
	return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <class T>
T getLargestRectangle(const vector<T>& h) {
  int n = h.size();
  stack<int> st;
  vector<int> L(n), R(n);
  for (int i = 0; i < n; i++) {
    while (!st.empty() && h[st.top()] >= h[i]) st.pop();
    L[i] = st.empty() ? 0 : (st.top() + 1);
    st.emplace(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && h[st.top()] >= h[i]) st.pop();
    R[i] = st.empty() ? n : st.top();
    st.emplace(i);
  }
  T res = 0;
  for (int i = 0; i < n; i++) {
    res = max(res, h[i] * (R[i] - L[i]));
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int H, W;
  while (cin >> H >> W, H) {
    string s[510];
    for (int i = 0; i < H; i++) {
      cin >> s[i];
    }
    int dp[510][510];
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0) dp[i][j] = s[i][j] == '.';
        else dp[i][j] = s[i][j] == '.' ? dp[i - 1][j] + 1 : 0;
      }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
      vector<int> h;
      for (int j = 0; j < W; j++) h.emplace_back(dp[i][j]);
      ans = max(ans, getLargestRectangle<int>(h));
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4288
from collections import deque,Counter

n,m,k = map(int,input().split())
frd = [[] for _ in range(n)]
blk = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    frd[a].append(b)
    frd[b].append(a)
for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    blk[c].append(d)
    blk[d].append(c)

ucnt = 0
uni = [-1]*n
stk = deque()
for i in range(n):
    if uni[i] != -1: continue
    stk.append((i,-1))
    while stk:
        cur,prev = stk.pop()
        uni[cur] = ucnt
        for nxt in frd[cur]:
            if nxt == prev: continue
            if uni[nxt] != -1: continue
            stk.append((nxt,cur))
    ucnt += 1
cnt = Counter(uni)

for i in range(n):
    ans = cnt[uni[i]] - 1
    for f in frd[i]:
        if uni[i] == uni[f]: ans -= 1
    for b in blk[i]:
        if uni[i] == uni[b]: ans -= 1
    print(ans,end=" ")

Measured memory_bytes: 111008
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
const int mod = 1e9+7;
bool dp[N];
int n,k;
//dp[mask] Number of ways if that is the mask;
void add_self(int &a,int b){
    a += b;
    if(a>=mod){
        a -= mod;
    }
}
int main(){
    cin>>n;
    std::vector<vector<int>> can(n,vector<int>(n));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            cin>>can[i][j];
        }
    }
    vector<int> dp((1<<n));
    dp[0] = 1;
    for(int mask=0;mask<(1<<n)-1;++mask){
        int a = __builtin_popcount(mask);
        for(int b=0;b<n;++b){
            if(can[a][b] && !(mask&(1<<b))){
                int ms = mask ^ (1<<b);
                add_self(dp[ms],dp[mask]);
            }
        }
    }
 //   dp[all set];
    cout<<(dp[(1<<n)-1])<<endl;
    return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll MOD=1000000007;
const double PI = acos(-1);

int main(){
  int n; cin>>n;
  vector<int>V(100005,0);
  ll sum = 0;
  rep(i,n){
    int a; cin>>a;
    V[a]++;
    sum += a;
  }
  int q; cin>>q;
  rep(i,q){
    int b,c; cin>>b>>c;
    sum += (c-b)*V[b];
    V[c] += V[b];
    V[b] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 3768
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, readline().split()))
    a = []
    ql = collections.deque()
    for i in range(h):
        al = list(str(readline().rstrip().decode('utf-8')))
        ta = []
        for j in range(w):
            if al[j] == ".":
                ta.append(True)
            else:
                ta.append(False)
                ql.append([0, i, j])
        a.append(ta)

    mc = 0
    while True:
        if len(ql) != 0:
            cost, xv, yv = ql.popleft()
            mc = max(mc, cost)
            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if a[xv][yv]:
                        ql.append([cost + 1, xv, yv])
                        a[xv][yv] = False
        else:
            break
    print(mc)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 146140
#include<stdio.h>
int main(void)
{
	int D[6],i,Top,Front,Right,t;
	char X[100];
	for(i=0;i<6;i++){scanf("%d",D+i);}
	scanf("%s",X);
	Top=1;Front=2;Right=3;
	for(i=0;X[i];i++)
	{
		switch(X[i])
		{
			case 'N':t=Top,Top=Front,Front=7-t;break;
			case 'E':t=Right,Right=Top,Top=7-t;break;
			case 'W':t=Top,Top=Right,Right=7-t;break;
			case 'S':t=Front,Front=Top,Top=7-t;break;
		}
	}
	printf("%d\n",D[Top-1]);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int N;

int main() {
    cin >> N;
    map<char, int> cnt;
    char c;
    map<map<char, int>, int> anagrams;
    for (int i = 0; i < N; i++) {
        map<char, int> cnt;
        for (int j = 0; j < 10; j++) {
            cin >> c;
            cnt[c]++;
        }
        anagrams[cnt]++;
    }
    long long ans = 0;
    for (auto itr = anagrams.begin(); itr != anagrams.end(); itr++) {
        long long n = 1LL * itr->second;
        ans += n * (n - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 49152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=3e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=998244353;
const ll INF=0x3f3f3f3f;

ll dp[MAXn][MAXn],d[MAXn];
ll add(ll a,ll b){
    ll ret = a+b;
    if (ret >= MOD) ret -= MOD;
    return ret;
}
ll mul(ll a,ll b){
    return a*b%MOD;
}
int main(){
    IOS();
    ll n,s;
    cin >> n >> s;
    REP1 (i,n) cin >> d[i];
    dp[0][0] = 1;
    REP1 (i,n) {
        REP (j,s+1) {
            if (j - d[i] >= 0) dp[i][j] = add(dp[i-1][j-d[i]],mul(dp[i-1][j],2LL));
            else dp[i][j] = mul(dp[i-1][j],2LL);
            debug(i,j,dp[i][j]);
        }
    }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 74120
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> res(N+1);
    rep0(i,Q){
        int input;
        cin >> input;
        res[input]++;
    }
    rep1(i,N){
        if(K-Q+res[i]>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

}


Measured memory_bytes: 3768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, D, Q;
int pos[500001];
int d[500000];
bool A[500001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> D;
  rep(i, N) cin >> d[i];
  pos[0] = D;
  rep(i, N) {
    if (d[i] >= 2*pos[i]) {
      pos[i+1] = pos[i];
    }
    else {
      pos[i+1] = abs(pos[i] - d[i]);
    }
  }

  int ng = 1;
  for (int i=N-1; i>=0; i--) {
    A[i] = pos[i] >= ng;

    int x = d[i];
    if (ng > x/2) ng += x;
  }

  cin >> Q;
  rep(i, Q) {
    int q;
    cin >> q;
    q--;
    cout << (A[q]?"YES":"NO") << "\n";
  }
  return 0;
}


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

int main(){ 
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
} 

Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (int s1; cin >> s1&&s1;) {
		int s2 = 0;
		for (int i = 0, a; i < 9; i++) {
			cin >> a;
			s2 += a;
		}
		cout << s1 - s2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int x;
int main() {
  ios::sync_with_stdio(false);
   cin>>x;
   LL y=x/500;
   x%=500;
   LL z=x/5;
   cout<<y*1000+z*5;
  return 0;
}

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

int main(){
  string str;

  getline(cin , str);

  for(int i=0;i<(int)str.size(); ++i){
    if( islower(str[i]) ){
      str[i] = toupper(str[i]);
    }else if( isupper(str[i]) ){
      str[i] = tolower(str[i]);
    }
  }

  cout << str << endl;

  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n) for(int i=z;i<n;i++)
#define forii(z,n) for(int i=z;i<=n;i++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    int first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    vector<vector<ll>> v(n+1,vector<ll>(3));
    fori(1,n+1)
    {
        ll a,b,c;cin>>a>>b>>c;
        v[i]={a,b,c};
    }
    ll dp[n+1][3];
    dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;
    fori(1,n+1)
    {
        dp[i][0]=max(dp[i-1][1]+v[i][0],dp[i-1][2]+v[i][0]);
        dp[i][1]=max(dp[i-1][0]+v[i][1],dp[i-1][2]+v[i][1]);
        dp[i][2]=max(dp[i-1][1]+v[i][2],dp[i-1][0]+v[i][2]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 8064
#include <cstring>
#include <deque>
#include <iostream>

using namespace std;

int main() {

	int n;

	cin >> n;

	while(n) {
		int o=0, s=0;
			char c[8];
		deque<int> b;
		while(o!=3) {
			cin >> c;
			if((strstr(c, "HIT")!=NULL)) {
				b.push_back(1);
				if(b.size()==4) {
					s++;
					b.pop_back();
				}
			}
			else if((strstr(c, "HOMERUN")!=NULL)) {
				s+=1+b.size();
				b.clear();
			}
			else if((strstr(c, "OUT")!=NULL)) {
				o++;
			}
		}
		cout << s << endl;
		n--;
	}

	return 0;

}

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

using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

const int MAXN=1e5;
const int MAXA=1e9;
int n;
ll count[2], sum[2];

int main(int argc, char *argv[])
{
    cin >> n;
    FOR(i,n) {
        int a;
        cin >> a;
        sum[0] += a;
        sum[1] -= a;
        FOR(j,2) {
            if (i%2 == 0) {
                if (sum[j] <= 0) {
                    ::count[j] += 1 - sum[j];
                    sum[j] = 1;
                }
            } else {
                if (sum[j] >= 0) {
                    ::count[j] += sum[j] + 1;
                    sum[j] = -1;
                }
            }
        }
    }

    cout << min(::count[0], ::count[1]) << endl;
    return 0;
}


Measured memory_bytes: 256
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
H = get_ints
A = []
B = []

M.times do |i|
  A[i], B[i] = get_ints_minus_one
end

goods = Array.new(N) { true }

M.times do |i|
  if H[A[i]] > H[B[i]]
    goods[B[i]] = false
  elsif H[A[i]] < H[B[i]]
    goods[A[i]] = false
  else
    goods[A[i]] = false
    goods[B[i]] = false
  end
end

puts goods.count { |x| x }


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

long long dp[309][309], nr[609][609], ret[309][309], power[609][609], mod, N, K;

void init() {
	for (int i = 0; i <= 600; i++) {
		for (int j = 0; j <= 600; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
	for (int i = 0; i <= 600; i++) {
		power[i][0] = 1;
		for (int j = 1; j <= 600; j++) power[i][j] = (power[i][j - 1] * i) % mod;
	}
	ret[0][0] = 1;
	for (int i = 0; i <= 300; i++) {
		for (int j = 0; j <= 300; j++) {
			ret[i + 1][j] += ret[i][j]; ret[i + 1][j] %= mod;
			ret[i][j + 1] += 1LL * ret[i][j] * (i + 1); ret[i][j + 1] %= mod;
		}
	}
}

long long ncr(long long a, long long b) {
	if (b < 0 || a < b) return 0;
	return nr[a - b][b];
}
long long modpow(long long a, long long b) {
	return power[a][b];
}

int main() {
	cin >> N >> K >> mod;
	init();
	dp[0][0] = 1;
	for (int i = 0; i < K; i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j] == 0) continue;
			for (int k = 0; k <= N - j; k++) {
				dp[i + 1][j + k] += dp[i][j] * ret[j][k];
				dp[i + 1][j + k] %= mod;
			}
		}
	}
	cout << dp[K][N] << endl;
	return 0;
}

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

using namespace std;

bool num[10];
// true →　useable

int main(){
 vector<int> vec(3); cin >> vec[0] >> vec[1] >> vec[2];
  
  sort(vec.begin(),vec.end());
  
  if( vec[0] == 5 && vec[1] == 5 && vec[2] == 7){ cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  
  return 0;
} 

Measured memory_bytes: 256
def run_c():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    b.append(0)

    c, d, o = 0, 0, 0
    for i in range(n+1):
        d = a[i] - c
        if d - b[i] <= 0:
            o += a[i]
            c = b[i] - d if d >= 0 else b[i]
        else:
            o += c + b[i]
            c = 0

    print(o)

if __name__ == "__main__":
    run_c()


Measured memory_bytes: 18396
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b) = get!(usize, usize);
    if a == b {
        println!("Draw");
    } else if a == 1 || (b != 1 && a > b) {
        println!("Alice");
    } else {
        println!("Bob");
    }
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);


        int N = sc.nextInt();
        int W = sc.nextInt();

        dp = new long[N+1][W+1];
        for (int i = 0; i <= N ; i++) {
            Arrays.fill(dp[i],-1);
        }
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        long ans = rec(w,v,0,W);

        System.out.println(ans);
    }


    static long[][] dp =null;
    static
    long rec(int[] w,int[] v ,int i, int W){

        if(i==w.length) return 0;

        if(dp[i][W] != -1){
            return dp[i][W];
        }


        long max = -1;
        //use
        if(W-w[i]>=0){
            max = Math.max(max, rec(w,v,i+1,W-w[i] ) +v[i] );
        }
        //not use
        max = Math.max(max,rec(w,v,i+1, W));

        dp[i][W] = max;

        return max;


    }

}

Measured memory_bytes: 126036
A = 10
B = 5
C = 1

N, Y = map(int, input().split())
Y //= 1000

res_A = -1
res_B = -1
res_C = -1

for num_A in [num_A for num_A in range(N + 1) if A * num_A <= Y]:
    diff_YA = Y - A * num_A
    for num_B in [num_B for num_B in range(N + 1 - num_A) if B * num_B <= diff_YA]:
        diff_YAB = diff_YA - B * num_B
        if (diff_YAB == C * (N - num_A - num_B)):
            res_A = num_A
            res_B = num_B
            res_C = N - num_A - num_B
            break
    else:
        continue
    break

print("{} {} {}".format(res_A, res_B, res_C))


Measured memory_bytes: 41180
h,w=map(int,input().split())
l=[]
for i in range(h):
    li=[]
    for j in input():
        if j==".":li.append(0)
        elif j=="#":li.append(1)
    l.append(li)
for i in range(h):
    for j in range(w):
        if l[i][j]==1:
            x=0
            if i>0:x+=l[i-1][j]
            if i<h-1:x+=l[i+1][j]
            if j>0:x+=l[i][j-1]
            if j<w-1:x+=l[i][j+1]
            if x==0:
                print("No")
                break
    else:continue
    break
else:print("Yes")

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % 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;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
bool isunb(string s){
	int cnt[26]={};
	rep(i,s.size()){
		cnt[s[i]-'a']++;
	}
	bool re=false;
	rep(i,26){
		if(cnt[i]>s.size()/2)re=true;
	}
	return re;
}
signed main(){
	string s;
	cin>>s;
	int n=s.size();
	if(s.size()==2){
		if(s[0]==s[1])cout<<1<<" "<<2<<endl;
		else cout<<-1<<" "<<-1<<endl;
		return 0;
	}
	rep(i,n-2){
		if(isunb(s.substr(i,3))){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 512
# frozen_string_literal: true

n = gets.to_i
a = Array.new(n)
b = Array.new(n)
n.times { |i| a[i], b[i] = gets.split.map(&:to_i) }
a.reverse!
b.reverse!

cnt = 0
n.times do |i|
  cnt += (b[i] - (cnt + a[i]) % b[i]) % b[i]
end
puts cnt


Measured memory_bytes: 3324
A=io.read("n")
B=io.read("n")
C=io.read("n")
X=io.read("n")
Y=io.read("n")
local cost=0
if C*2<=math.min(A,B) then
  cost=C*2*math.max(X,Y)
  elseif C*2>=A+B then
    cost=A*X+B*Y
  elseif C*2<A+B and C*2>=math.max(A,B) then
    if X>Y then
      cost=C*2*math.min(X,Y)+math.abs(X-Y)*A
    else 
      cost=C*2*math.min(X,Y)+math.abs(X-Y)*B
    end
  elseif C*2>math.min(A,B) and C*2<math.max(A,B) then
    if A<B and X<Y or A>B and X>Y then
      cost=C*2*math.max(X,Y)
    elseif A<B and X>Y then
      cost=C*2*Y+A*(X-Y)
    elseif  A>B and X<Y then
      cost=C*2*X+B*(Y-X)
    end
end
print(cost)

Measured memory_bytes: 508
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a[] = new long[n];
		for (int i = 0; i < n; i++) a[i] = sc.nextLong();
		solve(a, n);
	}

	private static void solve(long[] a, int n) {
		// TODO Auto-generated method stub
		long ans = 0, sum = 0, mod = 1_000_000_007;
		for (int i = 0; i < n; i++) {
			ans = (ans + a[i] * sum) % mod;
			sum = (sum + a[i]) % mod;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 51668
/*
 * main.c
 *
 *  Created on: 2019/03/09
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int sort_inc(const void *a, const void *b)
{
	return (*(int*)a - *(int*)b);
}
int main()
{
	int a[3] = {0};
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	qsort(a, 3, sizeof(int), sort_inc);
	printf("%d\n", (a[2]*10) + (a[1]) + a[0]);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

int main() {
  auto min = [](auto a, auto b) { return (a < b) ? a : b; };
  std::string s;
  std::cin >> s;
  int mind{2000000000};
  int N{static_cast<int>(s.length())};
  for (int i = 0; i < N - 2;i++){
    int a{std::stoi(s.substr(i, 3))};
    mind = min(mind, std::abs(a - 753));
  }
  printf("%d", mind);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
s = [['.'] * (W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.'] * (W + 2)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == '.':
            continue
        bcell = 0
        for x, y in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            if s[h + x][w + y] == '#':
                bcell += 1
        if bcell < 1:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main(void) {
  ll N;
  cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N));
  REP(i, 0, N) REP(j, 0, N) cin >> A[i][j];

  vector<ll> g(1 << N);
  REP(s, 0, 1 << N) {
    REP(i, 0, N) if (s & (1 << i)) {
      REP(j, i + 1, N) if (s & (1 << j)) {
        g[s] += A[i][j];
      }
    }
  }

  vector<ll> dp(1 << N, -INF);
  dp[0] = 0;

  REP(s, 1, 1 << N) {
    for (ll t = s;; t = (t - 1) & s) {
      dp[s] = max(dp[s], dp[s - t] + g[t]);
      if (t == 0) break;
    }
  }

  cout << dp[(1 << N) - 1] << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
 
int main(){
  ll N,Q;
  cin >> N >> Q;
  vector<vector<ll>> t(N);
  ll a,b;
  rep(i,N-1){
    cin >> a >> b;
    a--; b--;
    t[a].pb(b);
    t[b].pb(a);
  }
  vector<ll> ans(N,0);
 
  ll p,x;
  rep(i,Q){
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  vector<bool> chk(N,false);
  chk[0] = true;
  queue<ll> q;
  q.push(0);
  while(!q.empty()){
    ll now = q.front(); q.pop();
    rep(i,(int)t[now].size()){
      if(chk[t[now][i]]) continue;
      chk[t[now][i]] = true;
      q.push(t[now][i]);
      ans[t[now][i]] += ans[now];
    }
  }
 
  rep(i,N){
    if(i!=0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
 
  return 0;
}

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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    string S;
    cin >> S;

    int l = 0;
    int r = 0;
    int cnt = 0;
    for(int i=0; i<S.length(); i++){
        if(S[i] == '(') l++;
        else{
            r++;
            if(l == 0) continue;
            l--;
            cnt++;
        }
    }

    for(int i=0; i<r-cnt; i++){
        cout << '(';
    }
    cout << S;
    for(int i=0; i<l; i++){
        cout << ')';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    if sum(A) == X:
        print(N)
    else:
        ans = 0
        for a in A[:-1]:
            if a <= X:
                ans += 1
                X -= a
            else:
                break
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	while(true){
            String[] strArr = br.readLine().split(" ");

            int a = Integer.parseInt(strArr[0]);
            String op = strArr[1];
            int b = Integer.parseInt(strArr[2]);

            if(op.equals("?")) break;

            switch(op){
            	case "+":
            		System.out.println(a + b);
            		break;
            	case "-":
            		System.out.println(a - b);
            		break;
            	case "*":
            		System.out.println(a * b);
            		break;
            	case "/":
            		System.out.println(a / b);
            		break;
            	default:
            		break;
            }
    	}
    }
}

Measured memory_bytes: 24324
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    bool ok = true;
    if (N % 2 != 0) {
        ok = false;
    }
    else {
        for (int i = 0; i < N / 2; ++i) {
            if (S[i] != S[N / 2 + i]) {
                ok = false;
                break;
            }
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct dsu
{
  vector<ll> parent;
  vector<ll> rank;
  ll comp;
  void init(ll n)
  {
    parent.resize(n+1);
    rank.resize(n+1);
    for(ll p=1;p<=n;p++)
    {
      parent[p]=p;
      rank[p]=1;
    } 
    comp=n; 
  }
  ll f(ll x)
  {
    if(parent[x]==x)
      return x;
    return parent[x]=f(parent[x]);
  }
  void mer(ll a,ll b)
  {
      a=f(a);
      b=f(b);
    if(a!=b)
    {
      if(rank[a]<rank[b])
      {
        rank[b]+=rank[a];
        parent[a]=b;
      }
      else
      {
        rank[a]+=rank[b];
        parent[b]=a;
      }
      comp--;
    }
  }

}G;
int main()
{ 
  ll n,m;
  cin>>n>>m;
  G.init(n);
  for(ll p=0;p<m;p++)
  {
    ll x,y;
    cin>>x>>y;
    G.mer(x,y);
  }
  cout<<G.comp-1;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int return_gcd(int a, int b){
    if(b == 0) return a;
    return return_gcd(b, a%b);
}

int return_lcm(int a, int b){
    int gcd = return_gcd(a, b);
    return a / gcd * b;
}
signed main() {
    int n,m;
    cin >> n >> m;

    vector<int> a(n),mod(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int i = 0; i < n; i++){
        a[i] /= 2;
        int cnt = 0;
        int x = a[i];
        while(x % 2 == 0){
            x /= 2;
            cnt++;
        }
        mod[i] = cnt % 2;
    }

    bool flag = true;
    for(int i = 1; i < n; i++) if(mod[i-1] != mod[i]) flag = false;

    if(!flag){
        cout << 0 << endl;
        return 0;
    }

    int LCM = a[0];
    for(int i = 1; i < n; i++){
        LCM = return_lcm(LCM, a[i]);
    }

    int ans = (m + LCM) / LCM;
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int a[200001];
int main()
{
    ///optimize();
    int n,i,b;
    cin>>n;
    for(i=1;i<n;i++) {cin>>b; a[b]++;}
    for(i=1;i<=n;i++) cout<<a[i] el;




    return 0;

}





///Brainless people are gonna understand this code.




///Brainless_Loco Terminates Here!


Measured memory_bytes: 4400
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int S, W;
    cin >> S >> W;
    cout << (W >= S ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3608
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] t=sc.nextLine().split(" ");
 
//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

int W=Integer.parseInt(t[0]);
int H=Integer.parseInt(t[1]);
int N=Integer.parseInt(t[2]);

boolean[][] data=new boolean[H][W];

for(int i=0;i<N;i++){
t=sc.nextLine().split(" ");
int W2=Integer.parseInt(t[0]);
int H2=Integer.parseInt(t[1]);
int N2=Integer.parseInt(t[2]);
switch(t[2]){
case "1":
for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
if(k+1<=W2)data[j][k]=true;
}}
break;
case "2":
for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
if(k+1>W2)data[j][k]=true;
}}

break;
case "3":
for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
if(j+1<=H2)data[j][k]=true;
}}

break;
case "4":
for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
if(j+1>H2)data[j][k]=true;
}}

break;


}//swi

for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
//System.out.print(data[j][k]+" ");
}
//System.out.println();

}
//System.out.println();


}//for

//Queue<String> qA = new ArrayDeque<>();
int count=0;
for(int j=0;j<H;j++){
for(int k=0;k<W;k++){
//System.out.print(data[j][k]+" ");
if(data[j][k]==false)count++;
}
//System.out.println();

}


System.out.println(count);
	}
}

Measured memory_bytes: 24380
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, D; cin >> N >> D;

  int d = 2 * D + 1;
  cout << (N + d - 1) / d << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    bint N,A,B,C,D,E;
    std::cin >> N>>A>>B>>C>>D>>E;
    bint bottleneck = std::min<bint>({A,B,C,D,E});
    bint add = 0;
    if (N % bottleneck != 0) {
        add = N / bottleneck;
    } else {
        add = N / bottleneck - 1;
    }
    std::cout << 5 + add << std::endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = ""
if n == 0:
	print("0")
	exit()
else:
	i = 0
	while n != 0:
		m = n % (2 ** (i + 1))
		if m != 0:
			s = "1" + s
			if i % 2 == 0:
				n -= 2 ** i
			else:
				n += 2 ** i
		else:
			s = "0" + s
		i += 1
print(s)

Measured memory_bytes: 3060
from math import ceil
n = int(input())

res=0

for i in range(1,ceil(n/2)):
    for j in range(i+1,n):
        if i*j < n:
            res+=1
        else:
            break

if int(n**0.5) == n**0.5:
    print(res*2 + int(n**0.5) - 1)
else:
    print(res*2 + int(n**0.5))

Measured memory_bytes: 9428
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#define inf 1000000007
using namespace std;
 
int main(void){
    double n, k;
    cin >> n >> k;
    double ans = 0;
    int check;
    for(int i = 1; i <= n; i++){
        check = i;
        for(int j = 0; j < 100; j++){
            if(check >= k){
                check = j; break;
            }
            check*=2;
        }
        if(check>=1)
        ans += (1/n)*pow(0.5, double(check));
        else if(check==0)
        ans += 1/n;
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
x, y = map(int, input().split())

if y == 0:
    if x >= 0:
        print(x+1)
    else:
        print(-x)
    exit()

if x >= 0 and y >= 0:
    if x <= y:
        print(y-x)
    else:
        print(1+(-y+x)+1)
elif x >= 0 and y <= 0:
    if x >= -y:
        print(1+x-(-y))
    else:
        print(-y-x+1)
elif x <= 0 and y >= 0:
    if y >= -x:
        print(1+(y-(-x)))
    else:
        print(-y-x+1)
else:
    if x <= y:
        print(y-x)
    else:
        print(1-y+x+1)


Measured memory_bytes: 61944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
const ll mod=1e9+7;
ll n,m;
int main()
{
    //314 1592
    //cout<<(312*1590)<<endl;
    while(cin>>n>>m)
    {
        if(n==1&&m==1)
        {
            puts("1");
            continue;
        }
        if(n>m)
            swap(n,m);
        if(n==1 || m==1)
        {
            printf("%lld\n",m-2);
            continue;
        }
        printf("%lld\n",(n-2)*(m-2));
    }
    return 0;
}


Measured memory_bytes: 256