akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;
 
const int MOD=1e9+7;
const int INF=1e9;
const int magic=348;
 
int n,m;
int a[348][348];
vector<int> v[348];
priority_queue<Pair> q;
int cur[348];
bool used[348];
 
bool check(int cmp)
{
	if (cmp==n) return true;
	int i,j;
	for (i=1;i<=n;i++) cur[i]=1;
	for (i=1;i<=m;i++) v[i].clear();
	for (i=1;i<=n;i++) v[a[i][1]].pb(i);
	//for (i=1;i<=m;i++) cout<<v[i].size()<<' ';
	//cout<<endl;
	for (i=1;i<=m;i++) used[i]=true;
	for (i=1;i<=m;i++)
	{
		int maxn=-1,max_pos;
		for (j=1;j<=m;j++)
		{
			int len=v[j].size();
			//cout<<j<<' '<<v[j].size()<<' '<<maxn<<' '<<used[j]<<endl;
			if (used[j]==true && len>maxn)
			{
				//cout<<"#";
				//cout<<j<<' '<<v[j].size()<<endl;
				maxn=v[j].size();
				max_pos=j;
			}
		}
		if (maxn<=cmp) return true;
		if (i==m) return false;
		used[max_pos]=false;
		for (j=0;j<v[max_pos].size();j++)
		{
			int x=v[max_pos][j];
			cur[x]++;
			while (!used[a[x][cur[x]]]) cur[x]++;
			v[a[x][cur[x]]].pb(x);
		}
	}
	return false;
}
 
int main ()
{
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int l=1,r=n,mid,ans;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else
			l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
N, M, V, P = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse = True)

def solve(n):
    
    if n < P:
        return True
    
    if A[P-1] > A[n] + M:
        return False
    
    cnt = M * (P - 1 + N - n)
    for i in range(P-1,n):
        cnt += max(0, A[n] + M - A[i])
    
    return cnt >= M * V

left = 0
right = N

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        left = mid
    else:
        right = mid

print(right)

Measured memory_bytes: 20512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> SP(N, make_tuple("", 0, 0));
  string name;
  int score;
  for (int i = 0; i < N; i++) {
    cin >> name >> score;
    get<0>(SP[i]) = name;
    get<1>(SP[i]) = (-1) * score;
    get<2>(SP[i]) = i + 1;
  }
  sort(SP.begin(), SP.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(SP[i]) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  int h=0;
  int m=0;
  int s=0;
  while(n!=0){
  s++;
    if(s==60){
    s=0;
      m++;
    }
    if(m==60){
    m=0;
      h++;
    }
    n--;
  }
  cout<<h<<":"<<m<<":"<<s<<endl;
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
   int a,b,c,d,e=0,f,i,j,k;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   for(i=0;i<=a;i++)
   {
       for(j=0;j<=b;j++)
       {
           for(k=0;k<=c;k++)
           {
              if(500*i+100*j+50*k==d)
                e++;
           }
       }
   }

   printf("%d\n",e);
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=0;i<n;i++)

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

int main() {
  int n;
  cin >> n;
  string s[n];
  int cnt = 0;
  int firstB = 0;
  int lastA = 0;
  int bothAB = 0;

  rep(i, n) {
    cin >> s[i];
    char fst = s[i][0];
    char last = s[i][int(s[i].length()-1)];

    if (fst == 'B' && last == 'A') {
      bothAB++;
    } else if (fst == 'B') {
      firstB++;
    } else if (last == 'A') {
      lastA++;
    }

    rep1(j, s[i].length()) {
      char tmp = s[i][j-1];
      char cur = s[i][j];
      if (tmp == 'A' && cur == 'B') {
        cnt++;
      }
    }
  }

  if (bothAB > 0) {
    cnt += (bothAB - 1);
  }

  if (lastA > 0 && bothAB > 0) {
    cnt += 1;
    lastA -= 1;
  }

  if (firstB > 0 && bothAB > 0) {
    cnt += 1;
    firstB -= 1;
  }

  cnt += min(lastA, firstB);

  cout << cnt << endl;

  return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    string S;
    while(N){
        --N;
        S.push_back('a' + N % 26);
        N /= 26;
    }
    reverse(begin(S), end(S));
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3624
numMountains = 10
mountain = Array.new(numMountains).fill(0, 0...numMountains)

for i in 0...numMountains
  mountain[i] = gets.to_i
end

mountain.sort!{
  |x, y|  y.to_i <=> x.to_i
}

for i in 0...3
  puts mountain[i]
end

Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
lli m[1000005];
bool factors(lli n)
{
	lli i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i*i==n)
			{
				if(m[i]>=1)
				{
					return 0;
				}
			}
			else
			{
				if(m[i]>=1||m[n/i]>=1)
					return 0;
 
			}
		}
	}
	return 1;
}
int main() {
	fast;
	cin.tie(0);
	cout.tie(0);
	lli n;
	cin>>n;
	lli a[n],i;
	fr(i,n)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	if(m[1]==1)
	{
	    cout<<1;
	    return 0;
	}
	else if(m[1]>1)
	{
	    cout<<0;
	    return 0;
	}
	lli count=0;
	fr(i,n)
	{
	    if(m[a[i]]==1&&factors(a[i]))
	    {
	        count++;
	    }
	}
	cout<<count;
	
	return 0;
}

