akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
#define srep(i, j, k) for (int i = j; i < k; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

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

//�G�X�g���l�X���
vector<ll> estora(vector<ll> num) {
    int sel = 0;
    while (sel < num.size()) {
        int d = num[sel];
        for (int i = 0; i < num.size(); i++) {
            if (num[i] % d == 0 && num[i] != d && d != 1) {
                num.erase(num.begin() + i);
                i--;
            }
        }
        sel++;
    }
    return num;
}

const int INF = 1001001001;

//mint�p�̒萔 (10��9�� + 7)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    ll h;
    cin >> h;

    int num = log2(h) + 1.0;
    ll ans = 0;
    ll plus = 1;
    rep(i, num) {
        ans += plus;
        plus *= 2;
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
//i����ɑf���ɂ��Ă����Ȃ��Ƃ��܂��ł��Ȃ�&&�v�Z�ʃ��o�C
//�G�X�g���l�X��⿂őf����U����Ă����K�v�������肻��
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3808
import sys
import string
import operator
from collections import Counter

f = sys.stdin

while True:    
    n = int(f.readline())
    if n == 0:
        break
    counters = {c:Counter() for c in string.ascii_lowercase}
    for i in range(n):
        for word in f.readline().strip().split():
            counters[word[0]].update([word])
    c = f.readline().strip()

    candidate = counters[c].most_common()
    candidate.sort(key=operator.itemgetter(0))
    candidate.sort(key=operator.itemgetter(1), reverse=True)
    candidate = [word for word, count in candidate[:5]]
    if len(candidate) == 0:
        print('NA')
    else:
        print(*candidate)

Measured memory_bytes: 6728
from sys import stdin,stdout

if __name__=="__main__":

    n=int(stdin.readline())

    s=str(input())

    l=s[0]
    cnt=1

    for i in range(1,len(s)):
        if(s[i]!=l):
            cnt+=1
            l=s[i]

    stdout.write(str(cnt)+"\n")


Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define endl "\n"
using namespace std;
int n  , m, x  , c , k ;
const int N = 1000000;
int z ;
int inf = 1e14;
int dp[N][5];
int a[N];

int r , g , b;


signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> n ;
    int cnt = 0;

    for (int i=1;i<=round(sqrt(n));i++){
        if (n % i == 0){
            int a = i , b = n/i;
            m = a-1 , k = b;
            if (m!=0){
                if (n % m == k){
                    cnt+=m;
                }
            }
            m = b-1 , k = a;
            if (m!=0){
                if (n % m == k){
                    cnt+=m;
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll A,V; cin >> A >> V;
    ll B,W; cin >> B >> W;
    ll T; cin >> T;
    if (V <= W) {
        cout << "NO" << ln;
        return 0;
    }

    ll v = V-W;
    ll d = abs(B-A);
    cout << (v*T >= d ? "YES" : "NO") << ln;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}

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

	if (a < b) swap(a, b);
	
	ll lcm = a * b / gcd(a, b);
	cout << lcm << endl;
	return 0;
}

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


int main()
{
    int n;
    cin>>n;
    int temp = n;
    int ans = 0;
    while(temp)
    {
        ans += temp % 10;
        temp /= 10;
    }
    if(n%ans == 0)
        cout <<"Yes";
    else cout << "No";
    return 0;
}



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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


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

  pair<int, int> ans = make_pair(0, 0);
  vector<int> cnt(100100, 0);
  vector<bool> used(100100, false);

  REP(k, M){
    int i;
    string s;
    cin >> i >> s;
    i--;
    if(used[i]) continue;

    if(s == "WA") cnt[i]++;
    else{
      used[i] = true;
      ans.first++;
      ans.second += cnt[i];
    }
  }

  cout << ans.first << " " << ans.second << endl;

  return 0;
}

Measured memory_bytes: 1024
n = int(input())
if n < 105:
  print(0)
else:
  output = 0
  for i in range(105,n+1):
    if i % 2 == 0:
      continue
    yaku = 0
    for j in range(1,i+1):
      if i % j == 0:
        yaku += 1
      if yaku > 8:
        continue
    if yaku == 8:
      output += 1
  print(output)

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

const int MXN=100005;

int n,a[MXN],b[MXN],c[MXN];
int dp[MXN][3];

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i){
    scanf("%d%d%d",a+i,b+i,c+i);
  }
  for(int i=n;i>=0;--i){
    dp[i][0]=max({dp[i][0],a[i]+dp[i+1][1],a[i]+dp[i+1][2]});
    dp[i][1]=max({dp[i][1],b[i]+dp[i+1][0],b[i]+dp[i+1][2]});
    dp[i][2]=max({dp[i][2],c[i]+dp[i+1][0],c[i]+dp[i+1][1]});
  }
  printf("%d\n",max({dp[1][0],dp[1][1],dp[1][2]}));
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << max(max(a + b, a - b), a*b)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,temp,n=0;
	scanf("%d",&a);
	temp=a;
	while(a!=0)
	{
		n=n+a%10;
		a=a/10;
		n=n*10;
	}
	if(temp==n/10)
	printf("Yes");
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 128
while (n=gets.to_i)!=0
    table = {}
    for i in 1..n
        a,b = gets.split(" ")
        table[a] = b
    end


    n = gets.to_i
    ans = ""
    for i in 1..n
        c = gets[0]
        if table[c]!=nil
            c = table[c]
        end
        ans += c[0]
    end

    puts(ans)
end

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

int N;
const int MAX_N = 100 + 10;
int A[MAX_N];

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

    sort(A, A+N);
    
    cout << A[N-1] - A[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::max;
int ans,a[3005],b[3005],dp[2][3005],n,T,t[3005];
int main(){
	scanf("%d%d",&n,&T);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++){
		for (int j=0;j<=T;j++) t[j]=dp[1][j];
		for (int j=T-1;j>=0;j--) dp[1][j]=max(dp[1][j],dp[0][j]+b[i]);
		for (int j=T;j>=a[i];j--) dp[1][j]=max(dp[1][j],t[j-a[i]]+b[i]),dp[0][j]=max(dp[0][j],dp[0][j-a[i]]+b[i]);
	}
	for (int i=0;i<=T-1;i++) ans=max(ans,dp[1][i]);
	ans=max(ans,dp[0][T]);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define ull              unsigned long long
#define f                first
#define s                second
#define sqr(x)           (x)*(x)
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define intlim           2147483648
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define mk(x1,y1) make_pair(x1, y1)
#define maxl 100000
#define psz 20
using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdin);
//ios_base::sync_with_stdio(false);
 //cin.tie(NULL);
int main(){

    int n,l;
    cin>>n>>l;

    vector<int>v;

    int sum = 0;
    for(int i=1; i<=n; i++) v.pb(i+l-1), sum += i+l-1;

    int mini = 1000000,ans = 0;

    for(int i=0; i<n; i++){

        int tt = abs(sum - (sum-v[i]));
        if(tt < mini){

            mini = tt;
            ans = sum-v[i];
        }

    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
 
signed main(){
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = INF;
    rep(i, n) cin >> a[i+1];
    a[n+1] = 0;
    int x = 1000;
    int num = 0;
    rep(i, n+1) {
        if (i==0) continue;
        if (a[i]==a[i-1] && a[i]==a[i+1]) continue;
        if (a[i]<=a[i-1] && a[i]<=a[i+1]) {
            int tmp = x/a[i];
            num += tmp;
            x -= a[i]*tmp;
        }
        else if (a[i]>=a[i-1] && a[i]>=a[i+1]) {
            x += a[i]*num;
            num = 0;
        }
    }
 
    
    cout << x << endl;
    return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<vector<ll>> V(3, vector<ll>());
    ll x;
    REP(i, A) {
    	cin >> x;
    	V[0].pb(x);
    }
    REP(i, B){
    	cin >> x;
    	V[1].pb(x);
    }
    REP(i, C) {
    	cin >> x;
    	V[2].pb(x);
    }
    sort(all(V[0]));
    sort(all(V[1]));
    sort(all(V[2]));
    VI idx(3);
   	idx[0] = A - 1;
   	idx[1] = B - 1;
   	idx[2] = C - 1;
   	ll ans = 0;
    // while (X > 0 || Y > 0) {
    REP(k, X + Y) {
    	ll mx = 0, whi = 0, mn = LLONG_MAX, whiMn = 0;
    	for (int i = 0; i < 3; i++) {
    		// if (idx[i] < 0) continue;
    		if (i == 1 && idx[i] <= B - 1 - Y) continue;
    		if (i == 0 && idx[i] <= A - 1 - X) continue;
    		if (V[i][idx[i]] > mx) {
    			mx = V[i][idx[i]];
    			whi = i;
    		}
            // if (i < 2 && V[i][idx[i]] < mn) {
            //     mn = V[i][idx[i]];
            //     whiMn = i;
            // }
    	}
	    ans += mx;
	    idx[whi]--;
    	// if (whi == 2) {
	    // 	if (whiMn == 0) {
	    // 		X--;
	    // 	} else {
	    // 		Y--;
	    // 	}

    	// } else if (whi == 1) {
    	// 	Y--;
    	// } else if (whi == 0) {
    	// 	X--;
    	// }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3316
N = int(input())
h = list(map(int, input().split()))

cost = [0 for i in range(N)]
cost[0] = 0
cost[1] = abs(h[0]-h[1])

for i in range(2,N):
    #print(i)
    cost[i] = min(abs(h[i]-h[i-1])+cost[i-1], abs(h[i]-h[i-2])+cost[i-2])
    #print(cost[i])

print(cost[N-1])

Measured memory_bytes: 13980
#include <iostream>

using namespace std;

int main() {

  int n, s = 1e9, m = 0, l = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> l;
    m = max(m, l);
    s = min(s, l);
  }
  cout << m - s;
  return 0;
}


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

using namespace std;

int main()
{
	string a,b;
	cin >> a >> b;
	
	for(int i = 0; i < a.size(); i++)
	{
		cout << a[i];
		if(a.size() > b.size() && i == a.size() - 1)
		{
			break;
		}
		
		cout << b[i];
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import { stringLiteral } from "@babel/types"

// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { S: string } => {
  const S = lines[0]
  const obj = { S }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { S } = parseLines(lines)
  const initialValue :{ [index:string] : number } = {}
  const result = S.split('').reduce((prev, current): { [index: string]: number } => {
    if (!prev[current]) {
      prev[current] = 1
    } else {
      prev[current] += 1
    }
    return prev
  }, initialValue)

  return Object.keys(result).some(key => result[key] !== 2) ? 'No' : 'Yes'
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7628
n = int(input())
ans = [0] * (n + 1)

for i in range(1, 110):
    for j in range(1, 110):
        for k in range(1, 110):
            tmp = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i
            if tmp <= n:
                ans[tmp] += 1
for i in range(1, n + 1):
    print(ans[i])


Measured memory_bytes: 69388
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int N;
vector<vector<int>> g;

int findFarNode(int st){
    queue<int> Q;
    vector<int> dist(N,MOD);
    dist[st]=0;
    Q.push(st);
    while(!Q.empty()){
        int now=Q.front();
        Q.pop();

        for(auto nex:g[now]){
            if(dist[nex]==MOD){
                dist[nex]=dist[now]+1;
                Q.push(nex);
            }
        }
    }

    int last=st;
    rep(i,N) if(dist[i]>dist[last]) last=i;
    return last;
}

bool dfs(int now,int par,vector<int> &path,int goal){
    if(now==goal){
        path.push_back(now);
        return true;
    }
    for(auto nex:g[now]){
        if(nex==par) continue;
        if(dfs(nex,now,path,goal)){
            path.push_back(now);
            return true;
        }
    }
    return false;
}

vector<int> getDiameter(){
    int a=findFarNode(0);
    int st=findFarNode(a);
    int ed=findFarNode(st);

    vector<int> result;
    dfs(st,-1,result,ed);
    return result;
}

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

  cin>>N;
  g.resize(N);
  rep(i,N-1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
  }

  vector<int> diameter=getDiameter();

  queue<int> Q;
  vector<int> dist(N,MOD);
  rep(i,diameter.size()){
      Q.push(diameter[i]);
      dist[diameter[i]]=0;
  }
  while(!Q.empty()){
      int now=Q.front();
      Q.pop();

      for(auto nex:g[now]){
          if(dist[nex]==MOD){
              dist[nex]=dist[now]+1;
              Q.push(nex);
          }
      }
  }

  rep(i,N) if(dist[i]>=2){
      cout<<-1<<endl;
      return 0;
  }

  vector<vector<int>> result(2);
  rep(k,2){
      result[k].push_back(0);
      int num=1;
      for(int i=1;i<diameter.size();i++){
          int now=diameter[i];
          int prenum=num;
          for(int j=0;j+2<g[now].size();j++){
              result[k].push_back(++num);
          }
          result[k].push_back(prenum);
          num++;
      }
      reverse(diameter.begin(),diameter.end());
  }

  for(int i=0;i<N;i++){
      if(result[0][i]<result[1][i]){
          for(auto n:result[0]) cout<<n+1<<" ";
          cout<<endl;
          return 0;
      }
      if(result[0][i]>result[1][i]){
          for(auto n:result[1]) cout<<n+1<<" ";
          cout<<endl;
          return 0;
      }
  }

  for(auto n:result[0]) cout<<n+1<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 14840
// AtCoder :: Beginner Contest 179 :: D - Leaping Tak
// https://atcoder.jp/contests/abc179/tasks/abc179_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{998244353};
const int MAXN{200000};

vector<pair<int, int>> segments;
vector<ll> dp(MAXN+1, 0);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    segments.reserve(K);
    for (int i{0}; i < K; ++i) {
        int l, r;
        cin >> l >> r;
        segments.emplace_back(l, r);
    }

    // Start on [1, 2)
    ll acc{1};
    for (int i{1}; i < N; ++i) {
        acc = (acc + dp[i]) % MOD;
        if (acc > 0) {
            for (auto [sl, sr] : segments) {
                if (i+sl <= N) {
                    dp[i+sl] = (dp[i+sl] + acc) % MOD;
                }
                if (i+sr+1 <= N) {
                    dp[i+sr+1] = (dp[i+sr+1] - acc) % MOD;
                    if (dp[i+sr+1] < 0) {
                        dp[i+sr+1] += MOD;
                    }
                }
            }
        }
    }
    cout << (dp[N] % MOD) << endl;
    return EXIT_SUCCESS;
}


Measured memory_bytes: 4696
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}
typedef vector<string> vs;

int a['Z'+1];
bool nz['Z'+1];
vector<char> app;
bool used[10];

int dfs(int k, int cur){
    if(k==app.size()) return cur==0;
    int ans = 0;
    rep(i,10){
        if(used[i]) continue;
        if(nz[app[k]] && i==0) continue;
        used[i] = true;
        ans += dfs(k+1, cur+i*a[app[k]]);
        used[i] = false;
    }
    return ans;
}

int main(){
#ifdef DEBUG
    freopen("in","r",stdin);
#endif
    int n;
    while(cin>>n && n){
        memset(a,0,sizeof(a));
        memset(nz,0,sizeof(nz));
        memset(used,0,sizeof(used));
        app.clear();
        rep(i,n){
            string s; cin >> s;
            int ten = 1;
            rep(j,s.size()){
                char c = s[s.size()-1-j];
                a[c]+=ten * (i==n-1 ? -1 : 1);
                ten*=10;
                app.pb(c);
            }
            if(s.size()!=1) nz[s[0]]=true;
        }
        sort(all(app));
        app.erase(unique(all(app)), app.end());
        cout << dfs(0,0) << endl;
    }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=int(a); i<int(b); ++i)
#define FORD(i,a,b) for(int i=int(a); i<int(b); --i)
#define REP(i,N) for(int i=0; i<int(N); ++i)
#define REPD(i,N) for(int i=0; i<int(N); --i)
#define PB push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //配列の最大のrenge

int main() {
    int a,b,c,d;cin>>a>>b>>c>>d;
    int res = 0;
    int e,s;
    e = min(b,d);
    s = max(a,c);
    if (s < e) res = e - s;
    cout << res;
}

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

int main(void) {
    int h, n;
    scanf("%d%d", &h, &n);
    int a[n];
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);

    int sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];

    if (h <= sum) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

long long int power(long long int base,long long p,long long int mod)
{
    long long int ans=1;
    while(p)
    {
        if(p&1)
            ans=(ans*base)%mod,p--;
        else
            base=(base*base)%mod,p/=2;
    }
    return ans%mod;
}
void go()
{
    long long int n,o=0,z;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i] == '1')
            o++;
    }
    long long int sum_rem_add=0,sum_rem_sub=0;
    if(o == 1)
    {
        for(int i=0;i<n-1;i++)
        {
            if(s[i] == '0')
                cout<<1<<endl;
            else
                cout<<0<<endl;
        }
        if(s[n-1] == '0')
            cout<<2<<endl;
        else
            cout<<0<<endl;
        return;
    }
    for(int i=0;i<n;i++)
    {
        if(s[i] == '1')
        {
            sum_rem_add=(sum_rem_add+power(2,n-1-i,o+1))%(o+1);
            sum_rem_sub=(sum_rem_sub+power(2,n-1-i,o-1))%(o-1);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(s[i] == '0')
        {
            long long int temp_sum_rem=(sum_rem_add+power(2,n-1-i,o+1))%(o+1);
            long long int temp_ans=1;
            long long int temp=temp_sum_rem;
            while(temp)
                temp%=(__builtin_popcount(temp)),temp_ans++;
            cout<<temp_ans<<endl;
        }
        else
        {
            long long int temp_sum_rem=(sum_rem_sub-(power(2,n-1-i,o-1))+(o-1))%(o-1);
            long long int temp_ans=1;
            long long int temp=temp_sum_rem;
            while(temp)
                temp%=(__builtin_popcount(temp)),temp_ans++;
            cout<<temp_ans<<endl;
        }
    }
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
    go();
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    int bit[n];
    long count = 0;
    unordered_map <string, long> map;
    for(int i = 0; i < n; i++){
        cin >> s;
        sort(s.begin(), s.end());
        auto itr = map.find(s);
        if(itr != map.end()){
            count += map[s];
            map[s]++;
        }else{
            map[s] = 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 10660
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);

    const PY = arg.slice(1, M + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    const list = [];
    
    for(let i in PY) {
        let map = {p: PY[i][0], y: PY[i][1], originIdx: i};
        
        list.push(map);
    }
    
    // PY.sort((a,b)=> (a[0] - b[0]) || (a[1] - b[1]));
    list.sort((a,b)=> (a.p - b.p) || (a.y - b.y));
    
    const addZero = n => {
        const zeros = [];
        
        for(let i=0; i<6 - String(n).length; i++) {
            zeros.push("0");
        }
        
        return zeros.join("") + String(n);
    }
    
    let temp = [];
    let oldness = 1;
    
    for(let i in list) {
        if(list[i-1] && list[i-1].p !== list[i].p) {
            oldness = 1;
        }
        
        let first = addZero(list[i].p);
        let last  = addZero(oldness);
        
        let map = {id: first + last, originIdx: list[i].originIdx}
        
        temp.push(map);
        oldness++;
    }
    
    // console.log(PY.join("\n"));
    // console.log(addZero(3));
    
    temp.sort((a,b)=>a.originIdx - b.originIdx);
    
    let answer = [];
    
    for(let i in temp) {
        answer.push(temp[i].id);
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 85144
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;


int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 5) {
    cout << 0 << endl;
  } else if (6 <= a && a <= 12) {
    cout << b / 2 << endl;
  } else {
    cout << b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char a[1010];
	int i;
	fgets(a,1001,stdin);
	for(i=0;a[i]!='\0';i++){
		if(a[i]=='p'&&a[i+1]=='e'&&a[i+2]=='a'&&a[i+3]=='c'&&a[i+4]=='h'){
			a[i]='a';
			a[i+1]='p';
			a[i+2]='p';
			a[i+3]='l';
			a[i+4]='e';
		}
		else if(a[i]=='a'&&a[i+1]=='p'&&a[i+2]=='p'&&a[i+3]=='l'&&a[i+4]=='e'){
			a[i]='p';
			a[i+1]='e';
			a[i+2]='a';
			a[i+3]='c';
			a[i+4]='h';
		}
	}
	printf("%s",a);
	return 0;
}

Measured memory_bytes: 520
while 1:
    a = list(input())
    if a == ['.']:break
    stack = []
    for i in a:
        if i =='(' :stack.append('(')
        elif i == '[':stack.append('[')
        elif i ==')':
            if len(stack) ==0:
                stack.append(0)
                break
            b = stack.pop()
            if b =='(':pass
            else:
                stack.append(b)
                break

        elif i ==']':
            if len(stack) == 0:
                stack.append(0)
                break
            b = stack.pop()
            if b =='[':pass
            else:
                stack.append(b)
                break
    if len(stack) == 0 and len(stack) == 0:print("yes")
    else:print("no")

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  double r;
  cin >> r;
  cout << 2 * r * 3.141592 << endl;
}

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		
		boolean eat = A%3==0 || B%3==0 || (A+B)%3==0;
		String ans = eat ? "Possible" : "Impossible";
		
		System.out.println(ans);;
		

	}

}

Measured memory_bytes: 23636
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    int ans = 1;
    if (N % 2 && A[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = N % 2; i < N; i += 2) {
        if (A[i] != A[i + 1] || A[i] != i + 1) {
            cout << 0 << endl;
            return 0;
        }
        ans = (ans * 2) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;



int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,sub=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,most=0;
    int now,pre;
    //vector <int> v;
    //float f,g,h;
    //char now,pre;
    //string a;
    cin>>n>>most;
    cin>>pre;
    while(n>1)
    {
        cin>>now;
        if(pre+now>most)
        {
            sub=pre+now-most;
            sum+=sub;
            if(now>sub) now-=sub;
            else now=0;
        }
        pre=now;
        n--;
    }
    cout<<sum;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n;
  cin >> n;
  vector<int> v;
  int t;
  for (int i = 0; i < n; i++){
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v.size() << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nmx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Array.Sort(a);
            var b = a.TakeWhile(i => i < nmx[2]);
            Console.WriteLine(Math.Min(b.Count(),nmx[1]-b.Count()));
        }
    }
}

Measured memory_bytes: 13268
public static class Program
{
  public static void Main(string[] args)
  {
    int num = int.Parse(System.Console.ReadLine());
    
    long[] input = new long[num];
    for(int i = 0; i < num; i++)
    {
      string str = System.Console.ReadLine();
      input[i] = long.Parse(str);
    }
    
    long min = input[0];
    long maxDiff = long.MinValue; // 単調減少の場合も考慮
    long diff;
    for(int i = 1; i < num; i++)
    {
      diff = input[i] - min;
      
      if(input[i] < min)
      {
        min = input[i];
      }      
      
      if(diff > maxDiff)
      {
        maxDiff = diff;
      }
    }
    
    System.Console.WriteLine(maxDiff);
  }
}


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

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

using ll = long long;

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int m = min(x,y);
  int ans1 = 0, ans2 = 0, ans3 = 0;
  //余らせるab。ちょうどにするab。別々の購入
  ans1 = 2*c*max(x,y);
  ans2 = 2*m*c + a*(x-m) + b*(y-m);
  ans3 = a*x+b*y;
  int ans = min(ans1,min(ans2,ans3));
  //こんなきっかりとは限らないということ?
  cout<<ans<<endl;
  return 0;
}

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

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

