akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
class Combination():
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fact = self.make_fact(n)
        self.fact_inv = self.make_fact_inv(n)
    def make_fact(self, n):#0~nの階乗を求める
        res = [1]*(n+1)
        for i in range(1, n+1):
            res[i] = res[i-1]*i%self.mod
        return res
    def make_fact_inv(self, n):#0~nの階乗のmodに関する逆元を求める
        fact_inv = [1]*(n+1)
        fact_inv[n] = pow(self.fact[n], self.mod-2, self.mod)#フェルマーの小定理
        for i in range(n, 0, -1):
            fact_inv[i-1] = fact_inv[i]*i%self.mod
        return fact_inv
    def comb(self, m, k):
        if m<0 or k<0 or m<k:
            return 0
        return self.fact[m]*self.fact_inv[k]*self.fact_inv[m-k]%self.mod
mod = 998244353
n, m = map(int, input().split())
C = Combination(n+m*3, mod)
ans = 0
for i in range(min(n, m)+1):
    if m%2 != i%2:
        continue
    res = 0
    r = (m*3-i)//2
    res+=C.comb(r+n-1, r)
    res-=C.comb(r-m-1+n-1, n-1)*(n-i)
    res-=C.comb(r-m+n-1, n-1)*i
    res*=C.comb(n, i)
    res%-mod
    ans+=res
    ans%=mod
print(ans)



Measured memory_bytes: 81000
a, b = gets.chomp.split(" ").map(&:to_f)
a1 = (a / 0.08).ceil
a2 = ((a + 1.0) / 0.08).ceil - 1
b1 = (b / 0.1).ceil
b2 = ((b + 1.0) / 0.1).ceil - 1
puts ([*(a1..a2)] & [*(b1..b2)]).size == 0 ? -1 : ([*(a1..a2)] & [*(b1..b2)])[0]

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, n) for(int i = 1; i <= n; i++)
#define foru0(i, n) for(int i = 0; i < n; i++)
#define ford(i, n) for(int i = n; i >= 1; i--)
#define ford0(i, n) for(int i = n - 1; i >= 0; i--)
#define fors(i, a, b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;

void solve() {
    int n;
    cin >> n;
    vector<double> p(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    vector<vector<double> > dp(n + 1, vector<double>(n + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j < i) {
                dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * p[i];
            } else {
                dp[i][j] = dp[i-1][j-1] * p[i];
            }
        }
    }
    double res = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        res += dp[n][i];
    }
    cout << res;
}

int main() {
    #ifdef DEBUG
        freopen("solve.inp", "r", stdin);
        freopen("solve.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() << " ms.\n";
}


Measured memory_bytes: 70784
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
	int N,K; cin >> N>>K;
	for (int i = 0; i < N; ++i) cin >> h[i];

	//初期化
	for (int i = 0; i < 100010; i++) dp[i] = 1LL << 60;
	dp[0] = 0;

	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			if (i < j) break;
			dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}

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

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

struct Item {
	int v, w;
};

vector<Item> get_items(const unsigned int N) {
	vector<Item> items(N+1);
	items[0].v = 0;
	items[0].w = 0;
	for (int i = 1; i < items.size(); ++i) {
		cin >> items[i].v >> items[i].w;
	}
	return items;
}

int most_valuable(vector<Item> items, const unsigned int W)
{
	vector<vector<int> > dp_table(items.size(), vector<int>(W+1, 0));

	for (int i = 1; i < dp_table.size(); ++i) {
		for (int j = 1; j <= W; ++j) {
			if (j < items[i].w) {
				dp_table[i][j] = dp_table[i - 1][j];
			} else {
				dp_table[i][j] = max(dp_table[i - 1][j], dp_table[i - 1][j - items[i].w] + items[i].v);
			}
		}
	}


	return dp_table[dp_table.size()-1][W];
}

int main()
{
	unsigned int N, W;
	cin >> N >> W;

	vector<Item> items = get_items(N);
	int max_value = most_valuable(items, W);

	cout << max_value << endl;

	return 0;
}

