akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int betweenNum = 0;
    static int onlyWhiteNum = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N - 1];
        int[] b = new int[N - 1];
        for (int i = 0; i < N - 1; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a, b));

        sc.close();
    }

    static String solve(int[] a, int[] b) {
        int N = a.length + 1;

        @SuppressWarnings("unchecked")
        List<Integer>[] adjLists = new List[N];
        for (int i = 0; i < adjLists.length; ++i) {
            adjLists[i] = new ArrayList<>();
        }

        for (int i = 0; i < a.length; ++i) {
            adjLists[a[i]].add(b[i]);
            adjLists[b[i]].add(a[i]);
        }

        Boolean[] colors = new Boolean[N];
        colors[0] = true;
        colors[N - 1] = false;

        Queue<Integer> queue = new LinkedList<>();
        queue.offer(0);
        queue.offer(N - 1);

        int blackCount = 0;
        int whiteCount = 0;
        while (!queue.isEmpty()) {
            int head = queue.poll();

            if (colors[head]) {
                ++blackCount;
            } else {
                ++whiteCount;
            }

            for (int adj : adjLists[head]) {
                if (colors[adj] == null) {
                    colors[adj] = colors[head];
                    queue.offer(adj);
                }
            }
        }

        return (blackCount > whiteCount) ? "Fennec" : "Snuke";
    }
}

