akhauriyash/Code-Regression huggingface dataset:
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot1(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}

//----------------------------------SOLUTION-BELOW-------------------------------------------// 
void solve(){   
    ll n, m;
    cin >> n >> m;
    ll a[n];
    in(a, n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += a[i];
    }
    ll x = (4LL * m);
    ll y = sum / x;
    if(sum % x){
        y++;
    }
    sort(a, a + n, greater<ll>());
    for(int i = 0; i < m; i++){
        if(a[i] < y ) {
            cout << "No";
            return;
        }    
    }
    cout << "Yes";
}
int main(){


                                                            // #ifndef ONLINE_JUDGE    
                                                            // freopen("../input", "r", stdin);
                                                            // freopen("../output", "w", stdout);
                                                            // #else
                                                            // // online submission
                                                            // #endif


    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

que = deque([(0, 0)])
while que:
    h, w = que.popleft()

    A[h][w] = '?'

    if h == H - 1 and w == W - 1:
        break

    if h + 1 < H and A[h + 1][w] == '#':
        que.append((h + 1, w))
        continue

    if w + 1 < W and A[h][w + 1] == '#':
        que.append((h, w + 1))
        continue

cnt = sum([a.count('#') for a in A])
print('Possible' if cnt == 0 else 'Impossible')


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    map<ll, ll> m;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        ll v;
        cin >> v;
        m[v]++;
    }

    bool flag = true;
    for (auto it = m.begin(); it != m.end(); it++)
    {
        if( it->second >= 2 ) flag = false;
    }
        
    if(flag){
        cout << "YES" << endl;        

    }
    else{
        cout << "NO" << endl;

    }

}

Measured memory_bytes: 12800
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    while True:
        mi = min(A)
        A = [a % mi for a in A if a % mi != 0]
        A.append(mi)

        if len(A) == 1:
            print(mi)
            exit()

if __name__ == "__main__":
    main()


Measured memory_bytes: 63128
#[allow(unused_macros)]
macro_rules! chmax {
    ($a:expr, $b:expr) => {
        $a = std::cmp::max($a, $b)
    };
}

#[allow(unused_macros)]
macro_rules! chmin {
    ($a:expr, $b:expr) => {
        $a = std::cmp::min($a, $b)
    };
}

