akhauriyash/Code-Regression huggingface dataset:
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
int t,n,m,k,x,y,w;
signed main(){
	fastio;
	cin>>n;
	cout<<(n-2)*180<<ln;
	return 0;
}

Measured memory_bytes: 256
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 102
ans = 0
for i in range(-1,200):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a > abs(X - i):
    a = abs(X - i)
    ans = i
print(ans)

Measured memory_bytes: 62204
#include<string>
#include<iostream>
#include<list>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}



Measured memory_bytes: 34440
#include <iostream>
#include <cstdint>

int main() {
	int64_t n, m;
	std::cin >> n >> m;

	if (n == 1 && m == 1)
		std::cout << 1 << std::endl;
	else if (n == 1 || m == 1)
		std::cout << n * m - 2 << std::endl;
	else if (n == 2 || m == 2)
		std::cout << 0 << std::endl;
	else
		std::cout << n * m - m * 2 - n * 2 + 4 << std::endl;
}

Measured memory_bytes: 256
def shakutori(a):
    left =0
    right = 0
    su = 0
    su1 = 0
    ans = 0
    for left in range(len(a)):
        while right<len(a) and su+a[right]==su1^a[right]:
            su +=a[right]
            su1 = su1^a[right]
            right +=1
        ans+=right -left
        if left==right:
            right+=1
        else:
            su -=a[left]
            su1 ^= a[left]
    return ans
N = int(input())
A = [int(x) for x in input().split()]
print(shakutori(A))

Measured memory_bytes: 23560
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int64_t calc(const vector<pair<int64_t, int64_t>>& v,
             vector<pair<int64_t, int64_t>>& vy,
             vector<pair<int64_t, int64_t>>& vx) {
    int64_t x = 0, y = 0;

    for (auto xy : v) {
        x += xy.first;
        y += xy.second;
    }

    sort(vy.begin(), vy.end(), [](const auto& xy0, const auto& xy1) {
        return xy0.second * xy1.first < xy1.second * xy0.first;
    });
    sort(vx.begin(), vx.end(), [](const auto& xy0, const auto& xy1) {
        return xy0.second * xy1.first > xy1.second * xy0.first;
    });

    int64_t dist = x * x + y * y;

    int64_t dx2 = 0, dy2 = 0;
    for (const auto& xy1 : vx) {
        dx2 -= xy1.first;
        dy2 += xy1.second;

        int64_t tmp_dist = (x + dx2) * (x + dx2) + (y + dy2) * (y + dy2);
        if (dist < tmp_dist) {
            dist = tmp_dist;
        }
    }

    int64_t dx = 0, dy = 0;
    for (const auto& xy0 : vy) {
        dx += xy0.first;
        dy -= xy0.second;

        int64_t tmp_dist0 = (x + dx) * (x + dx) + (y + dy) * (y + dy);
        if (dist < tmp_dist0) {
            dist = tmp_dist0;
        }

        int64_t dx2 = dx, dy2 = dy;
        for (const auto& xy1 : vx) {
            dx2 -= xy1.first;
            dy2 += xy1.second;

            int64_t tmp_dist = (x + dx2) * (x + dx2) + (y + dy2) * (y + dy2);
            if (dist < tmp_dist) {
                dist = tmp_dist;
            }
        }
    }

    return dist;
}

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

    vector<pair<int64_t, int64_t>> pp, pn, np, nn;
    for (auto i : irange(0L, n)) {
        int64_t x, y;
        cin >> x >> y;

        if (x == 0 && y == 0) {
            continue;
        }

        if (x >= 0) {
            if (y >= 0) {
                pp.emplace_back(x, y);
            } else {
                pn.emplace_back(x, -y);
            }
        } else {
            if (y >= 0) {
                np.emplace_back(-x, y);
            } else {
                nn.emplace_back(-x, -y);
            }
        }
    }

    int64_t dist = 0;
    dist = max(dist, calc(pp, pn, np));
    cerr << dist << endl;
    dist = max(dist, calc(pn, pp, nn));
    cerr << dist << endl;
    dist = max(dist, calc(np, nn, pp));
    cerr << dist << endl;
    dist = max(dist, calc(nn, np, pn));

    cout << setprecision(15) << sqrt(dist) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll N = n;
  ll p = sqrt(n);
  p += 1000000;
  vector<int> v(0);
  int j = 0;
  for (int i = 2; i <= p; i++) {
    bool f = 1;
    while (n%i==0) {
      n/=i;
      if (f) {
        v.push_back(1);
        f = 0;
      }
      else v[j]++;
    }
    if (!f) j++;
  }
  int m = v.size();
  if (m==0 && n != 1) v.push_back(1);
  if (n != 1 && n != N) v.push_back(1);
  m = v.size();
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    ll j = 1;
    while (v[i] >= j) {
      v[i] -= j;
      sum++;
      j++;
    }
  }
  printf("%lld", sum);
}