Measured memory_bytes: 99660
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 1000000009;
int main() {
	int N, M;
	cin >> N >> M;
	int lim = max(N, 3);
	vector<int> fact(3 * lim + 1), inv(3 * lim + 1), factinv(3 * lim + 1), val(N + 1);
	fact[0] = 1; inv[1] = 1; factinv[0] = 1;
	for (int i = 1; i <= 3 * lim; ++i) fact[i] = (long long)(fact[i - 1]) * i % mod;
	for (int i = 2; i <= 3 * lim; ++i) inv[i] = (long long)(inv[mod % i]) * (mod - mod / i) % mod;
	for (int i = 1; i <= 3 * lim; ++i) factinv[i] = (long long)(factinv[i - 1]) * inv[i] % mod;
	val[0] = 1; int mul = 1;
	for (int i = 1; i <= N; ++i) {
		mul = (long long)(mul) * factinv[3] % mod;
		val[i] = (long long)(mul) * fact[3 * i] % mod * factinv[i] % mod;
	}
	vector<int> A(M), B(M), C(M);
	vector<int> cv;
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i] >> C[i];
		cv.push_back(A[i]);
		cv.push_back(B[i]);
	}
	sort(cv.begin(), cv.end());
	cv.erase(unique(cv.begin(), cv.end()), cv.end());
	int S = cv.size();
	vector<int> par(S);
	for (int i = 0; i < S; ++i) par[i] = i;
	function<int(int)> root = [&](int x) {
		if (x == par[x]) return x;
		return par[x] = root(par[x]);
	};
	for (int i = 0; i < M; ++i) {
		A[i] = find(cv.begin(), cv.end(), A[i]) - cv.begin();
		B[i] = find(cv.begin(), cv.end(), B[i]) - cv.begin();
	}
	vector<int> nA, nB;
	for (int i = 0; i < M; ++i) {
		if (C[i] == 0) {
			par[root(A[i])] = root(B[i]);
		}
		else {
			nA.push_back(A[i]);
			nB.push_back(B[i]);
		}
	}
	A = nA; B = nB;
	M = A.size();
	vector<int> inipar = par;
	int ans = 0;
	for (int i = 0; i < 1 << M; ++i) {
		par = inipar;
		int cnt = 0;
		for (int j = 0; j < M; ++j) {
			if ((i >> j) & 1) {
				par[root(A[j])] = root(B[j]);
				++cnt;
			}
		}
		vector<int> hist(S);
		for (int j = 0; j < S; ++j) {
			++hist[root(j)];
		}
		bool ok = true;
		int c1 = 3 * N - S, c2 = 0, c3 = 0;
		for (int j = 0; j < S; ++j) {
			if (hist[j] >= 4) {
				ok = false;
				break;
			}
			if (hist[j] == 3) ++c3;
			if (hist[j] == 2) ++c2;
			if (hist[j] == 1) ++c1;
		}
		if (!ok || c1 < c2) continue;
		int s1 = (c1 - c2) / 3, s2 = c2, s3 = c3;
		int sub = (long long)(fact[c1]) * factinv[c1 - c2] % mod * val[s1] % mod;
		if (cnt % 2 == 0) ans = (ans + sub) % mod;
		else ans = (ans - sub + mod) % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 41924
#include<bits/stdc++.h>
using namespace std;
const int mod=1e7+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string ss;
    cin>>ss;
    if(ss[2]==ss[3]&&ss[4]==ss[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
      ll n,k,ans=0;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        if(i-1<k)
            continue;
        ll pos=i-1;
        ll can=(i-k);
        ans+=(n/i)*can;
        ll rem=n%i;
        if(rem)
        {
            if(rem<k)
                continue;
            ans+=(rem-k+1);
            if(!k)
                ans--;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(){
  int r,c,table[101][101] = {0};
  int i,j;
  scanf("%d%d",&r,&c);

  //input                                                                                                                                                                                                   
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      scanf("%d",&table[i][j]);
    }
  }

  //?????????????¨????                                                                                                                                                                                            
  //?????????????¨????                                                                                                                                                                                            
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
    table[r][c] += table[i][c];
  }

  //output                                                                                                                                                                                                  
  for(i = 0;i <= r;i++){
    for(j = 0;j <= c;j++){
      printf("%d",table[i][j]);
      if(j != c)printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 652
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N, K;

  vector<ll> negLst;
  vector<ll> posLst;

  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp < 0)
      negLst.emplace_back(-tmp);
    else if(tmp == 0){
      K--;
    } else
      posLst.emplace_back(tmp);
  }

  if(K == 0){
    cout << 0 << endl;
    return 0;
  }

  reverse(negLst.begin(), negLst.end());

  ll min = 100000000000;
  if ((ll)posLst.size() >= K) min = posLst[K - 1];
  if ((ll)negLst.size() >= K && negLst[K - 1] < min) min = negLst[K - 1];

  // size_t sn = negLst.size();
  // size_t sp = posLst.size();

  for (ll i = 1; i <= K; i++) {
    if (i <= (ll)posLst.size() && K - i <= (ll)negLst.size() && 0 <= K - i - 1) {
      ll cand = 2 * posLst[i - 1] + negLst[K - i - 1];
      if (cand < min) min = cand;
    }
    if (i <= (ll)negLst.size() && K - i <= (ll)posLst.size() && 0 <= K - i - 1) {
      ll cand = 2 * negLst[i - 1] + posLst[K - i - 1];
      if (cand < min) min = cand;
    }
  }  // i

  cout << min << endl;

  return 0;
}


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

using namespace std;

int main() {
    int n, height, k = 0;
    cin >> n >> height;
    int h[n + 5];
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for(int i = 1; i <= n; i++) {
        if(h[i] >= height) k++;
    } 
    cout << k;
    return 0; 
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    int min_buy = A[0];
    int max_sell = 0;
    int ans = 1;
    for (int i = 1; i < N; ++i) {
        int sell = A[i] - min_buy;
        min_buy = min(min_buy, A[i]);
        if (sell == max_sell) {
            ans++;
        }
        max_sell = max(max_sell, sell);
    }

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

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;
    std::vector<int> a(n);

    a.push_back(0);
    for(int i = 1;i <= n;i++){
        std::cin>>a[i];
    }

    a.push_back(0);
    int s = 0;
    for(int i = 0; i < a.size(); i++){
        s += abs(a[i + 1] - a[i]);
    }
    std::vector<int> vec;
    for(int i = 1;i < a.size() - 1; i++){
        int k = s - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]);
        vec.push_back(k);
    }
    for(auto& x : vec){
        std::cout<<x<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 2552
#include <stdio.h>

#define N 100000
#define Q 50000

int main(){
  int i,j,S[N],T[Q],n,q,count=0,left,right,mid,key;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) scanf("%d",&T[i]);

  for(i=0; i<q; i++){
    left =0;
    right = n;
    while(left < right){
      key = T[i];
      mid = (left + right) / 2;
      if (S[mid] == key) {
	count++;
	break;
      }
      else if(key < S[mid])
	right = mid;
      else left = mid + 1;
    }
  }

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

  return 0;

}

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, b, c, cnt = 0;
	cin >> a >> b >> c;
	cnt += (a - b == 0 ? 1 : 0);
	cnt += (b - c == 0 ? 1 : 0);
	cnt += (c - a == 0 ? 1 : 0);
	cout << (cnt == 1 ? "Yes\n" : "No\n");
}


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

int main()
{
	int d;
	while (cin >> d)
	{
		int s = 0;
		for (int i = 1; i < 600 / d; i++)
		{
			s += d*d*d*i*i;
		}
		cout << s << endl;
	}
	return 0;

}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int H,W;
    cin >> H >> W;
    vector<string> C(H);
    REP(i,H)cin >> C[i];
    REP(i,H){
        cout << C[i] << "\n";
        cout << C[i] << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
    long long n; cin >> n;
    int ans = 1e9;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            ans = min(ans, max((int) to_string(i).size(), (int) to_string(n/i).size()));
        }
    }
    cout << ans;
}