Measured memory_bytes: 4956
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	long long int n, k, d[10], yojo = 0, cnt = 0, siri, del;
	cin >> n >> k;
	string s;
	for (int i = 0; i < k; i++) cin >> d[i];
	yojo = 0;
	for (long long int i = n; i < 100000; i++) {
		siri = i;
		s = to_string(siri);
		for (int j = 0; j < s.size(); j++) {
			for (int l = 0; l < k; l++) {
				del = s[j] - '0';
				if (del == d[l]) {
					yojo = 1;
					break;
				}
			}
			if (yojo)break;
		}
		if (yojo)yojo = 0;
		else {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[], int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int j,i,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  trace(A,N);
  insertionSort(A,N);

  return 0;
}
		     



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


int main(){
	int a,b,k;
	bool flag = false;
	cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(flag==false){
			flag=true;
			if(a%2==1)a-=1;
			
			b+=a/2;
			a/=2;
		}
		else{
			flag=false;
			if(b%2==1)b-=1;
			a+=b/2;
			b/=2;
		}
	}
	
	cout<<a<<" "<<b<<endl;
	
	return 0;
}


Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1ll<<i)<=x;i++);
    return i;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    int n;
    n=s.size();
    
    int x=LLONG_MAX;
    fff(i,n-2) {
        string t="";
        t=s[i];
        t+=s[i+1];
        t+=s[i+2];
        int p=stoi(t);
        x=min(x,abs(753-p));
    }
    
    cout << x;
    
        
    
    
	return 0;
    
}

Measured memory_bytes: 8832
import math
from math import atan, cos, tan

a, b, x = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

result =0

if x>=a**2 * b/2:
    result = math.degrees(atan((2*(b - x/a**2)/a)))
else:
    result = math.degrees(atan(a*b**2/2/x))

print(result)

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h)rep(j,w) cin>>s[i][j];
    int ans=10000000;

    for(int tmp = 0;tmp< (1<<(h-1)); tmp++){
        bitset<10> t(tmp);
        int x=t.count();
        if(ans<=x) continue;
        vector<vector<int>> a(x+1,vector<int>(w,0));
        int cntH=0;
        rep(i,h){
            rep(j,w){
                if(s[i][j]=='1') a[cntH][j] ++;
            }
            if(i<h-1 && t.test(i)) cntH ++;
        }
        vector<int> b(x+1,0);
        int cnt=0;
        rep(i,w){
            bool f=1;
            rep(j,x+1){
                if(b[j]+a[j][i]>k){
                    f=0;
                    break;
                }
            }
            if(!f){
                cnt ++;
                rep(j,x+1) b[j]=a[j][i];
                continue;
            }
            rep(j,x+1) b[j] +=a[j][i];
        }
        bool f2=1;
        rep(i,x+1) if(b[i]>k) f2=0;
        if(!f2){
            cnt=0;
            rep(i,x+1) b[i]=0;
            continue;
        }
        cnt +=x;
        ans =min(ans,cnt);
        cnt =0;
        rep(i,x+1) b[i]=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 0, mod = (int) 0;

int main() {
	string s;
	cin >> s;
	for (int j = 0; j < (int) s.size() - 8; ++j)
		cout << s[j];
	cout << endl;
}






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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;

    bool ok = false;
    rep(i, 1005){
        if(i * 100 <= n && n <= i * 105){
            ok = true;
        }
    }

    cout << ok << endl;

    return 0;
}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def bubbleSort(A, N):
    flag = 1
    cnt = 0;
    while flag:
        flag = 0;
        for i in reversed(range(1, N)):
            if A[i-1] > A[i]:
                A[i-1], A[i] = A[i] , A[i-1]
                flag = 1;
                cnt += 1
    showResult(A, cnt)

def showResult(A, cnt):
    N = len(A)
    for i in range(N-1):
        print(A[i], end = " ")
    print(A[N - 1 ])
    print(cnt)

N = int(input())
A = list(map(int, input().split())) 
#A = [1,5,4,3,2]
#N = len(A)

bubbleSort(A, N)



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

int main() {
  vector<int> v(5);
  for(int i = 0; i < 5; i++)
    cin >> v.at(i);
  int s = 0, m = 9;
  bool a = 1;
  for(int i = 0; i < 5; i++){
    if(v.at(i) % 10 != 0){
      m = min(m, v.at(i) % 10);
      v.at(i) = (v.at(i) / 10 + 1) * 10;
      a = 0;
    }
    s += v.at(i);
  }
  if(a)
    m = 0;
  else
    m -= 10;
  cout << s + m << endl;
}

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