#[allow(unused_macros)]
macro_rules! get_line {
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let mut ws = s.split_whitespace();
            ($(ws.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}

macro_rules! get_vec {
    ( $t:ty ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.split_whitespace().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    };
}

fn main() {
    let (n, m) = get_line!(usize, usize);
    let mut keys = vec![];
    for _ in 0..m {
        let (a, _) = get_line!(usize, usize);
        let c = get_vec!(usize);

        let mut bits = 0;
        for c_i in c {
            let c_i = c_i - 1;
            bits += 1 << c_i;
        }

        keys.push((a, bits));
    }

    let mut all = 0;
    for i in 0..m {
        let (_, key) = keys[i];
        all = all | key;
    }
    if all != (1 << n) - 1 {
        println!("-1");
        return;
    }

    let mut dp = vec![std::usize::MAX >> 2; 1 << n];
    dp[0] = 0;
    for s in 0..(1 << n) {
        for i in 0..m {
            let (price, key) = keys[i];
            chmin!(dp[s | key], dp[s] + price)
        }
    }

    println!("{}", dp[(1 << n) - 1]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

struct edge { int to, cap, rev; };
#define MAX_V	(202)
#define INF		(2000000000)

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge{ to, cap, (int)G[to].size() });
	G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
}

void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if (v == t) return f;
	for (int& i = iter[v]; i < G[v].size(); i++) {
		edge& e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

int main()
{
	int N;
	cin >> N;
	vector<pair<int, int>> RED(N);
	for (int i = 0; i < N; i++) {
		cin >> RED[i].first >> RED[i].second;
		add_edge(0, i + 1, 1);
	}
	sort(RED.begin(), RED.end());
	for (int i = 0; i < N; i++) {
		int c, d;
		cin >> c >> d;
		add_edge(i + N + 1, MAX_V-1, 1);
		for (int j = 0; j < N; j++) {
			auto red = RED[j];
			if (red.first < c) {
				if (red.second < d) {
					add_edge(j+1, i+N + 1, 1);
				}
			}
		}
	}
	cout << max_flow(0, MAX_V - 1);
}


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

#define SQR(x) ((x)*(x))

typedef long long ll;
typedef pair<int,int> ii;


int main() {
   // freopen("hi.txt","r",stdin);
    ll n,a,b,c,d;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    ll diff=d-c;
    ll cur=a+(ll)c*(n-1);
    for(ll i=n-1;i>=0;i--){
        //printf("%lld %lld\n",i,cur);
        if(cur<=b && b<=cur+(n-1)*diff){
            //printf("%lld %lld %lld\n",i,cur,cur+n*diff);
            printf("YES");
            return 0;
        }
        cur-=c+d;
    }
    printf("NO");
}


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

int main()
{
    long long int a,b,c,d,n,m;
    while(~scanf("%lld %lld %lld %lld",&a,&b,&c,&d))
    {
        if(a<=b)
        {
            n=a*c;
            printf("%lld\n",n);
        }
        else
        {
            n=b*c;
            m=(a-b)*d;
            printf("%lld\n",n+m);
        }
    }
    return 0;
}


Measured memory_bytes: 128
N,P = map(int,input().split())
from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

factors = factorize(P)
ans = 1
for k,v in factors.items():
    a = v//N
    ans *= k**a
print(ans)

Measured memory_bytes: 3444
import Data.Functor( (<$>))
import Control.Monad( replicateM)

main = do
    let
	readLine = (read <$>) . words <$> getLine

    [n,m] <- readLine
    matrixData <- replicateM n readLine
    b <- concat <$> replicateM m readLine
    let
	rowXcolumn r = sum $ zipWith (*) r b
	answer = rowXcolumn <$> matrixData

    print `mapM_` answer



Measured memory_bytes: 7608
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

class UnionFind
{
public:
    UnionFind(){};
    ~UnionFind(){};

    void Init(int num_entries) {
        num_entries_ = num_entries;
        par_.resize(num_entries_);
        rank_.resize(num_entries_, 0);
        for (int i = 0; i < num_entries_; ++i)
        {
            par_[i] = i;
        }
    }
    int Find(int x) {
        if (par_[x] == x)
        {
            return x;
        }
        else
        {
            return par_[x] = Find(par_[x]);
        }
    }
    void Unite(int x, int y) {
        x = Find(x);
        y = Find(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 Find(x) == Find(y);
    }

private:
    int num_entries_;
    std::vector<int> par_;
    std::vector<int> rank_;
};


int main(void)
{
    cin.sync_with_stdio(false);
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind uf1;
    UnionFind uf2;
    uf1.Init(N);
    uf2.Init(N);

    REP(k,K) {
        int p, q;
        cin >> p >> q;
        uf1.Unite(p-1, q-1);
    }
    REP(l,L) {
        int r, s;
        cin >> r >> s;
        uf2.Unite(r-1, s-1);
    }
    map<pair<int,int>,int> counter;
    REP(n,N) {
        auto v1 = uf1.Find(n);
        auto v2 = uf2.Find(n);
        ++counter[mp(v1, v2)];
    }
    REP(n,N) {
        auto v1 = uf1.Find(n);
        auto v2 = uf2.Find(n);
        if (n != 0) cout << " ";
        cout << counter[mp(v1, v2)];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int dd,n,m,d[100002],k;

int main()
{
	while(scanf("%d",&dd),dd){
		scanf("%d%d",&n,&m);
		rep(i,n-1)scanf("%d",d+i);
		d[n-1]=dd; d[n++]=0; sort(d,d+n);
		int ans=0;
		rep(i,m){
			scanf("%d",&k);
			if(!k)continue;
			int p=lower_bound(d,d+n,k)-d;
			ans+=min(d[p]-k,k-d[p-1]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1264
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int N, X, T;
  cin >> N >> X >> T;
  ll ttt = (N/X)*T;
  if(N%X != 0){
    ttt+=T;
  }
  cout << ttt << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

string L; cin >> L;

int N = L.size();
VVI cnt(N+1, VI(2, 0));
cnt[0][0] = 1; // 0桁目で0でない数が0個ある数の個数
rep(i, 0, N){
    (cnt[i+1][1] += 3 * cnt[i][1]) %= MOD;
    if (L[i] == '1'){
        (cnt[i+1][0] += 2 * cnt[i][0]) %= MOD;
        (cnt[i+1][1] += cnt[i][0]) %= MOD;
    }
    else {
        (cnt[i+1][0] += cnt[i][0]) %= MOD;
    }
}

cout << (cnt[N][0] + cnt[N][1]) % MOD << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<int,int>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H=INF,sum=0,num=0,flag=0;string S,T,O;
   cin >> N >> M;
   Vec(PW,lli,N,0);Vec(V,lli,N,0);
   rep(i,0,N)cin >> PW[i] >> V[i];
   DV(dp,lli,N+1,M+1,0);
   rrep(i,N,0)rep(j,0,M+1){
      if(j<PW[i])dp[i][j]=dp[i+1][j];
      else dp[i][j]=max(dp[i+1][j],dp[i+1][j-PW[i]]+V[i]);
      }
      Out(dp[0][M]);
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <map>
#include <cassert>
#include <sstream>
#include <numeric>
#include <regex>
#include <cctype>
#include <utility>
#include <stdio.h>
#include <set>
#include <queue>
#include <deque>

typedef long long ll;

#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>
#define FOR(i,n) for(int i{0}; i < n; ++i)

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, l;
  cin >> n >> l;
  vs w(n, "");
  FOR(i, n) {
      cin >> w[i];
  }
  sort(w.begin(), w.end());
  for (auto const& a: w) {
      cout << a;
  }
  cout << '\n';
  return 0;
}








Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int n; cin >> n;
	vector<ll> t(n), a(n);
	rep(i, n)cin >> t[i] >> a[i];
	
	ll vt = t[0];
	ll va = a[0];
	
	rep(i, n)
	{
		if (vt * a[i] == va * t[i]) continue;

		ll x = max((vt+t[i]-1)/t[i],(va+a[i]-1)/a[i]);
		vt = x * t[i];
		va = x * a[i];
	}
	ll ans = vt + va;
	cout << ans << endl;
    return;
}

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


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

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9){
        cout<<"hon\n";
    }else if(n==0||n==1||n==6||n==8){
        cout<<"pon\n";
    }else{
        cout<<"bon\n";
    }
    return 0;
}


Measured memory_bytes: 3636
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
n = len(s)
ans = 'Yes'
if s != s[::-1]:
    ans = 'No'
x = math.floor(n/2)
y = math.ceil(n/2)
a = s[0:x]
b = s[y:]
if a != a[::-1] or b != b[::-1]:
    ans = 'No'
print(ans)

Measured memory_bytes: 74316
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(){

  stack <int> sa;
  string m;
  int cnt=0,result=0,high=0,tmp=0,h[20000],i;
  vector <int> amo;

  cin>>m;
  for(i=m.size()-1;i!=-1;i--){
    if(m[i]=='\\') tmp++;
    if(m[i]=='/') tmp--;
    high=max(high,tmp);
    h[i]=high;
  }

  for(i=0;i<m.size();i++){   
    if(m[i]=='\\'){
      sa.push(i);
    } else if(m[i]=='/' && !sa.empty()) {
      cnt+=i-sa.top();
      sa.pop();
      if(sa.empty()){
	amo.push_back(cnt);
	result+=cnt;
	cnt=0;
      }
    }
    if(i<m.size()-1) if(h[i+1]-h[i]) sa.pop();
  }
  if(amo.empty()) cout<<"0"<<endl<<"0"<<endl;
  else{
    cout<<result<<endl<<amo.size()<<" ";
    for(i=0;i<amo.size()-1;i++) cout<<amo[i]<<" ";
    cout<<amo[amo.size()-1]<<endl;
  }
  return 0;

}



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

const int INF=1LL << 60;
int f(int startidx,int endidx,int t,vector<int> &a,vector<vector<int>> &dp){
    
    if(dp[startidx][endidx]!=INF){
        return dp[startidx][endidx];
    }
    if(startidx>=endidx){
        return dp[startidx][endidx]=0;
    }
    if(t==0){
    return dp[startidx][endidx]=max(a[startidx]+f(startidx+1,endidx,!t,a,dp),a[endidx-1]+f(startidx,endidx-1,!t,a,dp));
    }
    else{
    return dp[startidx][endidx]=min(f(startidx+1,endidx,!t,a,dp)-a[startidx],f(startidx,endidx-1,!t,a,dp)-a[endidx-1]);
    }
}

int32_t main() {
    int n;
    cin>>n;
    vector<vector<int>> dp(n+1,vector<int>(n+1,INF));
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<f(0,n,0,a,dp)<<endl;
}


Measured memory_bytes: 74288
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long k = sc.nextLong();
        long[] a  = new long[n];
        long[] f  = new long[n];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        for(int i = 0; i < n; i++){
            f[i] = sc.nextLong();
        }

        Arrays.sort(a);
        Arrays.sort(f);

        long ng = -1;
        long ok = (long) Math.pow(10, 12);

        while(ok - ng > 1){
            long mid = (ok + ng) / 2;
            long sum = 0;
            for(int i = 0; i < n; i++){
                sum += Math.max(a[i] - mid / f[n - i - 1], 0);
            }
            if(sum <= k){
                ok = mid;
            }else{
                ng = mid;
            }
        }

        System.out.println(ok);

    }

}


Measured memory_bytes: 102420
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		sc.close();
		for(int i = 1; i <= 2 * k - 1; i++) {
			System.out.println(x - k + i);
		}
	}
}

Measured memory_bytes: 24148
using System;

class B{
  public static void Main(){
    int n,i,count = 0;
    n = int.Parse(Console.ReadLine());
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[n];
    for(i = 0;i < n;i++){
      array[i] = int.Parse(str[i]);
    }
    for(i = 0;i < n;i++){
      int min = i;
      for(int j = i + 1;j < n;j++){
        if(array[min].CompareTo(array[j]) > 0)  min = j;
      }
        if(min != i){
          Swap(ref array[i],ref array[min]);
          count++;
        }
    }
    for(i = 0;i < n - 1;i++){
      Console.Write(array[i] + " ");
    }
    Console.Write(array[n - 1]);
    Console.WriteLine("");

    Console.WriteLine(count);
  }

  static void Swap(ref int x,ref int y){
    int temp;
    temp = x;
    x = y;
    y = temp;
  }
}


Measured memory_bytes: 9184
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int h1,m1,h2,m2,k;
        cin>>h1>>m1>>h2>>m2>>k;
        int hr=h1*60+m1;
        int tr=h2*60+m2;
        cout<<tr-hr-k;
        }




Measured memory_bytes: 3640
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // n+1跳ねる
        int n = in.nextInt();
        // x以下の領域
        int x = in.nextInt();

        // 個数
        int count = 1; // 1回目は0
        // 1つ前の座標
        int preD = 0;
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            // 座標
            int d = preD + l;
            if (d <= x) {
                count++;
            }
            preD = d;
        }
        
       System.out.println(count);
    }
}

Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main() {
    int n, r, p, c, top;
    int order[50][2];
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        top = n;
        for (int i = 0; i < r; ++i) {
            cin >> order[i][0] >> order[i][1];
        }
        for (int i= r - 1; i >= 0; --i) {
            p = order[i][0];
            c = order[i][1];
            if (top > n - p - c + 1) {
                if (top > n - c) {
                    top -= p - 1;
                }
                else {
                    top += c;
                }
            }
        }
        cout << top << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    int a[n];
    double res=0;
    lp(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    lp(i,0,n){
        res+=a[i];
        if(i)
            res/=2.0;
    }
    cout<<fixed<<setprecision(8)<<res;
}

Measured memory_bytes: 3808
package main

import "fmt"

func main() {

	var a int

	fmt.Scan(&a)

	if 1 > a {
		fmt.Println("No")
		return
	}
	for _, v := range kakeru(){
		if a == v {
			fmt.Println("Yes")
			return
		}		
	}

	fmt.Println("No")

}

func kakeru() []int {
	numList := make([]int, 81)	
	for i := 1; i < 10; i++{
		for j := 1; j < 10; j++ {
			numList = append(numList, i*j)	
		}
	}
	return numList
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>

void solve() {
    std::string s;
    std::cin >> s;

    int q;
    std::cin >> q;

    int way = 1;
    std::string fore, back;
    while (q--) {
        int t;
        std::cin >> t;

        if (t == 1) {
            way = 3 - way;
        } else {
            int f;
            char c;
            std::cin >> f >> c;

            if (f == way) {
                fore.push_back(c);
            } else {
                back.push_back(c);
            }
        }
    }

    std::reverse(fore.begin(), fore.end());
    fore += s;
    fore += back;
    if (way == 2) std::reverse(fore.begin(), fore.end());

    std::cout << fore << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 1300
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int t,x,y;
  for(int i=0; i<n; i++){
    scanf("%d %d %d",&t,&x,&y);
    if(t%2==(x+y)%2 && t>=x+y){
      ;
    }else{
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}
  

Measured memory_bytes: 128
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7
from fractions import gcd
# n = int(input())

# s = deque(input())
# q = int(input())

a, b = map(int, input().split())
# a = list(map(int, input().split()))



def lcm(x, y):
    return (x * y) // gcd(x, y)

print(lcm(a,b))

Measured memory_bytes: 5560
N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]


def order(X):
    lst_n = list(range(1, N + 1))
    res = 0
    for i in range(N - 1):
        j = 0
        while True:
            if X[i] == lst_n[j]:
                res = (res + j) * (N - i - 1)
                lst_n = lst_n[:j] + lst_n[j + 1:]
                break
            j += 1
    return res + 1


print(abs(order(P) - order(Q)))


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

        using namespace std;

        #define pb push_back
        #define mp make_pair
        #define fr first
        #define sc second

        typedef long long int lli;

        lli h, n, a[1001], b[1001], dp[10001], currmin;
        //vector<vector<lli> > dp;

        int main(){
            cin>>h>>n;
            for(int i = 1;i<=n;i++)
                cin>>a[i]>>b[i];
            //dp[0] = 0;
            for(int i = 1;i<=h;i++){
                    currmin = INT_MAX;
                for(int j = 1;j<=n;j++){
                    if(a[j] >= i){
                        currmin = min(currmin,b[j]);
                    }
                    else{
                        currmin = min(currmin,b[j] + dp[i-a[j]]);
                    }
                }
                dp[i] = currmin;
            }
            cout<<dp[h]<<endl;
            return 0;
        }


Measured memory_bytes: 384
import itertools

N = int(input())
S = [0] * N
ans = 0
for i in range(N):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S[i] = s
S = list(set(S))
if 0 in S:
    S.remove(0)
march = [0] * 5
for i in S:
    if i[0] == 'M':
        march[0] += 1
    elif i[0] == 'A':
        march[1] += 1
    elif i[0] == 'R':
        march[2] += 1
    elif i[0] == 'C':
        march[3] += 1
    else:
        march[4] += 1

for i, j, k in list(itertools.combinations([0, 1, 2, 3, 4], 3)):
    ans += march[i] * march[j] * march[k]
print(ans)

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

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

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);cout<<"\n";};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION  


void solve(void)
{
  int A,B;
  cin>>A>>B;
  if(A*B < 0)
  {
    cout<<"Zero"<<endl;
  }
  else if(A < 0 && B < 0)
  {
    if(abs(A-B)%2 == 1)
    {
      cout<<"Positive"<<endl;
    }
    else
    {
      cout<<"Negative"<<endl;
    }
    
  }
  else
  {
    cout<<"Positive"<<endl;
  }
  
  
  return;
}
  
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

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

  return 0;
}


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