using namespace std;

int main(void) {
	int N; cin >> N;
	vector<int> ans(N, 0);

	rep(i, N - 1) {
		int a; cin >> a;
		ans[a - 1]++;
	}

	for (int x : ans) {
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 4016
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define P(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN2(n,k);
  if (n%k==0) OUT(0);
  else OUT(1);
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
     var line= chunk.split(' ');
    

 if( Number(line[0]) < Number(line[1]) && Number(line[1]) < Number(line[2]) ) {
    console.log( 'Yes' );
  } else {
    console.log( 'No' );
  }
});

Measured memory_bytes: 15584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		String line;
		ArrayList<String> tmp = new ArrayList<String>();
		while (buffer.ready()){
			line=buffer.readLine();
			tmp.add(line);
		}
		String[] ab = tmp.get(0).split(" ");
		int[] num = new int[2];
		for(int i=0; i<2; i++)
			num[i] = Integer.parseInt(ab[i]);

		if(num[0]>num[1]){
			System.out.println("a > b");
		}else if(num[0] < num[1]){
			System.out.println("a < b");
		}else
			System.out.println("a == b");
			


	}
}

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

struct union_find_tree {
    std::vector<int> par, rank;
    union_find_tree(){}
    union_find_tree(int size)
    {
        par=std::vector<int>(size);
        rank=std::vector<int>(size);
        for(int i=0; i<size; ++i) par[i]=i;
    }
    int root(int x)
    {
        if (x==par[x]) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y)
    {
        x=root(x);
        y=root(y);
        if (x==y) return;
        if (rank[x]<rank[y]) {
            par[x]=y;
        }
        else {
            par[y]=x;
            if (rank[x]==rank[y]) ++rank[x];
        }
    }
    bool same(int x, int y)
    {
        return root(x)==root(y);
    }
};