int main(void){

    int A, B, C, D;

    scanf("%d%d%d%d", &A, &B, &C, &D);

    int ans = 0;

    if(A < B){
        ans += A;
    }else{
        ans += B;
    }

    if(C < D){
        ans += C;
    }else{
        ans += D;
    }

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

    return 0;
}

Measured memory_bytes: 1720
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int n;
    cin >> n ;
    vector<int> v(n);
    // vector<int> c(n);
    for(int i=0;i<n;i++)cin >> v.at(i);
    int c;
    int ans=0;
    for(int i=0;i<n;i++){
        cin >> c;
        if(v.at(i)-c>0) ans+= (v.at(i)-c);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

int main() {
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll g = gcd(a[0], a[1]);
    srep(i, n, 2) {
        g = gcd(g, a[i]);
    }
    ll ans = g;

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

Measured memory_bytes: 1024
s=input()
k=int(input())
string="abcdefghijklmnopqrstuvwxyz"
lists=[0 for i in range(len(s))]
for i in range(len(s)):
    lists[i]=s[i]

dic={}
for i in range(26):
    dic[string[i]]=(26-i)%26

ans=0
for i in range(len(s)):
    ans=ans+dic[lists[i]]
    if ans<=k:
        lists[i]="a"
    elif ans>=k:
        ans=ans-dic[lists[i]]
    if i==len(s)-1:

        left=(k-ans)%26
        index=dic[lists[len(s)-1]]
        index-=left
        strings="a"
        for some in dic.keys():
            if dic[some]==index%26:
                strings=some
        lists[i]=strings                   
an=""
for j in lists:
    an+=j
print(an)

Measured memory_bytes: 4340
#include <stdio.h>

int main(int argc,const char *argv[]){
    int a,b,c,n,c2,ab,i,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d",&a,&b,&c);
        if(a>c){
            tmp=a;
            a=c;
            c=tmp;
        }
        if(b>c){
            tmp=b;
            b=c;
            c=tmp;
        }
        
        c2=c*c;
        ab=a*a+b*b;
        
    
        if(ab!=c2){
            printf("NO\n");
        }else{
            printf("YES\n");
        }
    }
    return 0;
    }

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  rep(i,0,a+1) rep(j,0,b+1) rep(k,0,c+1) {
    if (500*i + 100*j + 50*k == x) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
fun main (args:Array<String>) {
    val (trytime, hrate) = readLine()!!.split(" ").map(String::toInt)
    if(trytime >= 10){
        val nrate = hrate
        print(nrate)
        return
    }
    else{
        val nrate = 100 * (10-trytime)
        print(hrate + nrate)
    }
}

Measured memory_bytes: 36304
N, U, V = gets.split.map(&:to_i)

E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map(&:to_i)

  E[a] << b
  E[b] << a
end

aoki_min = Hash.new(Float::INFINITY)
queue = [[V, 0]]

until queue.empty?
  v, dist = queue.shift

  next if aoki_min[v] <= dist
  aoki_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

takahashi_min = Hash.new(Float::INFINITY)
queue = [[U, 0]]

until queue.empty?
  v, dist = queue.shift

  next if takahashi_min[v] <= dist
  takahashi_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

max_d = -1

(1..N).each do |v|
  ad = aoki_min[v]
  td = takahashi_min[v]

  next if ad <= td

  if max_d < ad
    max_d = ad
  end
end

ans = max_d - 1

puts ans


Measured memory_bytes: 36192
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define F first
#define S second
using namespace std;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	long double n;
	cin >> n;
	long double x = n/3;
	cout<<fixed << setprecision(6) << x*x*x;
}

Measured memory_bytes: 256
def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans
print(solve())


Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmax(ll x, ll y){
    if(x>y) return x;
    else return y;
}

int main()
{
    int N; cin >> N;
    vector<int> T(N), A(N);
    REP(i,N){
        cin >> T[i] >> A[i];
    }
    ll first=1, second=1;

    REP(i,N){
        ll res=llmax((first-1)/T[i]+1,(second-1)/A[i]+1);
        //cout << first/T[i] << " " << second/A[i] << endl;
        first=T[i]*res;
        second=A[i]*res;
        //cout << "first= " << first << " second= " << second << endl;
    }

    cout << first+second << endl;

    return 0;
}


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

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

int main() {
    ll n,k; cin >> n >> k;
    ll ans = k;
    rep(i,n-1){
        ans *= (k - 1);
    }
    cout << ans << endl;
}

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

const int maxn=1000005;

int fa[maxn];
int dis[maxn];

int Find(int x)
{
    if(fa[x]==x)
        return x;
    int r=Find(fa[x]);
    dis[x]=dis[fa[x]]+dis[x];
    return fa[x]=r;
}

int Union(int x,int y,int z)
{
    int fx=Find(x);
    int fy=Find(y);

    if (fx==fy)
        return z==dis[y]-dis[x];
    fa[fy]=fx;
    dis[fy]=dis[x]+z-dis[y];
    return 1;
}

int main()
{
    int n,m;
    int flag= 1;
    cin>>n>>m;
    for (int i=1;i<=n;i++)
        fa[i]=i;
    for (int i=1;i<=m;i++)
    {
        int l,r,d;
        cin>>l>>r>>d;
        if (flag)
            flag=Union(l,r,d);
    }
    if (flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for(int i = 0; i < N; i++){
        cin >> T[i];
    }
    int ans = 0;
    int  i = 0;
    sort(T.begin(),T.end());
    while(i < N){
        int j = i;
        while(i - j < C && i < N && T[i] <= T[j] + K){
            i++;
        }
        ans++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 640
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

def sum_of_digit(n):
    res=0
    while n>0:
        res+=n%10
        n=n//10
    return res
count=0
for i in range(1,n+1):
    if a<= sum_of_digit(i) and sum_of_digit(i) <=b :
        count+=i
print(count)


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

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

        vector<int> A(N);
        vector<int> B(N);
        vector<int> C(N - 1);
        int score = 0;

        for (int i = 0; i < N; i++) {
                cin >> A.at(i);
        A.at(i)--;
        }
        for (int i = 0; i < N; i++) {
                cin >> B.at(i);
        }
        for (int i = 0; i < N - 1; i++) {
                cin >> C.at(i);
        }

        for (int i = 0; i < N - 1; i++) {
                if (A.at(i + 1) - A.at(i) == 1) {
                        score += C.at(A.at(i));
                }
        }
        for (int i = 0; i < N; i++) {
                score += B.at(i);
        }

        cout << score << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

const int MAXN=2002;
int n,l[MAXN],ans;

int main()
{
    read(n);
    for (int i=1;i<=n;++i) read(l[i]);
    sort(l+1,l+n+1);
    for (int i=1;i<n-1;++i)
        for (int j=i+1;j<n;++j)
        {
            int sum=l[i]+l[j];
            ans+=lower_bound(l+j+1,l+n+1,sum)-l-j-1;
            //printf("%d %d %d  -  %d\n",i,j,lower_bound(l+j+1,l+n+1,sum)-l,ans);
        }
    printf("%d",ans);
    return 0;
}

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

bool bellman_ford(const int v, const int s,
                  const vector<pair<pair<int, int>, int64_t>>& g,
                  vector<int64_t>& cost,
                  vector<bool>& negative)
{
    const int64_t inf = 1LL << 60;
    cost[s] = 0;
    for (auto i = 0; i < v; i++) {
        for (auto & elm : g) {
            if(cost[elm.first.first] == inf) continue;
            if(cost[elm.first.second] > cost[elm.first.first] + elm.second) {
                if(i == v - 1) negative[elm.first.second] = true;
                cost[elm.first.second] = cost[elm.first.first] + elm.second;
            }
            // 閉路から進んだ先は閉路を含む扱いにする
            if(negative[elm.first.first] == true) negative[elm.first.second] = true;
        }
    }
    return false;
}

int main(){
    int n, m; cin >> n >> m;
    vector<pair<pair<int, int>, int64_t>> g;
    const int64_t inf = 1LL << 60;
    vector<int64_t> cost(n, inf); vector<bool> negative(n, false);
    for (auto i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        g.emplace_back(make_pair(a, b), -c);
    }
    bellman_ford(n, 0, g, cost, negative);
    if(negative[n - 1]) {
        cout << "inf" << endl;
        return 0;
    }
    cout << -cost[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long mod=1000000007;
int main(){
    int N,K;cin>>N>>K;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];

    }
    int ans=0;
    sort(A.begin(),A.end());
    for(int i=0;i<K;i++){
        ans+=A[i];
    }
    cout<<ans<<endl;





}

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

int main(){
  ll n,ans = 0;cin >> n;
  for(ll i=1;i<=sqrt(n);++i){
    if(n%i==0)ans = i+n/i-2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

const ll N = 1e3 + 5, M = 1e4 + 5, INF = 1e9;

int main(){
	#define int ll
	ll n, k;
	cin >> n >> k;
	ll a[n + 1];
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = k + 1; i <= n; i++){
		if(a[i] > a[i - k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 5196
import kotlin.math.abs

fun main() {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map { it.toInt() }

    val dp = IntArray(n)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])

    for (i in 2 until n) {
        val a = abs(h[i] - h[i - 2]) + dp[i - 2]
        val b = abs(h[i] - h[i - 1]) + dp[i - 1]
        dp[i] = a.coerceAtMost(b)
    }
    print(dp[n - 1])

}

Measured memory_bytes: 50148
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_A
  * Structured Program I - Print a Rectangle
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt)).map { case Array(h, w) => (h, w) }
      .takeWhile(_ != (0, 0))
      .map { case (h, w) => createARectangle(h, w) }
      .foreach(_.foreach(println))
  }

  def createARectangle(h: Int, w: Int): Seq[String] = {
    (1 to h).map(_ => "#" * w) :+ ""
  }
}

Measured memory_bytes: 45660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int score[2000][2000];

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        int j=0,k=0,cnt;
        while(j<w){
            cnt=0;
            if(s[i][j]=='.'){
                cnt++;
                while(k<w-1&&s[i][k+1]=='.'){
                    cnt++;
                    k++;
                }
            }
            for(int a=j;a<=k;a++){
                score[i][a]=cnt;
            }
            j=k+1;
            k=k+1;
        }
    }
    for(int i=0;i<w;i++){
        int j=0,k=0,cnt;
        while(j<h){
            cnt=0;
            if(s[j][i]=='.'){
                cnt++;
                while(k<h-1&&s[k+1][i]=='.'){
                    k++;
                    cnt++;
                }
            }
            for(int a=j;a<=k;a++){
                score[a][i]+=cnt;
            }
            j=k+1;
            k=k+1;
        }
    }
    int ans=-1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans=max(ans,score[i][j]-1);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 19968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<int> a((1 << n));
  rep(i, (1 << n)) cin >> a[i];

  vector<pair<int, int>> dp((1 << n));
  rep(S, (1 << n)) {
    dp[S] = {S, -1};
    rep(i, n) {
      if (S >> i & 1) {
        int T = S & ~(1 << i);
        if (a[dp[T].first] > a[dp[S].first]) {
          dp[S] = {dp[T].first, dp[S].first};
          if (a[dp[T].second] > a[dp[S].second] && dp[S].first != dp[T].second) {
            dp[S].second = dp[T].second;
          }
        }
        else if (dp[S].second == -1) {
          dp[S].second = dp[T].first;
        }
        else if (a[dp[T].first] > a[dp[S].second] && dp[S].first != dp[T].first) {
          dp[S].second = dp[T].first;
        }
      }
    }
  }
  int ans = 0;
  FOR(S, 1, (1 << n)) {
    chmax(ans, a[dp[S].first] + a[dp[S].second]);
    //cout << dp[S].first << ' ' << dp[S].second << '\n';
    cout << ans << '\n';
  }


  




  
  return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

int main(){
   ll N; cin>>N;
   ll sum = 0;
   vector <ll> A;
   vector <ll>  xx(N+1);
   for(int i=1;i<=N;i++){
     ll a; cin>>a; 
     a = 2*a;
     xx[i] = a;
     sum += a;
   }

   ll sbstruct = 0;

   for(int i=2;i<=N;i+=2){
     sbstruct += xx[i];
   }

   sum = sum / 2;

   ll x = sum - sbstruct;

   for(int i=1;i<=N;i++){
       if(i==N) {cout<<x;break;}
     cout<<x<<" ";
     if(i==N) break;
     x = xx[i] - x;


   }
   

    return 0;
}



Measured memory_bytes: 2048
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include <bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li      int64_t
#define ld      double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define repir(i,v)  for(i=v.rbegin();i!=v.rend();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl          cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpli;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define rtr reverse_iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-2,-2,+1,-1};li dy[]={+1,-1,-2,-2};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

void solve(){
  string s;cin>>s;
  li n=s.length();
  if(n>=4){
    if(s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I'){
      cout<<"Yes";
      return ;
    }
  }
  cout<<"No";
}

int main(){
  opt
  #ifndef ONLINE_JUDGE
  #endif
  li t=1;
  //cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF (1LL << 40)
int main() {
	char str[200];
	scanf("%s", str);
	if (str[2] == str[3] && str[4] == str[5]) {
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int H,W;
  cin>>H>>W;
  vector<string>s(H);
  for(int i=0;i<H;i++){
    cin>>s[i];
  }
  int B=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i][j]=='#'){B++;}
    }
  }
  vector<int>dx={0,0,1,-1};
  vector<int>dy={1,-1,0,0};
  queue<pair<int,int>>q;
  q.push(make_pair(0,0));
  vector<vector<int>>ok(H,vector<int>(W,-1));
  ok[0][0]=0;
  while(!q.empty()){
    auto p=q.front();q.pop();
    int y=p.first,x=p.second;
    for(int i=0;i<4;i++){
      int dh=y+dy[i],dw=x+dx[i];
      if(dh<0||dh>=H||dw<0||dw>=W){
        continue;
      }
      if(s[dh][dw]=='#'){continue;}
      if(ok[dh][dw]>=1){continue;}
      ok[dh][dw]=ok[y][x]+1;
      q.push(make_pair(dh,dw));
    }
  }
  if(ok[H-1][W-1]==-1){cout<<-1<<endl;}
  else{cout<<H*W-B-(ok[H-1][W-1]+1)<<endl;}
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	int N;
	cin >> N;
	map<int, int> m;
	rep(i, 0, N) {
		int a;
		cin >> a;
		m[a]++;
	}

	int count = 0;
	for(map<int, int>::iterator itr = m.begin(); itr != m.end(); itr++) {
		if(itr->second % 2 == 0) count++;
	}
	if(count % 2 == 0) cout << m.size() << endl;
	else cout << m.size() - 1 << endl;

}


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