Measured memory_bytes: 3660
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for(int i = 0; i <= N; i++) {
        string w = s + (i < N ? t.substr(i) : "");
        int n = w.size();
        if(w.substr(n-N) == t) {
            ans = min(ans, n);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int i,n,a,ans;
 
   scanf("%d",&n);
   for (ans=i=0;i<n;i++) {
      scanf("%d",&a);
      if (a%2==0 && (a%3==0 || a%5==0)) ans++;
      else if (a%2==1) ans++;
   }
   if (ans==n) puts("APPROVED");
   else        puts("DENIED");
   return 0;
}


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

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

using namespace std;

const int INF=1<<30;

template<class T>
class segment_tree{
	int n;
	vector<T> dat;

	void update_min(int l,int r,int a,int b,int u,T v){
		if(l<=a && b<=r){ dat[u]=min(dat[u],v); return; }
		int c=(a+b+1)/2;
		if(l<c && a<r) update_min(l,r,a,c,2*u  ,v);
		if(l<b && c<r) update_min(l,r,c,b,2*u+1,v);
	}

public:
	segment_tree(int N,T val){
		for(n=1;n<N;n*=2);
		dat.assign(2*n,val);
	}

	void update_min(int l,int r,T v){ update_min(l,r,0,n,1,v); }

	T query(int u){
		u+=n;
		T res=dat[u];
		for(u/=2;u>=1;u/=2) res=min(res,dat[u]);
		return res;
	}
};

int main(){
	int n,q; scanf("%d%d",&n,&q);
	vector<int> x(n),l(n),r(n),d(q);
	rep(i,n){
		int s,t; scanf("%d%d%d",&s,&t,&x[i]);
		l[i]=s-x[i];
		r[i]=t-x[i];
	}
	rep(i,q) scanf("%d",&d[i]);

	vector<int> X;
	X.insert(X.end(),l.begin(),l.end());
	X.insert(X.end(),r.begin(),r.end());
	X.insert(X.end(),d.begin(),d.end());
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());

	int m=X.size();
	rep(i,n){
		l[i]=lower_bound(X.begin(),X.end(),l[i])-X.begin();
		r[i]=lower_bound(X.begin(),X.end(),r[i])-X.begin();
	}
	rep(i,q){
		d[i]=lower_bound(X.begin(),X.end(),d[i])-X.begin();
	}

	segment_tree<int> S(m,INF);
	rep(i,n) S.update_min(l[i],r[i],x[i]);
	rep(i,q){
		int p=S.query(d[i]);
		printf("%d\n",p<INF?p:-1);
	}

	return 0;
}


Measured memory_bytes: 15188
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        set.add(s);
        s = s % 2 == 0 ? s / 2: s * 3 + 1;
        while (!set.contains(s)) {
            set.add(s);
            s = s % 2 == 0 ? s / 2: s * 3 + 1;
        }
        System.out.println(set.size()+1);

    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>

