akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

using pii=pair<int,int>;

signed main()
{
    int n;
    while (cin >> n, n) {
        stack<pii> st;
        int tmp; cin >> tmp;
        st.push(pii(tmp,1));

        rep(i, n - 1) {
            int c; cin >> c;

            if (i % 2) {
                if (st.top().first == c) st.top().second += 1;
                else st.push(pii(c, 1));
            } else {
                if (st.top().first == c) st.top().second += 1;    
                else {
                    pii dat = st.top(); st.pop();
                    if (st.empty()) st.push(pii(c, dat.second + 1));
                    else st.top().second += dat.second + 1;
                }
            }
        }

        int ans = 0;

        while (st.size()) {
            if (st.top().first == 0) ans += st.top().second;
            st.pop();
        }

        cout << ans << endl;
    }
}

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

int main() {
  long N,K;cin>>N>>K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    A.at(i)--;
  }//　テレポーター指示
  int logK=1;
  while((1LL<<logK)<K) logK++;//2^logKがKを超えるまでlogKを増やす
  long DB[logK][N];//DB[i][j]をj番目のまちから2^i進んだ街にする
  for(int i=0;i<N;i++) DB[0][i]=A[i];//初期条件
  for(int i=0;i<logK-1;i++){
    for(int j=0;j<N;j++) DB[i+1][j]=DB[i][DB[i][j]];
  }//ここまで計算(下準備)
  
  int ans=0;
  for(int i=0;K>0;i++){
    if(K & 1) ans=DB[i][ans];
    K=K>>1;
  }
  cout<<ans+1<<endl;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int main() {
	string s = "1";
	int k;
	scanf("%d", &k);
	while (--k) {
		s[s.size()-1]++;
		if (s[s.size()-1] > '9' or s.size()>=2 and s[s.size()-1]-s[s.size()-2] >= 2) {
			if (s.size()==1) {
				s = "10";
				continue;
			}
			int pos = s.size()-1;
			while (pos >= 1 and (s[pos]-s[pos-1] >= 2 or s[pos] > '9')) {
				s[pos-1]++;
				s[pos] = max(char(s[pos-1]-1), '0');
				pos--;
			}
			if (s[0]>'9') {
				string t = "1";
				for (int i=0 ; i<s.size() ; i++) t+="0";
				s = t;
				//cout <<s<<endl;
				continue;
			} else {
			//	cout <<"s = "<<s<<endl;
				for (int i=pos+1 ; i<s.size() ; i++) {
				//	cout <<i<<endl;
					s[i] = max(char(s[i-1]-1), '0');
				}
			}
		}
		//cout <<s<<endl;
	}
	printf("%s\n", s.c_str());
	return 0;
}

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

using namespace std;