int main()
{
    int n, m; cin>>n>>m;
    vector<string> s(n);
    for(auto& e: s) cin>>e;

    union_find_tree ut(n*m);

#define rep(i, n) for(int i=0; i<n; ++i)
    int dr[4]={-1, 0, 1, 0};
    int dc[4]={0, -1, 0, 1};
    rep(i, n) rep(j, m) if (s[i][j]=='#') rep(k, 4) {
        int r=i+dr[k], c=j+dc[k];
        if (r<0 || r>=n || c<0 || c>=m || s[r][c]!='.') continue;
        ut.unite(i*m+j, r*m+c);
    }

    map<int, int> b, w;
    rep(i, n) rep(j, m) (s[i][j]=='#' ? b : w)[ut.root(i*m+j)]++;

    long res=0;
    for(auto& e: b) res+=1L*e.second*w[e.first];
    cout<<res<<endl;
}


Measured memory_bytes: 14592
import math
cos = math.cos(math.radians(60))
sin = math.sin(math.radians(60))

def koch(count, p1x, p1y, p2x, p2y):
    global cos
    global sin
    if count == 0:
        return
    sx, sy = (2*p1x + p2x)/3, (2*p1y + p2y)/3
    tx, ty = (p1x + 2*p2x)/3, (p1y + 2*p2y)/3
    ux, uy = cos*(sx + tx) - sin*(ty - sy), sin*(tx - sx) + cos*(sy + ty)

    koch(count-1, p1x ,p1y, sx, sy)
    print(sx, sy)
    koch(count-1, sx, sy, ux, uy)
    print(ux, uy)
    koch(count-1, ux, uy, tx, ty)
    print(tx, ty)
    koch(count-1, tx, ty, p2x, p2y)