void main()
{
    char a[2];

    scanf("%s", a);

    if((a[0] >= 'A') && (a[0] <= 'Z')){
        printf("A\n");
    }else if((a[0] >= 'a') && (a[0] <= 'z')){
        printf("a\n");
    }else{

    }
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
const int NMAX = 2000;

vector<ll> fac(NMAX+1);
vector<ll> inv(NMAX+1);
vector<ll> fnv(NMAX+1);
vector<ll> power(NMAX+1);

void com_init(){
    
    fac[0]=1LL;
    fac[1]=1LL;
    inv[0]=0LL;
    inv[1]=1LL;
    fnv[0]=1LL;
    fnv[1]=1LL;
    
    for(int i=2; i<NMAX+1; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - (MOD/i) * inv[MOD%i] % MOD;
        fnv[i] = fnv[i-1] * inv[i] % MOD;
    }
    return;
}

ll combi(int n, int k){
    if(n<k)return 0LL;
    if(k<0 || n<0 )return 0LL;
    
    return fac[n] * (fnv[k]*fnv[n-k] % MOD) % MOD;
}


int main(){
    com_init();
    int s;
    cin >> s;
    
    ll ans = 0;
    
    for(int i=1; i<=s/3; i++){
        ans += combi(s-2*i-1, i-1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

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

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  char c;
  for (int i = 0; i < H; i++) {
    cout << '#';
    for (int j = 0; j < W; j++) {
      cin >> c;
      cout << c;
    }
    cout << '#' << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class RangeUpdateQuery:
    def __init__(self, n):
        self.n0 = 2**(n-1).bit_length()
        self.INF = float("inf")
        self.data = [self.INF]*(2*self.n0-1)

    def update(self, l,r,v):
        l += self.n0
        r += self.n0
        while l < r:
            if r&1:
                r -= 1
                self.data[r-1] = v
            if l&1:
                self.data[l-1] = v
                l += 1
            l >>=1
            r >>=1

    def query(self, i):
        i += self.n0-1
        res = self.INF
        while i+1:
            if self.data[i] < res:
                res = self.data[i]
            i = ~-i//2
        return res

n,q = map(int, input().split())
start = [None]*q
se = set()

road = []
for i in range(n):
    s,t,x = map(int, input().split())
    road.append([x, x-t, x-s])
for i in range(q):
    d = int(input())
    start[i] = -d

start = start[::-1]

RUQ = RangeUpdateQuery(q)
road.sort(reverse=True)
from bisect import bisect_left,bisect_right
for i, (x, s, t) in enumerate(road):
    l = bisect_right(start, s)
    r = bisect_right(start, t)
    #print(x, (s,t), l, r)
    RUQ.update(l, r, x)

ans = []
for i in range(q):
    x = RUQ.query(i)
    if x == float("inf"):
        x = -1
    ans.append(x)
ans = ans[::-1]
print(*ans, sep="\n")

Measured memory_bytes: 124892
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int N,M,cnt=0;
    cin>>N>>M;
    vector <ll> v(N);

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

    ll total = accumulate(v.begin(), v.end(), 0LL);

    for(int i=0;i<N;i++)
    {
        if(v[i]*4*M >= total)
        {
            cnt=cnt+1;
        }
    }

    if(cnt>=M)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

}


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

int main() {
  int A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A);
  vector<int> b(B);
  for(int &x: a) cin>>x;
  for(int &x: b) cin>>x;
  vector<int> aa=a;
  vector<int> bb=b;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int ans=a[0]+b[0];
  for(int i=0;i<M;i++){
    int x,y,c;
    cin>>x>>y>>c; x--; y--;
    ans=min(ans,aa[x]+bb[y]-c);
  }
  cout<<ans<<endl;//O(N)で計算する
}
  

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

int main() {
	int n;
  	cin>>n;
  
  	int t[110000],x[110000],y[110000];
  
  	t[0]=x[0]=y[0]=0;
  	for(int i=0;i<n;i++)cin>>t[i+1]>>x[i+1]>>y[i+1];
  
  	bool can = true;
  for(int i=0;i<n;i++){
  	int dt = t[i+1]-t[i];
    int dist =abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt<dist)can=false;
    if(dist %2!=dt%2)can=false;
  }
  
  if(can)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  

}

Measured memory_bytes: 4712
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	int sum = 0,tmp;

	for(int i = 0; i < 5; i++){
		scanf("%d",&tmp);

		if(tmp >= 40)sum += tmp;
		else sum += 40;
	}

	printf("%d\n",sum/5);

    return 0;
}

Measured memory_bytes: 2752
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] ans_array = new int[N + 1];
    int cnt = 0;
    for(int x = 1; x <= 100; x++){
      for(int y = 1; y <= x; y++){
        for(int z = 1; z <= y; z++){
          int tmp = (x * x) + (y * y) + (z * z) + (x * y) + (x * z) + (y * z);
          if(tmp <= N){
            if(x == y && y == z){
              ans_array[tmp]++;
            } else if(x == y || y == z || x == z){
              ans_array[tmp] += 3;
            } else {
              ans_array[tmp] += 6;
            }
          } else {
            break;
          }
        }
      }

    }
    for(int i = 1; i <= N; i++){
      System.out.println(ans_array[i]);
    }
  }
}


Measured memory_bytes: 39016
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi v;
int n;
int sum;

void _add(int k, int i){
    if(i < 0) return;
    int over = (v[i]+k) / 10;
    int pre = v[i];
    v[i] = (v[i]+k) % 10;
    sum += v[i] - pre;

    if(over) _add(over, i-1);
}

void _mul(int k, int i){
    if(i < 0) return;
    int over = v[i]*k / 10;
    int pre = v[i];
    v[i] = (v[i]*k) % 10;
    sum += v[i] - pre;
    _mul(k, i-1);

    if(over) _add(over, i-1);
}

void add(int k){ _add(k, n-1); } 
void mul(int k){ _mul(k, n-1); } 

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    string s; cin >> s;
    v.push_back(0);
    rep(i,s.size()) v.push_back(s[i]-'0');
    n = v.size();

    mul(9);
    sum = 0;
    rep(i,n) sum += v[i];
    rep(i,n){
        if(sum <= 9*i){
            cout << i << endl;
            break;
        }
        add(9);
    }
    return 0;
}