bool skill(vector<long>& scores, long m, long x) {
    for (int i = 0; i < m; i++) {
        if (scores[i] < x) {
            return false;
        }
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long n, m, x;
    cin >> n >> m >> x;
    vector<vector<long>> books;
    vector<long> scores(m+1,0);
    long c;
    for (int i = 0; i < n; i++) {
        books.push_back(vector<long>());
        cin >> c;
        books[i].push_back(c);
        scores[0] += c;
        for (int j = 0; j < m; j++) {
            cin >> c;
            books[i].push_back(c);
            scores[j+1] += c;
        }
    }
    for (int i = 0; i < m; i++) {
        if (scores[i+1] < x) {
            cout << -1;
            return 0;
        }
    }
    long cost = scores[0];
    for (int i = 0; i < pow(2,n); i++) {
        long total = 0;
        vector<long> scorew(m,0);
        for (int j = 0; j < n; j++) {
            if (((i >> j) & 1) == 0) {
                total += books[j][0];
                for (int k = 0; k < m; k++) {
                    scorew[k] += books[j][k+1];
                }
            
            }
        }
        if (skill(scorew,m,x)) {
            if (total < cost) {
                cost = total;
            }
        }
    }
    cout << cost;   
}


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

using namespace std;

int main()
{
  int n;
  cin>>n;
  for(long long i=-2500;i<=2500;i++){
    for(long long j=-2500;j<=2500;j++){
     long long x=i*i*i*i*i, y=j*j*j*j*j;
      if(x-y==n){cout<<i<<' '<<j<<endl;return 0;}
    }
  }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
#define mpr make_pair
#define ff first
#define ss second
#define PI 3.1415926535897932384626
#define mod 1000000007
#define modd 998244353

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int n;
	cin>>n;
	vector<ll> fac(n+1,1);
	for(int i=2;i<=n;i++) {
		for(int j=i;j<=n;j+=i)
			fac[j]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans+=i*fac[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 81336
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    int dp[n+1];
    dp[n] = 0;
    constexpr int INF = 1<<30;
    for (int i = n-1, j = n; i >= 0; i--) {
        if (s[i] == '0') {
            while (j - i > m || (j > i && s[j] == '1')) j--;
            if (i == j) { cout << "-1\n"; return 0; }
            dp[i] = dp[j]+1;
        }
    }
    for (int i = 0, j = 0; i < n; i = j) {
        while (dp[i] == dp[j] || s[j] == '1') j++;
        cout << j-i << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && c == a) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
H, N = [int(i) for i in input().split()]
A=[]; B=[]
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    A.append(a); B.append(b)

# A : value  B : weight
INF = 10**9
dp = [[INF for _ in range(20010)] for _ in range(N+10)]

for i in range(N): dp[i][0] = 0

for i in range(N):
    for w in range(H+10000):
        dp[i+1][w] = min(dp[i+1][w], dp[i][w])
        if w >= A[i]: dp[i+1][w] = min(dp[i+1][w], dp[i+1][w-A[i]]+B[i])

res=INF
for i in range(H, H+10001):
    res = res if res < dp[N][i] else dp[N][i]
print(res)

Measured memory_bytes: 271496
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <iomanip>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)
#define ld long double
#define ll long long

using namespace std;

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;


int main(){
  int N;
  int A,B;
  cin >> N >> A >> B;
  int ans=0;
  int k;
  vector<int> P;
  for(int i=0;i<N;i++){
    cin >> k;
    P.push_back(k);
  }
  sort(P.begin(),P.end());
  int a=0,b=0,c;
  bool flag=true;
  for(int i=0;i<N;i++){
    if(P[i]>A && flag){
      a=i;
      flag =false;
    }
    if(P[i]>B){
      b=i;
      break;
    }
  }

  c=N-(b);
  b=b-a;
  ans=min({a,b,c});
  if(ans<0){
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string S;
  cin >> S;
  bool can=false;
  if(S[0]==S[1] && S[2]==S[3]) can =true;
  else if(S[0]==S[2] && S[1]==S[3]) can = true;
  else if(S[0]==S[3] && S[1]==S[2]) can=true;
  if(S[0]==S[1] && S[1]==S[2] && S[2]==S[3]) can=false;
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int g[15];
int a[1000000+100];
long long res=0;
int m;
void getG(){
    g[0]=1;
    m++;
    for(int i=1;;i++){
        g[i]=g[i-1]*3+1;
       if(g[i]>n)
        break;
       m++;
    }
}

void Insertion_sort(int g){

    for(int i=g;i<n;i++){
        int val=a[i];
        int j=i-g;
        while(j>=0 && a[j]>val){
            a[j+g]=a[j];
            res++;
            j-=g;
        }
        a[j+g]=val;
    }
}

void shell_sort(){
    getG();
    for(int i=14;i>=0;i--){
        Insertion_sort(g[i]);
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    shell_sort();
    cout<<m<<endl;
    cout<<g[m-1];
    for(int i=m-2;i>=0;i--)
        cout<<" "<<g[i];
    cout<<endl;
    cout<<res<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<endl;
}

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

int main(){
    int n;

    cin >> n;
    int x[n];
    int y[n];
    int h[n];
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    int l = 0;
    int ansx,ansy,ansh;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            while(h[l] == 0){
                l ++;
            }
            int H = abs(x[l]-i) + abs(y[l]-j) + h[l];
            for(int k=0;k<n;k++){
                if(max(H-abs(x[k]-i) -abs(y[k]-j),0) != h[k] ){
                    break;
                }
                if(k == n-1){
                    ansx = i;
                    ansy = j;
                    ansh = H;
                }
            }
        }
    }
    cout << ansx << " " << ansy << " " << ansh << endl;
    return 0 ;
}


Measured memory_bytes: 256
a = []
while true
  num = gets.split(" ").map(&:to_i)
  break if(num[0] == 0 && num[1] == 0)
  a.push(num)
end
a.each do |ver|
  h = ver[0]
  w = ver[1]
  h.times do
    w.downto(1) do |w|
      unless w == 1
        printf "#"
      else
        printf "#\n"
      end
    end
  end
  printf "\n"
end

Measured memory_bytes: 6112
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 2000005;
const ll mm = 1e+18;
vector<int>gr[N];
bool vis[N];
int tot=0;
void dfs(int he){
    tot++;
    vis[he]=true;
    for(auto x:gr[he]){
        if(!vis[x]) dfs(x);
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    rep1(i,m){
        int x,y;
        cin>>x>>y;
        gr[x].pb(y);
        gr[y].pb(x);
    }
    int ans=0;
    memset(vis,false,sizeof(vis));
    rep1(i,n){
        if(!vis[i]){
            dfs(i);
            ans=max(ans,tot);
            tot=0;
        }
    }
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 64976
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;


namespace atPra
{
    class Class1
    {
        static void Main()
        {
            string str = Console.ReadLine();
            char x = str[0];
            char y = str[1];
            char z = str[2];

            bool a = false;
            bool b = false;
            bool c = false;

            if (x == 'a' || y == 'a' || z == 'a') a = true;
            if (x == 'b' || y == 'b' || z == 'b') b = true;
            if (x == 'c' || y == 'c' || z == 'c') c = true;
            if (a == true && b == true && c == true) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc) { 
    for (auto vc: vvc) {
        for (auto e: vc) cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp) {
    for (auto pT: vp) cout << pT.first << " " << pT.second << endl;
}

int main() {
    string str; cin >> str;
    auto it = str.begin();
    int mini = INT_MAX;
    for (;it + 2 != str.end(); ++it) {
        int a = (*it - '0') * 100 + (*(it + 1) - '0') * 10 + (*(it + 2) - '0');
        mini = min(mini, abs(753 - a));
    }

    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int w,h,dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	while(cin>>w>>h,w||h){
		string s;
		int x=1,y=1,n;
		int dir=0;
		while(cin>>s,s!="STOP"){
			if(s=="FORWARD"){
				cin>>n;
				for(int i=0;i<n;i++){
					int nx=dx[dir]+x,ny=dy[dir]+y;
					if(nx>=1&&nx<=w&&ny>=1&&ny<=h){
						x=nx;y=ny;
					}else
						break;
				}
			}else if(s=="RIGHT"){
				dir++;
				dir%=4;
			}else if(s=="LEFT"){
				dir+=3;
				dir%=4;
			}else{
				cin>>n;
				for(int i=0;i<n;i++){
					int nx=dx[(dir+2)%4]+x,ny=dy[(dir+2)%4]+y;
					if(nx>=1&&nx<=w&&ny>=1&&ny<=h){
						x=nx;y=ny;
					}else
						break;
				}
				
			}
		}
		cout<<x<<' '<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int x,y,a,b;
	cin>>x>>y>>a>>b;
	vector<string> ans;
	for (int i = x; i < a; i++){
		ans.push_back("R");
	}
	for (int i = y; i < b; i++){
		ans.push_back("U");
	}
	for (int i = x; i < a; i++){
		ans.push_back("L");
	}
	for (int i = y; i < b; i++){
		ans.push_back("D");
	}

	ans.push_back("D");
	for (int i = x; i < a+1; i++){
		ans.push_back("R");
	}
	for (int i = y-1; i < b; i++){
		ans.push_back("U");
	}
	ans.push_back("L");
	ans.push_back("U");
	for (int i = a; i > x-1; i--){
		ans.push_back("L");
	}
	for (int i = b+1; i > y; i--){
		ans.push_back("D");
	}
	ans.push_back("R");
	for(auto c:ans)
		cout<<c;
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(M));
	rep(i, 0, N) rep(j, 0, M) { cin >> A[i][j]; A[i][j]--; }

	int ans = INF;
	vector<bool> used(M);
	rep(k, 0, M) {
		vector<int> num(M);
		rep(i, 0, N) {
			rep(j, 0, M) {
				if (used[A[i][j]])continue;
				num[A[i][j]]++;
				break;
			}
		}
		dump(num);
		auto it = max_element(all(num));
		chmin(ans, *it);
		used[it - num.begin()] = true;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

vector<int> G[10010];

signed main(){
	int n,c[10010],sum = 0,cnt = 0,ans[10010];
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	for(int i = 0;i < n;i++){
		cin >> c[i];
		sum += c[i];
		ans[i] = -1;
	}
	sort(c,c + n,greater<int>());
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int siz = que.size();
		for(int t = 0;t < siz;t++){
			int v = que.front();que.pop();
			ans[v] = c[cnt++];
			for(int to : G[v]){
				if(ans[to] == -1) que.push(to);
			}
		}
	}
	cout << sum - c[0] << endl;
	for(int i = 0;i < n;i++) cout << (i ? " " : "") << ans[i];
	cout << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll a;
    cin >> a;
    long double b;
    cin>>b;
    ll d=b*a;
    cout<<d<<endl;
}

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

const int mx = 2e5 + 5;

vector<pair<int , int> > adj[mx];
bool vis[mx];
int dis[mx];

void dfs(int src){
vis[src] = 1;
for(auto u : adj[src]){
    if(vis[u.first] == 0){
       dis[u.first] = (dis[src] + u.second);
       dfs(u.first);
    }
}
}

main(){
int n;
cin>>n;
for(int i=1 ; i<n ; i++){
    int u , v , w;
    cin>>u>>v>>w;
    adj[u].push_back({v , w});
    adj[v].push_back({u , w});
}

dfs(1);

for(int i=1 ; i<=n ; i++){
    cout<<dis[i]%2<<endl;
}
}


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

int main() 
{
   int a, b, c, d, e, k;
   cin >> a >> b >> c >> d >> e >> k;

   vector<int> A = {a, b, c, d, e};
   sort(A.begin(), A.end());

   if (A.at(4) - A.at(0) > k)
      cout << ":(" << endl;
   else
      cout << "Yay!" << endl;
}


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

int main(){
    vector<bool> b(64,false);
    int q; cin >> q;
    rep(i , q){
        int l , m;
        int query; cin >> query;
        int counter;
        uint64 val , base;
        bool flag = false;
        switch (query)
        {
        case 0: //test(i)
            cin >> l;
            if(b[l] == true) cout << 1;
            else cout << 0;
            cout << endl;
            break;
        case 1: //set(i)
            cin >> l;
            b[l] = true;
            break;
        case 2: //clear(i)
            cin >> l;
            b[l] = false;
            break;
        case 3: //flip(i)
            cin >> l;
            if(b[l] == true) b[l] = false;
            else if(b[l] == false) b[l] = true;
            break;
        case 4: //all
            rep(j ,64){
                if(!b[j]) { cout << 0 << endl; flag = true; break; }
            }
            if(!flag) cout << 1 << endl;
            break;
        case 5: //any
            rep(j ,64){
                if(b[j]){ cout << 1 << endl; flag = true; break; }
            }
            if(!flag) cout << 0 << endl;
            break;
        case 6: //none
            rep(j ,64){
                if(b[j]) {cout << 0 << endl; flag = true; break;}
            }
            if(!flag) cout << 1 << endl;
            break;
        case 7: //count
            counter = 0;
            rep(j ,64){
                if(b[j] == true ) ++counter;
            }
            cout << counter << endl;
            break;
        case 8: //val
            val = 0;
            base = 0;
            for(int j = 0 ; j < 64 ; ++j){
                base = pow(2 , j);
                if(b[j] == true){
                    val += base;
                }
            }
            cout << val << endl;
            break;
        default:
            break;
        }
    }
}


Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long k = sc.nextLong();
		
		int[] a = new int[n];
		int[] vis = new int[n];
		
		
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextInt()-1;
		}
		
		int pos = 0;
		int time = 1;
		
		int loopstart = -1;
		int looptime = 0;
		
		while(true)
		{
//			System.out.println("Time " + time + " on " + pos);
			vis[pos] = time;
			pos = a[pos];
			
			time++;
			if(vis[pos] > 0)
			{
				loopstart = pos;
				looptime = time - vis[pos];
//				System.out.println("Loop found start " + pos + " len " + looptime);
				break;
			}
		}
		
		pos = 0;
		long more = k;
		while(more > 0)
		{
//			System.out.println("Pos " + pos + " " + loopstart);
			if(pos == loopstart)
			{
				if(more >= looptime)more = more%looptime;
				while(more<0)more+=looptime;
			}
			if(more<=0)break;
			pos = a[pos];
			more--;
		}
		pos++;
		System.out.println(pos);
	}

}


Measured memory_bytes: 51488
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
const int N = 200010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

void init_f(){
    fact[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
    }
    invf[N-1] = divll(1, fact[N-1]);
    FORR(i,N-1,1){
        invf[i-1] = (invf[i] * i) % mod;
    }
}

int main(void){
    ll n, m, k;
    cin >> n >> m >> k;
    init_f();
    ll ans = 0;
    ll s = m;
    REP(i,n-k-1) s = (s * (m - 1)) % mod;
    REP(i,k+1){
        ans = (ans + s * nCr(n - 1, k - i)) % mod;
        s = (s * (m - 1)) % mod;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define int long long
#define mod 998244353
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n;
int leup[222222], lelo[222222], riup[222222], rilo[222222];
vector<P>point;
struct BIT {
	vector<int>bit;
	BIT(int x) {
		bit.resize(x + 1);
		rep(i, x + 1)bit[i] = 0;
	}
	int sum(int x) {
		int s = 0;
		while (x > 0) {
			s += bit[x]; x -= x & -x;
		}
		return s;
	}
	void add(int x, int y) {
		while (x < bit.size()) {
			bit[x] += y; x += x & -x;
		}
	}
};
void compress(vector<P>& v) {
	vector<int>x, y;
	for (P p : v) {
		x.push_back(p.first); y.push_back(p.second);
	}
	sort(all(x)); sort(all(y));
	x.erase(unique(all(x)), x.end()); y.erase(unique(all(y)), y.end());
	for (P& p : v) {
		p.first = lower_bound(all(x), p.first) - x.begin(); p.first++;
		p.second = lower_bound(all(y), p.second) - y.begin(); p.second++;
	}
}
signed main() {
	cin >> n;
	point.resize(n);
	rep(i, n)cin >> point[i].first >> point[i].second;
	sort(all(point)); compress(point);

	//X座標が小さい方から
	{
		BIT bit(n);
		rep(i, n) {
			lelo[i] = bit.sum(point[i].second);
			leup[i] = i - lelo[i];
			bit.add(point[i].second, 1);
		}
	}
	//X座標が大きい方から
	{
		BIT bit(n);
		for (int i = n - 1; i >= 0; i--) {
			rilo[i] = bit.sum(point[i].second);
			riup[i] = (n - 1 - i) - rilo[i];
			bit.add(point[i].second, 1);
		}
	}
	//計算
	int ans = 0;
	rep(i, n) {
		int p = mod_pow(2, lelo[i]) + mod_pow(2, riup[i]) - 1; p %= mod;
		int q = mod_pow(2, leup[i]) + mod_pow(2, rilo[i]) - 1; q %= mod;
		ans += mod_pow(2, n) - p * q % mod + mod; ans %= mod;
	}
	cout << ans << endl;
}

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >


ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
	ll n, k;
	cin>>n>>k;
	vl a(n);
	for(ll i = 0; i < n; i++) cin>>a[i];
	ll low = 1, high = 0;
	for(auto i : a)
	    high = max(high, i);
	ll ans;
	while(low <= high)
	{
	    ll mid = low + (high - low) / 2;
	    ll need = 0;
	    for(ll i = 0 ; i < n; i++)
	    {
	        need += ceil(1.0 * a[i] / mid) - 1;
	    }
	    if(need <= k)
	    {
	        ans = mid;
	        high = mid - 1;
	    }
	    else
	        low = mid + 1;
	}
	cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();		
	}
	return 0;
}

ll mulmod(ll a, ll b)
{
	ll res = 0; 
	a = a % MOD;
	while(b > 0)
	{
		if (b % 2 == 1)
			res = (res + a) % MOD;
 
		a = (a * 2) % MOD; 
		b /= 2;
	} 
	return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a = (a * a) % MOD;
	}
	return res;
}

void getprime(vector<bool>&prime)
{
	prime[0] = false;
	prime[1] = false;
	
	for(ll i = 2; i * i <= MAX; i++)
	{
		if(prime[i])
		{
			for(ll j = i*i; j <= MAX; j += i)
				prime[j] = false;
		}
	}
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
	fact[0] = 1;
	ifact[0] = 1;
	
	for(ll i = 1; i <= MAX; i++)
	{
		fact[i] = (fact[i-1] * i)%MOD;
		ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
	}
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
	ll res;
	res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
	return res;
}

Measured memory_bytes: 4748
#EDPC_F
s=input()
t=input()
lens=len(s)
lent=len(t)
dp=[[0]*(lent+1) for _ in range(lens+1)]
for i in range(lens):
    for j in range(lent):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
i=lens
j=lent
ans=''
while i>0 and j>0:
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1
        j-=1
    elif dp[i][j]==dp[i-1][j]:
        i-=1
    else:
        j-=1  
print(ans)

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

int gcd(int a,int b){
  if( b==0)return a;
  else gcd(b,a%b);
}
    
int main(){
  int x,y;
  cin>>x>>y;
  int c=gcd(x,y);
  cout<<x+y-c+1<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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

    lint n, a;
    cin>>n>>a;
    co(n*n-a);
}


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

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

#define MAX_V 1000000

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

  string s;
  cin >> s;

  ll rsl = 0;
  ll len = s.size();

  for(ll bit = 0; bit < (1 << (len - 1)); ++bit) {
      ll tmp = 0;
      ll cur = s[0] - '0';
      for(ll mask = 0; mask < len - 1; ++mask) {
          if(bit & (1 << mask)) {
              tmp += cur;
              if(mask == len - 1) cur = 0;
              else cur = s[mask + 1] - '0';
          } else {
              if(mask == len - 1) continue;
              else cur = cur * 10 + s[mask + 1] - '0';
          }
      }
      rsl += tmp + cur;
  }
  cout << rsl << endl;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h+2,vector<char>(w+2,'#'));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i+1][j+1];
    }
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      cout << a[i][j] ;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int A;
int B;
string S[112];

int main(){
	
	cin>>A>>B;
	
	REP( i, A ) cin>>S[i];
	
	REP( i, A ){
		if( !i ){
			REP( j, B+2 ) cout<<"#";
			puts("");
		}
		cout<<"#"<<S[i]<<"#"<<endl;
		if( i == A-1 ){
			REP( j, B+2 ) cout<<"#";
			puts("");
		}
	}
		
	
	
	return 0;

}

Measured memory_bytes: 256
function main(input) {
    const [N, A, B] = input.split(' ').map( n => parseInt(n, 10) );

    const nums = Array.from(new Array(N), (v, i) => ++i ).filter( (i) => {
        let n = i.toString().split('').reduce( (p, c) => p + parseInt(c, 10), 0 );
        return (n >= A && n <= B );
    })

    console.log( nums.reduce( (p, c) => p + c, 0 ) );
}

main( require('fs').readFileSync('/dev/stdin', 'utf8') )

Measured memory_bytes: 33808
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
const int N = 3050;
int mod = 1000000007;
 int rec[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n;
	while (~scanf("%d", &n))
	{
		for (int i = 0; i < n; i++)
			scanf("%d", rec + i);
		sort(rec, rec + n);
		int ans = 1;
		int pre = rec[0];
		for (int i = 1; i < n; i++)
			if (rec[i] > pre)
			{
				ans++;
				pre = rec[i];
			}
		printf("%d\n", ans);
	}
   	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

H,W,T = map(int,read().split())

MOD = 10 ** 9 + 7

a = gcd(H,T); b = gcd(W,T)

H //= a; W //= b

x = pow(2,H,MOD) + pow(2,W,MOD) + pow(2,gcd(H,W),MOD) - 3
answer = pow(x,a*b,MOD)
print(answer)


Measured memory_bytes: 5344
#include<stdio.h>
int M,Nmin,Nmax,P[300],g,r,i;
int main()
{
	for(;scanf("%d%d%d",&M,&Nmin,&Nmax),M;)
	{
		Nmin--;Nmax--;
		g=0;r=0;
		for(i=0;i<M;i++)scanf("%d",&P[i]);
		for(i=Nmax;i>=Nmin;i--)
		{
			if(g<P[i]-P[i+1])
			{
				g=P[i]-P[i+1];
				r=i+1;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

/**
 * Fenwick Tree 
 *
 * 0-indexed
 */
template<class T>
struct Fenwick {
    int N;
    vector<T> seg;
    Fenwick(int N) : N(N) {
        seg.resize(N+1);
        fill_n(begin(seg), N+1, 0);
    }
    /// i番目の要素にxを追加する
    void add(int i, T x) {
        i++;
        while (i <= N) {
            seg[i] += x;
            i += i & -i;
        }
    }
    /// [0, i)のsum
    T sum(int i) {
        T s{0};
        while (i > 0) {
            s += seg[i];
            i -= i & -i;
        }
        return s;
    }
    /// [a, b)のsum
    T sum(int a, int b) {
        return sum(b) - sum(a);
    }
};


const int MN = 100100;



int g[MN][3];

int main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n; j++) {
            cin >> g[j][i];
        }
    }

    int uc[2] = {};
    for (int i = 0; i < n; i++) {
        array<int, 3> d;
        for (int j = 0; j < 3; j++) {
            d[j] = g[i][j];
        }
        if (d[1] % 3 != 2) {
            cout << "No" << endl;
            return 0;
        }
        if (d[1] != min(d[0], d[2])+1) {
            cout << "No" << endl;
            return 0;
        }
        if (d[1] != max(d[0], d[2])-1) {
            cout << "No" << endl;
            return 0;
        }
        if (d[1] % 6 != (i%2)*3+2) {
            cout << "No" << endl;
            return 0;
        }
        if (d[0]+1 == d[1]) {
            uc[i%2]++;
        }
    }

    uc[0] += (n+1)/2;
    uc[1] += n/2;

    uc[0] %= 2;
    uc[1] %= 2;

    int sm = 0;
    Fenwick<ll> fw1(n);
    for (int i = 0; i < n; i+=2) {
        int x = (g[i][1]-2)/3;
        sm += fw1.sum(x, n)%2;
        fw1.add(x, 1);
    }
    if (sm % 2 != uc[1]) {
        cout << "No" << endl;
        return 0;
    }

    sm = 0;
    fw1 = Fenwick<ll>(n);
    for (int i = 1; i < n; i+=2) {
        int x = (g[i][1]-2)/3;
        sm += fw1.sum(x, n)%2;
        fw1.add(x, 1);
    }
    if (sm % 2 != uc[0]) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2944
from collections import Counter

mod = 1000000007

# nの素因数分解
def factor(n):
    d = Counter()
    i = 2
    while i*i <= n:
        while n%i == 0:
            n //= i
            d[i] += 1
        i += 1
    if n > 1:
        d[n] += 1
    return d


# xのn乗を計算する
def mod_pow(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        half = int(n / 2)
        half_x = mod_pow(x, half)
        return half_x * half_x % mod
    else:
        return x * mod_pow(x, n - 1) % mod


def nCr(n, r):
    x = 1
    r = min(r, n - r)
    for i in range(r):
        x *= n - i
        x %= mod
        x *= mod_pow(i + 1, mod - 2)
        x %= mod
    return x


def solve():
    N, M = map(int, input().split())
    p = factor(M)
    s = 1
    for i in p.values():
        s *= nCr(i + N - 1, N - 1)
        s %= mod
    print(s)


solve()

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main() {
	string S; cin >> S;
	string A;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') A.push_back('0');
		else if (S[i] == '1') A.push_back('1');
		else {
			if (A.size()) A.erase(A.end()-1);
		}
	}
	cout << A << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9 + 7;
const ld error = 1e-8;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = bt(16)+1;
///===========================================  template  =======================================================

int main(){
    FASTIO;
    int a, b, c;
    cin>>a>>b>>c;
    if(a == b && a != c){
        cout<<"Yes";
    }
    else if(a == c && a != b){
        cout<<"Yes";
    }
    else if(b == c && b != a){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
main=do
 n<-readLn;a<-replicateM n readLn
 print(f (tail a) (head a) 0)
  where f [] b i = i+(quot b 2)
        f [a] b i = i+(quot(a+b)2)
        f (x:a) b i = f a (min x (mod (x+b) 2)) (i+(quot (x+b) 2))

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

namespace ConsoleApplication14//abcdefghij
{
   class Program
    {
        static void Main()
        {
            string a = Console.ReadLine();
            char[] sss=new char [a.Length];
            for (int r = 0; r < a.Length; r++)
            {
                sss[r] = a[r];
            }
            int b = int.Parse(Console.ReadLine());
            for(int c = 0; c < b; c++)
            {
                string[] s = Console.ReadLine().Split();int f = int.Parse(s[1]), g = int.Parse(s[2]);
                switch (s[0][2]) {
                    case 'i':
                        for(int i = f; i < g+1; i++)
                        {
                            Console.Write(sss[i]);
                        }
                        Console.WriteLine();
                        break;
                    case 'v':
                            char[] sssss = new char[g-f+1];//5
                            for(int z = f; z < g+1; z++)
                            {
                                sssss[z-f] = sss[z];//0 3
                            }
                            for(int d = f; d < g+1; d++)
                            {
                                sss[d] = sssss[ g - d];
                            }
                        break;
                    case 'p':
                        for(int h = f; h < g+1; h++)
                        {
                            sss[h] = s[3][h-f];
                        }
                        break;
                }

            }
        }
    }
}

Measured memory_bytes: 9000
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)

100.downto(1){|d|
    flag = false
    work = 0
    arr.each{|x|
        work += x
        work -= d
        if work < 0
            flag = true
            break
        end
    }
    if !flag
        puts d
        break
    end
}


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

int main() {
    vector<vector<ll>> a(3,vector<ll>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            std::cin >> a[i][j];
        }
    }
    map<ll,bool> m;
    ll n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        ll t;
        std::cin >> t;
        m[t] = true;
    }
    
    for (int i = 0; i < 3; i++) {
        bool ok = true;
        for (int j = 0; j < 3; j++) {
            if(!m[a[i][j]]){
                ok=false;
                break;
            }
        }
        if(ok){
            std::cout << "Yes" << std::endl;
            return 0;
        }
        ok = true;
        for (int j = 0; j < 3; j++) {
            if(!m[a[j][i]]){
                ok=false;
                break;
            }
        }
        if(ok){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    if(m[a[0][0]]&&m[a[1][1]]&&m[a[2][2]]){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    if(m[a[0][2]]&&m[a[1][1]]&&m[a[2][0]]){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e18;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for( int i = 0; i < N; i++ ) cin >> L[i];
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( i%2 == 0 && L[i]%2 == 1 ) ans++;
  }
  cout << ans << endl;
 }

Measured memory_bytes: 3628
class BellmanFord():
	def __init__(self, adj, start):
		self.adj = adj
		self.start = start
		self.size = len(adj)
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0

	def solve(self):
		for _ in range(self.size-1):
			for x in range(self.size):
				for y, w in self.adj[x]:
					if self.dist[y] > self.dist[x] + w:
						self.dist[y] = self.dist[x] + w
		return

	#負閉路のせいでgoalへの距離が-infになるか
	def NegativeCycleToGoal(self, goal):
		res = self.dist[goal]
		for x in range(self.size):
			for y, w in self.adj[x]:
				if self.dist[y] > self.dist[x] + w:
					self.dist[y] = self.dist[x] + w
		if res != self.dist[goal]:
			return True
		else:
			return False

	def GetDistance(self, goal):
		return self.dist[goal]

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

bf = BellmanFord(adj, 0)
bf.solve()
if bf.NegativeCycleToGoal(n-1):
	print("inf")
else:
	print(-bf.GetDistance(n-1))

Measured memory_bytes: 3444