Measured memory_bytes: 3788
import math


def value(x_list, kaijo):

    num_list = list(range(len(x_list)+1))

    result = 1
    count = len(x_list)
    for x in x_list:
        kaijo /= count
        count -= 1
        target_value = num_list[x] - 1
        result += target_value * kaijo

        new_list = [0]*(len(x_list)+1)

        for i, num in enumerate(num_list):
            if num > target_value:
                new_list[i] = num-1
            else:
                new_list[i] = num

        num_list = new_list

    return int(result)


N = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))

kaijo = math.factorial(N)

p_value = value(p_list, kaijo)
q_value = value(q_list, kaijo)
print(abs(p_value-q_value))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll ans = a[0];
    if(n % 2 == 1) {
        FOR(i,1,(n-2)/2) {
            ans += a[i]*2;
        }
        ans += a[(n-2)/2+1];
    } else {
        FOR(i,1,(n-2)/2) {
            ans += a[i]*2;
        }
    }
    cout << ans << endl;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> dd;
  vector<int> cc;
  vector<int> mm;

  rep(i,n){
    if(s[i] == 'D') dd.push_back(i);
    if(s[i] == 'M') mm.push_back(i);
    if(s[i] == 'C') cc.push_back(i);
  }

  ll mSum[n];
  memset(mSum,0,sizeof(mSum));
  if(s[0] == 'M') mSum[0]++;
  FOR(i,1,n){
    if(s[i] == 'M') mSum[i] = mSum[i-1] + 1;
    else mSum[i] = mSum[i-1];
  }

  ll cSum[n];
  memset(cSum,0,sizeof(cSum));
  rep(i,n){
    if(s[i] == 'C') cSum[i] ++;
    if(i-1 >= 0) cSum[i] += cSum[i-1];
  }

  ll mcSum[n];
  memset(mcSum,0,sizeof(mcSum));
  rep(i,n){
    if(s[i] == 'C') mcSum[i] = mSum[i];
  }

  FOR(i,1,n){
    mcSum[i] += mcSum[i-1];
  }

  int q;
  cin >> q;
  rep(_,q){
    int k;
    cin >> k;
    ll ans = 0;
    for(int l: dd){
      auto itrR = lower_bound(all(cc), l+k);
      if(itrR == cc.begin()){
        continue;
      }
      int r = *(itrR - 1);
      ll ccnt = cSum[r];
      if(l - 1 >= 0) ccnt -= cSum[l-1];
      ans += mcSum[r] - mcSum[l] - ccnt * mSum[l];
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 30100
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<unordered_map>
#include<assert.h>
#include<time.h>
#include<stdlib.h>
#include<random>
#include<queue>
using namespace std;
using lld = long long int;
using pll = pair<lld, lld>;
using lf = double;
using pff = pair<lf, lf>;
using pif = pair<int, lf>;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using piii = pair<int, pii>;
#define M 1000000007
lld ncr[2009][2009];
int n;
void inil() {
	for (int i = 0; i <= 2008; i++) {
		ncr[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % M;
		}
	}
}
int main() {
	inil();
	int i, j, k, l;
	int t = 1, tv = 0;
	//scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		lld res = 0;
		for (i = 1; n - 2 * i - 1 >= i - 1; i++) {
			res = (res + ncr[n - 2 * i - 1][i - 1]) % M;
		}
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 24516
n = gets.to_i
a = n.times.map{gets.split.map(&:to_i)}
dp = Array.new(n+1).map{Array.new(3,0)}
for i in 0..n-1
    for j in 0..2
        for k in 0..2
            next if j == k
            dp[i+1][j] = dp[i][k] if dp[i+1][j] < dp[i][k]
        end
        dp[i+1][j] += a[i][j]
    end
end
p dp[n].max

Measured memory_bytes: 14716
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times {|i|yield(i)}                    end
def repl(st,en,n=1);       n*= -1 if st>en;st.step(en,n){|i|yield(i)} end

pl = Hash.new
pl['a'] = gc
pl['b'] = gc
pl['c'] = gc
turn = 'a'
loop{
break	if pl[turn].empty?
turn = pl[turn].shift
}

puts turn.upcase

Measured memory_bytes: 2044
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    string S;
    cin >> S;
    bool flag=true;
    FOR(i,1,S.length()){
        REP(j,i){
            if(S[j]==S[i]){
                flag = false;
                break;
            }else{
                flag = true&&flag;
            }
        }
    }
    if(flag){
        cout << "yes";
    }else{
        cout << "no";
    }
}

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

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

    string s, t;
    cin >> s >> t;

    int ss = s.size();
    int ts = t.size();
    if (ss == 0 || ts == 0) return 0;

    int dp[ss][ts];
    memset(dp, 0, sizeof dp);
    dp[0][0] = (s[0] == t[0]) ? 1 : 0;
    for (int i = 0; i < ss; i++) {
        for (int j = 0; j < ts; j++) {
            if (i == 0 && j == 0) continue;
            if (s[i] == t[j]) dp[i][j] = 1;
            if (i > 0 && j > 0) dp[i][j] += dp[i - 1][j - 1];
            if (i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
        }
    }

    int a = dp[ss - 1][ts - 1];
    char ans[a + 1];
    ans[a] = '\0';

    int i = ss - 1;
    int j = ts - 1;
    while (a > 0) {
        if (i > 0 && dp[i - 1][j] == dp[i][j]) {
            i--;
            continue;
        }
        if (j > 0 && dp[i][j - 1] == dp[i][j]) {
            j--;
            continue;
        }
        a--;
        ans[a] = s[i];
        i--;
        j--;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vector<pll> adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b;
ll a;
ll ans=0;
bool colour[100005];

void addedge(ll u, ll v,ll w)

	{
		adj[u].push_back(make_pair(v,w));
		adj[v].push_back(make_pair(u,w));
	}

void dfs(ll node)
	{
		//cout<<node<<endl;
		mark[node]=1;

		for(auto i=adj[node].begin();i<adj[node].end();i++)
		{	
			ll	v = i->first; 
        	ll  w = i->second;
			
			if(!mark[v])
				{	
					if(w%2==0)
					colour[v]=colour[node];
					
					else
					{	if(colour[node]==0)
						colour[v]=1;
						else
							colour[v]==0;
					}
					dfs(v);
				}			

			}
	}
	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
ll n;
cin>>n;
ll u,v,w;

for(ll i=1;i<=n;i++)
{
cin>>u>>v>>w;
addedge(u,v,w);
}

colour[1]=0;
dfs(1);

for(ll i=1;i<=n;i++)
{
	cout<<colour[i]<<" ";
}
cout<<endl;



}		





Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<string>w(8);string t;cin>>t;
  w.at(0)="a";w.at(1)="SAT";w.at(2)="FRI";w.at(3)="THU";w.at(4)="WED";w.at(5)="TUE";w.at(6)="MON";w.at(7)="SUN";
  for(int i=1;i<8;i++){if(w.at(i)==t)cout<<i<<endl;}
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



signed main(){

	int N, K;
	cin >> N >> K;
	int bit[42] = { 0 };
	int A[123456];
	for (int i = 0; i < N; i++) cin >> A[i];

	for (int b = 0; b < 42; b++){
		for (int i = 0; i < N; i++)
			if (A[i] & (1LL << b)) bit[b]++;
	}

	int X = 0;
	for (int b = 41; b >= 0; b--){
		if (bit[b] < N/2.0){
			// Xのbit目は1にすべき
			if ((X|(1LL << b)) <= K){
				cerr << b << endl;
				X = X|(1LL << b);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++){
		ans += X^A[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	const char* wall="####################";
	int n , b[1000] , f[1000] , r[1000] , v[1000];
	int p[3][10][4]={0,0,0};
	cin>>n;
	for(int i=0 ; i<n ; i++){
		cin>>b[i]>>f[i]>>r[i]>>v[i];
		p[f[i]-1][r[i]-1][b[i]-1]+=v[i]; //floor room building
	}
	for(int i=0 ; i<4 ; i++){
		for(int j=0 ; j<3 ; j++){
			for(int k=0 ; k<9 ; k++){
				cout << " " <<p[j][k][i];
			}
			//if(i==3 && j==2){
			//	cout << " " <<p[2][9][3];
			//} else {
				cout << " " <<p[j][9][i] << endl;
			//}
		}
		if(i!=3){
		cout << wall << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let x: usize = input();
    let a: Vec<usize> = (0..m).map(|_| input()).collect();

    let mut v = vec![0; n + 2];
    for i in 1..n + 2 {
        v[i] = v[i - 1];
        if a.contains(&i) {
            v[i] += 1;
        }
    }

    println!("{}", std::cmp::min(v[x], v[n + 1] - v[x]));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
int main(){
   int x,y;
   cin>>x>>y;
   if(y%2==1||y<2*x||y>4*x) cout<<"No";
   else cout<<"Yes";
   
    return 0;
    
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int ans = 0;
  int MIN;
  rep(i, p.size()) {
    MIN = p[0];
    for (int j = 1; j < p.size(); ++j) MIN = min(MIN, p[j]);
    if (p[i] == MIN) {
      ans += p[i];
      p.erase(p.begin() + i);
      i = -1;
      if (p.size() == n - k) break;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
 
int main(){
	int i,p;
	int f[100];
	int n;
	cin>>n;
	for(i=0;i<n;i++){
	cin>>f[i];}
	for(p=0;p<n-1;p++){
	cout<<f[n-p-1]<<" ";}
	cout<<f[0]<<endl;
    return 0;
    }


Measured memory_bytes: 1160
#include <cstdio>

using namespace std;

typedef unsigned long long ll;

ll count(ll a, ll m){
	ll c = 1;
	ll x = a;
	while(x != 1){
		x = (a * x) % m;
		++c;
	}
	return c;
}

ll gcd(ll a, ll b){
	ll c;
	while(b){
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}

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

int main(){
	int a1, a2, a3, m1, m2, m3;
	ll c1, c2, c3;
	while(scanf("%d %d %d %d %d %d", &a1, &m1, &a2, &m2, &a3, &m3)){
		if(!a1) break;
		c1 = c2 = c3 = 0;
		a1 = a1 % m1;
		a2 = a2 % m2;
		a3 = a3 % m3;
		c1 = count(a1, m1);
		c2 = count(a2, m2);
		c3 = count(a3, m3);
		printf("%lld\n", lcm(lcm(c1, c2), c3));
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(3);
    rep(i, 3) cin >> d[i];
    vector<P> q;
    string s;
    int a, b;
    rep(i, n)
    {
        cin >> s;
        if (s == "AB")
            a = 0, b = 1;
        if (s == "AC")
            a = 0, b = 2;
        if (s == "BC")
            a = 1, b = 2;
        q.push_back(P(a, b));
    }
    q.push_back(P(0, 1));
    string ans;
    auto add = [&](int a, int b) {
        d[a]++;
        d[b]--;
        ans += 'A' + a;
    };

    rep(i, n)
    {
        int a = q[i].first;
        int b = q[i].second;
        if (!d[a] && !d[b])
        {
            cout << "No" << endl;
            return 0;
        }
        if (!d[a])
        {
            add(a, b);
        }
        else if (!d[b])
        {
            add(b, a);
        }
        else
        {
            int na = q[i + 1].first;
            int nb = q[i + 1].second;
            if (a == na || a == nb)
            {
                add(a, b);
            }
            else
            {
                add(b, a);
            }
        }
    }
    cout << "Yes" << endl;
    rep(i, n)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4328
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

signed main() {
    int T;
    cin >> T;

    int ret = 1;

    for (int i = 0; i < T; i++) {
        int t;
        cin >> t;
        ret = lcm(ret, t);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
import math
  
def prime(num):
  if num==1 or num==2 or num==3:
    return True
  for i in range(2,int(math.sqrt(num))+1):
    if num%i==0:
      return False
  else:
    return True
  
n=int(input())
ans=0
for i in range(n):
  tmp=int(input())
  if prime(tmp):
    ans+=1
print(ans)


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

	int x;
	cin>>x;
	int y=100;

	int a = 0;
	while(y<x) {
		y*=(1.01);
		a++;
	}

	cout<<a;



	return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[100001];
	rep1(i, N) A[i] = getint();
	bool iketa = 0;
	int ima = A[1];
	A[1] = 0;
	int kazu = 1;
	while (ima) {
		if (ima == 2) {
			iketa = 1;
			break;
		}
		int k = A[ima];
		A[ima] = 0;
		ima = k;
		kazu++;
	}

	if (iketa) printf("%d", kazu);
	else printf("-1");


	Would you please return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  
  vector<int> B(N);
  for(int i=0;i<N;i++){
    B[A[i]-1]=i+1;
  }
  
  for(int i=0;i<N;i++){
    cout<<B[i]<<" "<<endl;
  }
}

Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int h = sc.nextInt();
        int w = sc.nextInt();
 
        char s[][] = new char[h+2][w+2];
        for (int i = 1; i <= h; i++) {
        	String str = sc.next();
			for (int j = 1; j <= w; j++) {
				s[i][j] = str.charAt(j - 1);
			}
		}
 
        
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                int count = 0;
                if (s[i][j] == '#') {
                    System.out.print('#');
                    continue;
                }
 
                if (s[i-1][j-1] == '#') count++;
                if (s[i][j-1] == '#') count++;
                if (s[i+1][j-1] == '#') count++;
                if (s[i-1][j] == '#') count++;
                if (s[i+1][j] == '#') count++;
                if (s[i-1][j+1] == '#') count++;
                if (s[i][j+1] == '#') count++;
                if (s[i+1][j+1] == '#') count++;
                System.out.print(count);
            }
            System.out.println();
        }
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;

    ll n = b-a;
    cout << (1+n)*n/2 - b << endl;
    return 0;
}

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

int main()
{
	std::vector<long> Dat = {};
	int t = 0;
	std::cin >> t;
	for (int i = 0; i<t; i++)
	{
		int tmp = 0;
		std::cin >> tmp;
		Dat.push_back(tmp);
	}
	long min=*Dat.begin(),max=-2E9;
	for (auto cur = Dat.begin()+1; cur != Dat.end() ; cur++)
	{
		if (*(cur - 1) < min)min = *(cur - 1);
		if (*cur - min > max)max = *cur - min;
	}
	std::cout << max<<std::endl;
	return 0;
}

Measured memory_bytes: 4780
def decide(num):
    q = ""
    if num[-1] in map(str, {2, 4, 5, 7, 9}):
        q = "hon"
    if num[-1] in map(str, {0, 1, 6, 8}):
        q = "pon"
    if num[-1] == "3":
        q = "bon"
    return q
num = input()
print(decide(num))




Measured memory_bytes: 9124
#include<stdio.h>
int main(void)
{
        char c[10];
        int i;
        for(i=0;i<10;i++) scanf("%c",&c[i]);
        c[3]='8';
        for(i=0;i<10;i++) printf("%c",c[i]);
        printf("\n");
        return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

vector<vector<int>> G;
int N,M;
int dp[100010];

int rec(int v){
    if(dp[v] != -1) return dp[v];
    int res = 0;
    for(auto next : G[v]){
        res = max(res,rec(next) + 1);
    }
    return dp[v] = res;
}

int main(){
   cin >> N >> M;
   G.resize(N);
   rep(i,N){
       dp[i] = -1;
   }
   rep(i,M){
       int x,y;
       cin >> x >> y;
       x--; y--;
       G[x].push_back(y);
   }
   int res = 0;
   rep(i,N){
       res = max(res,rec(i));
   }
   cout << res << endl;
}



Measured memory_bytes: 8192
/*input

*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>
#include <random>

using namespace std; 

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int const MOD = 998244353;

struct seg {
	int l, r;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	ll n, x, m;
	cin >> n >> x >> m;
	x%=m;
	vector<int> v;
	set<int> seen;
	ll ans=0;
	rep(i, n) {
		if(seen.find(x)!=seen.end()) break;
		ans+=x;
		seen.insert(x);
		v.push_back(x);
		x=(x*x)%m;
	}
	vector<ll> cyc;
	repm(i, v.size()-1, -1) {
		if(v[i]==x) {
			cyc.push_back(v[i]);
			break;
		}
		cyc.push_back(v[i]);
	}
	reverse(all(cyc));
	vector<ll> pre;
	pre.push_back(cyc[0]);
	repl(i, 1, cyc.size()) pre.push_back(pre.back()+cyc[i]);
	ll left = n-v.size();
	ans+=(left/pre.size())*pre.back();
	if(left%pre.size()) ans+=pre[left%pre.size()-1];
	cout << ans;
	return 0;	
}
// 787 788 789 790 791 792

Measured memory_bytes: 6736
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m,k = map(int,input().split())
uf = UnionFind(n)
data = [0]*n
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    uf.union(a,b)
    data[a] += 1
    data[b] += 1
for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    if uf.same(c,d):
        data[c] += 1
        data[d] += 1
print(*[uf.size(i)-data[i]-1 for i in range(n)])

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((0 <= x - r && x + r <= W) && (0 <= y - r && y + r <= H))
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include<stdio.h>

int f(int x){
  int i,m;
  i=2;
  m=1;
  while(i*i<=x){
    if(x%i==0){
      m=0;
    }
    i++;
  }
  return m;
}

int main(void){
  int X;
  scanf("%d",&X);
  
  while(f(X)==0){
    X++;
  }
  
  printf("%d",X);
  
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    vector<int> b(n);
    rep(i, n)
    {
        int cnt_b = 0;
        int number = a.at(i);
        while (number % 2 == 0)
        {
            cnt_b++;
            number /= 2;
        }
        b.at(i) = cnt_b;
    }

    cout << accumulate(b.begin(), b.end(), 0) << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m, count, sum = 0, ch = 0;
	llint s, a, aa, aaa, rr = 0, gg = 0, bb = 0;
	bool check = false;

	vector<llint> r, g, b;
	char c;
	cin >> a>>aa;
	if (a >= 13)cout << aa << endl;
	else if (a > 5)cout << aa / 2 << endl;
	else cout << 0 << endl;
	please AC;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  int ans = 0;
  rep(i,n-1){
    map<char, int> right, left;
    rep(j,n){
      if(j <= i){
        right[s[j]]++;
      }
      else{
        left[s[j]]++;
      }
    }
    
    int common = 0;
    rep(j,26){
      char tmp = 'a' + j;
      if(right[tmp] && left[tmp]){
        common++;
      }
    }

    ans = max(ans, common);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import fractions as fr

N,M=[int(i) for i in input().split()]
S=input()
T=input()
Slist=list(S)
Tlist=list(T)
ans=0
GCD=0

if M==N:
    if S==T:
        ans=len(S)
    else:
        ans=-1
else:
    GCD=fr.gcd(N,M)
    if GCD==1:
        if Slist[0]==Tlist[0]:
            ans=int(N*M/GCD)
        else:
            ans=-1
    else:
        LCM=int(N*M/GCD)
        a=int(LCM/N)
        b=int(LCM/M)
        LCM2=int(a*b/fr.gcd(a,b))
        f=0
        for i in range(int(LCM/LCM2)):
            if Slist[i*b]!=Tlist[i*a]:
                f+=1
                break
        if f==0:
            ans=LCM
        else:
            ans=-1
print(ans)

Measured memory_bytes: 6628
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main(){
  string s;
  cin >> s;
  int s_1,s_2;
  string answer;
  s_1 = atoi(s.substr(0,2).c_str());
  s_2 = atoi(s.substr(2,2).c_str());
  if (0 < s_1 && s_1 < 13){
    if (0 < s_2 && s_2 < 13) answer = "AMBIGUOUS";
    else answer = "MMYY";
  }
  else if(0 < s_2 && s_2 < 13) answer = "YYMM";
  else answer = "NA";
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(n);
	for(int i=0;i<n;i++)
	a[i]=in();
	multiset<int> s;
	reverse(all(a));
	s.insert(a[0]);int x;
	for(int i=1;i<n;i++)
	{
		x=a[i];
		auto it=s.upper_bound(x);
		if(it==s.end())s.insert(x);
		else
		{
			s.insert(x);s.erase(it);
		}
	}
	cout<<s.size();
}

Measured memory_bytes: 8712
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

int main(){
	int n;
	cin >> n;
	cout << (n+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var ABC = readLine()!!.split(" ").map(String::toInt)

    if (ABC[0] == ABC[1] && ABC[1] == ABC[2]) {
        println(0)
        return
    }

    val oddCount = ABC.count { it % 2 == 1 }

    var count = 0
    if (oddCount == 1 || oddCount == 2) {
        count++
    }
    ABC = ABC.map {
        if (oddCount == 1 && it % 2 == 0) {
            it + 1
        } else if (oddCount == 2 && it % 2 == 1) {
            it + 1
        } else {
            it
        }
    }

    var array = ABC.toIntArray()
    while (true) {
        if (array[0] == array[1] && array[1] == array[2]) {
            println(count)
            return
        }
        array[array.indexOfFirst { it == array.min() }] += 2
        count++
    }

}




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

using namespace std;

int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    a += b;
    c += d;
    if (a == c) {
        cout << "Balanced" << endl;
    }
    else if (a > c) {
        cout << "Left" << endl;
    }
    else {
        cout << "Right" << endl;
    }

    return (0);
}


Measured memory_bytes: 256
n = int(input())
s = input()
cnt = 0
cnt_start = 0
for i in range(n):
    if '(' in s[n-i-1]:
        if cnt > 0:
            cnt -= 1
        else:
            cnt_start += 1
    else:
        cnt += 1
for i in range(cnt_start):
    s = s+')'
for j in range(cnt):
    s = '('+s
print(s)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)

int di[4] = {-1, 0, 1, 0};
int dj[4] = { 0, 1, 0,-1};

int d[4] = {1, 0, -1, 2};

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        char mat[h][w];
        for(int i = 0; i < h*w; i++)    cin >> mat[i/w][i%w];
        int people = 0;
        vector<vector<int>> v(h, vector<int>(w, -1));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(mat[i][j]=='N')  people++, mat[i][j]='.', v[i][j] = 0;
                if(mat[i][j]=='E')  people++, mat[i][j]='.', v[i][j] = 1;
                if(mat[i][j]=='S')  people++, mat[i][j]='.', v[i][j] = 2;
                if(mat[i][j]=='W')  people++, mat[i][j]='.', v[i][j] = 3;
            }
        }
        int tim = 0;
        while(++tim <= 180){
            vector<vector<int>> next(h, vector<int>(w, -1));

            // change direction
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(v[i][j] == -1)   continue;
                    for(int k = 0; k < 4; k++){
                        int dir = (v[i][j]+d[k]+4)%4;   // change direction(try)
                        int ni = i+di[dir], nj = j+dj[dir]; // move forward(try)
                        if(inRange(ni,0,h)&&inRange(nj,0,w)&&v[ni][nj]==-1&&mat[ni][nj]!='#'){
                            v[i][j] = dir;  // change direction(decide!)
                            break;
                        }
                    }
                }
            }
            
            // move
            for(int k = 3; k >= 0; k--){
                for(int i = 0; i < h; i++){
                    for(int j = 0; j < w; j++){
                        if(v[i][j] != k)    continue;
                        int ni = i + di[k], nj = j + dj[k];
                        if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]!='#'&&v[ni][nj]==-1&&next[ni][nj]==-1){
                            next[ni][nj] = v[i][j];
                            v[i][j] = -2;
                            continue;
                        }
                    }
                }
            }

            // move(stupid)
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(v[i][j] != -1 && v[i][j] != -2)   next[i][j] = v[i][j];
                }
            }
            
            // vanish
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(mat[i][j]=='X'&&next[i][j]!=-1){
                        next[i][j] = -1;
                        people--;
                    }
                }
            }
            
            v = next;
            if(people == 0) break;
        }

        if(tim > 180)   cout << "NA" << endl;
        else            cout << tim << endl;
    }
    return 0;
}



Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
class slime {
public:
	int color, height;
};
signed main() {
	int N; cin >> N; vector<int>v(N + 1, 0); rep(i, 1, N + 1)cin >> v[i];
	sort(all(v));
	vector<int>sum(v); rep(i, 1, N + 1)sum[i] += sum[i - 1];
	int ans(1);

	for (int i = N - 1; 1 <= i; i--) {
		if (v[i+1] <= sum[i] * 2)ans++;
		else break;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1792
#import math
 
def factorization(n):
    arr = []
    temp = n
    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
            arr.append([i, cnt])

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

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

    return arr



N=int(input())
if N==1:
  print(0)
  exit(0)
c=0
p=factorization(N)
#print(p)
for i in range(len(p)):
    r=1
    s=0
    while 1:
        s+=r
        if p[i][1]>=s:
            N/=pow(p[i][0],r)
            #print(N)
            c+=1
            r+=1
        else:
            break
            
print(c)

Measured memory_bytes: 9500
#include "bits/stdc++.h"

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

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

	vector<ll> number;

	ll days;
	cin >> days;

	number.push_back(100);
	int cont = 1;
	while(number.back() < days){
		number.push_back(number.back() + number.back() / 100);
	}

	cout << (int)number.size() - 1 << endl;

	

	return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define pb(x) push_back(x)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;
const int mx=5e3+10;
int arr[mx][5];
ll ans[mx];
int main()
{
	int n;
	cin>>n;
	loop(i,1,n-1)cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	ans[n]=0;
	for(int i=n-1;i>0;i--)
	{
        ll ak=arr[i][0]+arr[i][1];
        for(int j=i+1;j<n;j++)
        {
            if(ak<=arr[j][1])
            {
                ak=ans[j];
                break;
            }
            else if((ak-arr[j][1])%arr[j][2])
            {
                ak+=(arr[j][2]-((ak-arr[j][1])%arr[j][2]));
                ak+=arr[j][0];
            }
            else ak+=arr[j][0];
        }
        ans[i]=ak;
        //cout<<ak<<endl;
	}
	loop(i,1,n)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

s = itertools.permutations(range(1, n+1))
l = []
for v in s:
    l.append(v)
p_index = l.index(p)
q_index = l.index(q)
print(abs(p_index - q_index))


Measured memory_bytes: 13940