akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n ; 
    cin >> n ; 
    int cnt = 0 ; 
    for(int i=1;i<=n;i++){
    	int x ;
    	cin >> x ; 
    	if ( x != i ) cnt++ ; 
    }
    if ( cnt == 0 || cnt == 2 ){
    	cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0 ;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int N = int.Parse(str);
            string[] S = new string[N];
            int[] P = new int[N];
            string[] p = new string[N];
            string[] Sp = new string[N];
            //string[,] Sp = new string[2,N];
            for(int i = 0; i < N; i++)
            {
                string[] str1 = Console.ReadLine().Split(' ');
                S[i] = str1[0];
                P[i] = int.Parse(str1[1]);
                p[i] = (100 - P[i]).ToString();
                if (p[i].Length == 1)
                {
                    p[i] = "0" + p[i];
                }
                else if (p[i].Length == 3)
                {
                    p[i] = "999";
                }
                
                Sp[i] = S[i] + p[i];
                //Sp[0, i] = str1[0];
                //Sp[1, i] = str1[1];
                
            }

            string[] s = new string[N];
            for(int i = 0; i < N; i++)
            {
                s[i] = Sp[i];
            }
            //string[] s = Sp;

            //大文字小文字を区別しない序数比較で並び替える
            StringComparer cmp = StringComparer.OrdinalIgnoreCase;

            Array.Sort(Sp, cmp);
            for (int i = 0; i < N; i++)
            {
                
                string a = Sp[i];
                for(int j = 0; j < N; j++)
                {
                    if (s[j] == a)
                    {
                        Console.Write(j+1+"\r\n");
                        break;
                    }
                }
                
            }



        }
    }
}


Measured memory_bytes: 11220
def gcd(x, y):
    if y==0: return x
    z = x % y
    return gcd(y, z)
        
while True:
    try:
        a, b = (int(i) for i in input().split())
    except EOFError:
        break
    if a<b: print(gcd(b,a))
    else: print(gcd(a,b))
    

Measured memory_bytes: 7644
# coding: utf-8
# Your code here!
# 猫確定，わからない，いなければならない猫の数
A,B,X = map(int,input().split())

total = A + B
if X < A or total < X :# 猫がX匹より少ない or 全体よりX匹猫いる  
    print("NO")
else:
    print("YES")

Measured memory_bytes: 2940
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]
li=[[0,0] for i in range(n+1)] 
wa=0
ans=0
# print(ps)
for i in range(m):
    if li[int(ps[i][0])][0]==0:
        if ps[i][1]=="AC":
            li[int(ps[i][0])][0]+=1
        else:
            li[int(ps[i][0])][1]+=1
    else:
        continue
for i in range(n+1):
    if li[i][0]==0:
        continue
    else:
        ans+=1
        wa+=li[i][1]
print(ans)
print(wa)

Measured memory_bytes: 73564
def binary_search(key):
    """二分探索法 O(logN)

    Args:
        key (int): 基準値

    Vars:
        ok (int): 条件を満たすindexの上限値/下限値
        ng (int): 条件を満たさないindexの下限値-1/上限値+1
    
    Returns:
        int: 条件を満たす最小値/最大値
    """
    ok = 10 ** 12
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if isOK(mid, key):
            ok = mid
        else:
            ng = mid
    
    return ok

def isOK(i, key):
    """条件判定

    Args:
        i   (int): 判定対象の値
        key (int): 基準値

    Returns:
        bool: iが条件を満たすか否か
    """
    cnt = 0
    for v, d in l:
        if v > i:
            cnt += (v - i + d - 1) // d

    return cnt <= key


n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort(reverse=True)
f.sort()
l = []
for i in range(n):
    l.append([a[i]*f[i], f[i]])

print(binary_search(k))

Measured memory_bytes: 126412
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a;cin >> n;
    vector <pair<int, int>> v;
    for(int i =1; i <= n; i++){
        cin >> a;
        v.push_back(make_pair(a, i));
    }
    sort(v.begin(), v.end());
    for(int i =0; i < n; i++)
        cout << v.at(i).second << " ";
    cout << endl;
}


