akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
D - 連結 / Connectivity
https://atcoder.jp/contests/abc049/tasks/arc065_b

"""
import sys


class DisjointSet(object):
    def __init__(self, n):
        self.rank = [0] * n
        self.p = list(range(n))
        self.size = [1] * n

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.size[self.p[x]] += self.size[self.p[y]]
            self.p[y] = self.findSet(x)
        else:
            self.size[self.p[y]] += self.size[self.p[x]]
            self.p[x] = self.findSet(y)
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


from collections import Counter

def solve(N, K, L, PQ, RS):
    r_d = DisjointSet(N+1)
    for p, q in PQ:
        r_d.unite(p, q)
    t_d = DisjointSet(N+1)
    for r, s in RS:
        t_d.unite(r, s)
    for i in range(1, N+1):
        r_d.findSet(i)
        t_d.findSet(i)

    connectivity = Counter()
    for i in range(1, N+1):
        connectivity[(r_d.p[i], t_d.p[i])] += 1
    return [connectivity[(r_d.p[i], t_d.p[i])] for i in range(1, N + 1)]


def main(args):
    N, K, L = map(int, input().split())
    PQ = [[int(i) for i in input().split()] for _ in range(K)]
    RS = [[int(i) for i in input().split()] for _ in range(L)]
    ans = solve(N, K, L, PQ, RS)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 141892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll ans = 0;
    rep(i, n){
        ans += min(b[i], a[i]);
        b[i] -= min(b[i], a[i]);
        ans += min(b[i], a[i+1]);
        a[i+1] -= min(b[i], a[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
s=str(input())
a=int(s[2:])
b=int(s[:2])
if 1<=a<=12 and 1<=b<=12:
        print('AMBIGUOUS')
elif  1<=a<=12:
        print('YYMM')
elif 1<=b<=12:
        print('MMYY')
else:
        print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int SZ = 60;
ll myx[SZ];
ll calc(ll a){
	if(a==0LL) return 0LL;
	if(a==1LL) return 1LL;
	if(a==2LL) return 3LL;
	ll ans = 0LL;
	for(ll i=SZ-1;i>=0LL;i--){
		ll tmp = (1LL<<i);
		if(a>=tmp){
			ans ^= (((a-tmp)%2ll==0LL ? tmp : 0LL));
			if(i==1LL) ans^=1LL;
			ans^=calc(a-tmp);
			break;
		}
	}
	return ans;
}
int main(void){
	ll n,m; scanf("%lld %lld",&n,&m);
	myx[0]=1ll,myx[1]=3ll;
	for(ll i=2;i<SZ;i++) myx[i]=(1LL<<i);
	if(n==0LL){
		printf("%lld",m);
		return 0;
	}
	n--;
	ll ans = 0;
	ans^=calc(m);
	ans^=calc(n);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,A,B,t;
    scanf("%d %d %d",&N,&A,&B);
    t=N*A;
    if(t>B){
        printf("%d\n",B);
    }
    else{
        printf("%d\n",t);
    }
    return 0;
}


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

int main()
{
	int n, k;
	cin >> n >> k;
	int now[101] = {};
	int d;
	for (int i = 0; i < k; ++i)
	{
		cin >> d;
		int in;
		for (int j = 0; j < d; ++j)
		{
			cin >> in;
			now[in] = 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans += (now[i] == 0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
s = input()
t = int(input())
e1 = eval(s)

e2 = int(s[0])
i = 1
while i < len(s):
    x = int(s[i+1])
    if s[i] == '+':
        e2 += x
    else:
        e2 *= x
    i += 2

if e1 == t and e2 == t:
    print("U")
elif e1 == t:
    print("M")
elif e2 == t:
    print("L")
else:
    print("I")

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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;
}

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

/*
int num = 200010;
vector<ll> fact(num), ifact(num);
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i < num; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
}
for (int i = 0; i < num; i++) {
    ifact[i] = modpow(ifact[i], mod-2);
    ifact[i] %= mod;
}
*/

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    rep(i, N-1) {
        ll cnt = 0;
        REP(j, i, N) {
            if (A[i] > A[j]) cnt++;
        }
        ans += cnt * K;
        ans %= mod;
    }
    rep(i, N) {
        ll cnt = 0;
        rep(j, N) if (A[i] > A[j]) cnt++;
        ll tmp = (K % mod * (K-1) / 2) % mod;
        ans += cnt * tmp;
        ans %= mod;
    }
    cout << ans << endl;
}

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

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

  for(int i = 0; i < 3; i++) {
    if(x.at(i) == x.at(i+1)) {
      cout << "Bad" << endl;
      break;
    }
    else if(i == 2) cout << "Good" << endl;
  }

}

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

int main() {
  typedef long long ll;
  ll n;
  cin >> n;

  if (n % 2) {
    cout << 0 << endl;
  } else {
    ll ans = 0;
    while (n) {
      ans += n / 10;
      n /= 5;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  map<ll, ll, greater<ll>> mp;
  rep(i, n) {
    ll v;
    cin >> v;
    mp[v]++;
  }
  vector<vl> c(51, vl(51, 0));
  c[0][0] = 1;
  rep2(i, 1, 51) rep(j, i + 1) {
    if(j == 0)
      c[i][j] = 1;
    else
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  ll x = a;
  double ave = 0;
  for(auto v : mp) {
    ll k = v.first;
    ll m = v.second;
    if(m < x) {
      ave += k * m;
      x -= m;
    } else if(x == a) {
      printf("%.6f\n", double(k));
      ll ans = 0;
      rep2(i, a, b + 1) ans += c[m][i];
      cout << ans << endl;
      return 0;
    } else {
      ave += k * x;
      ave /= double(a);
      printf("%.6f\n", ave);
      cout << c[m][x] << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3784
object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val S = sc.next
    sc.close()

    val remain = 15 - S.length
    val win = S.count(_ == 'o')

    remain + win match {
      case c if c >= 8 => println("YES")
      case _           => println("NO")
    }
  }
}

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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()

void solve(){
  string s,t;
  cin>>s>>t;
  int cnt=t.size();
  for(int i=0;i<=s.size()-t.size();i++){
  	int diff=0;
  	for(int j=0;j<t.size();j++){
  		if(t[j] != s[j+i])
  			diff++;
	  }
	  cnt = min(cnt,diff);
  }
  cout<<cnt<<endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}

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

int main() {
    int n, x[100], y[100];
    cin >> n;
    rep(i,n) cin >> x[i];
    rep(i,n) cin >> y[i];

    double d[4] = {};

    for (int p = 1; p <= 3; p++) {
        rep(i,n) {
            d[p] += pow(abs(x[i] - y[i]), p);
        }
        d[p] = pow(d[p], 1.0/p);
    }

    rep(i,n) {
        d[0] = (d[0] < abs(x[i] - y[i]) ? abs(x[i] - y[i]) : d[0]);
    }

    printf("%lf\n%lf\n%lf\n%lf\n", d[1], d[2], d[3], d[0]);
}


Measured memory_bytes: 3356
while gets
  x1,y1,x2,y2,xq,yq=$_.split(",").map(&:to_f)
  a=y2-y1
  b=x1-x2
  c=y1*x2-x1*y2
  k=2*(a*xq+b*yq+c)/(a**2+b**2)
  xr=(xq-a*k).round(6)
  yr=(yq-b*k).round(6)
  puts "#{xr} #{yr}"
end

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

int main() {
  int A , B;
  cin>> A >> B;
  int C = A+B;
  int D = A-B;
  int E = A*B;
  
   if( C>=D && C>=E){
     cout << C << endl;
   }
   else if(D>=C && D>=E){
     cout << D << endl;
   }
     else {
       cout << E << endl;
     }
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define PI acos(-1)
#define eps 1e-10
#define mem(x) memset(x,0,sizeof(x))
#define _for(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define __for(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

const int INF=0x3f3f3f3f;
const int MAX=1e5+5;
const int MOD=1e9+7;

string s;
int a[200];
int main(){
    std::ios::sync_with_stdio(false);
    cin>>s;
    int len=s.size();
    
    if(len==26){
    	int pos=0;
    	__for(i,len-1,0){
    		char t=s[i];
    		char ans=t;
    		_for(j,i,len-1){
    			char tt=s[j];
    			if(tt>t){
    				if(ans==t) ans=tt;
    				ans=min(tt,ans);
    			}
    		}
    		if(ans!=s[i]){
    			_for(k,0,i-1){
    				cout<<s[k];
    			}
    			cout<<ans;
    			return 0;
    		}
    	}
    	cout<<-1<<endl;
    	
    }
    else{
    	int pos=0;
    	_for(i,0,len-1){
	    	a[s[i]]++;
	    }
    	_for(i,'a','z'){
    		if(a[i]==0){
    			pos=i;
    			break;
    		}
    	}
    	cout<<s<<char(pos)<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
/*  CF_CC
        4U7H0R:_C4551DY */

#include <bits/stdc++.h>

using namespace std;

#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(im) for(int i=0;i<a;i++)
#define lb lower_bound
#define ll long long
#define pii pair<ll,ll>
#define vec vector<int>
#define fir first
#define sec second
const int mxi=1e7+10;
const int mod=1e9+7;

ll a,b,c;set <int> s;
int main()
{
    IC
    cin >> a;
    f(im){
    cin >> b;
    s.insert(b);
    c++;
    }
    if(s.size()==c)
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1e9,MOD=1e9+7;

int main(){
	int n,m,k; cin>>n>>m>>k;
	string ans="No";
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(n*j+m*i-2*i*j==k) ans="Yes";
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

string s;
unordered_map<char, int> um;

signed main() {
    cin >> s;
    for (auto &c:s) um[c]++;
    bool f = false;
    for (auto &it:um) if (it.second != 2) f = true;
    cout << (f ? "No" : "Yes") << endl;
}
// 配列

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 1e14 ;
const ll MOD = 1000000007;

const int N = 404;
int ar[N] , ps[N] , dp[N][N];
int n;

int sum(int l , int r){
    return ps[r] - (l ? ps[l - 1] : 0);
}

signed main(){

#ifndef ONLINE_JUDGE
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);
    
    cin >> n;
    fo(i , n) cin >> ar[i];
    fo(i , n){
       if(i) ps[i] += ps[i - 1];
       ps[i] += ar[i];
    }
    //mcm style dp
    for(int len = 1 ; len <= n ; len++){
        for(int l = 0 , r = l + len - 1 ; r < n ; l++ , r++){
            if(l == r){
                dp[l][r] = 0;
                continue;
            }
            dp[l][r] = oo;
            for(int k = l ; k < r ; k++)
                dp[l][r] = min(dp[l][r] , dp[l][k] + dp[k + 1][r] + sum(l , r)); 
        }
    }

    cout << dp[0][n - 1] << '\n';

    return 0;

}



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

typedef long long int ll;

using namespace std;

int main(void){

    int N;
    ll total = 0;

    cin >> N;

    vector<int> A(N);
    vector<int> X(N);

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

    for(int i = 0;i < N;i++){
        total += A[i];
    }

    X[0] = total;

    for(int i = 1;i < N;i += 2){
        X[0] -= 2*A[i];
    }

    for(int i = 1;i < N;i++){
        X[i] = 2*A[i-1] - X[i-1];
    }

    for(int i = 0;i < N;i++){
        cout << X[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,count=0;
    cin >> n;
    int num[n];
    rep(i,n) cin >> num[i];
    rep(i,n){
        if(i%2==0 && num[i]%2==1){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#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(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9+3;
const ll INF = 1e18+3;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int MAX_V = 1e5;
vector<int> es[MAX_V];
int ans = 0;
int N, K;

int dfs(int now, int pre){
    int size = 1;
    for(auto &e: es[now]){
        if(e == pre) continue;
        int s = dfs(e, now);
        if(s > K) ans++;
        elif(s == K && now != 0) ans++;
        else chmax(size, s+1);
    }
    return size;
}

int main(){
    cin >> N >> K;
    int A;
    cin >> A;
    if(A != 1) ans++;
    rep2(i, 1, N-1){
        cin >> A; A--;
        es[i].pb(A), es[A].pb(i);
    }
    dfs(0, -1);
    cout << ans << endl;
}

Measured memory_bytes: 10368
a = input().split()
b = []
for i in a:
    if i.isdigit():
        b.append(int(i))
    else:
        if i == '+':
            s1 = b.pop()
            s2 = b.pop()
            b.append(s1+s2)
        elif i == '-':
            s1 = b.pop()
            s2 = b.pop()
            b.append(s2-s1)
        elif i == '*':
            s1 = b.pop()
            s2 = b.pop()
            b.append(s1*s2)
print(b[0])

Measured memory_bytes: 7728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class Time{
public:
	int id,score;
	Time(int _id,int _score){
		id = _id;
		score = _score;
	}
	bool operator<(const Time &t)const{
		return score < t.score;
	}
};

int main(void){
	int n;
	while(cin>>n,n){
			vector<Time> v;
		for(int i=0;i<n;i++){
			int id;
			cin>>id;
			int sum = 0;
			for(int j=0;j<4;j++){
				int x,y;
				cin>>x>>y;
				sum += x * 60 + y;
			}
			v.push_back(Time(id,sum));
		}
		sort(v.begin(),v.end());
		cout<<v[0].id<<endl;
		cout<<v[1].id<<endl;
		cout<<v[v.size()-2].id<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <cassert>
#define rep(i,n) for (ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int dep[200000];
int cnt[3];
int ans[200000];
bool used[200001];
vector<int> e[200000];

void dfs(int v, int p) {
    rep(i,e[v].size()) {
        if (e[v][i] == p) continue;
        dep[e[v][i]] = dep[v]+1;
        dfs(e[v][i], v);
    }
}

int main() {
    memset(ans, -1, sizeof(ans));
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n-1) {
        int a, b; cin >> a >> b; a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    rep(i,3) cnt[i] = n/3;
    if (n%3 >= 1) cnt[1]++;
    if (n%3 >= 2) cnt[2]++;
    dfs(0,0);
    int hoge[2] = {0};
    rep(i,n) {
        if (dep[i]%2) hoge[1]++;
        else hoge[0]++;
    }
    memset(ans, -1, sizeof(ans));
    int pi = 0, yo = 1;
    if (hoge[0] > hoge[1]) swap(pi, yo);

    if (hoge[pi] <= cnt[0]) {
        rep(i,n) {
            if (dep[i]%2 == pi && cnt[0]) {
                ans[i] = (cnt[0]--)*3;
                used[ans[i]] = true;
            }
        }
        int pos = 1;
        rep(i,n) {
            if (ans[i] != -1) continue;
            while (used[pos]) pos++;
            ans[i] = pos++;
        }
    } else {
        rep(i,n) {
            if (dep[i]%2 == pi && cnt[1]) {
                ans[i] = (--cnt[1])*3+1;
                used[ans[i]] = true;
            }
            if (dep[i]%2 == yo && cnt[2]) {
                ans[i] = (--cnt[2])*3+2;
                used[ans[i]] = true;
            }
        }
        assert(cnt[1] == 0 && cnt[2] == 0);
        int pos = 1;
        rep(i,n) {
            if (ans[i] != -1) continue;
            while (used[pos]) pos++;
            ans[i] = pos++;
        }
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 21760
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int ans = 0;

  static int Main() {

    int cnt = 0;

    int n = int.Parse(Console.ReadLine());

    int[] v = new int[n];
    int[] c = new int[n];
    string[] nyu = Console.ReadLine().Split(' ');
    for (int i = 0; i < n;  i ++) {
      v[i] = int.Parse(nyu[i]);
    }
    string[] nya = Console.ReadLine().Split(' ');
    for (int i = 0; i < n;  i ++) {
      c[i] = int.Parse(nya[i]);
    }
    // ここまで入力

    int[] sa = new int[n];
    for (int i = 0; i < n;  i ++) {
      sa[i] = v[i] - c[i];
      if (sa[i] > 0) {
        cnt += sa[i];
      }
    }

    ans = cnt;

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif



void Main() {
    ll N;
    cin >> N;
    vector<ll> P(N);
    rep(i, N) cin >> P[i];
    ll m = P[0];
    ll ans = 0;
    rep(i, N) {
        ll p = P[i];
        if (p <= m) {
            ans++;
        }
        m = min(m, p);
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {

	var N int
	var flag bool

	sum := 0
	fmt.Scan(&N)

	H := make([]int, N)
	sc := wordScanner()
	for i := range H {
		H[i] = getInt(sc)
	}

	for i := range H {
		if i == 0 {
			sum++
			continue
		}
		for k := i - 1; k >= 0; k-- {
			if H[k] > H[i] {
				flag = true
				break
			}
		}
		if flag {
			flag = false
			continue
		}
		sum++

	}

	fmt.Println(sum)

}

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func getInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int(i)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a,b,h;
  	cin>>a>>b>>h;
  	cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		String s = st.nextToken();
		if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static int[][] M;

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        M = new int[n][n];
        int u, k;
        for(int i = 0; i < n; i++){
            String[] t = br.readLine().split(" ");
            u = Integer.parseInt(t[0]);
            u--;//for M[u][v]                                                      
            k = Integer.parseInt(t[1]);
            for(int j = 0; j < k; j++){
                int v = Integer.parseInt(t[j+2]);
                v--;//for M[u][v]                                                  
                M[u][v] = 1;
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(j != 0) sb.append(" ");
                sb.append(M[i][j]);

            }
            sb.append("\n");
        }
        System.out.print(sb);
    }

}

Measured memory_bytes: 25468
#include<stdio.h>
int main(){
  double n;
  int i,m;
  while(scanf("%lf",&n),n+1){
    m=n=n*16;
    if(m-n)printf("NA\n");
    else{
      for(i=12;i--;){
	printf("%d",(m>>i)%2);
	if(i==4)printf(".");
      }
      printf("\n");
    }
  }
  return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

//---------------------------------------------------------------------------------------------------

void _main() {
    string s;
    cin >> s;
    int input[4];
    rep(i, 0 , 4) {
        input[i] = s[i] - '0';
    }
    char op[3];
    rep(x, 0, 2) {
        rep(y, 0, 2) {
            int sum = input[0];
            if (x==0) sum += input[1]; else sum -= input[1];
            if (y==0) sum += input[2]; else sum -= input[2];
            if (7 == sum + input[3]) {
                op[0] = ((x == 0) ? '+' : '-');
                op[1] = ((y == 0) ? '+' : '-');
                op[2] = '+';
                break;
            }else if ( 7 == sum - input[3]) {
                op[0] = ((x == 0) ? '+' : '-');
                op[1] = ((y == 0) ? '+' : '-');
                op[2] = '-';
                break;
            }
        }
    }
    cout << input[0] << op[0] << input[1] << op[1] << input[2] << op[2] << input[3] << "=7" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int N, H[20];
    cin >> N;
    rep(i,N) cin >> H[i];

    int ans = 1;
    int highest = H[0];
    for (int i = 1; i < N; i++) {
        if (H[i] >= highest) {
            ++ans;
            highest = H[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a = input().split()

b = input().split()
b = [int(i) for i in b]

c = input().split()
c = [int(i) for i in c]

X = int(a[2])
Y = int(a[3])

Z = list(range(X+1,Y+1))

def max(x):
    max = x[0]
    for i in range(1,len(x)):
        if max < x[i]:
            max = x[i]
    return max

def min(x):
    min = x[0]
    for i in range(1,len(x)):
        if min > x[i]:
            min = x[i]
    return min

bmax = max(b)
cmin = min(c)

if bmax >= cmin:        
    print("War")

else:
    X = list(range(bmax+1,cmin+1))
    for i in X:
        if i in Z:
            print("No War")
            break
    else:
        print("War")


Measured memory_bytes: 3064
#https://qiita.com/drken/items/fd4e5e3630d0f5859067

import numpy as np

n=int(input())
l=np.array([0,0,0])
d=l
rest="Yes"

for _  in range(n):
	t=np.array(list(map(int,input().split())))
	t2=t-d
	if t2[0]-t2[1]-t2[2] >=0 and (t2[0]-t2[1]-t2[2])%2 ==0:
		d=t2
	else:
		rest="No"

print(rest) 


Measured memory_bytes: 20460
x1, y1, x2, y2 = gets.split.map(&:to_i)
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)
puts "#{x3} #{y3} #{x4} #{y4}"


Measured memory_bytes: 1788
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    char x = '1';
    for(int i = 0; i < k; i++) {
        if(s[i] != '1'){
            x = s[i];
            break;
        }
    }
    cout << x;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		for(int i = 0; i < 3; i++) {
			list.add(scan.nextInt());
		}
		
		for(int i = list.size()-1; i > 0; i--) {
			for(int j = 0; j < i; j++) {
				if(list.get(j) > list.get(j + 1)) {
					int temp = list.get(j);
					list.set(j, list.get(j + 1));
					list.set(j + 1, temp);
				}
			}
		}
		
	
		System.out.println(list.get(0) + " " + list.get(1) + " " + list.get(2));
		
		
		
	}

}



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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  for (auto& x : m) cin >> x;
  for (const auto& x : m) X -= x;
  int min = *min_element(m.begin(), m.end());
  cout << (N + X / min) << endl;
}


Measured memory_bytes: 256
def examA():
    X, Y = LI()
    ans = -1
    if X%Y!=0:
        ans = X
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 3440
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};
typedef BinaryIndexedTree<int> BIT;

bool cmp(pair<int, int> a, pair<int, int> b) {
    return 1ll*a.first*b.second<1ll*b.first*a.second;
}

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

    int N;
    cin >> N;

    vi A(N), B(N), C(N);
    rep(i, N)cin >> A[i] >> B[i] >> C[i];

    const int need = (N*(N - 1) / 2 + 1) / 2;
    auto f = [&](vi a, vi b, vi c) {
        vector<pii> di(N);
        rep(i, N) {
            if (b[i] < 0)a[i] *= -1, b[i] *= -1, c[i] *= -1;
            di[i] = mp(-a[i], b[i]);
        }
        sort(all(di));
        di.erase(unique(all(di)), di.end());
        sort(all(di), cmp);

        double lb = -1e16, ub = 1e16, x;
        rep(ITER, 100) {
            x = (lb + ub)*0.5;
            BIT bit(N);
            vector<pair<double, int> > ry(N);
            rep(i, N) {
                ry[i] = mp((-a[i]*x+c[i])/b[i], i);
            }
            sort(all(ry));
            int cnt = 0;
            rep(k, N) {
                int ly, i;
                i = ry[k].second;
                ly = lower_bound(all(di), mp(-a[i], b[i]), cmp) - di.begin();
                cnt += bit.sum(0, ly);
                bit.add(ly, 1);
            }
            (cnt >= need ? ub : lb) = x;
        }
        return ub;
    };

    double x = f(A, B, C), y = f(B, A, C);

    cout << fixed << setprecision(20) << x << ' ' << y << endl;
}


Measured memory_bytes: 2432
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int sum = 0;
        int tmp = 0;
        for(int i = 0; i < M; i++) {
            tmp = sc.nextInt();
            sum += tmp;
        }

        if(sum > N)
            System.out.println("-1");
        else
            System.out.println(N - sum);
    }
}


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

int main()
{
    int a,b;
    std::cin >> a >> b;
    if(a > b){
        if(b == 1) std::cout << "Bob";
         else std::cout << "Alice";
    }
    else if(b > a){
        if(a == 1) std::cout << "Alice";
        else  std::cout << "Bob";
    }
    else std::cout << "Draw";
    return 0;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;



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

	int A, B;
	cin >> A >> B;

	if (B%A == 0)
	{
		cout << A + B << endl;
	}
	else
	{
		cout << B - A << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
using namespace std;

int main() {
  long long int h, n, k, i, j;
  vector<int> v;
  long long int u[200000];
  cin >> n >> k;

  for (i = 0; i < n; i++) {
    cin >> h;
    v.push_back(h);
  }

  for (i = 0; i < n; i++) {
    u[i] = 1000000000;
  }

  u[0] = 0;
  for (i = 0; i < n; i++) {
    for (j = 1; j <= k; j++) {
      u[i+j] = min(u[i+j], u[i] + abs(v[i] - v[i+j]));
    }
  }

  cout << u[n - 1] << endl;
}


Measured memory_bytes: 1528
from functools import reduce
n, a = map(int, input().split())
s = [int(i) for i in input().split()]
for i in range(n):
    s[i] = abs(a-s[i])
    
def saidaikouyakusuu(x, y):
    while x%y != 0:
        x, y = y, x%y
    return (y)

print(reduce(saidaikouyakusuu, s))

Measured memory_bytes: 14596
#include<stdio.h>

int N=100;
int min(int x,int y){
  if(x<=y) return x;
  else return y;
}

int main(){
  int n,p[N+1],m[N+1][N+1],j,l,i,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=2000000000;
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}

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

const int N = 1e5 + 10;

long long a[N];

int main(){
	int n;
	long long l, r, l1, r1;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%lld",&a[i]);
	if (a[n] != 2){
		printf("-1\n");
		return 0;
	}
	l = 2; r = 3;
	for (int i = n - 1; i >= 1; i--){
		l1 = ((l - 1) / a[i] + 1) * a[i];
		r1 = (r / a[i] + 1) * a[i] - 1;
		if (r < l1 || l > r1){
			printf("-1\n");
			return 0;
		}
		l = l1; r = r1;
	}
	printf("%lld %lld\n", l, r);
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;

	int n;
	cin>>n;
	int b[n-1],a[n];

	for(int i=0;i<n-1;i++){
		cin>>b[i];
	}

	a[n-1] = b[n-2];
	for(int i=n-2;i>=0;i--){
		if(b[i]<a[i+1]){
			a[i+1] = b[i];
			a[i] = b[i];
		}else{
			a[i] = b[i];
		}
	}

	ll ans = 0;
	for(int i=0;i<n;i++){
		ans = ans + a[i];
	}
	cout<<ans;
	return 0;
}

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

int main(int, char**) {
  int N;
  cin >> N;
  vector<int> nums;
  nums.resize(N);
  for (int i = 0; i<N; ++i) {
    cin >> nums[i];
  }
  int ans = -1;
  for (int i = 0; i < nums.size(); ++i) {
    for (int j = 0; j < nums.size(); ++j) {
      if (i != j) {
        ans = max(ans, abs(nums[i] - nums[j]));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;

class blanch{
	public:
		int weight;
		int from;
		int to;
		blanch():
			weight(0),from(0),to(0){};
		blanch(int newweight, int newfrom, int newto):
			weight(newweight),from(newfrom),to(newto){};
};
typedef vector <blanch> vb;

bool operator<( const blanch &blanch1, const blanch &blanch2){
	return (blanch1.weight > blanch2.weight);
	}

bool operator>( const blanch &blanch1, const blanch &blanch2){
	return (blanch1.weight < blanch2.weight);
	}

int make_graph(vvi &graph, vi &stamp){
	int n=graph.size();
	for (int j=0; j<n; j++){
		for (int i=0; i<n; i++){
			cin>>graph[i][j];
		}
		stamp[j] = 0;
	}
	return 0;
}

int Minimum_Spanning_Tree(vvi &graph, vi &stamp){

	priority_queue<blanch, vb, less<vb::value_type> > pq;
	int n = graph.size(), p1=0, total=0;
	stamp[p1] = 1;

	while (p1!=-1){
		for (int p2=0; p2<n; p2++){
			int *tmp = &graph[p1][p2];
			if (*tmp!=-1 && stamp[p2]==0){
				pq.push(blanch(*tmp, p1, p2));
			}
		}
		p1 = -1;
		while (! pq.empty()){
			blanch tmp = pq.top();
			if (stamp[tmp.from]==1 && stamp[tmp.to]==0){
				p1 = tmp.to;
				stamp[p1] = 1;
				total += tmp.weight;
				pq.pop();
				break;
			}
			pq.pop();
		}
	}
	return total;
}

int main(void){

	int n;
	cin>>n;
	vvi G(n, vi(n));
	vi stamp(n);

	make_graph(G, stamp);

	cout<<Minimum_Spanning_Tree(G, stamp)<<endl;

	return 0;
} 

Measured memory_bytes: 1344
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 2e5, M = 2e5;
int n, m;
set<int>nei[N + 1][2];
int col[N + 1];
bool dead[N + 1];


int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	cin >> n >> m;
	string s; cin >> s;
	rep(i, 0, n){
		col[i + 1] = (s[i] == 'A');
	}
 	rep(_, 0, m){
		int u, v; cin >> u >> v;
		nei[u][col[v]].insert(v);
		nei[v][col[u]].insert(u);
	}
	vector<int>q;
	rep(i, 1, n + 1){
		if(SZ(nei[i][0]) == 0 or SZ(nei[i][1]) == 0){
			q.pb(i);
			dead[i] = true;
		}
	}
	rep(i, 0, SZ(q)){
		int v = q[i];
		rep(j, 0, 2){
			for(auto& w : nei[v][j]){
				if(w != v){
					nei[w][col[v]].erase(v);
					if(!dead[w] and SZ(nei[w][col[v]]) == 0){
						q.pb(w);
						dead[w] = true;
					}
				}
			}
		}
	}
	if(SZ(q) == n){
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
    return 0;
}


Measured memory_bytes: 39240
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int r; cin>>r;
    cout<<r*r<<endl;
    return 0;   
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
typedef long long int ll;

int main(void){
    double W , H , x , y , S ;
    cin >> W >> H >> x >>y ;
    S = W * H ;
    double s1 , s2 ;
    
    cout << (W * H) / 2.0 << " " ;
    if(x == (double)W /2 && y == (double)H / 2 ){
        cout << 1 << endl;
    }else {
        cout << 0 << endl;
    }
    return 0;
}

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

int64_t MOD = 1e9+7;

//---------- べき乗 ----------
int64_t power(int64_t a, int64_t n){
    if(n == 0) return 1;

    int64_t res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % MOD;
        a = a * a % MOD;
        n /= 2;
    }

    return res;
}

//---------- 逆元 ----------
int64_t inv(int64_t a){
    return power(a, MOD-2);
}


//--------- 組み合わせ ---------
int64_t comb(int64_t n, int64_t r){
  int64_t bunbo = 1, bunshi = 1;

  for(int i=0; i<r; i++){
    bunbo = bunbo * (r-i) % MOD;
    bunshi = bunshi * (n-i) % MOD;
  }

  return bunshi * inv(bunbo) % MOD;
}


int main(){ 
  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t ans = power(2, N) - comb(N, A) - comb(N, B) - 1;
  while(ans < 0) ans += MOD;

  cout << ans << endl;
}

Measured memory_bytes: 256
n,m =list(map(int,input().split()))
ac = [0]*n
wa = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)-1
    if ac[p]: continue
    if s == "AC":
        ac[p] = 1

    elif s == "WA":
        wa[p]+=1
AC = 0
pena = 0

for i in range (n):
    AC += ac[i]
    if ac[i]: pena += wa[i]
print(str(AC)+" "+str(pena))



Measured memory_bytes: 4596
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,m,tt,ans,dfn[233],low[233];
int cnt,head[233],nxt[233],to[233];
void tarjan(int u,int fa)
{
	dfn[u]=low[u]=++tt;
	for(int i=head[u],v;i;i=nxt[i])
		if(!dfn[v=to[i]])
		{
			tarjan(v,u);
			if(low[v]>dfn[u])++ans;
			low[u]=min(low[u],low[v]);
		}else if(v!=fa)low[u]=min(low[u],dfn[v]);
	
}
int main()
{
	re(n),re(m);
	for(int u,v;m--;)
	{
		re(u),re(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	tarjan(1,0);
	printf("%d\n",ans);
}

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int a, ans;
    rep(i, 5) {
        cin >> a;
        if(a == 0) {
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


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


int main(){
  ll n, k;
  cin >> n >> k;
  
  map<ll, ll> ma;
  
  for(int i=0; i<n; i++){
    int a; cin >> a;
    ma[a]++;
  }
  
  int res = 0;
  
  vector<ll> b;
  for(auto it:ma){
    b.push_back(it.second);
  }
  
  sort(b.begin(), b.end());
  int index=0;
  for(int i=k; i<ma.size(); i++){
    res += b[index];
    index++;
  
  }
  
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 17768
a,b=input().split()
a=int(a)
b=int(b)
c=0
for i in range(a,b+1):
  if (i//10000)==(i-(i//10)*10) and (i//1000-(i//10000)*10) ==(i//10-(i//100)*10):
    c=c+1
print(c)

Measured memory_bytes: 9112
//07-1 ?????§??????(??¬???)
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    bool flg = true;
    while(flg){
        int n,k;
        cin >> n >> k;
        if(n==0 && k==0){
            flg = false;
        }
        else{
            int a[100000] = {};
            int max = 0;
            int now = 0;
            for(int i=0; i<n; i++){
                int tmp;
                cin >> tmp;

                a[i] = tmp;

                if(i+1<=k){
                    now += tmp;
                    max += tmp;
                }
                else if(i+1>k){
                    now -= a[i-k];
                    now += tmp;
                    if(now>max) max = now;
                }
            }
            cout << max << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3380