int main(){
  int N,i;
  string S;

  cin>>N;
  for(i=0;i<N;i++){
    cin>>S;
    if(S=="Y"){
      cout<<"Four";
      break;
    }
  }
  if(i==N){
    cout<<"Three";
  }
}


Measured memory_bytes: 256
R, C, K = map(int, input().split())

I = [[0]*C for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp0 = [[0 for j in range(C+1)] for i in range(R+1)]
dp1 = [[0 for j in range(C+1)] for i in range(R+1)]
dp2 = [[0 for j in range(C+1)] for i in range(R+1)]
dp3 = [[0 for j in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        dp3[i][j] = max(dp3[i][j], dp2[i][j]+I[i][j])
        dp2[i][j] = max(dp2[i][j], dp1[i][j]+I[i][j])
        dp1[i][j] = max(dp1[i][j], dp0[i][j]+I[i][j])
        dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j], dp1[i]
                          [j], dp2[i][j], dp3[i][j])
        dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])
        dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
        dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
        dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])


# print(*dp, sep=' \n')

ans = max(dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1])
print(ans)


Measured memory_bytes: 459964
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/

void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    int Bo[3][3];
    int* wh[101];
    for (int i = 0; i < 101; i++) wh[i] = new int(-1);
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            cin >> Bo[i][j];
            wh[Bo[i][j]] = &Bo[i][j];
        }

    int n; cin >> n;
    vi b(n);
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        int d = *wh[x];
        if (d > 0) (*wh[x]) = 0;
    }

    bool ans(false);
    for (int i = 0; i < 3; i++)
        if (Bo[i][0] + Bo[i][1] + Bo[i][2] == 0) ans = true;
    for (int i = 0; i < 3; i++)
        if (Bo[0][i] + Bo[1][i] + Bo[2][i] == 0) ans = true;
    if (Bo[0][0] + Bo[1][1] + Bo[2][2] == 0) ans = true;
    if (Bo[0][2] + Bo[1][1] + Bo[2][0] == 0) ans = true;
 
    if (ans) cout << "Yes\n";
    else cout << "No\n";

    //for (int i = 0; i < 3; i++) {
    //    for (int j = 0; j < 3; j++)
    //        cout << Bo[i][j] << " ";
    //    cout << endl;
    //} cout << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <atcoder/dsu>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N, M; std::cin >> N >> M;
    atcoder::dsu uf(N);
    {
        int A, B;
        for(int i(0); i < M; ++i){
            std::cin >> A >> B;
            uf.merge(A-1, B-1);
        }
    }
    int ans(-1);
    for(int i(0); i < N; ++i){
        if(i == uf.leader(i)) ++ans;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3788
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize, w: usize,
        a: [chars; h],
    }
    let mut h_v = vec![];
    let mut w_v = vec![];

    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '#' {
                h_v.push(i);
                w_v.push(j);
            }
        }
    }
    h_v.sort();
    h_v.dedup();
    w_v.sort();
    w_v.dedup();

    for &h_ in &h_v {
        let mut acc = vec![];
        for &w_ in &w_v {
            acc.push(a[h_][w_]);
        }
        println!(
            "{}",
            acc.iter()
                .fold(String::new(), |acc, c| acc + &c.to_string())
        )
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
struct Node{
    int parent,right,left;
    Node(){ parent=right=left=-1; }
};
Node tree[25];
int high(int n){
    int lef,rig;
    lef=rig=0;
    if(~tree[n].left) lef=high(tree[n].left)+1;
    if(~tree[n].right) rig=high(tree[n].right)+1;
    return max(lef,rig);
}
int main(){
    int n;
    scanf("%d",&n);
    int id,l,r;
    for(int i=0;i<n;++i){
        scanf("%d%d%d",&id,&l,&r);
        tree[id].left=l; tree[id].right=r;
        if(~l) tree[l].parent=id;
        if(~r) tree[r].parent=id;
    }
    for(int i=0;i<n;++i){
        int sib=-1,deg=0,dep=0,hei;
        string type=tree[i].parent==-1?"root":tree[i].left!=-1||tree[i].right!=-1?"internal node":"leaf";
        if(~tree[i].parent){
            int par=tree[i].parent;
            sib=tree[par].left==i?tree[par].right:tree[par].left;
            while(~par){
                dep++;
                par=tree[par].parent;
            }
        }
        deg+=tree[i].left!=-1;
        deg+=tree[i].right!=-1;
        hei=high(i);
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",i,tree[i].parent,sib,deg,dep,hei,type.c_str());
    }
    return 0;
}

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

int a[3],ans=9999999,z;
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++)
	for(int k=0;k<3;k++)
	{
		if(i!=j&&i!=k&&j!=k)
		{
			z=0;
			z+=a[i]-a[j]<0?-(a[i]-a[j]):(a[i]-a[j]);
			z+=a[k]-a[j]<0?-(a[k]-a[j]):(a[k]-a[j]);
			if(ans>z) ans=z;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
#define rep(i,n) for (long (i)=(0);(i)<(long)(n);++(i))
#define p(x) cout<<(x)<<endl;
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() { 
  long n; cin >> n;
  vector <vector<long>>ls(n);
  rep(i, n){
    vector <long> ll(2);
    cin >> ll[0];
    cin >> ll[1];
    ls[i] = ll;
  }
  sort(&ls[0], &ls[n], [](auto& x, auto& y){return x[1] < y[1];});

  long time = 0;
  rep(i, n) {
    time += ls[i][0];
    if (ls[i][1] < time) {
      p("No");
      return 0;
    }
  }
  p("Yes");
}


Measured memory_bytes: 11136
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def is_palindrome(s):
  n=len(s);b=True
  for i in range(int(0.5*n)):
    if s[i]!=s[n-i-1]:b=False
  return b

def main():
  n=aint();x=ints();p=sum(x)//n
  l1=[(x[i]-p)**2for i in range(n)];l2=[(x[i]-p-1)**2for i in range(n)];print(min(sum(l1),sum(l2)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572