Measured memory_bytes: 1780
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    a.resize(n);
    Vi v(n);
    rep(i,n){
        cin>>a[i];
        v[i] = a[i];
    }
    Sort(v);
    rep(i,n){
        if(a[i]==v[0]){
            print(v[1]);
        }else{
            print(v[0]);
        }
    }
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll n,k; cin >> n >> k;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll cur = 1;
  map<ll, ll> m;
  ll dif = 0;
  ll ka = 0;
  rep(t,n+2){
    if(m.count(cur)<=0){
      m[cur]=t;
      if(k==t){
        cout << cur << endl;
        return 0;
      }
      cur = a[cur-1];
      continue;
    }
    ll tp = m[cur];
    dif = t - tp;
    ka = k-t;
    break;
  }
  vector<ll> ans;
  for(ll i = 0; i< dif; i++){
    ans.push_back(cur);
    cur=a[cur-1];
  }
  cout << ans[ka%ans.size()];
  return 0;
}

Measured memory_bytes: 16960
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    long long n;
    cin >> n;
    long long ans=1;
    const long long mod=1000000007;
    vector<long long> a(n+1);
    for(int i=2; i<=n; i++){
        int number=i;
        for(int j=2; j*j<=i; j++){
            if(number%j==0){
                while(number%j==0){
                    number/=j;
                    a[j]++;
                }
            }
        }
            if(number>1) a[number]++;
    }
    for(int i=2; i<=n; i++){
        ans=ans*(a[i]+1)%mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if( T[u].parent == NIL ) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0;
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int v, l, r, root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	for(int i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(int i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(int i=0;i<n;i++) print(i);
	
	return 0;
}


Measured memory_bytes: 2692
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        int ans = 0;
        int ans1 = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 1){
                ans1 ++;
            }else{
                if(ans1 > ans){
                    ans = ans1;
                }
                ans1 = 0;
            }
        }
        System.out.println(Math.max(ans +1, ans1+1));
    }
}



Measured memory_bytes: 26500
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	vector<int> a(N), b(N);
	for (int i = 0; i < N; ++ i) {
		cin >> X[i] >> Y[i];
		-- X[i]; -- Y[i];
		a[X[i]] = Y[i];
		b[Y[i]] = X[i];
	}
	dsu D(N);
	set<int> hoge;
	for (int i = 0; i < N; ++ i) {
		bool ok = false;
		for (auto it = hoge.begin(); it != hoge.end(); ) {
			if (*it > a[i]) break;
			ok = true;
			D.merge(b[*it], i);
			if (it == hoge.begin()) {
				++ it;
			} else {
				it = hoge.erase(it);
			}
		}
		if (!ok) hoge.insert(a[i]);
	}
	vector<int> res(N);
	for (auto g : D.groups()) {
		int n = g.size();
		for (int x : g) res[x] = n;
	}
	for (int i = 0; i < N; ++ i) {
		cout << res[X[i]] << endl;
	}
}