Measured memory_bytes: 12892
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	for(int i = 0; i < n; i++) {
		cout << s[i];
		cout << t[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const int MAXN = 1005;
const int MAXV = MAXN * MAXN; // The number of vectices is N*(N-1)/2
vector< vector<int> > to; // Adjacency matrix
int id[MAXN][MAXN];
int toId(int i, int j) {
  if (i > j) { swap(i, j); }
  return id[i][j];
}

int dp[MAXV]; // Max length of path from v.
bool calculated[MAXV];
int dfs(int v) {
  if (dp[v] >= 0) {
    if (!calculated[v]) { return -1; } // If calculated[v] is false, loop exists.
    return dp[v];
  }
  dp[v] = 0;
  for (auto u : to[v]) {
    int res = dfs(u);
    if (res == -1) { return -1; } // Loop exists
    dp[v] = max(dp[v], res + 1);
  }
  calculated[v] = true;
  return dp[v];
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vector< vector<int> > A(N, vector<int>(N-1));
  rep(i, N) {
    rep(j, N-1) {
      cin >> A[i][j];
      --A[i][j];
    }
  }

  int V = 0;
  for (int i = 0; i < N-1; ++i) {
    for (int j = i + 1; j < N; ++j) {
      id[i][j] = V++;
    }
  }

  to.resize(V);
  rep(i, N) {
    for (int j = 0; j < N - 2; ++j) {
      int p = toId(i, A[i][j]);
      int n = toId(i, A[i][j+1]);
      to[p].push_back(n);
    }
  }

  int ans = 0;
  memset(dp, -1, sizeof(dp));
  rep(i, V) {
    int res = dfs(i);
    if (res == -1) {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, res);
  }

  cout << ans + 1 << endl;
}


Measured memory_bytes: 39936
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
	int S, K = 0, ans = 1;
	map<string, int>mp;

	cin >> S;

	for (int i = 0; i < S; i++) {
		string N;
		cin >> N;
		int s = N.size();
		mp[N]++;
		if (mp[N] != 1) {
			ans = 0;
		}
		if (i) {
			if (K != N[0]-'0') {
				ans = 0;
			}
		}
		K = N[s - 1]-'0';
	}

	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

s = [True] * n #訪れているかを判定するlist
c = [1] #訪ずれた順番を記録するlist
now = 0 #現在地
while s[now]:
    s[now] = False #訪ずれた地点を記録
    now = a[now] - 1
    c.append(now+1)

start_cycle = c.index(c[-1]) #ループに入る点
loop = c[start_cycle:-1] #ループのlist
cycle = len(loop)

if k < start_cycle: #ループまで到達できないK
    print(c[k])
else:
    k -= start_cycle
    k %= cycle
    print(loop[k])

Measured memory_bytes: 32296
#include <iostream>
#include <map>
using namespace std;
typedef long long  ll;
#define repe(i,s,n)for(ll i=s;i<=n;i++)
 
ll A[100001] = {};
ll S[100001] = {};
map<ll, ll> mp;
int main() {
	ll N, M; cin >> N >> M;
	repe(i, 1, N) {
		cin >> A[i];
		S[i] = S[i - 1] + A[i];
		mp[S[i] % M]++;
	}
 
	ll cnt = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		ll c = it->second;
		if (c >= 2) {
			cnt += c * (c - 1) / 2;
		}
	}
	cout << mp[0] + cnt << endl;
	return 0;
}

Measured memory_bytes: 5760
/*
 * atcoder/abc140_3rd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template <class T, class T2>
void group(T &xs, vector<pair<T2, int> > &result) {
  int i=0, j;
  while (i<xs.size()) {
    j=i;
    while (j < xs.size() and xs[j] == xs[i]) j++;
    result.push_back({ xs[i], j-i });
    if (j==i) i++;
    i=j;
  }
}

/*
 * 幸福度の最大数はN-1で、十分に操作を繰り返せば任意のSをこの状態にできる.
 * また、一度の操作で増える幸福度の最大値は+2.
 * よって、もともとの幸福度をAとするとmin(A + 2 * K, N-1)
 */
ll N, K;
string S;
void solve() {
  cin >> N >> K >> S;
  vector<pair<char, int> > A;
  group(S, A);
  ll score = 0;
  for (auto&&a: A) score += a.second-1;
  cout << min(score + 2 * K, N-1);
  cout << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 1528
#include <stdio.h>

int main(void)
{
	int r, c, a, b, goukei2;
	int hi[100][100];
	
	scanf("%d %d", &r, &c);
	
	goukei2 = 0;
	
	for(a = 0; a < r; a++){
		for(b = 0; b < c; b++){
			scanf("%d", &hi[a][b]);
			goukei2 = goukei2 + hi[a][b];
		}
	}
	
	a = 0;
	b = 0;
	
	int goukei = 0;
	
	
	for(a = 0; a < r; a++){
		for(b = 0; b < c; b++){
			printf("%d ", hi[a][b]);
		    goukei = goukei + hi[a][b];
			if((b + 1) == c){
				printf("%d\n", goukei);
			}
		}
	    goukei = 0;
	}
	
	int goukei3 = 0;
	
	for(a = 0; a < c; a++){
		for(b = 0; b < r; b++){
			goukei3 = goukei3 + hi[b][a];
		}
		printf("%d ", goukei3);
		goukei3 = 0;
	}
	
	printf("%d\n", goukei2); 
			
	
	return (0);
}
	
	

Measured memory_bytes: 1788
#define _XOPEN_SOURCE 500
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n;
int a[200005];
int cnt[200005];
void solve() {
    cin >> n;
    reps(i, n - 1) {
        cin >> a[i];
        --a[i];
        ++cnt[a[i]];
    }

    rep(i, n) cout << cnt[i] << endl;
}

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


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

int main() {
	int A,B,C;

	cin >> A >> B >> C;
	
	if (A,B,C <= 100 and A,B,C >= -100){
	    if(A-B==0){
	        cout << C << endl;
	    }
	    if (A-C==0){
	        cout << B << endl;
	    }
	    if (B-C==0){
	        cout << A << endl;
	    }
	    
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int W,H,x,y,r;
W =sc.nextInt();
H =sc.nextInt();
x =sc.nextInt();
y =sc.nextInt();
r =sc.nextInt();
if((x+r)<=W && (x-r)>=0 && (y+r)<=H && (y-r)>=0) System.out.println("Yes");
else System.out.println("No");

}
}

Measured memory_bytes: 17304
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 999999999
const int mod = 1000000007;
ll cnt = 0;
 
int main(){
  ll n,m; cin >> n ;
  map<ll,ll>a;
  ll b[n];
  ll maxx = 0;
  for(int i=0;i<n;i++){
      cin >> b[i];
      a[b[i]]++;
      maxx=max(maxx,b[i]);
  }
  ll ans=0;
  for(auto p:a){
      int x = p.first;
      int n = p.second;
      if(n<x)ans+=n;
      else ans+=n-x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 

 
signed main(){
    int l,r;
    cin>>l>>r;
    if(r-l>2019)cout<<0;
    else{
        int ans=(l*r)%2019;
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
        cout<<ans;
    }
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,ans;
    char op;
    while(1){
         cin >> a >> op >> b;
         if(op == '+'){
             ans = a + b;
             cout << ans << "\n";
         }else if(op == '-'){
             ans = a - b;
             cout << ans << "\n";
         }else if(op == '/'){
             ans = a / b;
             cout << ans << "\n";
         }else if(op == '*'){
             ans = a * b;
             cout << ans << "\n";
         }else{
             break;
         }
       }
    return 0;
}


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

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

int main(void)
{
    ll money=1000,kabu=0;
    int n;
    cin >> n;
    ll a[n+1]={};
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(int i=0;i<n;i++)
    {
        //cout << money << endl;
        //cout << kabu << endl;
        if(kabu!=0)
        {
            money += kabu*a[i];
            kabu=0;
        }
        if(a[i]<a[i+1])
        {
            kabu += money/a[i];
            money -= kabu*a[i];
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 3580
s = str(input())

#import
import itertools

#resultcounter
count = 0

# シグマ
for i in range(len(s)):
    # 全挟み込みかたを記述
    bet = len(s) -1
    #betのindex
    betindex = [i for i in range(bet)]
    

    # betの組み合わせ
    for v in itertools.combinations(betindex, i):
            # str分割のリストの入れものの準備
        li = []
        #liの要素
#         li[0] = s[:v[0]+ 1]
#         li[1] = s[v[0]+ 1:v[1]+ 1]
#         .......

#イテレーションを回すためにlist化
        v = list(v)
        v = [i+1 for i in v]
        v.insert(0, 0)
        v += [len(s)]
        for j in range(len(v) - 1):
            li += [s[v[j]:v[j+1]]]
            
#             print(li)
        li = [int(i) for i in li]
        count += sum(li)
            
            
print(count)
            
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=(1e5)+10;
int n,k,a[maxn];
ll jc[maxn],iv[maxn],ivjc[maxn],ans,tmp;
ll C(ll x,ll y) {
	if (x<y) return 0;
	return jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(k);
	for (int i=1;i<=n;i++) read(a[i]);
	jc[0]=iv[0]=ivjc[0]=1;
	jc[1]=iv[1]=ivjc[1]=1;
	for (int i=2;i<=n;i++) {
		jc[i]=jc[i-1]*i%mod;
		iv[i]=(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=ivjc[i-1]*iv[i]%mod;
	}
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) {
		tmp=mod-(ll)a[i]*C(n-i,k-1)%mod;
		ans=(ans+tmp)%mod;
		tmp=(ll)a[i]*C(i-1,k-1)%mod;
		ans=(ans+tmp)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 2944
n,m=map(int,input().split())
if n%2==1:
    for i in range(m):
        print(i+1, n-i-1)
else:
    used = [False]*n
    next = [i+1 for i in range(m)][::-2]+[i+1 for i in range(m)][-2::-2]
    i=0
    now=0
    count=0
    while True:
        if used[now]==False and used[now+next[i]]==False:
            print(now+1, now+next[i]+1)
            count+=1
            if count==m:
                break
            used[now]=True
            used[now+next[i]]=True
            i+=1
            now+=1
        else:
            now+=1

Measured memory_bytes: 14136
# from typing import List
import sys

sys.setrecursionlimit(100000)

# 木の根を返す
# def find(x: int, S: List[int]) -> int:
def find(x, S):
    if S[x] == x:
        return x
    else:
        S[x] = find(S[x], S)
        return S[x]

# xとyが同じ集合に属すかの判定
# def same(x: int, y: int, S: List[int]) -> bool:
def same(x, y, S):
    return find(x, S) == find(y, S)

# xとyの属する集合を結合
# def unite(x: int, y: int, S: List[int]) -> None:
def unite(x, y, S):
    rx = find(x, S)
    ry = find(y, S)
    if rx == ry:
        return None
    else:
        S[rx] = ry

if __name__ == '__main__':
    [V, E] = [int(i) for i in input().split()]

    S = [i for i in range(V)]
    edges = []

    ans = 0

    for i in range(E):
        edges.append([int(i) for i in input().split()])

    for s, t, w in sorted(edges, key=lambda x: x[2]):
        if same(s, t, S):
            continue
        else:
            unite(s, t, S)
            ans += w


    print(ans)





Measured memory_bytes: 27796
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    char c;
    cin>>c;
    if(c=='a' || c=='e' || c=='i'||c=='o'||c=='u') puts("vowel");
    else puts("consonant");
    return 0;
}

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

const int N = 3000;

int n;
double p[N], f[2][N];

int main() {
	scanf("%d", &n);
	int cur = 0;
	for(int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
	f[1][0] = 1;
	for(int i = 1; i <= n; ++i) {
		memset(f[cur], 0, sizeof(f[cur]));
		for(int j = 0; j <= i; ++j) {
			f[cur][j] += f[cur ^ 1][j] * (1 - p[i]);
			f[cur][j] += f[cur ^ 1][j - 1] * p[i];
		}
		cur ^= 1;
	}
	double ans = 0;
	for(int i = n / 2 + 1; i <= n; ++i) ans += f[cur ^ 1][i];
	printf("%.15lf\n", ans);
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n; cin >> n;
	string s(n, '.');
	for (int i = 0; i < n; i++) {
		s[i] = '0' + i + 1;
	}
	vector<string> perm;
	do {
		perm.push_back(s);
	} while (next_permutation(all(s)));

	string a(n, '.'), b(n, '.');
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		a[i] = '0' + x;
	}
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		b[i] = '0' + x;
	}

	int ida = lower_bound(all(perm), a) - perm.begin();
	int idb = lower_bound(all(perm), b) - perm.begin();
	int ans = abs(ida - idb);
	cout << ans << endl;
}


Measured memory_bytes: 2424
def getGrundyNumber(x):
    ans = 1
    while x % (ans * 2) == 0:
        ans *= 2
    return ans


N, L = map(int, input().split())
Ss = [input() for i in range(N)]

Ss.sort()

Hgts = {L: 2}
prev = '_'
for S in Ss:
    for iS, (a, b) in enumerate(zip(prev, S)):
        if a != b:
            Hgts[L - iS] -= 1
            for h in range(L - len(S) + 1, L - iS):
                Hgts[h] = Hgts.get(h, 0) + 1
            break
    prev = S

ans = 0
for Hgt, num in Hgts.items():
    if num % 2:
        ans ^= getGrundyNumber(Hgt)

if ans:
    print('Alice')
else:
    print('Bob')


Measured memory_bytes: 15204
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    int Max = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        Max = (Max < a[i]) ? a[i] : Max;
    }
    typedef long long ll;
    ll c[Max + 1];
    for (int i = 0; i <= Max; i++) {
        c[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        c[a[i]]++;
    }/*
    for (int i = 0; i <= Max; i++) {
        cout << c[i] << " ";
    }
    cout << endl;*/
    for (int i = 1; i <= Max; i++) {
        c[i] += c[i - 1];
    }
    for (int i = 0; i <= Max; i++) {
        c[i]--; //0 start
    }/*
    for (int i = 0; i <= Max; i++) {
        cout << c[i] << " ";
    }
    cout << endl;*/
    int b[n];
    for (int i = n - 1; i >= 0; i--) {
        b[c[a[i]]] = a[i]; //a[i]はcountされた番目にいく
        c[a[i]]--; //次同じ数来たら
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << b[i];
    }
    cout << endl;
}



Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  long long n, k;
  cin >> n >> k;
  cout << (long long)(k * pow(k - 1, n - 1)) << '\n';
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int i,j,n;
    cin>> n;
    for(i=3;i<=n;i++){
        if(i%3==0){
            cout<< " "<< i;
        }else{  
            for(j=10;j<i;j*=10){
                if((i%j)==3||(i/j)%10==3){
                    cout<< " "<< i;
                    break;
                }
            }
        }
    }
    cout<< endl;
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

bool is[105];

int main() 
{
    FAST;
    ll x,n;
    cin>>x>>n;
    ll p;
    for(int i=0;i<n;i++)
    {
        cin>>p;
        is[p]=1;
    }
    ll y=x;
    while(y>=0 && x<105)
    {
        if(!is[y])
        {
            cout<<y;
            break;
        }
        if(!is[x])
        {
            cout<<x;
            break;
        }
        y--;
        x++;
    }
    subt;
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g;}
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int main()
{
	vvi list(4);
	rep(i, 3)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		list[a].push_back(b);
		list[b].push_back(a);
	}
	rep(i, 4)
	{
		if (sz(list[i]) > 2)
		{
			co("NO");
			return 0;
		}
	}
	co("YES");
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int x;cin>>x;
    cout<<x*x*x<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------




/*
9 4
1 0 1 0 1 0 0 1 1
1 2
2 4
2 3
4 5
1 6
6 7
6 8
7 9
*/



































Measured memory_bytes: 3232
#include <stdio.h>

int main(void) {
	int n, sum, x;
	scanf("%d %d", &n, &sum);
	for (int i = 0; i <= n; i++)
	{
		x = n - i;
		for (int j = 0; j <= n - i; j++)
		{
			if (i * 10000 + j * 5000 + x * 1000 == sum)
			{
				printf("%d %d %d", i, j, x);
				return 0;
			}
			x--;
		}
	}
	printf("-1 -1 -1");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    ll in = 0, out = 0;
    rep(i, n) {
        if (s[i] == 'a') {
            if ((a + b) > (in + out)) {
                in++;
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
        }
        else if (s[i] == 'b') {
            if (((a + b) > (in + out)) && (b > out)) {
                out++;
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 848
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
  string str;
  int alp[26]={};
  while(getline(cin,str)){
    for(int i=0,l=str.size();i<l;i++){
      if(str[i]>='a'&&str[i]<='z') alp[str[i]-'a']++;
      else  if(str[i]>='A'&&str[i]<='Z') alp[str[i]-'A']++;
    }
  }
  for(int i=0;i<26;i++){
    printf("%c : %d\n",i+'a',alp[i]);
  }
}


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

int n,m,k,a,b[100005],c,l[100005],p;
string s;
int main(){
    cin>>n>>m;
    for (int i=0; i<m; i++){
        cin>>a>>s;
        if (l[a]==0){
            if (s=="WA"){
                b[a]++;
            }
            else{
                c++;
                l[a]=1;
            }
        }
    }
    for (int i=0; i<n; i++){
        if (l[i+1]==1){
            p+=b[i+1];
        }
    }
    cout<<c<<' '<<p<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void AGC031B();

int main()
{
	AGC031B();
	fflush(stdout);
	return 0;
}

static void AGC031B()
{
	int N;
	getint(N);

	std::vector<int> ci(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		getint(ci[i]);
	}

	std::vector<int> lastPos(2 * 100000 + 1, 0);
	std::vector<LLONG> dp(N + 1, 0);
	dp[0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1];
		int lpos = lastPos[ci[i]];
		if ((lpos > 0) && (lpos < (i - 1))) {
			dp[i] = (dp[i] + dp[lpos]) % MOD_NUM;
		}
		lastPos[ci[i]] = i;
	}
	printf("%lld\n", dp[N]);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
int n,m,s,t;
ll d=1000000000000000;
vector <pair<int,ll>> a[200000];
vector <pair<int,ll>> b[200000];
ll r1[200000];
ll r2[200000];
set<pair<ll,int>> a1;
bool visit1[200000];
set<pair<ll,int>> b1;
bool visit2[200000];
int main() {
	//ios_base::sync_with_stdio(false);
	cout<<setprecision(20);
	cin>>n>>m>>s>>t;
	s--;
	t--;
	for(int i=0;i<m;i++){
	    int u, v;
	    ll x,y;
	    cin>>u>>v>>x>>y;
	    u--;
	    v--;
	    a[u].push_back(make_pair(v,x));
	    a[v].push_back(make_pair(u,x));
	    b[u].push_back(make_pair(v,y));
	    b[v].push_back(make_pair(u,y));
	}
	int det1=0;
	for(int i=0;i<n;i++){
	    if(i!=s){
	        a1.insert(make_pair(1000000000000000,i));
	        r1[i]=1000000000000000;
	    }
	    else{
	        a1.insert(make_pair(0,i));
	    }
	}
	std::set<pair<ll,int>>::iterator it;
	while(det1<n){
	    it=a1.begin();
	    pair<int,ll> u=*it;
	    a1.erase(it);
	    if(visit1[u.second]==1) continue;
	    visit1[u.second]=1;
	    det1++;
	    for(int i=0;i<a[u.second].size();i++){
	        if(r1[a[u.second][i].first]>r1[u.second]+a[u.second][i].second){
	            r1[a[u.second][i].first]=r1[u.second]+a[u.second][i].second;
	            a1.insert(make_pair(r1[a[u.second][i].first],a[u.second][i].first));
	        }
	    }
	}
	int det2=0;
	for(int i=0;i<n;i++){
	    if(i!=t){
	        b1.insert(make_pair(1000000000000000,i));
	        r2[i]=1000000000000000;
	    }
	    else{
	        b1.insert(make_pair(0,i));
	    }
	}
	while(det2<n){
	    it=b1.begin();
	    pair<int,ll> u=*it;
	    b1.erase(it);
	    if(visit2[u.second]==1) continue;
	    visit2[u.second]=1;
	    det2++;
	    for(int i=0;i<b[u.second].size();i++){
	        if(r2[b[u.second][i].first]>r2[u.second]+b[u.second][i].second){
	            r2[b[u.second][i].first]=r2[u.second]+b[u.second][i].second;
	            b1.insert(make_pair(r2[b[u.second][i].first],b[u.second][i].first));
	        }
	    }
	}
	ll ans[200000];
	ll max=0;
	for(int i=n-1;i>-1;i--){
	    ll locans=d-r1[i]-r2[i];
	    if(locans>max) max=locans;
	    ans[i]=max;
	   // cout<<d<<" "<<r1[i]<<" "<<r2[i]<<endl;
	}
	for(int i=0;i<n;i++) cout<<ans[i]<<'\n';
}

Measured memory_bytes: 39168
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
int D[55];
int T[55];

int solve() {
  if (N >= 24) return 0;

  int res = 0;
  for (int bit = 0; bit < (1<<N); ++bit) {
	if (bit % 2 == 0) continue;
	int tmp = 30;
	T[0] = 0;
	for (int i = 0; i < N; ++i) {
	  if (bit & (1<<i)) T[i+1] = D[i];
	  else T[i+1] = 24 - D[i];
	}
	sort(T, T+N+1);
	for (int i = 0; i < N+1; ++i) {
	  int j = (i+1) % (N+1);
	  int diff = min( abs(T[j] - T[i]), 24 - abs(T[j] - T[i]) );
	  chmin(tmp, diff);
	}
	chmax(res, tmp);
  }
  return res;
}

int main() {
    while (cin >> N) {
	  for (int i = 0; i < N; ++i) cin >> D[i];
	  cout << solve() << endl;
    }
}



















Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,q,i,j,k,key;
  int left,right,mid,cnt;
  int s[100000],t[50000];

  cnt = 0;
  key = 0;
  //this is binary search function here
   scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  
  scanf("%d",&q);
  for(j=0;j < q;j++){
    scanf("%d",&t[j]);
  }
    
  for(k=0;k < q;k++){
    left = 0; right = n;
    while( left < right){
      mid = (left + right) / 2;
      if (s[mid] == t[k]){
	cnt++;
	break;
      } else if (s[mid] > t[k]){
	right = mid;
      } else {
	left = mid + 1;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}




Measured memory_bytes: 2308
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
cin.tie(0); ios::sync_with_stdio(false);
int N; cin >> N;
VS s(N); 
rep(i, 0, N) cin >> s[i];
rep(i, 0, N) sort(ALL(s[i]));
sort(ALL(s));

ll cnt=0, len = 1;

rep(i, 0, N-1){
	if (s[i] == s[i+1]) ++len;
	else {
		cnt += (len-1)*len /2;
		len = 1;
	}
}
cnt += (len-1)*len/2;
cout << cnt << "\n";

return 0;
}

// 境界のチェック


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
 
#define pb push_back
 
typedef long long ll;

const int inf=0x3f3f3f3f;
const int N=100000+10;

int n;
int a[N];
int x,y,z;
int main() {
 
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	//freopen("in.txt","r",stdin);
	cin>>n;
	FOR(i,n) cin>>a[i];
	FOR(i,n) {
		if (a[i]%4==0) a[i]=4;
		else if (a[i]%2==0) a[i]=2;
		else a[i]=1;
		if (a[i]==1) x++;
		if (a[i]==2) y++;
		if (a[i]==4) z++;
	}
	if (y==0) {
		if (x<=z+1) {
			cout<<"Yes"<<endl;
		} else cout<<"No"<<endl;
	} else {
		if (x<=z) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
import numpy as np

N, M, K = map(int, input().split())

LR = np.zeros(shape=(N + 1, N + 1), dtype=np.int32)
L, R = np.array([input().split() for _ in range(M)], dtype=np.int32).T
np.add.at(LR, (L, R), 1)

np.cumsum(LR, axis=0, out=LR)
np.cumsum(LR, axis=1, out=LR)

ans = []
for _ in range(K):
    p, q = map(int, input().split())
    p -= 1
    ans.append(LR[q, q] - LR[p, q] - LR[q, p] + LR[p, p])

print(*ans, sep='\n')

Measured memory_bytes: 77668
# https://atcoder.jp/contests/arc069/tasks/arc069_b

from collections import deque

N = int(input())
S = input()

# 両方試すかな？ (1が羊(0)のとき，1が狼(1)のとき)
def valid(ans):
    # print(ans)
    for i in range(1, N - 1):
        if S[i] == 'o':
            if ans[i] == 0:
                ans[i + 1] = ans[i - 1]
            else:
                ans[i + 1] = 1 - ans[i - 1]
        else:
            if ans[i] == 0:
                ans[i + 1] = 1 - ans[i - 1]
            else:
                ans[i + 1] = ans[i - 1]

    flag1 = False
    if ans[-1] == 0:
        if S[-1] == 'o':
            flag1 = ans[-2] == ans[0]
        else:
            flag1 = ans[-2] != ans[0]
    else:
        if S[-1] == 'o':
            flag1 = ans[-2] != ans[0]
        else:
            flag1 = ans[-2] == ans[0]

    flag2 = False
    if ans[0] == 0:
        if S[0] == 'o':
            flag2 = ans[1] == ans[-1]
        else:
            flag2 = ans[1] != ans[-1]
    else:
        if S[0] == 'o':
            flag2 = ans[1] != ans[-1]
        else:
            flag2 = ans[1] == ans[-1]
    return flag1 and flag2

for (v0, v1) in [(0, 0), (0, 1), (1, 0), (1, 1)]:
    ans = [-1] * N
    ans[0] = v0
    ans[1] = v1
    flag = valid(ans)
    # print(ans, flag)
    if flag:
        for ch in ans:
            print('S' if ch == 0 else 'W', end='')
        print()
        exit()

print("-1")

Measured memory_bytes: 78644
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


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

	if(n < 1200) cout << "ABC" << endl;
	else if(n < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}


Measured memory_bytes: 764
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		boolean[][] table = new boolean[24][60];
		Scanner sc = new Scanner(System.in);
		
		for (int t = 0; t < 2; t++){
			int n = sc.nextInt();
			
			for (int i = 0; i < n; i++){
				int h = sc.nextInt();
				int m = sc.nextInt();
				table[h][m] = true;
			}
		}
		
		boolean donefirst = false;
		for (int h = 0; h < 24; h++){
			for (int m = 0; m < 60; m++){
				if (table[h][m]){
					if (donefirst){
						System.out.print(" ");
					}
					else {
						donefirst = true;
					}
					System.out.printf("%d:%02d", h, m);
				}
			}
		}
		
		System.out.println("");
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

class UnionFind{
    public:
        vector<int> par;
        vector<int> rank;
        vector<int> size;

        UnionFind(int n){
            for(int i = 0; i < n; i++){
                par.push_back(i);
                rank.push_back(0);
                size.push_back(1);
            }
        }

        int find(int x){
            if(x == par[x])
                return x;
            else
                return par[x] = find(par[x]);
        }

        void unite(int x, int y){
            x = find(x);
            y = find(y);
            if(x == y) return;

            if(rank[x] < rank[y]){
                par[x] = y;
                size[y] += size[x];
            }
            else{
                par[y] = x;
                size[x] += size[y];
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        bool same(int x, int y){
            return find(x) == find(y);
        }

        int get_size(int x){
            return size[find(x)];
        }
};

int main(){
    int N, M;
    cin >> N >> M;
    UnionFind uni(N);
    REP(i,M){
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uni.unite(x, y);
    }

    ll ans = 0; 
    set<int> root;
    REP(i,N){
        int r = uni.find(i);
        if(root.find(r) == root.end()){
            ans++;
            root.insert(r);
        }
    }

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


Measured memory_bytes: 6124
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
  ($line:expr, $name:ident, $t:tt) => {
    let $name = value!($line, $t);
  };
}

macro_rules! values_def {
  ($lines:expr, $n:expr, $name:ident, $t:tt) => {
    let $name = {
      let mut vec = Vec::new();
      for i in 0..$n {
        let mut next = $lines.next().unwrap().split_whitespace();
        vec.push(value!(next, $t));
      }
      vec
    };
  };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
  let mut input = String::new();
  io::stdin().read_to_string(&mut input).unwrap();
  let output = solve(input.trim().to_string());
  println!("{}", output);
}

fn solve(input: String) -> String {
  let list = input.chars().map(|x| x == '0').collect::<Vec<_>>();
  (std::cmp::min(
    list.clone().into_iter().filter(|&x| x).count(),
    list.clone().into_iter().filter(|&x| !x).count(),
  ) * 2)
    .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "0011\n" => "4\n",
    test2: "11011010001011\n" => "12\n",
    test3: "0\n" => "0\n",
}


Measured memory_bytes: 4352