Measured memory_bytes: 26644
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int a[1100][1100] = {};

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		a[x1][y1]++;
		a[x1][y2]--;
		a[x2][y1]--;
		a[x2][y2]++;
	}
	
	for(int i = 0; i <= 1000; i++){
		for(int j = 1; j <= 1000; j++){
			a[i][j] += a[i][j - 1];
		}
	}
	
	for(int i = 0; i <= 1000; i++){
		for(int j = 1; j <= 1000; j++){
			a[j][i] += a[j - 1][i];
		}
	}
	
	int ans = 0;
	for(int i = 0; i <= 1000; i++){
		for(int j = 0; j <= 1000; j++){
			ans = max(ans, a[i][j]);
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7420
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
long long n,k,h=1;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
    	if(h<k)h+=h;
    	else h+=k;
    }
    cout<<h<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
integers = list(map(int, input().split()))

max_moves = 0
moves = 0
for i in range(n-1):
    if integers[i] >= integers[i+1]:
        moves += 1
    else:
        moves = 0
    if max_moves < moves:
        max_moves = moves
print(max_moves)

Measured memory_bytes: 14224
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())
K = int(input())
a = S[K-1]
ans = []
for k in S:
    if k != a:
        ans.append("*")
    else:
        ans.append(k)

answer = "".join(ans)
print(answer)

Measured memory_bytes: 3060
//by ciwomuli
//AK JSOI 2019
//I love wyt
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <sstream>
#define LL long long
using namespace std;
template <typename T>
inline void read(T &t)
{
    int f = 0, c = getchar();
    t = 0;
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        t = t * 10 + c - 48, c = getchar();
    if (f)
        t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}

