akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main(){
	int N;
	
	while(cin >> N, N){
		vector<pair<int, int> > a;
		a.push_back(make_pair(0, 0));
		
		for(int i = 0; i < N - 1; i++){
			int n, d;
			cin >> n >> d;
			switch(d){
			case 0:
			a.push_back(make_pair(a[n].first - 1, a[n].second));
			break;

			case 1:
			a.push_back(make_pair(a[n].first, a[n].second - 1));
			break;

			case 2:
			a.push_back(make_pair(a[n].first + 1, a[n].second));
			break;

			case 3:
			a.push_back(make_pair(a[n].first, a[n].second + 1));
			break;
			}
		}
		int minx = 0, maxx = 0, miny = 0, maxy = 0;
		for(int i = 0; i < a.size(); i++){
			if(minx > a[i].first) minx = a[i].first;
			if(maxx < a[i].first) maxx = a[i].first;
			if(miny > a[i].second) miny = a[i].second;
			if(maxy < a[i].second) maxy = a[i].second;
		}
		cout << maxx - minx + 1 << " " << maxy - miny + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 100000000000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[200020][2] = {};

const ll MAX = 200030;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}


signed main()
{
  COMinit();
  
  ll n;
  cin >> n;
  string s;
  cin >> s;

  dp[0][0] = 1;

  ll nofk = 0;

  for (int i = 1; i <= 2*n; i++)
  {

    if (s.at(i - 1) == 'B') //odd
    {
      dp[i][0] = 0;

      if (nofk%2==0)
      { //前偶数
        dp[i][1] = dp[i - 1][1]+dp[i-1][0];
        nofk++;
      }
      else
      {
        dp[i][1] = ((dp[i - 1][1]+dp[i-1][0])%mod) * nofk;
        nofk--;
      }
    }
    else //even
    {
      dp[i][1] = 0;

      if (nofk%2==1)
      { 
        dp[i][0] = dp[i - 1][1]+dp[i-1][0];
        nofk++;
      }
      else{
        dp[i][0] = ((dp[i - 1][1]+dp[i-1][0])%mod) * nofk;
        nofk--;

      }
    }

    dp[i][0]%=mod;
    dp[i][1]%=mod;
    //cout<<i<<":"<<dp[i][0]<<":"<<dp[i][1]<<":"<<nofk<<endl;

    if(nofk<0 || (nofk!=0 && i==2*n)){
      cout<<0<<endl;
      return 0;
    }
  }

  cout << ((dp[2 * n][1]%mod)*(fac[n]%mod))%mod << endl;
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    string S; cin >> S;
    if (S[0] == 'S') cout << "Cloudy" << endl;
    if (S[0] == 'C') cout << "Rainy" << endl;
    if (S[0] == 'R') cout << "Sunny" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

// https://yamakasa.net/atcoder-abc-130-c/
// http://drken1215.hatenablog.com/entry/2019/06/17/003300

int main(void) {

    ll w,h,x,y;
    cin >> w >> h >> x >> y;

    // double mid_x = w/2, mid_y = h/2;
    double area = (double)w*h/2;

    short check = 0;

//   if (w % 2 == 1 || h % 2 == 1) {
//    check = 0;
//   } else 
    // if (((double)x == mid_x && (double)y == mid_y)||((double)y == mid_x && (double)x == mid_y)) {
    if ((2*x == w && 2*y == h)||( 2*y == w && 2*x == h)) {
        check = 1;
    }

    cout << area << " " << check << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

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

    ll N,M; cin >> N >> M;
    vel A(N); rep(i,N) cin >> A[i];
    ve_vel D(M, vel(2)); rep(i,M) cin >> D[i][1] >> D[i][0];

    sort(rall(A)); sort(rall(D));

    int cnt = 0;
    int ia = 0;
    int id = 0;
    ll ans = 0LL;
    while(cnt < N) {
        if(id >= M) { cnt++; ans += A[ia]; ia++; }

        else if(ia >= N) {
            if( N - cnt < D[id][1]) {cnt = N; ans += (N - cnt) * D[id][0]; }
            else { cnt += D[id][1]; ans += D[id][0] * D[id][1]; id++; }
        }

        else if(A[ia] >= D[id][0]) { cnt++; ans += A[ia]; ia++; }

        else {
            if( N - cnt < D[id][1]) { ans += (N - cnt) * D[id][0]; cnt = N; }
            else { cnt += D[id][1]; ans += D[id][0] * D[id][1]; id++; }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
from collections import Counter
n,p=map(int,input().split())
s=input()

ans=0
if p==2 or p==5:
    for i,j in enumerate(s):
        if int(j)%p==0:
            ans +=i+1
else:
    num,point=0,1
    A=[0]
    for i in s[::-1]:
        num +=int(i)*point
        num %=p
        A.append(num)
        point *=10
        point %=p

    A=Counter(A)
    for i,j in A.items():
        if j>=2:ans +=j*(j-1)//2
print(ans)

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

int main() {
  int N;
  cin >> N;
  
  if (N % 1111 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N - N % 10) % 1110 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	long long n; cin >> n;
	long long ret = 0;
	for (int i = 1; (long long)i * i <= n; i++) if (n % i == 0) {
		long long a = i, b = n / i;
		if (a < b) swap(a, b);
		a--;
		if (a > b) ret += a;
	}
	cout << ret << "\n";
	
	return 0;
}


Measured memory_bytes: 384
class FenwickTree
    def initialize(n)
        @data = Array.new(n){0}
    end
    def add(i, x)
        i += 1
        while i <= @data.size
            @data[i - 1] += x
            i += i & -i
        end
    end
    def sum(r)
        s = 0
        while r > 0
            s += @data[r - 1]
            r -= r & -r
        end
        s
    end
end 

N,Q=gets.split.map(&:to_i)
ft=FenwickTree.new(N)
A=gets.split.map(&:to_i)
N.times{|i|
	ft.add(i, A[i])
}
Q.times{
	q,a,b=gets.split.map(&:to_i)
	case q
	when 0
		ft.add(a, b)
	when 1
		puts ft.sum(b)-ft.sum(a)
	end
}


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

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

    int k, a, b;
    cin >> k >> a >> b;
    int lst=b/k*k;
    if (lst>=a) {
        cout << "OK";
    }
    else {
        cout << "NG";
    }

    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main (void){
    int x;
    int y;
    int W;
    int H;
    int r;
    
    
    
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if (0<= x-r && x+r<=W && 0<=y-r && y+r<=H ){
        printf("Yes\n");
    }
    else{printf("No\n");
    
    }
    
    return 0;
}

Measured memory_bytes: 584
# https://atcoder.jp/contests/abc142/tasks/abc142_d

A, B = map(int, input().split())

# 素因数分解　何個あるかどうかを返却
def factrization(n, B):
    table = []  # 素因数を格納する
    temp = n    # nを素因数で割っていった値を一時的に格納する
    value = 0

    for i in range(2, int(n**0.5//1) + 1):
        if temp % i == 0:
            cnt = 0

            while temp % i == 0:
                cnt += 1
                temp //= i

            table.append([i, cnt])

            if B % i == 0:
                value += 1


    if temp != 1:
        table.append([temp, 1])

        if B % temp == 0:
            value += 1

    if temp == []:
        table.append([n, 1])

        if B % n == 0:
            value += 1

    return value


value = factrization(A, B)

print(value + 1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
char s[10];
int main(void)
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int a=0; int b=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='A') a++;
		else b++;
	}
	if(a&&b) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[101][100002];
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    int n; cin>>n;
    ll W; cin>>W;
    ll wei[n+1],val[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>wei[i]>>val[i];
    }
    for(int i=0;i<=n;i++)
    {
        for(ll w=0;w<=W;w++)
        {
            if(w==0 || i==0) dp[i][w] = 0;
            else if(wei[i-1] <= w){
                dp[i][w] = max(dp[i-1][w-wei[i-1]] + val[i-1],dp[i-1][w]);
            }
            else dp[i][w] = dp[i-1][w];
        }
    }
    cout<<dp[n][W]<<endl;
    return 0;
}


Measured memory_bytes: 79232
import math
import re

n = int(raw_input())
v = raw_input().split()
c = raw_input().split()
#s = list(raw_input())

cnt = 0
for i in v:
    v[cnt] = int(i)
    cnt += 1

cnt = 0
for i in c:
    c[cnt] = int(i)
    cnt += 1

total = 0
for i in range(n):
    if v[i] - c[i] > 0:
        total += v[i] - c[i]

print total

Measured memory_bytes: 2568
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;
int n, k, r, s, p;

int main(){
    FASTIO
    
    cin >> n >> k >> r >> s >> p;
    string a;
    cin >> a;
    vector<int> v(n, 0);
    rep(i, 0, n){
    	if(a[i] == 'r')
    		v[i] = p;
    	else if(a[i] == 'p')
    		v[i] = s;
    	else
    		v[i] = r;
	}
	rep(i, k, n){
		if(a[i] == a[i-k]){
			v[i] = 0;
			a[i] = '#';
		}
	}
	int ans = 0;
	rep(i, 0, n){
		ans += v[i];
	}
	cout << ans;
}


Measured memory_bytes: 848
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y, a, b, c = map(int, input().split())
    pqr = []
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    for i in range(a):
        pqr.append([p[i], 1])
    for i in range(b):
        pqr.append([q[i], 2])
    for i in range(c):
        pqr.append([r[i], 0])
    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0
    for v, k in pqr:
        if k == 1 and c_a < x:
            ans += v
            c_a += 1
        elif k == 2 and c_b < y:
            ans += v
            c_b += 1
        elif k == 0 and c_a + c_b + c_c < x + y:
            ans += v
            c_c += 1
        if c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 96280
#include<bits/stdc++.h>
#define ll long long int
using namespace std;


int main(){
	
	string s;
	cin>>s;
	unordered_map<char,int>mp;
	unordered_map<char,vector<pair<int,int>>>store;
	int n=s.size();
	int st,ed,flag=0;
	for(int i=0;i<n;i++){
		mp[s[i]]++;
		store[s[i]].push_back({i,mp[s[i]]});
	}
	for(auto x:store){
		
		if((int)x.second.size()>=2){
			//cout<<x.first<<endl;
			
			int temp_sz=0;
			int cnt=0;
			int i=0,j=1,sz=(int)x.second.size();
			while(j<sz){
				int temp;
				temp_sz=x.second[j].first-x.second[i].first+1;
				temp=temp_sz/2;
				cnt=x.second[j].second;
				if(i>0){
					cnt-=x.second[i-1].second;
				}
				if(cnt>temp){
					flag=1;
					st=x.second[i].first,ed=x.second[j].first;
				}
				i++;
				j++;
				if(flag){
					break;
				}
			}
			
		}
		if(flag){
					break;
				}
	}
	if(flag==0){
		cout<<"-1 -1\n";
	}
	else{
		cout<<st+1<<" "<<ed+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 4872
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    boolean isOk = false;
    for(int i=1; i<=9; i++){
      if( N%i == 0 && String.valueOf(N/i).length() == 1){
        isOk = true;
        break;
      }
    }
    if(isOk){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int H,N,dp[10001],A[1000],B[1000];
    cin >> H>>N;
    rep(i,N){
      cin>>A[i]>>B[i];
    }
    for(int i=1;i<=H;i++){
      dp[i]=INT_MAX;
      rep(j,N){
        dp[i]=min(dp[i],dp[max(0,i-A[j])]+B[j]);
        //cout<<"i:"<<i<<" dp[i]:"<<dp[i]<<" j:"<<j<<" max(0,i-A[j]):"<<max(0,i-A[j])<<endl;
      }
    }
    cout << dp[H] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for(int i = 0; i < N;i++)cin >> X[i] >> Y[i];
    int wa = abs(X[0])+abs(Y[0]);
    for(int i = 0; i < N;i++){
        if(wa%2 != (abs(X[i])+abs(Y[i]))%2){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<ll> d;

    for(int s = 32;s >= 0;s--){
        d.push_back(bit(s));
    }
    if((X[0]+Y[0])%2 == 0){
        d.push_back(1);
    }
    cout << d.size() << endl;
    rep(i,d.size()){
        cout << d[i] << " ";
    }
    cout << endl;
    for(int i = 0; i < N; i++){
        string ans = "";
        ll u = X[i] + Y[i];
        ll v = X[i] - Y[i];
        ll nx = 0;
        ll ny = 0;
        for(int j = 0; j < d.size();j++){
            //目的地まで+にしたい
            if(nx <= u){
                nx += d[j];
                if(ny <= v){
                    ny += d[j];
                    ans.push_back('R');
                }
                else{
                    ny -= d[j];
                    ans.push_back('U');
                }
            }
            else{
                nx -= d[j];
                if(ny <= v){
                    ny += d[j];
                    ans.push_back('D');
                }
                else{
                    ny -= d[j];
                    ans.push_back('L');
                }
            }
        }
        ll mx = 0;
        ll my = 0;
        for(int i = 0; i < d.size();i++){
            if(ans[i] == 'R')mx += d[i];
            if(ans[i] == 'L')mx -= d[i];
            if(ans[i] == 'U')my += d[i];
            if(ans[i] == 'D')my -= d[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        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 count = 0;
        for (int i = 0 ; i < n ; i++) {
            if (a[a[i] - 1] - 1 == i) {
                count++;
            }
        }
        System.out.println(count/2);
    }

}

Measured memory_bytes: 50940
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
struct vertex{
    int words, prefixes;
    unordered_map<int, vertex *> m;
    vertex(){
        words = prefixes = 0;
    }
};

int l;
struct Trie{
    vertex * head;
    const int d;
    Trie(): d(97){ 
        head = new vertex();
    }

    void add(const string& w, int i = 0, vertex * v = NULL){
        if(i == 0){
            v = head;
        }
        if(i == w.length()){
            (v -> words)++;
            (v -> prefixes)++;
            return;
        }
        (v -> prefixes)++;
        if(v->m[w[i] - d] == NULL){
            v-> m[w[i] - d] = new vertex;
        }
        add(w,i+1, v -> m[w[i] - d]);
    }

    int countPrefixes(const string& w, int i = 0, vertex * v = NULL){
        if(i == 0)v = head;
        if(i == w.length()) return v->prefixes;
        else if(v->m[w[i] - d] == NULL) return 0;
        else return countPrefixes(w, i +1, v -> m[w[i] - d]);
    }

    int val(int depth, vertex * v = NULL){
        if(depth == 0)v = head;
        if(depth == l+1)return 0;
        if(v == NULL){
            int temp = l - depth; 
            int ans = 1;
            while((temp & 1) == 1){
                temp /= 2;
                ans *= 2;
            }
            return ans;
        } 
        int ans= 0;
        if(v-> m['0' - d] == NULL && v->m['1' - d] == NULL)return 0;
        for(char i = '0'; i <= '1'; i++){
            ans ^= val(depth + 1, v-> m[i - d]);
        }
        return ans;
    }
};

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

    int n; cin >> n >> l;
    Trie t;
    string s;

    FOR(i, n){
        cin >> s;
        t.add(s);
    }
    if(t.val(0)){
        cout << "Alice" << endl; 
    }else{
        cout << "Bob" << endl;
    }

}




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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

#define MAX_V 100010
#define MAX_LOG_V 20

vector<int> edge[MAX_V];
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

struct LCA{
  int root;

  LCA(int r): root(r){}

  void add_edge(int a, int b) {
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  
  void dfs(int v, int par, int dep) {
    parent[0][v] = par;
    depth[v] = dep;
    for (auto child : edge[v]) {
      if (child != par) dfs(child, v, dep + 1);
    }
  }

  void init(int V) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
	if (parent[k][v] < 0) {
	  parent[k+1][v] = -1;
	} else {
	  parent[k+1][v] = parent[k][parent[k][v]];
	}
      }
    }
  }

  int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
	v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
	u = parent[k][u];
	v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

int main() {
  int N;
  LCA lca(0);
  
  scanf("%d", &N);
  REP(i, N) {
    int k;
    scanf("%d", &k);
    REP(j, k) {
      int c;
      scanf("%d", &c);
      lca.add_edge(i, c);
    }
  }
  lca.init(N);
  int Q;
  scanf("%d", &Q);
  REP(i, Q) {
    int u, v;
    scanf("%d %d", &u, &v);
    printf("%d\n", lca.lca(u, v));
  }
  return 0;
}

Measured memory_bytes: 19820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<int> queries(q);
	for(int i = 0; i < q; ++i){ cin >> queries[i]; }
	for(const int k : queries){
		ll d = 0, m = 0, dm = 0, answer = 0;
		for(int i = 0; i < n; ++i){
			if(i - k >= 0){
				if(s[i - k] == 'D'){
					dm -= m;
					d  -= 1;
				}else if(s[i - k] == 'M'){
					m  -= 1;
				}
			}
			if(s[i] == 'D'){
				d  += 1;
			}else if(s[i] == 'M'){
				dm += d;
				m  += 1;
			}else if(s[i] == 'C'){
				answer += dm;
			}
		}
		cout << answer << endl;
	}
	return 0;
}



Measured memory_bytes: 1948
#include<iostream>

using namespace std;

int main( )
{
	int a[102][102] = { {0} } ;
	int n, m, l;
	int i, j, k;

	cin>>n>>m>>l;

	for( int i=0; i<n; i++ ) {
		for( int j=0; j<m; j++ ) {
			cin>>a[i][j];
		}
	}
	int b[102][102] = { {0} } ;
	for( i=0; i<m; i++ ) {
		for( j=0; j<l; j++ ) {
			cin>>b[i][j];
		}
	}

	long long c[102][102] = { {0} } ;	
	for( i=0; i<n; i++ ) {
		for( j=0; j<l; j++ ) {
			for( k=0; k<m; k++ ) {
				c[i][j] += a[i][k]*b[k][j];
			}
		}
	}

	for( i=0; i<n; i++ ) {
		for( j=0; j<l-1; j++ ) {
			cout<<c[i][j]<<" ";
		}
		cout<<c[i][j]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin>>a.at(i);
	}
	long long int  ans=0;
	for(int i=1; i<n; i++){
		if(a.at(i)<a.at(i-1)){
			ans+=a.at(i-1)-a.at(i);
			a.at(i)=a.at(i-1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n;
  cin >> n;
  vector<int> cnt(10001, 0);

  for (int x = 1; x <= 500; x++) {
    for (int y = 1; y <= 500; y++) {
      for (int z = 1; z <= 500; z++) {

        int now = x * x + y * y + z * z + x * y + y * z + z * x;

        if (now <= 10000) cnt[now]++;


      }
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
} 

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

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;
const int F = 26;

int n;
vector<int> c(F);
vector<vector<int>> a;

void init() {
    cin >> n;
    a.resize(n, vector<int>(F));
    for(int i = 0; i < F; i++)cin >> c[i];
    for(int i = 0; i < n; i++)for(int j = 0; j < F; j++)cin >> a[i][j];
}

int main()
{
    init();
    for(int i = 0; i < n; i++)cout << max_element(a[i].begin(), a[i].end()) - a[i].begin() + 1 << endl;
}

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

int main(){
    int W,a,b;
    cin>>W>>a>>b;
    int ans=a<b?b-a-W:a-b-W;
    if(ans<0){
        cout<<"0"<<endl;
    }else{
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int w, h, x, y, r;

	scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);

	if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VVI = vector<vector<int>>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  int N;
  cin >> N;
  vector<double> A(N);
  rep(i,N) cin >> A[i];

  double den {0};
  double num {1};
  rep(i,N) {
    double c {1};
    rep(j,N) {
      if (i==j) continue;
      c *= A[j];
    }
    den += c;
    num *= A[i];
  }
  double answer = num/den;
  cout << fixed << answer << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,s;
deque<pair<ll,ll> >vec;
ll rec(){
	if(vec.empty()) return 0LL;
	int sz = vec.size();
	if(vec[0].sc >= vec[sz-1].sc){
		vec[0].sc += vec[sz-1].sc;
		ll pos = vec[sz-1].fi;
		vec.pop_back();
		sz--;
		if(vec[0].fi > s){
			return pos-s;
		}
		else if(vec[sz-1].fi < s){
			return s-vec[0].fi-vec[0].fi+pos;
		}
		else{
			if(vec[0].sc >= vec[sz-1].sc){
				ll cst = pos-vec[sz-1].fi;
				ll ans = rec();
				return ans+cst;
			}
			else{
				ll cst = pos-vec[0].fi;
				ll ans = rec();
				return ans+cst;
			}
		}
	}
	else{
		vec[sz-1].sc += vec[0].sc;
		ll pos = vec[0].fi;
		vec.pop_front();
		sz--;
		if(vec[sz-1].fi < s){
			return s-pos;
		}
		else if(vec[0].fi > s){
			return vec[sz-1].fi-s-pos+vec[sz-1].fi;
		}
		else{
			if(vec[0].sc >= vec[sz-1].sc){
				ll cst = vec[sz-1].fi-pos;
				ll ans = rec();
				return ans+cst;
			}
			else{
				ll cst = vec[0].fi-pos;
				ll ans = rec();
				return ans+cst;
			}
		}
	}
}
int main(){
	cin>>n>>s;
	rep(i,n){
		int x,p ; cin>>x>>p;
		vec.pb(pair<ll,ll>(x,p));
	}
	if(vec[0].fi > s){
		cout<<vec[n-1].fi-s<<endl;
		return 0;
	}
	if(vec[n-1].fi < s){
		cout<<s-vec[0].fi<<endl;
		return 0;
	}
	ll ans = rec();
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include<stdio.h>

int main(){
  int n,m,c,sum;
  int a[20][20];
  int b[20];
  int count=0;
  
  scanf("%d%d%d",&n,&m,&c);
  
  for(int k=0; k<m;k++)
    scanf("%d",&b[k]);
    
  for(int j=0;j<n;j++){
    sum=c;
  for(int i=0;i<m;i++){
    scanf("%d",&a[j][i]);
   sum+=a[j][i]*b[i];
  }
    if(sum>0)
      count++;
  }
  
  printf("%d",count);
  
  
  return 0;
}


Measured memory_bytes: 128
import heapq

T = int(input())

for _ in range(T):
    N = int(input())
    List = []
    ans = 0
    
    for _ in range(N):
        K, L, R = map(int,input().split())
        ans += min(L, R)
        List.append((K, L, R))
    
    S1 = []
    S2 = []
    
    List.sort()
    
    for i in range(N):
        K, L, R = List[i]
        if L-R > 0:
            heapq.heappush(S1, L-R)
        if K < len(S1):
            heapq.heappop(S1)
    
    for i in range(N):
        K, L, R = List[N-i-1]
        K = N - K
        
        if R-L > 0:
            heapq.heappush(S2, R-L)
        if K < len(S2):
            heapq.heappop(S2)
    
    ans += sum(S1) + sum(S2)
    
    print(ans)

Measured memory_bytes: 46248
public class Hello{
    public static void Main(){
        int N = int.Parse(System.Console.ReadLine());
        string[] s = System.Console.ReadLine().Split(' ');
        int[] L = new int[N];
        int max = 0;
        int ans = 0;
        for(int i=0; i<N; i++){
            L[i] = int.Parse(s[i]);
            if(max < L[i]){
                max = L[i];
            }
            //System.Console.WriteLine(L[i]);
            ans += L[i];
            if(i == N-1){
                ans -= max;
                //System.Console.WriteLine(ans);
            }
        }
        
        if(max < ans){
            System.Console.WriteLine("Yes");
        }else{
            System.Console.WriteLine("No");
        }    
    }
}

Measured memory_bytes: 17708
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int a[101010];
int c[101010];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    for(int i=0;i<n;i++){
        int x = a[i];
        c[x-1]++;
        c[x]++;
        c[x+1]++;
    }

    int mx = 0;
    for(int i=0;i<=100001;i++){
        if (mx < c[i]){
            mx = c[i];
        }
    }
    printf("%d\n", mx);
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
int main(){
    int a,b;
    cin >> a >> b;
    if(b == 100) a *= 1000;
    else if(b >= 10) a *= 100;
    else a *= 10;
    double x = sqrt(a + b);
    int y = x;
    if(x == y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()


li cnt[55][26];

li res[26];

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		for (auto && c : s) {
			cnt[i][c - 'a']++;
		}
	}
	rep(j, 26) {
		res[j] = cnt[0][j];
	}
	repp(i, 1, n) {
		rep(j, 26) {
			res[j] = min(res[j], cnt[i][j]);
		}
	}

	rep(j, 26) {
		rep(k, res[j]) {
			cout << (char)('a' + j);
		}
	}
	cout << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    int a[n];
    int hist[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        hist[i] = 0;
    }

    int flag = 0, next = 1, cnt = 0;
    while (1) {
        next = a[next - 1];
        cnt++;

        if (hist[next - 1]) {
            break;
        }

        if (next == 2) {
            flag = 1;
            break;

        }
        hist[next - 1] = 1;
    }

    if (flag) {
        printf("%d\n", cnt);
    } else {
        printf("%d\n", -1);
    }

    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N, 0);
    vector<vector<int>> E(N);
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }
    vector<int> L(N, -1);
    L[0] = 0;
    stack<int> st;
    st.push(0);
    while(!st.empty()) {
        int i = st.top();
        st.pop();
        for(auto c: E[i]) {
            if(L[c] == -1) {
                L[c] = L[i] + 1;
                st.push(c);
            }
        }
    }


    for(int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        C[p] += x;
    }

    stack<pair<int, int>> sst;
    sst.push(make_pair(0, C[0]));

    while(!sst.empty()) {
        auto p = sst.top();
        int i = p.first, c = p.second;
        sst.pop();
        for(auto j: E[i]) {
            if(L[j] < L[i]) continue;
            C[j] += c;
            sst.push(make_pair(j, C[j]));
        }
    }
    for(auto x: C) {
        cout << x << endl;
    }
}

Measured memory_bytes: 17140
while 1:
	x=raw_input().split()
	op= x[1]
	a = int(x[0])
	b = int(x[2])

	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)

Measured memory_bytes: 6444
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int N = 2e5 + 1;
//ll int freq[100001];
ll int bigPower(ll int x, unsigned ll int y, ll int p)
{
    ll int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
void findAns()
{
    int n;
    cin >> n;

    int data[n];

    map<int, int> values;

    for (int i = 0; i < n; i++)
    {
        cin >> data[i];

        values[data[i]]++;
    }

    int size  = *max_element(data, data + n);

    bool exist[size + 1];

    memset(exist, true, sizeof(exist));

    for (auto x : values)
    {
        int c = x.first;
        for (int i = 2 * c; i <= size; i += c)
            exist[i] = false;
        if (x.second > 1) exist[c] = false;
    }
    int count = 0;

    // for (int i = 0; i < 25; i++) cout << exist[i] << " ";
    // cout << "\n";
    for (int i = 0; i < n; i++)
    {
        if (exist[data[i]] == true) count++;
    }
    cout << count << "\n";








}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
// #endif

    fastio;

    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();
}

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

int main(){
    ll N; cin >> N;
    vector<ll> c(100002, 0);
    rep(i, 0, N){
        ll a; cin >> a;
        c[a]++;
    }
    ll ans = c[0] + c[1];
    rep(i, 1, 100001){
        ans = max(ans, c[i-1] + c[i] + c[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var eve = (N / 2);
            Console.WriteLine(eve*(N-eve));
        }
    }

}


Measured memory_bytes: 13140
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){

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

	int64_t k;
	cin >> k;

	queue<int64_t> q;
	q.emplace(1);
	q.emplace(2);
	q.emplace(3);
	q.emplace(4);
	q.emplace(5);
	q.emplace(6);
	q.emplace(7);
	q.emplace(8);
	q.emplace(9);

	int64_t x;
	while(k--) {
		x = q.front();
		q.pop();
		if(x % 10) {
			q.emplace(10 * x + (x % 10) - 1);
		}
		q.emplace(10 * x + (x % 10));
		if(x % 10 != 9) {
			q.emplace(10 * x + (x % 10) + 1);
		}
	}

	cout << x << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vi odd, even;

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a; cin >> a;
		if(a % 2) odd.pb(a);
		else even.pb(a);
	}
	if(sz(odd) <= 2) {
		vector<int> ans;
		vector<int> ord;
		if(sz(odd) == 0) {
			ans.pb(1);
			rep(i, 0, sz(even)) {
				ord.pb(even[i]);
				ans.pb(even[i]);
			}
			ans[M]--;
		}
		else if(sz(odd) == 1) {
			ans.pb(1);
			rep(i, 0, sz(even)) {
				ord.pb(even[i]);
				ans.pb(even[i]);
			}
			ord.pb(odd[0]);
			if(odd[0] != 1) ans.pb(odd[0] - 1);
		}
		else {
			ans.pb(odd[0] + 1);
			ord.pb(odd[0]);
			rep(i, 0, sz(even)) {
				ord.pb(even[i]);
				ans.pb(even[i]);
			}
			ord.pb(odd[1]);
			if(odd[1] != 1) ans.pb(odd[1] - 1);
		}
		rep(i, 0, sz(ord)) {
			cout << ord[i] << " ";
		}
		cout << "\n";
		cout << sz(ans) << "\n";
		rep(i, 0, sz(ans)) {
			cout << ans[i] << " ";
		}
		cout << "\n";
	}
	else {
		cout << "Impossible\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int k, s;
    int counter = 0;
    cin >> k >> s;
    for (int x = 0; x <= k; x++){
        for (int y = 0; y <= k; y++){
            int z = s - x - y;
            if (0 <= z && z <= k) counter++;
        }
    }
    cout << counter << endl;
}

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


int main(){
    int N;
    cin >> N;
    deque<int> ans;
    for(int i = 0; i < N; i++){
        int a;
        scanf("%d", &a);
        if(i % 2){
            ans.push_back(a);
        }else{
            ans.push_front(a);
        }
    }
    for(int i = 0; i < N; i++){
        int j;
        if(N % 2){
            j = i;
        }else{
            j = N - 1 - i;
        }
        cout << (i?" ":"") << ans[j];
    }cout << endl;

    return 0;
}

Measured memory_bytes: 2944
// AtCoder.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>
#include <cmath>

using namespace std;

int main() {
    int r;
    cin >> r;
    cout << M_PI * r * 2 << endl;
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  
  ll ans = 0;
  for (ll i = 1; i <= n; i++){
    if (n % i == 0){
      ans += n / i - 1;
    }
    else 
      ans += n / i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    i32 N;
    cin >> N;
    Vec<i32> H(N);
    for (i32 i = 0; i < N; i++) cin >> H[i];
    Vec<bool> O(N, false);
    for (i32 i = 0; i < N - 1; i++) O[i] = (H[i] >= H[i + 1]);
    i32 max_v = 0;
    i32 sum = 0;
    for (i32 i = 0; i < N; i++) {
        if (i != N - 1 && O[i]) sum++;
        else {
            if (sum > max_v) max_v = sum;
            sum = 0;
        }
    }
    cout << max_v << endl;
}


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

namespace abc148
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            int[] ary = { 1, 2, 3 };
            var ans = ary.Where(w => w != a && w != b).ToArray();
            Console.WriteLine(ans[0]);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
typedef long long lo;
 
template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

namespace {
	int mo;
    inline int add(int x, int y) { x += y; return x >= mo ? x - mo : x; }
    inline int sub(int x, int y) { x -= y; return x < 0 ? x + mo : x; }
    inline int mul(int x, int y) { return (lo) x * y % mo; }
    inline int power(int a, int k = mo - 2) {
		int ans = 1;
		for (; k; k >>= 1, a = mul(a, a))
			if (k & 1) ans = mul(ans, a);
		return ans;
    }
	inline void U(int &x, int y) { x = add(x, y); } 
}

const int N = 3333;
int n, C[N][N], p2[N], dp[N][N];

inline int calc(int S) {
	int other = power(2, n - S);
	{
		int ans = 0;
		re0 (i, S + 1) U(ans, mul(power(other, i), dp[S][i]));
		return ans;
	}
	vector <int> dp(S + 1, 0);
	dp[0] = 1;
	for (int i = 1; i <= S; i++) {
		vector <int> new_dp(S + 1, 0);
		for (int j = 0; j <= S; j++)
			if (dp[j]) {
				U(new_dp[j], mul(j + 1, dp[j]));
				U(new_dp[j + 1], mul(other, dp[j]));
			}
		swap(dp, new_dp);
	}
	int ans = 0;
	for (int &i : dp) U(ans, i);
	return ans;
}

int main(void) {
	read(n); read(mo);
	re0 (i, n + 1) C[i][0] = 1;
	rep (i, n) rep (j, i) C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
	dp[0][0] = 1;
	rep (i, n) {
		re0 (j, i + 1) if (dp[i - 1][j]) {
			U(dp[i][j], mul(j + 1, dp[i - 1][j]));
			U(dp[i][j + 1], mul(1, dp[i - 1][j]));
		}
	}
	// cout << C[4][2] << "\n";
	p2[0] = 1;
	rep (i, n) p2[i] = (lo) p2[i - 1] * 2 % (mo - 1);
	int ans = 0;
	for (int S = 0; S <= n; S++) {
		int ways = calc(S);
		U(ans, mul(mul(C[n][S], S & 1 ? mo - 1 : 1), mul(power(2, p2[n - S]), ways)));
	}
	cout << ans << "\n";
}


Measured memory_bytes: 80768
from collections import Counter

N = int(input())
V = [int(i) for i in input().split()]
V1 = V[1::2]
V2 = V[0::2]

v1 = Counter(V1).most_common(2)
v2 = Counter(V2).most_common(2)

v1.append((0,0))
v2.append((0,0))


if v1[0][0] != v2[0][0]:
  print(N - v1[0][1] - v2[0][1])
  
else:
  print(min(N - v1[1][1] - v2[0][1], N - v1[0][1] - v2[1][1]))

Measured memory_bytes: 15972