n = int(input())
print(0, 0)
koch(n, 0, 0, 100, 0)
print(100, 0)


Measured memory_bytes: 5784
#include<bits/stdc++.h>
using namespace std;
long long q,h,s,d,n,ans;
int main(){
    cin>>q>>h>>s>>d>>n;
    ans=min(q*4,min(h*2,s));
    if(ans*2<=d)
        cout<<ans*n<<endl;
    else
        cout<<((n%2)*ans)+n/2*d<<endl;
    return 0;
}

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

int main() {
    int n = 0;
    cin >> n;
    int dp[n+1][3];
    for (int i = 0; i < 3; ++i)
        dp[0][i] = 0;
    for (int i = 0; i < 3; ++i)
        for (int  j = 1; j < n+1; ++j)
            dp[j][i] = -INF;
    for (int i = 1; i < n+1; ++i) {
        for (int j = 0; j < 3; ++j) {
            int buf = 0;
            cin >> buf;
            for (int k = 0; k < 3; ++k) {
                if (k == j) continue;
                else {
                    dp[i][j] = max(dp[i][j], dp[i-1][k]+buf);
                }
            }
        }
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
}


Measured memory_bytes: 4800
#include<stdio.h>
#define MAX 10001
int main(){
  int datanum,datanum2,i,j;
  int a[MAX];
  int b[MAX];
  int ans = 0;
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&datanum2);
  for(i=0;i<datanum2;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<datanum2;i++)
    for(j=0;j<datanum;j++){
      if(a[j] == b[i]){
	ans++;
	break;
      }
    }
  printf("%d\n",ans);
  return 0;
}



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

