akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<int> a(n);
  rep(i,n)
    std::cin >> a[i];

  bool flag = true;
  int cnt = 0;
  while(flag) {
    rep(i,n){
      if(a[i]%2==0){
        a[i] /= 2;
      }
      else{
        flag = false;
        break;
      }
    }

    if(flag == true)
      cnt++;
  }

  std::cout << cnt << '\n';
  return 0;
}


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

using namespace std;

int main() {
    string c;
    cin >> c;

    if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VL p(n);
    REP(i,n)cin>>p[i];
    LL ans = 0;
    REP(i,n-2){
        if((p[i+1] < p[i] && p[i+1] > p[i+2]) || 
               (p[i+1] > p[i] && p[i+1] < p[i+2]))ans++;
    }
    PUTS(ans);
}

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

void dfs(vector<vector<int>> &adj,vector<int> &dp, vector<int> &visit, int u)
{
    visit[u]=1;
    for(int tt : adj[u])
    {
        if(visit[tt]==0)
        {
            dfs(adj,dp,visit,tt);
        }
        dp[u] = max(dp[u],1+dp[tt]);
    }
}
int main() {
	// your code goes here
	int n;
	int m;
	cin>>n>>m;
	int u,v;
	vector<int> visit(n,0);
	vector<vector<int>> adj(n);
	for(int i=0;i<m;i++)
	{
	    cin>>u>>v;
	    u--,v--;
	    adj[u].push_back(v);
	}
	vector<int> dp(n,0);
	for(int i=0;i<n;i++)
	{
	    if(visit[i]==0)
	    {
	        dfs(adj,dp,visit,i);
	    }
	}
	int ans=INT_MIN;
    for(int i=0;i<n;i++)
	{
	    ans = max(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}


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

int main(){
 int a, b, c, t;
 cin >> a >> b >> c;

 if ( a > b ){ t = a; a = b; b = t; }
 if ( b > c ){ t = b; b = c; c = t; }
 if ( a > b ){ t = a; a = b; b = t; }

 cout << a << " " << b << " " << c << endl;

 return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll A[N];
    vector<int> p, z, n;
    rep(i, N){
        cin >> A[i];
        if(A[i] > 0) p.pb(A[i]);
        elif(A[i] == 0) z.pb(A[i]);
        else n.pb(A[i]);
    }
    ll sum = 0;
    rep(i, N) sum += abs(A[i]);
    if(!n.empty() && !p.empty()){
        cout << sum << endl;
        ll now1 = n[n.size()-1];
        rep(i, p.size()-1){
            cout << now1 << ' ' << p[i] << endl;
            now1 -= p[i];
        }
        ll now2 = p[p.size()-1];
        rep(i, n.size()-1){
            cout << now2 << ' ' << n[i] << endl;
            now2 -= n[i];
        }
        cout << now2 << ' ' << now1 << endl;
        rep(i, z.size()){
            cout << sum << ' ' << 0 << endl;
        }
    }
    elif(n.empty()){
        sort(A, A+N);
        cout << sum-2*A[0] << endl;
        ll now = A[0];
        rep2(i, 1, N-2){
            cout << now << ' ' << A[i] << endl;;
            now -= A[i];
        }
        cout << A[N-1] << ' ' << now << endl;
    }
    else{
        sort(A, A+N, greater<ll>());
        cout << sum+2*A[0] << endl;
        ll now = A[0];
        rep2(i, 1, N-1){
            cout << now << ' ' << A[i] << endl;
            now -= A[i];
        }
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

const int MAX_N = 101;

bool solve(vector<int> &deg) {
	bool isBreak = false;
	for (int i = 2; i < MAX_N; i++) {
		if (deg[i] & 1) {
			return false;
		}
	}

	for (int i = 0; i < 2; i++) {
		if (deg[i] % 2 == 0) {
			return false;
		}
	}

	return true;
}

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

	int a, b;
	while (true) {
		vector<int> deg(MAX_N);
		int a = -1333;
		while (cin >> a >> b) {
			a--; b--;
			if (a == -1 && b == -1) {
				break;
			}

			// a -> b
			deg[a]++;
			deg[b]++;
		}
		if (a == -1333) {
			return 0;
		}

		cout << (solve(deg) ? "OK" : "NG") << endl;
	}

	return 0;
}



Measured memory_bytes: 3024
(let ((s (read-line))
    (firstA -1)
    (lastZ 0))
    (loop for i below (length s) do
        (let ((c (char s i)))
            (if (and (string= c "A") (= firstA -1))
                (setq firstA i)
            )
            (if (string= c "Z")
                (setq lastZ i)
            )
        )
    )
    (princ (+ (- lastZ firstA) 1))
)

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

int main(){
    int64_t n, k;
    cin >> n >> k;
    int64_t a[110000], b[110000];
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    int64_t count[110000] = {};
    for(int i=0; i<n; i++){
        count[a[i]] += b[i];
    }
    for(int i=0; ; i++){
        k -= count[i];
        if(k <= 0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

/* macros */
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve(){
    string s;
    cin>>s;
    int sum = 0;
    for (char c : s){
        sum += c-'0';
    }
    if (sum%9 == 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3776
#include<queue>
#include<cstdio>

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

using namespace std;

const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class T,class U>
struct Edge{
	int v,rev;
	T capa;
	U cost;
	T flow;
};

template<class T,class U>
struct AdjList:public vector< vector< Edge<T,U> > >{
	AdjList(int n):vector< vector< Edge<T,U> > >(n){}
};

template<class T,class U>
void add_edge(AdjList<T,U> &adj,int u,int v,T capa,U cost){
	adj[u].push_back((Edge<T,U>){v,adj[v].size()  ,capa, cost,0});
	adj[v].push_back((Edge<T,U>){u,adj[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(AdjList<T,U> &adj,int s,int t,vector<U> &pot,bool first){
	int n=adj.size();
	vector<int> pre(n);
	vector<U> d(n,COST_INF); d[s]=0;

	if(first){
		rep(u,n) rep(i,adj[u].size()) {
			Edge<T,U> &e=adj[u][i];
			if(e.capa-e.flow>0 && d[u]+e.cost<d[e.v]){
				d[e.v]=d[u]+e.cost;
				pre[e.v]=e.rev;
			}
		}
	}
	else{
		// Dijkstra
		bool ok=false;
		priority_queue< pair<U,int> > pq; pq.push(make_pair(0,s));
		while(!pq.empty()){
			int u=pq.top().second;
			U cost=-pq.top().first; pq.pop();

			if(cost<d[u]) continue;
			if(u==t) ok=true;

			rep(i,adj[u].size()){
				Edge<T,U> &e=adj[u][i];
				U cost2=cost+e.cost+pot[u]-pot[e.v];
				if(e.capa-e.flow>0 && cost2<d[e.v]){
					d[e.v]=cost2;
					pre[e.v]=e.rev;
					pq.push(make_pair(-cost2,e.v));
				}
			}
		}

		if(!ok) return make_pair(0,0);
	}

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		Edge<T,U> &e1=adj[v][pre[v]];
		Edge<T,U> &e2=adj[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		Edge<T,U> &e1=adj[v][pre[v]];
		Edge<T,U> &e2=adj[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(AdjList<T,U> &adj,int s,int t){
	T ans1=0;
	U ans2=0;
	vector<U> pot(adj.size());
	for(int i=0;;i++){
		pair<T,U> tmp=augment(adj,s,t,pot,i==0);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	int m,n,k; scanf("%d%d%d",&m,&n,&k);
	int w[10000];
	rep(i,n) scanf("%d",w+i);

	AdjList<int,int> adj(k+1);

	int wsum=0;
	int pre[10000];
	rep(a,n) pre[a]=-1;
	rep(i,k){
		int a; scanf("%d",&a); a--;
		add_edge(adj,i,i+1,i<k-1?CAPA_INF:m-1,0);
		if(~pre[a]){
			if(pre[a]+1<i) add_edge(adj,pre[a]+1,i,1,-w[a]);
			else           wsum-=w[a];
		}
		pre[a]=i;
		wsum+=w[a];
	}

	printf("%d\n",wsum+primal_dual(adj,0,k).second);

	return 0;
}

Measured memory_bytes: 0
from math import sqrt

while True:
    e = int(input())
    if e == 0: break
    ans = e
    for z in range(e):
        if z ** 3 > e: break
        y = int(sqrt(e - z ** 3))
        x = e - (z ** 3 + y ** 2)
        ans = min(ans, x + y + z)
    print(ans)

Measured memory_bytes: 6808
import sys


def solve():
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    cnt = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int s[][] = new int[h + 2][w + 2];
        Queue<Pair> que = new ArrayDeque<>();
        for (int i = 0; i < h; i++) {
            char c[] = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if (c[j] == '.') {
                    s[i + 1][j + 1] = -1;
                } else if (c[j] == '#') {
                    que.add(new Pair(i + 1, j + 1));
                }

            }
        }
        sc.close();

        Pair p;
        int ans = 0;
        while (!que.isEmpty()) {
            p = que.poll();
            ans = s[p.x][p.y];
            if (s[p.x + 1][p.y] == -1) {
                s[p.x + 1][p.y] = ans + 1;
                que.add(new Pair(p.x + 1, p.y));
            }
            if (s[p.x - 1][p.y] == -1) {
                s[p.x - 1][p.y] = ans + 1;
                que.add(new Pair(p.x - 1, p.y));
            }
            if (s[p.x][p.y + 1] == -1) {
                s[p.x][p.y + 1] = ans + 1;
                que.add(new Pair(p.x, p.y + 1));
            }
            if (s[p.x][p.y - 1] == -1) {
                s[p.x][p.y - 1] = ans + 1;
                que.add(new Pair(p.x, p.y - 1));
            }
        }
        System.out.println(ans);
    }
}

class Pair {
    int x;
    int y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

Measured memory_bytes: 65900
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	int a, b, c,d; cin >> a>>b>>c;
	//string s,t,u; cin >> s>>t>>u;
	//vector<int> n(3);
	cout << (a + b) * c / 2;

	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint X, t;
    cin >> X >> t;
    cout << max(0LL, X - t) << "\n";
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int N;
    vector<int> A;

    cin >> N;
    A.assign(N, 0);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        if (i > 0) {
            sum += abs(A[i] - A[i - 1]);
        }
        else sum += abs(A[i]);
    }
    sum += abs(A[N - 1]);

    rep(i, N) {
        ll a = sum;

        if (i == 0) {
            a -= abs(A[0]);
            a -= abs(A[1] - A[0]);
            a += abs(A[1]);
        }
        else if (i == N - 1) {
            a -= abs(A[N - 1] - A[N - 2]);
            a -= abs(A[N - 1]);
            a += abs(A[N - 2]);
        }
        else {
            a -= abs(A[i] - A[i - 1]);
            a -= abs(A[i + 1] - A[i]);
            a += abs(A[i + 1] - A[i - 1]);
        }

        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

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

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define INF INT_MAX/3


int main(){
    cin.sync_with_stdio(false);
    int n, q, k;
    cin >> n;
    vector<P> edge[n];
    rep(i, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        edge[a].pb(P(c, b)), edge[b].pb(P(c, a));
    }
    cin >> q >> k; k--;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, k));
    bool visited[100005] = {};
    ll cost[100005] = {};
    while(que.size()) {
        P p = que.top(); que.pop();
        if (visited[p.se]) continue;
        visited[p.se] = true;
        cost[p.se] = p.fi;
        rep(i, edge[p.se].size()) {
            int u = edge[p.se][i].se, c = edge[p.se][i].fi;
            if (!visited[u]) que.push(P(p.fi + c, u));
        }
    }
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        cout << cost[x - 1] + cost[y - 1] << endl;
    }
    return 0;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<char> image(H*W);
  for(int i=0;i<H*W;i++){
    cin >> image.at(i);
  }
  for(int i=0;i<(W+2);i++){
  cout << "#";
  }
  cout << endl;
  for(int i=0;i<W*H;i++){
    if(i%W==0){
    cout <<"#";
    }
    cout << image.at(i);
    if((i+1)%W==0){
    cout <<"#" <<endl;
    }
  }
  
  for(int i=0;i<(W+2);i++){
      cout << "#"; 
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        if(s.equals("AAA") || s.equals("BBB")) {
        	System.out.println("No");
        }else {
        	System.out.println("Yes");
        }
    }
}

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

int main(){
	int a, b;
	char s[10], t[10], u[10];
	
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if(s[1] == u[1]) a--;
	else b--;
	cout << a <<" " <<b << "\n";
	
	return 0;
}

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

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

// qsort に関数ポインタとして渡す関数
int compare_base(const void *b, const void *f) {
  return (strncmp(*(char **)b, *(char **)f, 10));
}

int main(void) {
  int scan; // scanf result
  int answer; // to output 
  int n; // to input 
  char **s;
  
  answer = 0;
  scan = scanf("%d", &n);
  s = (char **)malloc(sizeof(char *) * (n + 1));
  for (int i = 0; i < n; i++) {
    s[i] = (char *)malloc(sizeof(char) * 11);
    scan = scanf("%s", s[i]);
  }

  qsort((void *)s, n, sizeof(char *), compare_base);
  for (int i = 0; i < n; i++) {
    if (i == 0 || (i >= 1 && strncmp(s[i - 1], s[i], 10) != 0)) {
      answer++;
    }
  }

  printf("%d", answer);
  return (0);
}


Measured memory_bytes: 10768
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  if (N%2 == 0) std::cout << 0.5 << std::endl;
  else std::cout << (double)(N + 1)/(2 * N) << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
main(){
    FIO;
    //OJ;
    int n,ac=0,tle=0,re=0,wa=0;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        if(s=="AC")
            ac++;
        else if(s=="TLE")
            tle++;
        else if(s=="RE")
            re++;
        else 
            wa++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

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

int main() {

    string word;          //単語
    vector<string> vector;//vector配列

    int N;
    cin >> N;
    
    for ( int i=0; i<N; i++ ){
      cin >> word;
      vector.push_back(word);
    }
    //vector配列に格納した単語を、辞書順にソートする
    sort(vector.begin(), vector.end());

    map<string, int> mp;

    for ( int i=0; i<N; i++ ){
      mp[vector[i]]++;
    }
   
    int max=0;
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if ( iter->second > max) {
          max = iter->second;
        }
    }

    for (auto iter = begin; iter != end; iter++) {
        if ( iter->second == max ) {
          cout << iter->first << "\n";
        }
    }

    return 0;
    
}

Measured memory_bytes: 26736
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
        vector<int> x;
        int input_val;
        int input_num = 0;

        do{
                cin >> input_val;
                x.push_back(input_val);
                input_num++;
        } while(input_val != 0);

        for(int i = 0; i < input_num; i++)
        {
                if( x[i] != 0 )
                {
                        cout << "Case " << (i+1) << ": " << x[i] << endl;
                }
        }
        return 0;
}

Measured memory_bytes: 1320
n=int(input())

nmax = 1000000000000001

def elc(idx):
    return( chr(ord('a') + idx ) )

k = n - 1
res =[]
while True:
    wkm = k % 26
    wks = k // 26
    res.append(elc(wkm))
    if wks == 0:
        break
    k = wks - 1

res.reverse()
print(''.join(res))


Measured memory_bytes: 61896
#再帰関数
#もし残り体力が１なら一回切るだけ
#それ以外では１回(モンスターを一回きる)+2*int(体力//2)回必要
def attack(x):
  if x==1:
    return 1
  else:
    return 2*attack(x//2)+1
h=int(input())
print(attack(h))


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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

string S;

int main(){
  cin>>S;
  if(S.back()=='1'||S.front()=='0'||S[S.size()-2]=='0'){
    cout<<-1<<endl;
    return 0;
  }
  int n=S.size();
  for (int i = 0,j = n-2; i < j; i++,j--) {
    if(S[i]!=S[j]){
      cout<<-1<<endl;
      return 0;
    }
  }
  int cur=1,next=2;
  for (next = 2; next <= n/2+1; next++) {
    cout<<cur<<" "<<next<<endl;
    if(S[next-2]=='1')
      cur=next;
  }
  for (int i = next; i <= n; i++) {
    cout<<cur<<" "<<i<<endl;
  }
  return 0;
}



Measured memory_bytes: 1664
import math
N=int(input())
engines = tuple((complex(*map(int, input().split())) for _ in range(N)))
engines = sorted(list((engine, math.atan2(engine.imag, engine.real))for engine in engines if engine != 0), key=lambda x:x[1])
N=len(engines)
if N == 0:
    print(0)
else:
    total = sum(engine[0] for engine in engines)
    head_index = max(i if engines[i][0].imag < 0 else -1 for i in range(N))
    tail_index = 0
    tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
    maximum = max(abs(tmp), abs(total - tmp))

    while True:
        if head_index < N-1:
            if (engines[head_index+1][0]/engines[tail_index][0]).imag >= 0:
                head_index += 1
            else:
                tail_index += 1
        else:
            if (engines[0][0]/engines[tail_index][0]).imag < 0:
                tail_index += 1
            else:
                break
        tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
        maximum = max(maximum, abs(tmp), abs(total - tmp))

    print(maximum)

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

long long dp[100007][107];
int n,w;
vector<int>v[107];

long long solve(int x,int i)
{
    if(i>=n) return 0;
    if(x==0) return 0;
    if(dp[x][i]!=-1) return dp[x][i];
    dp[x][i]=0;
    if(x-v[i][0]>=0)
    {
        dp[x][i]=max(dp[x][i],solve(x-v[i][0],i+1)+1ll*v[i][1]);
    }
    return dp[x][i]=max(dp[x][i],1ll*solve(x,i+1));

}

int main()
{
    scanf("%d%d",&n,&w);
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);

        v[i].push_back(a); v[i].push_back(b);
    }
    memset(dp,-1,sizeof(dp));
    printf("%lld\n",solve(w,0));
    return 0;
}


Measured memory_bytes: 83840
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c,i=0;cin>>a>>b>>c;
  ll d=a+b+c;
  ll e=max({a,b,c}),f=min({a,b,c}),g=d-e-f;
  d=(e-f)+(e-g);
  e=d/2;
  if(d%2==1)e+=2;
  cout<<e;
}


Measured memory_bytes: 27004
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

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

    vector<int> counter(N + 1, 0);
    for (int i = 0; i < N - 1; i++) {
        int x;
        cin >> x;
        counter[x]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << counter[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4060
n, m = map(int, input().split())
list_XYZ = [ list(map(int,input().split(" "))) for i in range(n)]
list_ANS = [[] for _ in range(8)]

for i in range(n):
    l = list_ANS[0]
    l.append(list_XYZ[i][0]+list_XYZ[i][1]+list_XYZ[i][2])

for i in range(n):
    l = list_ANS[1]
    l.append(-list_XYZ[i][0]+list_XYZ[i][1]+list_XYZ[i][2])

for i in range(n):
    l = list_ANS[2]
    l.append(list_XYZ[i][0]-list_XYZ[i][1]+list_XYZ[i][2])

for i in range(n):
    l = list_ANS[3]
    l.append(list_XYZ[i][0]+list_XYZ[i][1]-list_XYZ[i][2])

for i in range(n):
    l = list_ANS[4]
    l.append(list_XYZ[i][0]-list_XYZ[i][1]-list_XYZ[i][2])

for i in range(n):
    l = list_ANS[5]
    l.append(-list_XYZ[i][0]+list_XYZ[i][1]-list_XYZ[i][2])

for i in range(n):
    l = list_ANS[6]
    l.append(-list_XYZ[i][0]-list_XYZ[i][1]+list_XYZ[i][2])

for i in range(n):
    l = list_ANS[7]
    l.append(-list_XYZ[i][0]-list_XYZ[i][1]-list_XYZ[i][2])

ans = 0

for i in range(8):
    l = list_ANS[i]
    l.sort()
    ans = max(ans, abs(sum(l[:m])), abs(sum(l[-m:])))

if m == 0:
    ans = 0
print(ans)

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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N; cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    int ans = 0;
    int th = H[0];
    int cont = 0;
    for (int i = 1; i < N; ++i) {
        if (H[i] <= th) {
            cont += 1;
            th = H[i];
        } else {
            ans = max(ans, cont);
            cont = 0;
            th = H[i];
        }
    }
    ans = max(ans, cont);

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

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

void program(vector<int> &A, vector<int> &B, int N, int Q, int K) {
    rep(i,Q) {
        B.at(A.at(i)) += 1;
    }
    rep(i,N) {
        if (K - Q + B.at(i) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    vector<int> B;
    B.resize(N);
    rep(i,Q) {
        cin >> A.at(i);
        A.at(i) -= 1;
    }
    
    program(A, B, N, Q, K);
    
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
typedef struct City{
  int pref;
  int index;
  int order;
  long year;
} City;

int compare(City *a, City *b);

City CITIES[100001];
int CITY_IN_PREF[100001];
City *CITY_PTR_MAP[100001];

int main(void) {
  int N,M;

  scanf("%d %d", &N, &M);
  for(int i=0;i<M;i++) {
    scanf("%d %ld", &(CITIES[i].pref),&(CITIES[i].year));
    CITIES[i].index = i;
  }
  qsort(CITIES, M, sizeof(City), (int (*)(const void *, const void *))compare);

  for(int i=0;i<N;i++) CITY_IN_PREF[i] = 0;
  for(int i=0;i<M;i++) {
    CITY_IN_PREF[CITIES[i].pref]++;
    CITIES[i].order = CITY_IN_PREF[CITIES[i].pref];
    CITY_PTR_MAP[CITIES[i].index] = &(CITIES[i]);
  }

  for(int i=0;i<M;i++) {
    City *c = CITY_PTR_MAP[i];
    printf("%06d%06d\n", c->pref, c->order);
  }

  return 0;
}

int compare(City *a, City *b) {
  if(a->year > b->year) {
    return 1;
  }
  return -1;
}

Measured memory_bytes: 4956
a,b = map(int, input().split())

if a>0:
    print('Positive')
elif a<0:
    if b<0 and (b-a+1)%2==0:
        print('Positive')
    elif b<0 and (b-a+1)%2==1:
        print('Negative')
    elif b>0:
        print('Zero')

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

int main() {
    int n,x;
    cin >> n >> x;
    int a[n];
    int sum;
    int min= 1100;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a,a+n);
    cout << ((x-sum)/a[0])+n<<endl;
}

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

int main(){
  char a[10];
  int stack[100];
  int head=0;

  while(scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      stack[head-2]=stack[head-2]+stack[head-1];
      head--;
    }else if(a[0]=='-'){
      stack[head-2]=stack[head-2]-stack[head-1];
      head--;
    }else if(a[0]=='*'){
      stack[head-2]=stack[head-2]*stack[head-1];
      head--;
    }else{
      stack[head]=atoi(a);
      head++;
    }
  }
  
  prinf("%d\n",stack[0]);
  
  return 0;
}
  

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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Node{
    ll index;
    ll state;
    Node(ll i, ll s){
        index = i;
        state = s;
    }
    Node(){}
    string ToString(){
        stringstream ss;
        ss << "Node " << index << ' ' << state;
        return ss.str();
    }
};

vector<vector<Node> > G[3];
const int N_MAX = 100010;

ll d[3][N_MAX];

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

    // input
    ll N, M;
    cin >> N >> M;
    G[0].resize(N);
    G[1].resize(N);
    G[2].resize(N);

    FOR(i, 0, M){
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        G[0][u].push_back(Node(v, 1));
        G[1][u].push_back(Node(v, 2));
        G[2][u].push_back(Node(v, 0));
    }

    ll S, T;
    cin >> S >> T;
    S--;
    T--;

    FOR(i, 0, 3){
        FOR(j, 0, N_MAX){
            d[i][j] = inf;
        }
    }

    queue<Node> que;
    que.push(Node(S, 0));
    d[0][S] = 0;

    // pn(G[0][S][0].ToString());
    // return 0;

    while(!que.empty()){
        auto cur = que.front();
        que.pop();
        // p(cur.ToString());

        for(Node to : G[cur.state][cur.index]){
            if(d[to.state][to.index]!=inf) continue;
            d[to.state][to.index] = d[cur.state][cur.index] + 1;
            // pn(d[to.state][to.index]);
            que.push(to);
        }
    }

    if(d[0][T]==inf){
        p(-1);
    }else{
        p(d[0][T]/3);
    }
    
    return 0;
}

Measured memory_bytes: 19072
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

void call(int n) {
	int i = 1;
	
	while (true) {
		int x = i;
		bool flag = true;
		if (x % 3 == 0) {
			cout << " " << i;
			flag = false;
		}
		while (flag) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
			if (!x) {
				break;
			}
		}
		if (++i > n) {
			break;
		}
	}
	cout << endl;
}

int main(int argc, char **argv){
	int n;
	cin >> n;
	call(n);
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
int n, k, cnt[maxn];
int arr[maxn];


int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        cnt[arr[i]]++;
    }

    vector<int>vals;
    for(int i=1;i<=n;i++) {
        if(cnt[i] > 0) {
            vals.pb(cnt[i]);
        }
    }

    if(vals.size() < k) {
        cout<<0;
        return 0;
    }

    sort(vals.begin(), vals.end());

    int br = vals.size();
    int sum = 0;
    for(int i=0;br>k;i++) {
        sum += vals[i];
        br--;
    }
    cout<<sum;

    return 0;
}


Measured memory_bytes: 2936
/*
NAME:
 ___   _      _   ___  
/ __| /_\    /_\ |   \ 
\__ \/ _ \  / _ \| |) |
|___/_/ \_\/_/ \_\___/ 

lang: 
  ___   _      _   
 / __)_| |_  _| |_ 
( (__(_   _)(_   _)
 \___) |_|    |_|  

*/
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
 
using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef long l;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<l> vl;
typedef vector<ll> vll;

const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
 
void solve(){
	int n;
	cin>>n;
	if(n>=30) cout<<"Yes";
	else cout<<"No";
}

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

	solve();

	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

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

const long long INF = 1LL << 60;
string s;
ll res = 0;
int main()
{
	cin >> s;
	vector<char> op = {'+','-'};
	for (int bit = 0; bit < (1 << 3); bit++) {
		ll sum = s[0]-'0';
		for (int i = 0; i < 3; i++) {
			if (bit & 1 << i) {
				sum -= s[i+1]-'0';
			}
			else {
				sum += s[i + 1]-'0';
			}
		}
		if (sum == 7) {
			cout << s[0];
			for (int j = 0;j < 3;j++) {
				cout << op[(bit >> j) & 1] << s[j + 1];
				if (j == 2) {
					cout << "=7" << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<ll>
#define vvi vector<vi>
#define llINF 1e18
#define ll long long
using namespace std;
bool vis[2222];
struct Edge{
  ll to,cost;
};
const ll MAX_V=2510;
vector<vector<Edge>> E(MAX_V);
vi dist(MAX_V,llINF);
bool bellman_ford(ll s){
  queue<ll>que;
  que.push(s);
  dist[s]=0;
  for(int i = 0;i < MAX_V;i++){
    ll n = que.size();
    bool used[MAX_V] = {};
    for(int j = 0;j < n;j++){
      ll now=que.front();
      que.pop();
      for(int k = 0;k < E[now].size();k++){
	Edge e = E[now][k];
	if(dist[e.to] > dist[now] + e.cost){
	  dist[e.to] = dist[now] + e.cost;
	  if(i == MAX_V-1)
	    if(vis[e.to])
	      return true;
	  if(used[e.to] == false)
	    que.push(e.to);
	  used[e.to]=true;
	}
      }
    }
  }
  return false;
}
vvi E2(MAX_V);
int main(){
  ll n,m,p;
  cin>>n>>m>>p;
  for(int i=0;i<m;i++){
    ll a,b,c;cin>>a>>b>>c;
    E[--a].push_back({--b,-(c-p)});
    E2[b].push_back(a);
  }
  queue<ll>que;
  que.push(n-1);
  vis[n-1]=true;
  while(que.size()){
    ll hoge=que.front();que.pop();
    for(auto a:E2[hoge])
      if(vis[a]==false){
	que.push(a);
	vis[a]=true;
      }
  }
  if(bellman_ford(0)==false){
    cout<<max(0LL,-dist[n-1])<<endl;
  }else cout<<-1<<endl;
}


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

using namespace std;

int main(){
  int N, C;
  cin >> N >> C;
  
  vector<vector<int>> r(C, vector<int>(1e5 + 1, 0));
  for(int i = 0; i < N; i++){
    int s, t, c;
    cin >> s >> t >> c;
    r[c - 1][s]++;
    r[c - 1][t]--;
  }
  
  for(int i = 1; i <= 1e5; i++){
    for(int c = 0; c < C; c++){
      r[c][i] += r[c][i - 1];
    }
  }
  
  for(int i = 1; i <= 1e5; i++){
    for(int c = 0; c < C; c++){
      if(r[c][i] == 1 && r[c][i - 1] == 0){
        r[c][i - 1]++;
      }
    }
  }
  
  int ch = 0;
  for(int i = 0; i <= 1e5; i++){
    int ri = 0;
    for(int c = 0; c < C; c++) ri += r[c][i];
    ch = max(ch, ri);
  }
  
  cout << ch << endl;
  
  return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n;
	int f=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x%3!=0&&x%5!=0&&x%2==0&&f==0)
		{
			cout<<"DENIED";
			f=1;
		}
	}
	if(f==0)
	{
		cout<<"APPROVED";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define inv(x) (ksm(x, P - 2))

using namespace std;

const int maxn = 4e6 + 5;
const int P = 1e9 + 7;

int n, k, f[2005][2005], fac[maxn], ifac[maxn];

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

inline int pls(int x, int y) { x += y; return x >= P ? x - P : x; }
inline int dec(int x, int y) { x -= y; return x < 0 ? x + P : x; }
inline int ksm(int x, int k, int rnt = 1) {
	for(int i = k; i; i >>= 1, x = 1ll * x * x % P) if(i & 1) rnt = 1ll * rnt * x % P;
	return rnt;
}

const int inv2 = inv(2);

inline int C(int n, int m) { return 1ll * fac[n] * ifac[n - m] % P * ifac[m] % P; }

int main() {
	n = read(); k = read(); fac[0] = 1; int N = n * k;
	if(k == 1) { puts("1"); return 0; }
	rep(i, 1, N) fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[N - 1] = inv(fac[N - 1]);
	dep(i, N - 2, 0) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
	f[0][0] = 1;
	rep(i, 1, n) rep(j, 0, i) {
		f[i][j] = pls(f[i][j], f[i - 1][j]);
		if(j) f[i][j] = pls(f[i][j], 1ll * f[i][j - 1] * (n - j + 1) % P * C(N - i - (k - 1) * (j - 1) - 1, k - 2) % P);
	}
	cout << f[n][n] << endl;
	return 0;
}
/*
1 1 2 2
1 2 1 2
1 2 2 1
2 1 1 2
2 1 2 1
2 2 1 1

0 1 0 2
0 0 1 2
0 0 2 1
0 0 1 2
0 0 2 1
0 2 0 1
 0 1 
0 2 0 1
0 0 1 2
0 1 0 2
*/

Measured memory_bytes: 47232
#include <iostream>
using namespace std;
int main(){
        int n;
        long long int z;
        long long int x=2;
        long long int y=1;
        cin >> n;
        if(n==0) {
                cout << 2 << endl;
        }
        else if(n==1) {
                cout << 1 << endl;
        }
        else{
                for(int i=1; i<n; i++) {
                        z=x+y;
                        x=y;
                        y=z;
                }
                cout << z << endl;
        }
}


Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2020/04/09
 *      Author: SkAaO
 */

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	string S, T;
	cin >> S >> T;

	sort(S.begin(), S.end());
	sort(T.begin(), T.end(), greater<char>());


	char is_can = 0;
	int min_size = min(S.size(), T.size());

	for(int i = 0; i < min_size; i++){
		if(S.at(i) > T.at(i)){
			is_can = 1;
			break;
		}if(S.at(i) < T.at(i)){
			is_can = 2;
			break;
		}
	}

	if(is_can == 0){
		if(S.size() >= T.size()){
			is_can = 1;
		}else{
			is_can = 2;
		}
	}

	if(is_can == 1){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

	return 0;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		//String t= sc.next();
		//int n = sc.nextInt();
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}*/

		if(s.equals("Sunny")) {
			System.out.println("Cloudy");
		}else if(s.equals("Cloudy")){
			System.out.println("Rainy");
		}else {
			System.out.println("Sunny");
		}

		//System.out.println(n*n*n);
	}
}




Measured memory_bytes: 23508
#!/usr/bin/env python3
class UnionFind:
    __slots__ = ['id','sz']

    def __init__(self, n):
        self.id = [-1] * n
        self.sz = n

    def root(self, x):
        if self.id[x] < 0:
            return x
        else:
            self.id[x] = self.root(self.id[x])
            return self.id[x]

    def find(self, x, y):
        return uf.root(x) == uf.root(y)

    def union(self, x, y):
        s1, s2 = self.root(x), self.root(y)
        if s1 != s2:
            if self.id[s1] <= self.id[s2]:
                self.id[s1] += self.id[s2]
                self.id[s2] = s1
            else:
                self.id[s2] += self.id[s1]
                self.id[s1] = s2
            self.sz-=1
            return True
        return False

output=[]
n,m = map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
uf = UnionFind(n)
ab=ab[::-1]
now=n*(n-1)//2
for a,b in ab:
    output.append(now)
    if uf.find(a-1,b-1):
        continue
    A, B =uf.id[uf.root(a-1)], uf.id[uf.root(b-1)]
    now-=A*B
    uf.union(a-1,b-1)
while output:
    print(output.pop())



    

Measured memory_bytes: 34820