Measured memory_bytes: 15368
n = int(input())
a = list(map(int, input().split()))
x = {}
for i in range(n):
    t = min(a[i] // 400, 8)
    if t in x.keys():
        x[t] += 1
    else:
        x[t] = 1
m = 0
l = len(x.keys())
if 8 in x.keys():
    ans = [max(1, l - 1), l - 1 + x[8]]
else:
    ans = [l, l]
print(*ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  vector<ll> a(3);
  rep(i,3){
  cin >> a.at(i);
  }
sort(all(a));

if (a.at(0) + a.at(1) == a.at(2)) {
  cout << "Yes" << endl;
  return 0;
}else{
cout << "No" << endl;
}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <tuple>
#include <functional>
class Tree {
	long long int mHeight = 0;
	std::vector<std::tuple<long long int, int>> mCanJump{};
public:
	Tree() {}
	Tree(long long int height) :mHeight{ height } {}
	void addCanJump(long long int time, int to) {
		if (time <= mHeight) mCanJump.push_back(std::make_tuple(time, to));
	}
	const std::vector<std::tuple<long long int , int>> canJump() const {
		return mCanJump;
	}
	long long int height() const { return mHeight; }
};
struct IntPair {
	long long int first, second;
	bool operator<(const IntPair &other) const { return first < other.first; }
	bool operator>(const IntPair &other) const { return first > other.first; }
};
int main() {
	int n, m, x;
	std::cin >> n >> m >> x;
	std::vector<Tree> trees(n);
	{
		long long int height;
		for (auto &tree : trees) {
			std::cin >> height;
			tree = Tree(height);
		}
	}
	{
		int a, b;
		long long int t;
		for (auto i = 0; i < m; ++i) {
			std::cin >> a >> b >> t;
			trees[a - 1].addCanJump(t, b - 1);
			trees[b - 1].addCanJump(t, a - 1);
		}
	}
	std::vector<long long int> minCost(n, LLONG_MIN);
	std::priority_queue<IntPair> queue;
	minCost[0] = x;
	queue.push(IntPair{ x, 0 });
	while (queue.size() != 0 && queue.top().second != n - 1) {
		auto tree = queue.top().second;
		auto height = queue.top().first;
		queue.pop();
		if (minCost[tree] == height) {
			for (auto jump : trees[tree].canJump()) {
				auto to = std::get<1>(jump);
				auto time = std::get<0>(jump);
				if (height - time > minCost[to] && trees[to].height() > minCost[to]) {
					if (height - time > trees[to].height()) {
						minCost[to] = trees[to].height();
					}
					else {
						minCost[to] = height - time;
					}
					queue.push(IntPair{ minCost[to], to });
				}
			}
		}
	}
	if (queue.size() == 0) std::cout << -1 << std::endl;
	else std::cout << x + trees[n - 1].height() - minCost[n - 1] * 2 << std::endl;
}


Measured memory_bytes: 20716
ac=0
wa=0
tle=0
re=0
n=int(input())
for _ in range(n):
  x=input()
  if x=='AC':
    ac+=1
  elif x=='WA':
    wa+=1
  elif x=='TLE':
    tle+=1
  elif x=='RE':
    re+=1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b,k;
    cin>>k;
    cin>>a>>b;
    rep(a,i,b+1){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string ans = "";
  while(n!=0){
    if(n%2!=0){
      n--;
      ans = "1" + ans;
    }
    else{
      ans = "0" + ans;
    }
    n /= -2;
  }
  if(ans=="") cout << 0 << endl;
  cout << ans << endl;
}

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

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

ans = 0
L = Bit(n)
R = Bit(n)

B = [[A[i], i, n-i-1] for i in range(n)]
B.sort()
for i in range(n):
    # print(*[L.sum(i) for i in range(1, n+1)])
    ind = B[i][1]+1
    l = 0
    r = ind+1
    m = (l+r)//2
    lind = L.sum(ind)
    while r-l>1:
        if L.sum(m)< lind:
            l = m
        else:
            r = m
        m = (l+r)//2
    a = l
    L.add(ind+1, 1)
    # print(ind-1,a)

    ind = B[i][2]+1
    l = 0
    r = ind+1
    m = (l+r)//2
    rind = R.sum(ind)
    while r-l>1:
        if R.sum(m) < rind:
            l = m
        else:
            r = m
        m = (l+r)//2
    b = l
    R.add(ind+1, 1)

    ans += (i+1) * (B[i][1]+1 - a) * (n+1-b - (B[i][1]+1))
    # print(i+1, B[i][1]+1, a, n+1-b, ans)


print(ans)

Measured memory_bytes: 100176
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
  stack<string> s;
  int n;
  cin >> n;
  string a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 0; i < n; i++) {
    if (a[i] == "A") s.push("A");
    else {
      if (!s.empty() && s.top() == "A") s.pop();
      else s.push("Un");
    }
  }
  if (s.empty()) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 3172
H, W = map(int, input().split())
maze = [input() for i in range(H)]



def search_wall(H, W, x, y):
    tmp = []
    if x + 1 < W:
        tmp.append([0, 1])
    if x - 1 >= 0:
        tmp.append([0, -1])
    if y + 1 < H:
        tmp.append([1, 0])
    if y - 1 >= 0:
        tmp.append([-1, 0])
    return tmp
    
for row in range(H):
    for column in range(W):
        if (maze[row][column] == '#'):
            check = 0
            for y, x in search_wall(H, W, column, row):
                if maze[row + y][column + x] == '#':
                    check = 1
            if check != 1:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 100000

int parent(int i) {
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

int main() 
{
  int H, i, A[MAX+1];
  
  scanf("%d", &H);
  for(i = 1; i<=H; i++) {
    scanf("%d",&A[i]);
  }
  
  for(i=1; i<=H; i++) {
    printf("node %d: key = %d, ", i,A[i]);
    if(parent(i) >=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <=H) printf("left key = %d, " ,A[left(i)]);
    if(right(i) <= H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
r, c = map(int, input().split())
mtx = [[int(i) for i in input().split()] for j in range(r)]
for m in mtx:
    m.append(sum(m))
    print(' '.join(list(map(str, m))))
print(' '.join(list(map(str, [sum([j[i] for j in mtx]) for i in range(c + 1)]))))


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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

struct LowLink
{
  UnionFind uf;
  vector< vector< int > > g;
  vector< int > used, ord, low, parent;

  LowLink(size_t v) : g(v), used(v, 0), ord(v), low(v), uf(v), parent(v, -1) {}

  virtual void add_edge(int x, int y)
  {
    g[x].push_back(y);
    g[y].push_back(x);
  }

  void dfs(int idx, int &k, int par = -1)
  {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];

    for(auto &to : g[idx]) {
      if(!used[to]) {
        dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        parent[to] = idx;
        if(ord[idx] >= low[to]) uf.unite(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
  }

  void dfs()
  {
    int k = 0;
    for(int i = 0; i < g.size(); i++) {
      if(used[i]) continue;
      dfs(i, k);
    }
  }
};

struct BiConnectedComponents : LowLink
{
  vector< pair< int, int > > edges;
  vector< int > comp;

  BiConnectedComponents(size_t v) : LowLink(v), comp(v) {}

  void add_edge(int x, int y)
  {
    LowLink::add_edge(x, y);
    edges.push_back(minmax(x, y));
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  vector< pair< int, int > > build(vector< vector< int > > &t)
  {
    LowLink::dfs();
    int ptr = 0;
    vector< int > cc(g.size());
    for(int i = 0; i < g.size(); i++) {
      if(i == uf.find(i)) cc[i] = ptr++;
    }

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      comp[i] = cc[uf.find(i)];
    }
    vector< pair< int, int > > vs;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      vs.emplace_back(e.first, e.second);
      t[x].push_back(y);
      t[y].push_back(x);
    }
    sort(begin(vs), end(vs));
    return (vs);
  }
};

vector< vector< int > > g;
int sz[100000];
int dp[2][100000];

void dfs(int idx, int par)
{
  dp[0][idx] = 0;
  dp[1][idx] = sz[idx];
  for(auto &to : g[idx]) {
    if(to == par) continue;
    dfs(to, idx);
    dp[0][idx] += max(dp[0][to], dp[1][to]);
    dp[1][idx] += dp[0][to];
  }
}

int main()
{
  int N, M;
  scanf("%d %d", &N, &M);
  BiConnectedComponents graph(N);
  for(int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    graph.add_edge(a, b);
  }
  graph.build(g);

  for(int i = 0; i < N; i++) ++sz[graph[i]];
  int ret = 0;

  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < g.size(); i++) {
    if(~dp[0][i]) continue;
    dfs(i, -1);
    ret += max(dp[0][i], dp[1][i]);
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 18492
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEFINE
#include "../../DEBUG.hpp"
#endif

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  cout << s << '\n';
  return 0;
}



Measured memory_bytes: 3032
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 static int a_dist[];
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        int M = sc.nextInt();	
	        for(long i=0;i<N;i++)list.add(new ArrayList<Integer>());
	        long[][] a = new long[M][2];
	        for(long i=0;i<M;i++) {
	        	int ai = sc.nextInt()-1;
	        	int bi = sc.nextInt()-1;
	        	list.get(ai).add(bi);
	        	list.get(bi).add(ai);
	        }
	        long ans = 0;
	        boolean[] visited = new boolean[N];
			LinkedList<Integer> q= new LinkedList<Integer>();
			for(int i=0;i<N;i++) {
				if(visited[i]==true)continue;
				int cnt =1;
	        	visited[i]=true;
				q.add(i);
				q.add(-1);
				while(!q.isEmpty()) {
			    	int now=q.poll();
			        int parent=q.poll();
			    	for(int j=0;j<list.get(now).size();j++) {
			    		int next = list.get(now).get(j);
			    		if(next == parent)continue;			    		
			    		if(visited[next]==true)continue;
			    		visited[next]=true;
			    		cnt++;
			    		q.add(next);
			    		q.add(now);
			    	}
		    		
				}
				ans=Math.max(ans,cnt);
	        	
	        }
	        
	        System.out.println(ans);
		 }
		 
	}

Measured memory_bytes: 90968
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin>>n>>s;
  vector<int> a(26,0);
  for(int i=0;i<n;i++){
    a[s[i]-'a']++;
  }
  vector<int> b(n,0);
  int ans=0;
  for(int i=0;i<n;i++){
    b[s[i]-'a']++;
    a[s[i]-'a']--;
    int sum=0;
    for(int j=0;j<26;j++){
      if (a[j] > 0 && b[j] > 0) {
        sum++;
      }
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

ll N, a[200010];
int main() {
	scanf("%lld", &N);
	rep(i, 0, N) scanf("%lld", &a[i]);

	ll AllXor = a[0];
	rep(i, 1, N) AllXor ^= a[i];

	rep(i, 0, N) {
		printf("%lld", AllXor ^ a[i]);
		if(i != N-1) printf(" ");
	}
	printf("\n");
    return 0;
}


Measured memory_bytes: 4620
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(a), reverse=True)
for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Measured memory_bytes: 16484
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
        int N=sc.nextInt();
        int K=sc.nextInt();
        Integer[] p=new Integer[N];
		for( int i=0;i<N;i++){
          p[i]=sc.nextInt();
        }
        Arrays.sort(p);
        int syutu=0;
        for(int i=0;i<K;i++){
          syutu=syutu+p[i];
        }
        System.out.println(syutu);
}
}

Measured memory_bytes: 38952
from statistics import mean 
from math import ceil,floor 
n=int(input())
arr=[int(x) for x in input().split()]
a1=ceil(mean(arr))
a2=floor(mean(arr))
s1=0
s2=0
for i in range(n):
    s1+=((arr[i]-a1)**2)
    s2+=((arr[i]-a2)**2)

print(min(s1,s2))
    
    

Measured memory_bytes: 5128
#include "iostream"
#include "string.h"
using namespace std;
 
int main(){
 
  int A,B,C,K;
  int r;
  
  cin >> A >> B >> C >>K;
  
  r = K-A;
  
  if(r<=0) cout << K;
  else{
    
    r = r-B;
    
    if(r<=0) cout << A;
    else{
      cout << A-r;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


void gen(int left, string s, char mx) {
	if (left == 0) {
		cout << s << "\n";
		return;
	}
	for (char i = 'a'; i <= mx; i++) {
		gen(left - 1, s + i, (i == mx ? char(mx + 1) : mx));
	}
}


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	gen(n - 1, "a", 'b');
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int N,M,Q;
vector<int> Graph[110000];
vector<int> mx(110000);
vector<int> ans(110000);

struct q {
  int v;
  int d;
  int c;
};

void query(int v,int d,int c) {
  queue<P> que;
  que.push(make_pair(v,d));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.S < 0) {
      break;
    }
    if (mx[p.F] >= p.S) {
      continue;
    } else {
      mx[p.F] = p.S;
    }

    if (ans[p.F] == -1) {
      ans[p.F] = c;
    }
    
    for (int i = 0; i < (int)Graph[p.F].size(); i++) {
      int s = Graph[p.F][i];
      que.push(make_pair(s,p.S-1));
    }
  }
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  cin >> Q;
  vector<q> querys(Q);
  for (int i = 0; i < Q; i++) {
    cin >> querys[i].v >> querys[i].d >> querys[i].c;
    querys[i].v--;
  }
  reverse(querys.begin(),querys.end());
  for (int i = 0; i < N; i++) {
    mx[i] = -1; ans[i] = -1;
  }
  for (int i = 0; i < Q; i++) {
    query(querys[i].v,querys[i].d,querys[i].c);
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      cout << 0 << endl;
    } else {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 12280
#include <iostream>

using namespace std;
long long C(int n, int r) {
    if(n<r)
        return 0;
    if (n==r)
        return 1;
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
int main()
{
    int n,m;
    cin>>n>>m;
    cout<<C(n,2)+C(m,2);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int lint;
int n, x;
int ar[3005];
int mm[2005][2005];
lint ans = 1ll<<60;

int m(int a, int b)
{
    return mm[a][b];
}

int main()
{
    scanf("%d %d", &n, &x);
    for(int i=1;i<=n;i++)
    {
        scanf("%d", ar+i);
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(j==i)mm[i][j] = ar[j];
            else mm[i][j] = min(mm[i][j-1], ar[j]);
        }
    }

    for(int t=0;t<n;t++)
    {
        lint sum = 0;
        for(int i=1;i<=n;i++)
        {
            int d;
            if(i-t<1)d = min(m(1, i), m(n+i-t, n));
            else d = m(i-t, i);
            sum+=(lint)d;
        }
        sum+=(long long)t*(long long)x;
        if(ans>sum)ans = sum;
    }
    printf("%lld", ans);
    return 0;
}


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

#define int long long
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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

using P=pair<int,int>;
int h,w;
vector<string> maze;
int dist[25][25];

void bfs(int y, int x){
    rep(i,h)rep(j,w)dist[i][j]=-1;
    queue<P> que;
    dist[y][x]=0;
    que.push(P(y,x));
    while(!que.empty()){
        int y=que.front().first;
        int x=que.front().second;
        que.pop();
        rep(i,4){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&maze[ny][nx]=='.'&&dist[ny][nx]==-1){
                que.push(P(ny,nx));
                dist[ny][nx]=dist[y][x]+1;
            }
        }

    }
}

signed main(){
    cin >> h >> w;
    maze.resize(h);
    rep(i,h) cin >> maze[i];
    //rep(i,h)rep(j,w)dist[i][j]=0;
    int res=0;
    rep(i,h){
        rep(j,w){
            if(maze[i][j]=='#') continue;
            bfs(i,j);
            rep(k,h){
                rep(l,w){
                    chmax(res,dist[k][l]);
                }
            }
        }
    }
    cout<<res<<endl;
}

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

int main(){
	int N;
	char yohou[4];
	char real[4];
	
	cin >> yohou;

	cin >> real;
	
	int cnt = 0;
	for(int i = 0; i < 3; i++){
		if (yohou[i] == real[i]) cnt++;
	}
	cout << cnt << endl;
}

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

using namespace std;

int main()
{
    int N,M;
    cin>>N>>M;
    vector<int> Z(M,0);
    for(int i = 0;i <N ;i++){
        int K;
        cin>>K;
         for(int a = 0;a < K;a++){
             int A;
             cin>>A;
             Z[A-1]++;
        }
    }
    int s=0;
    for(int W = 0;W < M;W++){
        if(Z[W]==N){
            s++;
  }
        }
    cout<<s<<endl;
    return 0;

}


Measured memory_bytes: 256
N=int(input())
words={}
for i in range(N):
  c = input()
  if c not in words:
    words[c]=1
  else:
    words[c]+=1
M=int(input())
for i in range(M):
  c = input()
  if c not in words:
    words[c]=-1
  else:
    words[c]-=1
print(max(0,max(list(words.values()))))

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
typedef pair<int,int> P;

int main(){
  int n,m,h,k;
  while(cin>>n>>m>>h>>k,n){
    vector<int> s(n);
    vector<P> stc(m);
    REP(i,n)cin>>s[i];
    REP(i,m){
      int a,b;
      cin>>a>>b;
      stc[i] = P(b,a-1);
    }
    sort(stc.begin(),stc.end());
    int memo[100000][2];
    int now[100000];
    int point[1000];
    REP(i,n)now[i] = i;
    REP(i,m){
      memo[i][0] = now[stc[i].second];
      memo[i][1] = now[stc[i].second+1];
      swap(now[stc[i].second], now[stc[i].second+1]);
    }
    int fstans = 0;
    int subans = 0;
    REP(i,n)point[now[i]] = s[i];
    REP(i,k)fstans+=point[i];
    REP(i,m){
      if(memo[i][0]<k&&memo[i][1]>=k){
        subans = min(subans, -point[memo[i][0]]+point[memo[i][1]]);
      }
      if(memo[i][1]<k&&memo[i][0]>=k){
        subans = min(subans, -point[memo[i][1]]+point[memo[i][0]]);
      }
    }
    cout<<fstans+subans<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

vector<mint> factorials;

int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    factorials.resize(h + w);
    factorials[0] = 1;
    for (int i = 1; i < (h + w); i++) {
        factorials[i] = factorials[i - 1] * i;
    }

    ll top_height = h - a - 1;

    vector<mint> under(w);
    for (ll i = 0; i < w; i++) {
        under[i] = (factorials[top_height + i]) / factorials[top_height] / factorials[i];
    }

    vector<mint> top(w);
    ll under_height = a - 1;
    for (ll i = 0; i < w; i++) {
        ll index = w - 1 - i;
        top[i] = factorials[index + under_height] / factorials[index] / factorials[under_height];
    }


    mint ans = 0;
    for (ll i = b; i < w; i++) {
        mint now = top[i] * under[i];
        ans += now;
    }

    cout << ans.x << endl;


}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a, LL n, int m) {LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x; }
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet

#define N 10009

int main() {
	char s[11];
	int n, inAB = 0, B_A = 0, B_x = 0, x_A = 0;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%s", s);
		int l = strlen(s);
		rep(j, l - 1)if (s[j] == 'A' && s[j + 1] == 'B')inAB++;
		if (s[0] == 'B' && s[l - 1] == 'A')B_A++;
		else if (s[0] == 'B' && s[l - 1] != 'A')B_x++;
		else if (s[0] != 'B' && s[l - 1] == 'A')x_A++;
	}
	//書いてみた結果
	if (B_A) {
		inAB += B_A + mi(B_x, x_A);
		if (B_x + x_A == 0)inAB--;
	}
	else inAB += mi(B_x, x_A);

	printf("%d\n", inAB);
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0,d=0;
    int i;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='R')
            c++;
        else
            d++;
    }
    if(c>d)
    {
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (W, H, x, y) = readLine()!!.split(" ").map { it.toDouble() }

    val hasMultipleAnswer = if (x * 2 == W && y * 2 == H) 1 else 0

    println("${W * H / 2.0} $hasMultipleAnswer")
}


Measured memory_bytes: 37872
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static int queryCount=0;
    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        int N=scanner.nextInt();
        int K=scanner.nextInt();
        int[] ints=new int[N];
        int[] counts=new int[N];
        for(int i=0;i<N;i++){
            ints[i]=scanner.nextInt();
            counts[ints[i]-1]++;
        }
        int kind=0;
        for(int i=0;i<N;i++){
            if(counts[i]>0) kind++;
        }
        int[] n_1=new int[kind];
        int index=0;
        for(int i=0;i<counts.length;i++){
            if(counts[i]>0){
                n_1[index]=counts[i];
                index++;
            }
        }
        Arrays.sort(n_1);
        int result=0;
        for(int i=0;i<n_1.length;i++){
            if(kind<=K)break;
            result+=n_1[i];
            kind--;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 70620
#include<bits/stdc++.h>
using namespace std;
int main()
{
	cin.tie(0); 	
	cout.tie(0); 
	ios::sync_with_stdio(false);
	int n; 
	cin >> n;
	int nums[n];
	int four=0,two=0,one=0;
	for(int i = 0; i < n; i++)
	{
		cin >> nums[i];
		if(nums[i] % 4 == 0){
			four++;
		} else if(nums[i] % 2 == 0){
			two++;
		} else{
			one++;
		}
	 } 
	
	if(one>four+1||one==four+1&&two!=0)
	{
		cout << "No";
	}
	else
	cout << "Yes";
	
	return 0;		
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int a, b, q;
  cin >> a >> b >> q;
  vl s(a), t(b);
  rep (i, a) cin >> s[i];
  rep (i, b) cin >> t[i];
  sort(all(s));
  sort(all(t));
  while (q--) {
    ll x;
    cin >> x;
    ll rs = INF, rt = INF, ls = -INF, lt = -INF;
    auto itr = upper_bound(all(s), x);
    if (itr != s.begin()) {
      itr--;
      ls = *itr;
    }
    itr = upper_bound(all(t), x);
    if (itr != t.begin()) {
      itr--;
      lt = *itr;
    }
    itr = lower_bound(all(s), x);
    if (itr != s.end()) {
      rs = *itr;
    }
    itr = lower_bound(all(t), x);
    if (itr != t.end()) {
      rt = *itr;
    }
    //DEBUG(rs);DEBUG(rt); DEBUG(ls); DEBUG(lt);
    //DEBUG(x);
    ll ans = INF;
    chmin(ans, max(rs, rt) - x);
    chmin(ans, x - min(ls, lt));
    chmin(ans, rs - x + rs - lt);
    chmin(ans, rt - x + rt - ls);
    chmin(ans, x - ls + rt - ls);
    chmin(ans, x - lt + rs - lt);
    cout << ans << endl;
  }
}


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

#define REP(i, n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 1e9

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

typedef long long ll;

using namespace std;


int main(int argc, char const *argv[])
{
    int N;
    int A, B;
    cin >> N;

    if (N > 1)
    {
      cin >> A;
      cin >> B;
      cout << A + B << endl;
    }
    else
    {
      cout << "Hello World" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <numeric>
#include <tuple>
#include <type_traits>

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), Tp const&>::type x) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), Tp const&>::type x) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(size, make_vector<Tp, N-1>(sizes, x));
}
}  // detail::*

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

constexpr intmax_t mod = 1e9+7;

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  char buf[131072];
  scanf("%s", buf);
  std::string L = buf;

  size_t N = L.length();
  auto dp = make_vector<intmax_t>({N+1, 2_zu}, 0);
  dp[0][1] = 1;
  for (size_t i = 0; i < N; ++i) {
    for (size_t j = 0; j <= 1; ++j) {
      // j for tightness
      for (int d = '0'; d <= '1'; ++d) {
        // d for digits
        if (j && L[i] < d) continue;
        size_t nj = j && (d == L[i]);
        if (d == '0') {
          (dp[i+1][nj] += dp[i][j]) %= mod;  // 00
        } else {
          (dp[i+1][nj] += 2 * dp[i][j]) %= mod;  // 10, 01
        }
      }
    }
  }

  intmax_t res = (dp[N][0] + dp[N][1]) % mod;
  printf("%jd\n", res);
}