template <typename T>
struct flow_graph {
	
	struct edge {
		int from, to;
		T cap, f;
	};
	
	vector<edge> edges;
	vector<vector<int>> g;
	vector<bool> used;
	int n, st, fin;
	T flow;
	
	flow_graph(int n, int st, int fin) : n(n), st(st), fin(fin) {
		assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
		g.resize(n);
		used.resize(n);
		flow = 0;
	}
	
	void clear_flow() {
		for (const edge &e : edges) {
			e.f = 0;
		}
		flow = 0;
	}
	
	void add(int from, int to, T cap = 1, T rev_cap = 0) {
		assert(0 <= from && from < n && 0 <= to && to < n);
		g[from].emplace_back(edges.size());
		edges.push_back({from, to, cap, 0});
		g[to].emplace_back(edges.size());
		edges.push_back({to, from, rev_cap, 0});
	}
	
	T dfs(int now, T f = numeric_limits<T>::max()) {
		if (now == fin) {
			return f;
		}
		used[now] = true;
		for (int id : g[now]) {
			edge &e = edges[id];
			if (!used[e.to] && 0 < e.cap - e.f) {
				T d = dfs(e.to, min(f, e.cap - e.f));
				if (0 < d) {
					e.f += d;
					edges[id ^ 1].f -= d;
					return d;
				}
			}
		}
		return 0;
	}
	