int main(){
    int n;
    read(n);
    cout << n * n;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
S = input()
binary = []
one = []
zero = []
tmp_z = 0
tmp_o = 0
zeroflag = (S[0]=="0")
saigozero = (S[-1]=="0")
for i,s in enumerate(S):
    if s=="0":
        tmp_z += 1
        if not zeroflag:
            one.append(tmp_o)
            tmp_o=0
            zeroflag=True
    if s =="1":
        tmp_o+=1
        if zeroflag:
            zero.append(tmp_z)
            tmp_z=0
            zeroflag=False
if tmp_z!=0:
    zero.append(tmp_z)
if tmp_o!=0:
    one.append(tmp_o)

zeroflag = (S[0]=="0")
saigozero = (S[-1]=="0")

if zeroflag:
    one = [1] + one
if saigozero:
    one.append(1)
    
one_sum = [0]*(len(one)+1)
zero_sum = [0]*(len(zero)+1)
for i in range(len(one)):
    one_sum[i+1] = one_sum[i]+one[i]
for i in range(len(zero)):
    zero_sum[i+1]=zero_sum[i]+zero[i]
    


if len(zero)<=k:
    print(len(S))
else:
    ans = 0
    
    for i in range(len(zero)-k + 1):
        if zeroflag and i==0:
#             tmp = sum(zero[i:i+k])+sum(one[i:i+k+1]) -1
            tmp = zero_sum[i+k]-zero_sum[i]+one_sum[i+k+1]-one_sum[i]-1
        elif saigozero and i==len(zero)-k:
            tmp = zero_sum[i+k]-zero_sum[i]+one_sum[i+k+1]-one_sum[i]-1
        else:
            tmp = zero_sum[i+k]-zero_sum[i]+one_sum[i+k+1]-one_sum[i]
        ans = max(ans,tmp)
    print(ans)


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

#define INF (1<<29)

int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  
  int ans = INF;
  
  for(int H = 1 ; H <= n ; H++){
    for(int W = n ; H*W >= n ; W--){
      int cnt = 1;
      int xa, xb, xc, xd, ya, yb, yc, yd;
      for(int i = 1 ; i <= H ; i++){
	for(int j = 1 ; j <= W ; j++){
	  if(cnt == a){
	    ya = i, xa = j;
	  }
	  else if(cnt == b){
	    yb = i, xb = j;
	  }
	  else if(cnt == c){
	    yc = i, xc = j;
	  }
	  else if(cnt == d){
	    yd = i, xd = j;
	  }
	  cnt++;
	}
      }
      int res = abs(xa-xb)+abs(ya-yb)+abs(xc-xd)+abs(yc-yd);
      ans = min(ans, res);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int L,R,A,B,C,D;
    cin >> A >> B >> C >> D;
  L=A+B;
  R=C+D;
  if (L>R) cout << "Left" <<endl;
    else if (L==R) cout << "Balanced" <<endl;
  else cout << "Right" << endl;
}      

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
///////////////////////
class f
{
public:
	int x,y;
	f(int X,int Y)
	{
		x=X;
		y=Y;
	}
};
int main()
{
	int H,W;
	int x2,y2;
	int count=0;
	char keep[10]={};
	char str[102][102]={};
	int flag[102][102]={};
	int sum[2][10]={
						{1,0,-1,0},
						{0,1,0,-1}
					};
	stack<f> st;
	while(1)
	{
		count=0;
		s_2(H,W);
		if(H==0 && W==0)break;
		rep_to(0,i,H+2)rep_to(0,j,W+2)flag[j][i]=0;
		rep_to(1,i,H+1)rep_to(1,j,W+1)s_1(str[j][i]);
		
		rep_to(1,i,H+1)
		{
			rep_to(1,j,W+1)
			{
				if(flag[j][i]==1)continue;
				count++;
				keep[0]=str[j][i];
				st.push(f(i,j));
				flag[j][i]=1;
				while(!st.empty())
				{
					x2=st.top().x;
					y2=st.top().y;
					st.pop();
					rep(k,4)
					{
						if(str[y2+sum[0][k]][x2+sum[1][k]]==keep[0] && flag[y2+sum[0][k]][x2+sum[1][k]]!=1)
						{
							st.push(f(x2+sum[1][k],y2+sum[0][k]));
							flag[y2+sum[0][k]][x2+sum[1][k]]=1;
						}
					}
				}
			}
		}
		debug(count);
	}
	
	return 0;
}

Measured memory_bytes: 1312
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end
n = inp[0]
a = inp
b = inp
ind = 0
turn = 0
while true
  i = ind % n
  r = (i+1)%n
  l = (i-1)%n
  sum = b[l]+b[r]
  if(a[i] != b[i] and b[i] > sum)
    o = b[i]
    b[i] %= sum
    if(b[i] < a[i])
      if((a[i]-b[i])%sum != 0)
        p -1
        exit
      else
        b[i] = a[i]
      end
    end
    turn += (o-b[i])/sum
    ind -= 1
  else
    break if(ind > 2000000)
    ind += 1
  end
end
if(a.join != b.join)
  p -1
  exit
end
p turn

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  if (s[0] == '1') ++cnt;
  if (s[1] == '1') ++cnt;
  if (s[2] == '1') ++cnt;
  cout << cnt << endl;
  return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
    map<char, int> mci;
    mci['R'] = 0;
    mci['G'] = 1;
    mci['B'] = 2;
    int n;
    string s;
    cin >> n >> s;
    vector<int> vi(3, 0);
    REP(i, n)
    {
        vi[mci[s[i]]]++;
    }
    ll ans = (ll)vi[0] * (ll)vi[1] * (ll)vi[2];
    REP(i, n - 2)
    FOR(j, i + 1, n)
    {
        int idx = j * 2 - i;
        if (idx >= n)
            break;
        if (mci[s[i]] != mci[s[j]] && mci[s[i]] != mci[s[idx]] && mci[s[idx]] != mci[s[j]])
            ans--; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
 
#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  int N;
  cin >> N;
 
  LL T = 0, px = 0, py = 0;
  REP(i,N){
	LL t, x, y;
	cin >> t >> x >> y;
	LL dt = t - T;
	LL dx = abs(px - x) + abs(py - y);
	if(dx > dt || (dt - dx)%2 == 1){
	  cout << "No" << endl;
	  return 0;
	}
 
	T = t;
	px = x;
	py = y;
  }
  cout << "Yes" << endl;
 
  return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10 , NODE = 4e5 + 10 , M = 26;
int sz[NODE] , ed[NODE] , ne[NODE][M] , _ , rt;
int n , Q , cnt[N][M][M] , big[N];
string s[N] , order;

void ins(int c,string&s,int p) {
  sz[c] ++;
  if(p == sz(s)) {
    ed[c] ++;
    return;
  }
  int t=s[p]-'a';
  if(ne[c][t]==0)
    ne[c][t]=++_;
  ins(ne[c][t],s,p+1);
}

void ask(int c,string&s,int p,int id) {
  big[id] += ed[c];
  if(p == sz(s)) {
    return;
  }
  int t=s[p]-'a';
  rep(i,0,M) if(i!=t) cnt[id][t][i]+=sz[ne[c][i]];
  ask(ne[c][t],s,p+1,id);
}

int main() {
  cin >> n;
  rt = ++_;
  rep(i,0,n) {
    cin >> s[i];
    ins(rt , s[i] , 0);
  }
  rep(i,0,n) ask(rt , s[i] , 0 , i);
  cin >> Q;
  rep(i,0,Q) {
    int K;
    cin >> K >> order;
    --K;
    int ans = big[K];
    rep(i,0,M) rep(j,0,i) ans += cnt[K][order[i]-'a'][order[j]-'a'];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 284544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		n = sc.nextInt();
		m = sc.nextInt();
		char[][] a = new char[n][n];
		char[][] b = new char[m][m];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < m; i++) {
			b[i] = sc.next().toCharArray();
		}

		boolean exist = false;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < n; x++) {
				if(y + m - 1 >= n || x + m - 1 >= n) continue;

				boolean match = true;
				for (int y2 = 0; y2 < m; y2++) {
					for (int x2 = 0; x2 < m; x2++) {
						if(a[y + y2][x + x2] != b[y2][x2]) match = false;
					}
				}
				if(match) exist = true;
			}
		}

		System.out.println(exist ? "Yes" : "No");
	}
}