Measured memory_bytes: 5888
object Main extends App {
  val scanner = new java.util.Scanner(System.in)
  
  val inputs = Iterator.continually {
    val cards = scanner.next()
    if(cards != "-") {
      val m = scanner.nextInt()
      val hs = (1 to m).map(_ => scanner.nextInt())

      (cards, m, hs)
    } else ("-", 0, Nil)   
  }.takeWhile(_._1 != "-")

  val outputs = inputs.map {
    case (cards, _, hs) =>
      hs.foldLeft(cards) { (acc, h) =>
        val (top, bot) = acc.splitAt(h)
        bot ++ top
      }
  }

  outputs.foreach(println)
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif

const int MAXN = 100;
//#define int long long
const int INF = 1e9;

int gcd(int a, int b){
	while (b){
		a %= b;
		swap(a, b);
	}
	return a;
}

int cnt[1000100];

void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int g = a[0];
	for (int i = 1; i < n; i++) g = gcd(g, a[i]);
	//cout << g << '\n';

	for (int i = 0; i < n; i++) cnt[a[i]]++;

	int f = 0;
	for (int i = 2; i < 1000100; i++){
		int c = 0;
		for (int j = i; j < 1000100; j += i){
			c += cnt[j];
		}
		if (c > 1) f = 1;
		if (f) break;
	}

	if (!f){
		cout << "pairwise coprime\n";
	} else if (g == 1) {
		cout << "setwise coprime\n";
	} else {
		cout << "not coprime\n";
	}
}

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

		solve();

    return 0;
}


Measured memory_bytes: 11064