	T max_flow() {
		fill(used.begin(), used.end(), false);
		for (T f = dfs(st); 0 < f; fill(used.begin(), used.end(), false), f = dfs(st)) {
			flow += f;
		}
		return flow;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	flow_graph<int64_t> g(n, 0, n - 1);
	for (int i = 0; i < m; i++) {
		int from, to;
		int64_t cost;
		cin >> from >> to >> cost;
		g.add(from, to, cost);
	}
	cout << g.max_flow() << endl;
	return 0;
}

Measured memory_bytes: 3212
/*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long
   #define w(t) int t; cin>>t; while(t--)
   #define fo(i,n) for(int i=0;i<n;i++)
   #define endl "\n" 
   #define MOD 1000000007
   void Tez(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
   }
   int main(){
      Tez();
      string s,t;
      cin>>s>>t;
      int ans=INT_MAX;
      for(int i=0;i<(s.length()-t.length()+1);i++){
         int lans=0;
         int k=i;
         for(int j=0;j<t.length();j++){
             if(s[k++]!=t[j]) lans++;
         }
         ans=min(ans,lans);
      }
      cout<<ans;
      return 0;
   }



Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 150005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(void) {
    ll x;
    cin >> x;
    if(x==3 || x==5 || x==7) {
        puts("YES");
    }else {
        puts("NO");
    }
    
    
    
    
}

Measured memory_bytes: 256