using namespace std;

#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 FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int k;
  int a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	int N,x=0;
	cin>>N;
	string S;
	cin>>S;
	for(int i=0;i<N;i++)
	{
		if(S[i]==')')
		{
			x--;
			if(x<0)
				cout<<'(',
				x++;
		}
		else	x++;
	}
	cout<<S;
	for(int i=0;i<x;i++)
		cout<<')';
	puts("");
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val mod = 1e9.toLong() + 7
    val n = readLine()!!.toInt()

    val fs = IntArray(n + 1)

    for (i in 2..n) {
        var x = i
        for (j in 2..i) {
            while (x % j == 0) {
                fs[j]++
                x /= j
            }
        }
    }

    var ans = 1L
    for (i in 2..n) {
        if (fs[i] > 0) {
            ans *= fs[i] + 1
            ans %= mod
        }
    }
    println(ans)
}


Measured memory_bytes: 33484
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.next();
		Map<String, Integer> map = new HashMap<>();
		while (sc.hasNext()) {
			char[] array = sc.nextLine().toCharArray();
			Arrays.sort(array);
			String input = String.valueOf(array);
			Integer integer = map.getOrDefault(input, 0);
			map.put(input, integer + 1);
		}
		long sum = 0;
		for (Integer v : map.values()) {
			sum = (v * (v - 1l) / 2l) + sum;
		}
		System.out.println(sum);
	}
}


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

	int main(){
		int n,m,k,temp;	cin >> n >> m;
		
		vector<int> v[m];
		for(int i=0 ; i<m ; i++){
			cin >> k;
			while(k--){
				cin >> temp;
				v[i].push_back(temp);
			}
		}
		
		int p[m],ans = 0;
		for(int i=0; i<m; i++)	cin >> p[i];
		int qw = 1<< n ;
		qw-- ;
		for(int i = 0 ; i<= qw ; i++){
			int ww = 0;
			bitset<1100> B(i);
			for(int j = 0; j< m ; j++){
				int bit_cnt = 0;
				for(int q = 0; q<v[j].size() ; q++){
					if(B[v[j][q]-1]==1) bit_cnt++;
				}
		//	cout << bit_cnt << " " << p[j] << "   aaa ";
				if(bit_cnt%2 == p[j])	ww++;
				//cout << "   aaaaa  " << ww << endl;
			}
	
			if(ww==m)	ans++;
		}
		cout << ans;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main(){
	int n;
	while(cin >> n){
		memset(a,0,sizeof(a));
		for(int i = 1; i <= n; i++){
			int x;
			cin >> x;
			a[x] = i;
		}
		for(int i = 1; i <= n; i++){
			cout << a[i];
			if(i == n) cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
using namespace std;

int main()
{
	ll t;
//	cin>>t;
	t=1;
	while(t--){
		ll n;
		cin>>n;
		ll ans=0;
		ll ar[n+1];
		for(ll i=1;i<=n;i++){
			cin>>ar[i];
		}
		ll mx=0;
		for(ll i=1;i<=n;i++){
			if(ar[i]<mx){
				ans+=mx-ar[i];
			}
			else{
				mx=ar[i];
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 5164
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=1e6+10;
int n,ans,p[30],pos; char s[N],t[N];

queue<int> q;

int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	if (s[1]!=t[1]) return puts("-1"),0;
	if (strcmp(s+1,t+1)==0) return puts("0"),0;
	int pos=n;
	for (int i=n;i;i--)
		if (i==1||t[i]!=t[i-1]){
			pos=min(pos,i);
			while (pos>=1&&s[pos]!=t[i]) pos--;
			if (pos<1) return puts("-1"),0;
			while (!q.empty()&&q.front()-(int)q.size()+1>i) q.pop();
			q.push(pos);
			if (i!=pos) ans=max(ans,(int)q.size());
		}
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
vector<ll> adj[N];
ll parent[N], rank1[N];

// initialise parent[i]=i,rank1[i]=1

ll findRoot(ll curr) {
  if (curr == parent[curr])
    return curr;
  return (parent[curr] = findRoot(parent[curr]));
}

void union1(ll a, ll b) {
  ll root1 = findRoot(a);
  ll root2 = findRoot(b);
  if (root1 == root2)
    return;

  if (rank1[root1] < rank1[root2]) {
    parent[root1] = root2;
  } else if (rank1[root1] > rank1[root2]) {
    parent[root2] = root1;
  } else {
    parent[root2] = root1;
    rank1[root1]++;
  }
}

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

  ll n, m;
  cin >> n >> m;

  for (ll i = 1; i <= n; i++) {
    parent[i] = i;
    rank1[i] = 1;
  }

  for (ll i = 1; i <= m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;

    union1(x, y);
  }

  map<ll, ll> par;
  for (ll i = 1; i <= n; i++)
    par[findRoot(i)];
  cout << par.size() << en;
  return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int H, W;
    while (1)
    {
        cin >> H >> W;

        if (H == 0 && W == 0)
            break;

        rep(i, H)
        {
            rep(j, W)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


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

int main() {
    int cnt = 0;
    string r;
    cin >> r;
    string s = r;
    reverse(r.begin(), r.end());
    // cout << r << "," << s << endl;
    rep(i, s.size()) {
        if(s[i] != r[i]) {
            cnt++;
        }
    }

    cout << cnt / 2 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string tmp;
  vector <string> v;
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> tmp;
    v.push_back(tmp);
  }
  

  cout << "AC x " << count(v.begin(), v.end(), "AC") << '\n';
  cout << "WA x " << count(v.begin(), v.end(), "WA") << '\n';
  cout << "TLE x " << count(v.begin(), v.end(), "TLE") << '\n';
  cout << "RE x " << count(v.begin(), v.end(), "RE") << '\n'; 
}

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


int main() 
{
	int N=0,a=1,counter = 1;
	cin >> N;
	vector<int> A(N);

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

	for (int i = 0; i < N; i++)
	{
		if (A.at(a - 1) == 2)
		{
			cout << i + 1 << endl;
			break;
		}
		else
		{
			a = A.at(a - 1);
		}
	}

	if (A.at(a - 1) != 2)
	{
		cout << -1 << endl;
	}

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
int dp[42][1<<17], mx[1 << 17];
#define up(a,b) {if((a += b) >= MOD) a-=MOD;}
int main() {
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    int ans = 1;
    for(int i = 1; i < (1 << 17); i++) {
        for(int j = 20; j >= 0; j--) {
            if(i & (1 << j)) {
                mx[i] = j + 1;
                break;
            }
        }
    }
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        ans = ans * 10LL % MOD;
        for(int j = 0; j < (1 << 17); j++) {
            int src = dp[i][j];
            if(src == 0) continue;
            for(int k = 1; k <= 10; k++) {
                int to = j;
                while(mx[to] + k > 17) {
                    to -= (1 << (mx[to] - 1));
                }
                to <<= k;
                to += (1 << (k - 1));
                int bs = (1 << (x+y+z-1)) + (1 << (y+z-1)) + (1 << (z-1));
                if((to & bs)==bs) {
                    // cout << i << " " << j << " " << k << endl;
                    continue;
                }
                up(dp[i+1][to], src);
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < (1 << 17); i++) up(sum, dp[n][i]);
    cout << (ans - sum + MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 20224
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
const ll base = 1013;

int N, hashes[100010];
vector<int> G[100010];

void dfs(int cur, int par=-1) {
    for(auto to : G[cur]) {
        if(to == par) continue;
        dfs(to, cur);
        (hashes[cur] += hashes[to]) %= MOD;
    }
    (hashes[cur] *= base) %= MOD;
    (hashes[cur] += 1) %= MOD;
}

map<int, int> memo;
signed main() {
    cin >> N;
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(0);
    for(int i=0; i<N; i++) memo[hashes[i]]++;

    int ans = 0;
    for(auto e : memo) ans += e.second * (e.second - 1) / 2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 21896
n, k, c = map(int, input().split())
s = input()

l = [0] * k
r = [0] * k
l_idx = 0
r_idx = k - 1
l_cnt = r_cnt = 0
for i in range(n):
    if s[i] == "o" and (l_cnt >= c or l_idx == 0) and l_idx < k:
        l[l_idx] = i
        l_cnt = -1
        l_idx += 1
    if s[n-i-1] == "o" and (r_cnt >= c or r_idx == k - 1) and r_idx >= 0:
        r[r_idx] = n - i - 1
        r_cnt = -1
        r_idx -= 1
    l_cnt += 1
    r_cnt += 1

for i in range(k):
    if l[i] == r[i]:
        print(l[i] + 1)

Measured memory_bytes: 73172
<?php

$args = [];
$input = explode(' ', trim(fgets(STDIN)));

$d = (int)$input[0];
$g = (int)$input[1];

$cnt = 0;
$probrems = [];
$flg = 0;
$total_amount = 0;
for ($i=1; $i <= $d ; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$probrems[$i] = [
		'point'  => $i * 100,
		'amount' => (int)$input[0],
		'bonus'  => (int)$input[1],
		'total'  => (int)$input[0] * $i * 100 + (int)$input[1],
		'point_only'  => ((int)$input[0]-1) * $i * 100,
	];
	$flg += pow(2, $i-1);
	$total_amount += (int)$input[0];
}

$min = $total_amount + 1;
for ($i=0; $i <= $flg; $i++) { 
	$bin = decbin($i);
	$len = strlen($bin);
	$tmp_sum = 0;
	$tmp_cnt = 0;
	$used = [];
	for ($k=$len; $k>0; $k--) { 
		$tmp_flg = $bin[$k-1];
		if ($tmp_flg == '1') {
			$tmp_sum += $probrems[$len - $k + 1]['total'];
			$tmp_cnt += $probrems[$len - $k + 1]['amount'];
			$used[] = $len - $k + 1;
		}
	}
	
	if ($tmp_sum >= $g) {
		$min = min($min, $tmp_cnt);
	}else{
		for ($j=$d; $j > 0; $j--) { 
			if (!in_array($j, $used) && $probrems[$j]['point_only'] + $tmp_sum >= $g) {
				$tmp_cnt += (int)ceil(($g - $tmp_sum) / $probrems[$j]['point']);
				$min = min($min, $tmp_cnt);
				break;
			}
		}
	}
}
echo $min;

Measured memory_bytes: 4604
/**
ID: albert.28
LANG: C++14
PROB: poetry
**/

/// Time:

#include <bits/stdc++.h>

/**
Mod operations in O(lg n)
Source: Benjamin Qi, https://github.com/bqi343/USACO/blob/master/Implementations/11%20-20(4)/Operators/modOp.cpp?fbclid=IwAR0m2afS-1xVg9kgeF8q8EJIeP9TP3Lct8dYb_hPJuI5gqHP1Utp5EkiOQ8
**/

using namespace std;

#define MAXN 105
#define MOD 1000000007

#define FOR(g,i,n) for(int i = g; i < n; i++)
#define FORD(g,i,n) for(int i = g; i >= n; i--)

#define apple() ios_base::sync_with_stdio(0)
#define hentai() cin.tie(); cout.tie()

#define mp make_pair
#define pb push_back
#define	ll long long
// #define int ll
#define INF (1e9*1)+5
#define LL_INF (1e18*1)+5
#define bitinc(s) (s&-s)
#define endl '\n'

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mi;
#define f first
#define s second
typedef vector<pii> vii;
typedef set<pii> sii;
typedef map<pii, pii> mii;

void fileio(char* in, char* out)
{
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}

namespace modOp
{
    int ad(int a, int b, int mod = MOD) { return (a+b)%mod; }
    int sub(int a, int b, int mod = MOD) { return (a-b+mod)%mod; }
    int mul(int a, int b, int mod = MOD) { return (ll)a*b%mod; }

    int AD(int& a, int b, int mod = MOD) { return a = ad(a,b,mod); }
    int SUB(int& a, int b, int mod = MOD) { return a = sub(a,b,mod); }
    int MUL(int& a, int b, int mod = MOD) { return a = mul(a,b,mod); }

    int po (int b, int p, int mod = MOD) { return !p?1:mul(po(mul(b,b,mod),p/2,mod),p&1?b:1,mod); }
    int inv (int b, int mod = MOD) { return po(b,mod-2,mod); }

    int invGeneral(int a, int b) { // 0 < a < b, gcd(a,b) = 1
        if (a == 0) return b == 1 ? 0 : -1;
        int x = invGeneral(b%a,a);
        return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
    }
}

using namespace modOp;

int n,w[MAXN];
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> w[i];
	int eygmath = INF;
	for(int i = 0; i < n; i++)
	{
		int lsum=0,rsum=0;
		for(int j = i; j >= 0; j--)
		{
			lsum += w[j];
		}
		for(int j = i+1; j < n; j++)
		{
			rsum += w[j];
		}
		eygmath = min(eygmath, abs(lsum-rsum));
	}
	cout << eygmath << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T1, typename T2>
istream& operator >> (istream& is, pair<T1, T2>& p){
  is >> p.first >> p.second;
  return is;
}


struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int>> es(M);
  for (int i = 0; i < M; ++i) {
    cin >> es[i];
    es[i].first--, es[i].second--;
  }

  int cnt = 0;
  for (int m = 0; m < M; ++m) {
    UnionFindTree tree(N);
    for (int i = 0; i < M; ++i) {
      if (i == m) continue;
      tree.Unite(es[i].first, es[i].second);
    }

    if (tree.Size(0) != N) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256