Measured memory_bytes: 23892
#include <stdio.h>

#define S 0
#define L 1
#define F 2

int w, h;
int map[50][50];

void dfs(int, int);

int main(){
    int i, j, num_of_land;

    while(1){
        scanf("%d%d", &w, &h);
        if(w == 0 && h == 0){
            break;
        }

        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                scanf("%d", &map[i][j]);
            }
        }

        num_of_land = 0;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(map[i][j] == L){
                    num_of_land++;
                    dfs(i, j);
                }
            }
        }

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

    }

    return 0;
}

void dfs(int y, int x){
    if(map[y][x] == L && x >= 0 && y >= 0 && y < h && x < w){
        map[y][x] = F;
        dfs(y-1, x-1);
        dfs(y, x-1);
        dfs(y+1, x-1);
        dfs(y-1, x);
        dfs(y+1, x);
        dfs(y-1, x+1);
        dfs(y, x+1);
        dfs(y+1, x+1);
    }
}

Measured memory_bytes: 752
from collections import defaultdict

nv, ne, r = map(int, input().split())

in_edges = defaultdict(set)
out_edges = defaultdict(set)
while ne:
    s, t, w = map(int, input().split())
    in_edges[t].add((w, s))
    out_edges[s].add((w, t))
    ne -= 1


def chu_liu_edmond(vertices, cycle_cost):
    global in_edges, out_edges, nv, r

    total_cost = cycle_cost
    prev_v = defaultdict(int)
    next_vs = defaultdict(set)

    for t in vertices:
        if t == r:
            continue
        min_in_w, min_in_s = min(in_edges[t])
        total_cost += min_in_w
        prev_v[t] = min_in_s
        next_vs[min_in_s].add(t)

    visited = {r}
    queue = set(next_vs[r])
    while queue:
        t = queue.pop()
        visited.add(t)
        queue.update(next_vs[t])

    cycles = []
    for i in vertices:
        if i in visited:
            continue

        cycle_vertices = set()
        while i not in visited:
            visited.add(i)
            cycle_vertices.add(i)
            i = prev_v[i]

        # Branched single path from cycle
        if i not in cycle_vertices:
            continue

        # Current cycle_vertices are not necessarily cycle only (may contain branch)
        cycle_vertices, j = {i}, prev_v[i]
        while j != i:
            cycle_vertices.add(j)
            j = prev_v[j]

        cycles.append(cycle_vertices)

    if not cycles:
        return total_cost

    for cycle in cycles:
        vertices.difference_update(cycle)
        vertices.add(nv)

        for v in cycle:
            prev_e_cost = min(in_edges[v])[0]
            cycle_cost += prev_e_cost
            for w, t in out_edges[v]:
                if t in vertices:
                    out_edges[nv].add((w, t))
                    in_edges[t].remove((w, v))
                    in_edges[t].add((w, nv))
            for w, s in in_edges[v]:
                if s in vertices:
                    new_w = w - prev_e_cost
                    in_edges[nv].add((new_w, s))
                    out_edges[s].remove((w, v))
                    out_edges[s].add((new_w, nv))
            del in_edges[v]
            del out_edges[v]

        nv += 1

    return chu_liu_edmond(vertices, cycle_cost)


print(chu_liu_edmond(set(range(nv)), 0))

Measured memory_bytes: 8760
#include <bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main(){
    int a,b,c;cin>>a>>b>>c;
    if(c-a-b<0){cout<<"No"<<endl;return 0;}
    // cout<<c-a-b<<" "<<a<<" "<<b<<endl;
    if(4*(a*b)<(c-a-b)*(c-a-b))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
d = int(input())
c = list(map(int, input().split()))
score = []
for i in range(d):
    score.append(list(map(int, input().split())))
last_day = [0 for i in range(26)]
k = 0
for i in range(d):
    ans = 0
    max_score = -10**9
    for j in range(1, 27):
        s = score[i][j-1]
        for k in range(1,27):
            if j == k:
                continue
            else:
                s -= c[k-1] * (d - i+1 - last_day[k-1])
        if s > max_score:
            ans = j
            max_score = s
    last_day[ans-1] = i+1
    print(ans)

Measured memory_bytes: 68616
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    string s;
    cin >> s;
    string a;
    for(int i = 0; i < s.size(); i+=2){
        a+=s.at(i);
    }
    cout << a << endl;
}

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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int n, m, k;
bool used[1000001];

int main() {
    cin >> n >> m >> k;

    if (k % n == 0 or k % m == 0) {
        cout << "Yes" << endl;
        return 0;
    }

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (j * n + (m - j) * i - j * i > n * m) break;
            used[j * n + (m - j) * i - j * i] = true;
        }
    }
    for (int i = 0; i <= m; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (j * m + (n - j) * i - j * i > n * m) break;
            used[j * m + (n - j) * i - j * i] = true;
        }
    }

    used[0] = used[m * n] = true;

    if (used[k]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1280
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [0] * (N + 1)
dp[0] = 3

ans = 1
for a in A:
    ans *= dp[a]
    ans %= MOD
    dp[a] -= 1
    dp[a + 1] += 1

print(ans)

Measured memory_bytes: 14060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <fstream>
#include <cmath>

using namespace std;

//#define DEB
#ifdef DEB
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif

#define EPS (1e-9)
#define EQ(a,b) (abs((a)-(b))<EPS)

//  é^[É é}XÚÉ¢ém¦
double dp[2][101][101];
char field[1001];
int n,t,l,b;

double dfs(int yasu,int tern,int pl){
	if(!EQ(dp[yasu][tern][pl],-1))
		return dp[yasu][tern][pl];
	else if(pl==n)
		return 1;
	if(tern==t)
		return 0;
	double res=0;
	if(field[pl]=='L'&&yasu==0)
		return dfs(1,tern+1,pl);
	else if(field[pl]=='B')
		return dfs(0,tern,0);
	else{
		for(int i=1; i <= 6; i++){
			if(i+pl<=n)
				res+=dfs(0,tern+1,pl+i)/6.0;
			else
				res+=dfs(0,tern+1,n-(i+pl-n))/6.0;
		}
	}
	return dp[yasu][tern][pl]=res;
}

int main(){

	while(cin>>n>>t>>l>>b&&!(n==0&&t==0&&l==0&&b==0)){
		memset(field,0,sizeof(field));
		for(int i = 0; i < 101; i++)
			for(int j = 0; j < 101; j++)
				dp[0][i][j]=dp[1][i][j]=-1;
		for(int i = 0; i < l; i++){
			int a;
			cin>>a;
			field[a]='L';
		}
		for(int i = 0; i < b; i++){
			int a;
			cin>>a;
			field[a]='B';
		}
		double res=dfs(0,0,0);
		printf("%.10f\n",res);
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100000
int n,m;
struct node
{
	int num,cl;
}box[MAXN+5];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9'){if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read(),m=read();
	box[1].cl=1;
	for(int i=1;i<=n;i++)
		box[i].num=1;
	for(int i=1;i<=m;i++)
	{
		int f=read();
		int t=read();
		if(box[f].cl==1)
		{
			if(box[f].num>1)
			{
				box[f].num--;
				box[t].cl=1;
				box[t].num++;
			}
			else 
			{
				box[f].num--;
				box[f].cl=0;
				box[t].cl=1;
				box[t].num++;
			}
		}
		else 
		{
			box[f].num--;
			box[t].num++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	if(box[i].cl)
	{
		ans++;
	}
	printf("%d",ans);
}
//

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){int N;cin>>N;vector<string>a(N);for(int i=0;i<N;i++)cin>>a.at(i);
           sort(a.begin(),a.end());int x=N;
           for(int i=1;i<N;i++)if(a.at(i)==a.at(i-1))x--;
           cout<<x<<endl;}


Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
typedef long long int lli;
int llint_compare(const void*a,const void*b){return *(lli*)a-*(lli*)b;}
int main(void)
{
    lli n,k;
    static lli a[100000],b[100000],su[100000]={0};
    lli cnt=0;

    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a[i],&b[i]);
        su[a[i]-1]+=b[i];
    }
    qsort(a,n,sizeof(lli),llint_compare);
    for(lli i=0;i<n;i++){
        if(a[i-1]==a[i]){
            continue;
        }
        cnt+=su[a[i]-1];
        if(cnt>=k){
            printf("%lld\n",a[i]);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3324
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> N >> W >> H;
	vector<int>x(W + 1);
	vector<int>y(H + 1);
	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		x[max(0, a - c)]++;
		x[min((int)W, a + c)]--;
		y[min((int)H, b + c)]--;
		y[max(0, b - c)]++;
	}
	bool xflag = true;
	bool yflag = true;
	for (int i = 1; i < W; i++) {
		x[i] += x[i - 1];
		if (!x[i])xflag = false;
	}
	for (int i = 1; i < H; i++) {
		y[i] += y[i - 1];
		if (!y[i])yflag = false;
	}
	if (!x[0])xflag = false;
	if (!y[0])yflag = false;
	//for (int i = 0; i <W; i++) {
	//	cout << i << " " << x[i] << endl;
	//}
	//for (int i = 0; i <H; i++) {
	//	cout << i << " " << y[i] << endl;
	//}
	if (!xflag&&!yflag) cout << "No\n";
	else cout << "Yes\n";
	return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(abs(a - ((a + b) / 2)) == abs(b - ((a + b) / 2))){
        cout << (a + b) / 2;
    }else{
        cout << "IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 256