akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 002_agc_b / Link: https://agc002.contest.atcoder.jp/tasks/agc002_b?lang=en  ----- */
/* ------問題------

N 個の箱があります。 箱は 1 から N まで番号が振られています。 最初、1 番目の箱には赤いボールが 1 個入っています。 また、2～N 番目の箱には白いボールが 1 個ずつ入っています。
高橋君は M 回の操作を順に行います。 i 回目の操作では、xi 番目の箱から適当なボールを 1 個選び、それを yi 番目の箱へ移します。
高橋君がすべての操作を終えた後、赤いボールが入っている可能性のある箱は何個か求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, M;

LL ans = 0LL;

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

	cin >> N >> M;
	VI red(N, 0);
	red[0] = 1;
	VI ball(N, 1);
	FOR(i, 0, M) {
		int a, b; cin >> a >> b; a--, b--;
		if (red[a]) {
			if (ball[a] == 1) {
				ans--;
				red[a] = 0;
			}
			if (red[b] == 0)ans++;
			red[b] = 1;
		}
		ball[a]--;
		ball[b]++;
	}
	cout << ans + 1 << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if(a <= 5)
		printf("0\n");
	else
		if(a <= 12)
			printf("%d\n", b/2);
		else
			printf("%d\n", b);

	return 0;
}

Measured memory_bytes: 128
n,m,k=map(int,input().split())
for x in range(n+m+1):
    for a in range(min(n+1,x+1)):
        if 0<=x-a<=m:
            num=a*m+(x-a)*(n-2*a)
            if k==num:
                print("Yes")
                exit()
print("No")


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

int main(){
  size_t n,k; cin>>n>>k;
  vector<int> v(n);
  for(auto&& vi:v){
    cin>>vi;
  }
  auto m=min(n,k);
  int ret=0;
  for(size_t a=0; a<=m; ++a){
    for(size_t b=0; b<=m-a; ++b){
      vector<int> u=v;
      u.erase(begin(u)+a, end(u)-b);
      sort(begin(u),end(u));
      for(size_t i=0; i<k-a-b; ++i){
        u[i]=max(u[i], 0);
      }
      ret=max(ret, accumulate(begin(u),end(u),0));
    }
  }
  cout<<ret<<'\n';
}


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

using namespace std;

int main(void) {
  int cnt[26] = {0};
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < str.size(); i++) {
      if (str[i] >= 'a' && str[i] <= 'z')
        cnt[str[i] - 'a']++;
      else if (str[i] >= 'A' && str[i] <= 'Z')
        cnt[str[i] - 'A']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << cnt[i] << endl;
  }
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
#define rep(i,n) for(int i = 0; i < n; i++)
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main(){
    int n; cin >> n;
    int l[n];
    
    rep(i,n){cin >> l[i];}
    sort(l,l+n);
    int sum = 0;
    rep(i,n-1){
        sum += l[i];
    }
    if(sum > l[n-1]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;

int main(){
    int n,d;
    cin >> n >> d;
    double x[n],y[n];
    double dis;
    for(int i=0;i<n;i++){
        
        cin >> x[i] >> y[i];
        
    }
    for(int i=0;i<n;i++){
        double xi=x[i],yi=y[i];
        dis= pow(xi*xi+yi*yi,0.5);
        if(dis<=d)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7612
#include <stdio.h>
#include <string.h>

int n;
char given_string[10000];

int main() {
  scanf("%d", &n);
  scanf("%s", given_string);
  int len = strlen(given_string);
  for (size_t i = 0; i < len; i++) {
    if (65 <= given_string[i] <= 90) {
      given_string[i] += n;
      if (given_string[i] > 90) given_string[i] -= 26;
    }
    printf("%c", given_string[i]);
  }
  printf("\n");
  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
#coding:utf-8
import numpy as np
from collections import Counter
import math
def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A = np.cumsum(A)
#print (A)
c = Counter(A)
ans = 0
for v in c.values():
    if (v>1):
        ans+= (nCr(v,2))
print (ans)

Measured memory_bytes: 38016
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main(){

    int N;
    cin >> N;

    vll A(N);
    ll mx = 0;
    ll cnt1 = 0;
    REP(i, N){
        cin >> A[i];
        chmax(mx, A[i]);
        if (A[i] == 1) cnt1++;
    }

    if(cnt1 == 1){
        cout << 1 << endl;
        return 0;
    } else if (cnt1 > 1){
        cout << 0 << endl;
        return 0;
    }

    vll B(mx + 1, 0);
    for(ll a: A){
        ll i = a;
        while(i <= mx){
            B[i]++;
            i += a;
        }
    }

    ll ans = 0;
    for(ll a: A){
        if(B[a] == 1) ans ++;
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 12732
from sys import stdin

input = stdin.readline

MAX_TIME = 10

N = int(input())

F = [[int(j) for j in input().split()] for i in range(N)]

P = [[int(j) for j in input().split()] for i in range(N)]


def main():
    ans = -11000000001

    # 営業時間帯 最低でも ひとつの時間帯
    # 選択パターン
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        # 他の店
        for j in range(N):
            # 各時間帯
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
int main(int argc, char const *argv[])
{
	int r,c;
	std::cin >> r >> c;
	std::vector<std::vector<int>> table(r+1,std::vector<int>(c+1,0));
	for(int i = 0 ; i < r ; i ++){
		for(int j = 0 ; j < c ; j ++){
			std::cin >>table[i][j] ;
		}
	}
	for(int i = 0 ; i < r ; i ++){
		for(int j = 0 ; j < c ; j ++){
			table[i][c] += table[i][j];
			table[r][j] += table[i][j];
		}
		table[r][c] += table[i][c];
	}
	for(int i = 0 ; i <= r ; i ++){
		for(int j = 0 ; j < c ; j ++){
			std::cout << table[i][j] << " ";
		}
		std::cout << table[i][c] << std::endl;
	}
	return 0;
}

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

int main()
{
    int S;
    cin >> S;
    int A = S / 100;
    int B = S % 100;
    if(1 <= A && A <= 12)
    {
        if(1 <= B && B <= 12)
        {
            cout << "AMBIGUOUS" << "\n";
        }
        else
        {
            cout << "MMYY" << "\n";
        }
    }
    else
    {
        if(1 <= B && B <= 12)
        {
            cout << "YYMM" << "\n";
        }
        else
        {
            cout << "NA" << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n, a[100011];
bitset<2000*2000 + 123> s;
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n;
	int sum = 0, mx = 0;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		sum += a[i];
		mx = max(mx, a[i]);
	}
	s[0] = 1;
	for(int i = 1; i <= n; i ++){
		s = (s | (s << (a[i])));
	}
	for(int i = sum / 2 + sum % 2; i <= sum; i ++){	
		if(s[i] == 1){
			cout << i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

using namespace std;
int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    bool tak = true;
    rep(i, k) {
        if(tak) {
            a = a / 2 * 2;
            b += a / 2;
            a /= 2;
        } else {
            b = b / 2 * 2;
            a += b / 2;
            b /= 2;
        }
        tak ^= 1;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a,b,c;cin>>a>>b;
  c=a+b;
  if(a%3==0||b%3==0||c%3==0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
}

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

const int maxn = 105, maxv = 1005;
const ll INF = 1e18;
int N, W;
int weight[maxn], val[maxn];
ll dp[maxn][maxv*maxn];

ll f(int i, int v) { //dp for min cost to obtain this value
    if (v < 0) return INF;
    if (i == N) {
        return v == 0 ? 0 : INF;
    }
    if (dp[i][v] != -1) return dp[i][v];
    return dp[i][v] = min(weight[i] + f(i+1,v-val[i]),f(i+1,v));            
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> weight[i] >> val[i];
    }
    memset(dp,-1,sizeof dp);
    int ans = 0;
    for (int v = 1; v <= N*1000; v++) {
        if (f(0,v) <= W) ans = v;
    }
    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 86784
#include<stdio.h>
int main(void){
	int a;
	int b;
	scanf("%d %d",&a,&b);
	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}
	
	return 0;
	}

Measured memory_bytes: 580
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int prime[55555],vis[56000];
int t;
void getprime(int maxn)
{
    for(int i=2;i<=maxn;i++)
    {
        bool flag=true;
        for(int j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                flag=false;
                break;
            }
        }
        if(flag)
        {
            prime[++t]=i;
            vis[i]=1;
        }
    }
    return ;
}
int ans[55555];
int main()
{
    t=0;
    memset(vis,0,sizeof vis);
    getprime(55555);
    int index=1;
    int n;
    cin>>n;
    for(int i=1;i<=55;i++)
    {
        while(prime[index]%5!=1)
            index++;
        ans[i]=prime[index];
        index++;
    }
    for(int i=1;i<=n;i++)
    {
        if(i==1) cout<<ans[i];
        else cout<<" "<<ans[i];
    }
    cout<<endl;
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];

  string res = "APPROVED";
  rep(i, N) {
    if (a[i] % 2 == 0 && a[i] % 3 && a[i] % 5) {
      res = "DENIED";
      break;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ld l;
	cin >> l;
	cout << fixed << setprecision(10) << pow(l / 3, 3) << endl;

	return 0;
}

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

int main(){
    ll n;   cin >> n;
    ll ans=1e+5;
    for(int i=1; i<=n/2; i++){
        ll b = n-i, a=i, sum=0;

        while(0<b){
            sum += b%10;
            b /= 10;
        }
        while(0<a){
            sum += a%10;
            a /= 10;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  int n, i;
  cin >> n;
  vector<int> A(1900);
  for(i=1; i<32; i++){
    A[i] = i*i;
  }
  for(i=2; i<11; i++){
    if(i==4) continue;
    if(i==9) continue;
    else A[i+32] = i*i*i;
  }
  A[43] = 32;
  A[44] = 243;
  A[45] =128;
  A[46] =512;
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  //rep(i, 1000) cout << A[i] << endl;
  rep(i, 1000){
    if(n>=A[i]) {
      cout << A[i] << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
newH=[(t-x*0.006,i) for i,x in enumerate(H)]
newH=sorted(newH)
from bisect import bisect_left, bisect_right
Ht=[newH[i][0] for i in range(n)]
Hi=[newH[i][1] for i in range(n)]
i=bisect_left(Ht, a)
if i==0:
    ans=Hi[0]+1
elif i==n:
    ans=Hi[n-1]+1
else:
    if abs(a-Ht[i-1])>abs(a-Ht[i]):
        ans=Hi[i]+1
    else:
        ans=Hi[i-1]+1
print(ans)

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

int main() {
	int n;
	cin >> n;
	set<int> a;
	for (size_t i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (a.count(x))a.erase(x);
		else a.insert(x);
	}
	cout << a.size() << endl;
}

Measured memory_bytes: 4864
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=1e6+5;
int a[N],b[N],c[N],fa[N],ok[2][N];
int n,m,q,g,z,P;
int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void merge(R int x,R int y){fa[find(y)]=find(x);}
inline int id(R int x,R int y,R int z){return x*6+(y<<1)+z;}
int main(){
//  freopen("testdata.in","r",stdin);
    n=read(),m=read(),q=read(),P=read();
    fp(i,1,m)a[i]=read(),b[i]=read(),c[i]=read(),g=__gcd(g,abs(c[i]-c[1]));
    !g?g=P:0,P=__gcd(P,3*g),z=c[1]%g;
    fp(i,0,n*6-1)fa[i]=i;
    fp(i,1,m){
        int u=a[i]-1,v=b[i]-1,w=(c[i]-z)/g%3;
        fp(x,0,2){
            merge(id(u,x,0),id(v,((x<<1)+w)%3,1)),
            merge(id(v,x,0),id(u,((x<<1)+w)%3,1)),
            merge(id(u,x,1),id(v,((x<<1)+w)%3,0)),
            merge(id(v,x,1),id(u,((x<<1)+w)%3,0));
        }
    }
//  fp(i,0,n*6-1)printf("%d %d\n",i,find(i));
    for(R int i=0,j=z;i<(P<<1);++i,j=(j<<1)%P)ok[i&1][j]=1;
    while(q--){
        int s=read()-1,t=read()-1,r=read(),res=0;
        fp(x,0,2)fp(y,0,1)find(id(t,0,0))==find(id(s,x,y))?res|=ok[y][((r+z-x*g)%P+P)%P]:0;
        puts(res?"YES":"NO");
    }
    return 0;
}

Measured memory_bytes: 19456
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;

int main(){
    int n;
    cin>>n;
    vector<ll>a(n),b(n);
    for(int i=0;i<n;i++)cin>>a.at(i);
    for(int i=0;i<n;i++)cin>>b.at(i);
    ll ans=0;
    for(int i=0;i<n;i++){
        ll ad=0,bd=0;
        if(a.at(i)==b.at(i))continue;
        if(a.at(i)<b.at(i)){
            ad=b.at(i)-a.at(i);
        ad/=2;
        }
        else  bd=a.at(i)-b.at(i);
        ans+=ad-bd;
    }
    if(ans>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 512
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    if(!getAns(n)) {
        println(0)
        return
    }
    val tmp = n/2
    var ans = 1
    for(i in (1..tmp)) {
        ans *= 2
        ans %= (1000000000 + 7)
    }
    println(ans)
}

fun getAns(n:Int):Boolean {
    val numberList = readLine()!!.split(" ").map { it.toInt() }
    val cnt = mutableMapOf<Int, Int>()
    for(i in numberList) {
        if(i%2 != (n-1)%2) {
            return false
        }
        if(cnt.containsKey(i)) {
            cnt[i] = cnt[i]!!+1
        } else {
            cnt[i] = 1
        }
    }
    if(cnt.containsKey(0)) {
        if(cnt[0] != 1) {
            return false
        }
    }
    return cnt.filter { it.key != 0 }.all{it.value == 2}
}

Measured memory_bytes: 59224
N = int(input())
A = list(map(int,input().split()))
a = A
def calc(n):
  if(n%2 == 0):
    return int(n/2)
  else:
    return False

cnt = 0
while all(a) == True:
  a = list(map(calc, a))
  cnt += 1
print(cnt-1)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ids(M + 1);
  using P = pair<int, int*>;
  vector<priority_queue<P, vector<P>, greater<P>>> cache(N + 1);
  for (int city = 1; city <= M; ++city) {
    int P, Y;
    cin >> P >> Y;
    ids[city].first = P;
    cache[P].emplace(Y, &ids[city].second);
  }

  for (auto&& years : cache) {
    for (int cnt = 0; !years.empty(); years.pop()) {
      auto&& p = years.top();
      *p.second = ++cnt;
    }
  }

  for (int city = 1; city <= M; ++city) {
    auto&& p = ids[city];
    cout << setw(6) << setfill('0') << p.first
         << setw(6) << setfill('0') << p.second << '\n';
  }
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	return cout<<n*n<<"\n" , 0 ;
	return 0 ;
}		

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 1234567
using namespace std;
int main(void)
{
    string s;
    cin>>s;
    char c=s[s.size()-1];
    if(c=='2' || c=='4' || c=='5' || c=='7' || c=='9') puts("hon");
    else if(c=='0' || c=='1' || c=='6' || c=='8') puts("pon");
    else puts("bon"); //main();
    return 0;
}


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

int main()
{
    int a ,b;
	string s , t , u;
	cin>>s>>t>>a>>b>>u;
	if (u==s)
		a -=1;
	else b -=1;
	cout<<a<<" "<<b<<endl;
	return 0;
}
	


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<5000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> {
        val m = readInt; isPrime(m)
      }
    })
  }
}

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

int main() {
  int p;
  int r1, r2, r3;
  int temp1, temp2, temp3;
  /*
  懐かしの整数問題
  p=x*q+rを利用する
  10進法なので割る数は1,10,100
  for文を使えないのでコードが汚い
  */
  cin >> p;
  r1 = p % 100;
  temp1 = (p - r1) / 100;
  r2 = p % 10;
  temp2 = (p - r2 - temp1 * 100) / 10;
  r3 = p % 1;
  temp3 = (p  - temp1 * 100 - temp2 * 10 - r3) / 1;
  //cout << temp1 << endl;
  //cout << temp2 << endl;
  //cout << temp3 << endl;
  cout << temp1 + temp2 + temp3 << endl;
}

Measured memory_bytes: 256
def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を素数10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n,10**9+7)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

def combi(a,b,n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(mod)
aa=find_power(10**5,10**9+7)
bb=find_inv_power(10**5)
mod=10**9+7

n,k=map(int,input().split())
lists=list(map(int,input().split()))
import collections 
L=collections.Counter(lists)
L=dict(L)
uselist=[]
for a,v in L.items():
    uselist.append((a,v))
uselist=sorted(uselist,key=lambda x:x[0])
maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MAX=0

for j in range(1,len(maxlist)):
    MAX+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MAX=MAX%mod

  
uselist=uselist[::-1]

maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MIN=0

for j in range(1,len(maxlist)):
    MIN+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MIN=MIN%mod

print((MAX-MIN)%mod)


Measured memory_bytes: 108104
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		StringBuffer sb=new StringBuffer();
		for(int i = 0; i<s.length(); i++){
			if((26-(s.charAt(i)-'a'))<=k && s.charAt(i)!='a'){
				k-=26-(s.charAt(i)-'a');
				sb.append('a');
			}else{
				sb.append(s.charAt(i));
			}
		}
		if(k>0){
			char t=sb.charAt(s.length()-1);
			sb.delete(s.length()-1,s.length());
			sb.append((char)('a'+(t-'a'+k)%26));
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 27728
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int h,w,k;
  while(cin >> h >> w >> k){
    vector<string> s(h); cin >> s;

    vector<vector<int>> ans(h, vector<int>(w));

    int mark = 0;

    REP(j,w){
      int c = 0;

      REP(i,h){
        if(s[i][j] == '#'){
          ++mark;

          if(c == 0){
            REP(k,i){
              ans[k][j] = mark;
            }
          }
          
          c = mark;
        }else{
        }

        if(c != 0){
          ans[i][j] = c;
        }
      }
    }

    REP(i,h){
      FOR(j,1,w){
        if(ans[i][j] == 0){
          ans[i][j] = ans[i][j-1];
        }
      }
    }

    REP(i,h){
      REV(j,w-2,0){
        if(ans[i][j] == 0){
          ans[i][j] = ans[i][j+1];
        }
      }
    }


    REP(i,h){
      join(cout, ALL(ans[i]));
    }
  }


  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string X;
	cin >> X;
	int stock = 0;
	int ans = X.size();
	rep(i, X.size()) {
		if (X[i] == 'S')stock++;
		if (stock&&X[i] == 'T') {
			ans -= 2;
			stock--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
# N A B

n, a, b = gets.chomp.split(" ").map(&:to_i)

r = []

(1..n).each do |i|
  s = i.to_s(10)

  sum = 0
  s.chars.each do |c|
    sum += c.to_i
  end

  if a <= sum && sum <= b
    r << i
  end
end

puts (r.inject(0) {|s, i| s + i})


Measured memory_bytes: 1916
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
	int count = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'o') count++;
	}
	count += 15 - (int)s.size();
	if (count >= 8) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
untasty , tasty_ant , poison = input().split()
untasty = int(untasty)
tasty_ant = int(tasty_ant)
poison = int(poison)
tasty = 0

if (untasty + tasty_ant) == poison:
    tasty = tasty_ant + poison
elif (untasty + tasty_ant) > poison:
    tasty = tasty_ant + poison
elif (untasty + tasty_ant) < poison:
    tasty = untasty + (2 * tasty_ant) + 1

print(tasty)


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

using namespace std;

const long long linf = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<vector<int>> g(n);
  
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  
  queue<int> q;
  vector<int> a(n), b(n);
  vector<int> used(n);
  
  for (int v = 0; v < n; ++v) {
    for (int to: g[v]) {
      if (s[to] == 'A')
        ++a[v];
      else
        ++b[v];
    }
    if (!a[v] || !b[v]) {
      q.push(v);
      used[v] = 1;
    }
  }
  
  int cnt = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    ++cnt;
    
    for (int to: g[v]) {
      if (used[to])
        continue;
      if (s[v] == 'A')
        --a[to];
      else
        --b[to];
      if (!a[to] || !b[to]) {
        q.push(to);
        used[to] = 1;
      }
    }
  }
  
  cout << (cnt < n ? "Yes" : "No") << endl;
}


Measured memory_bytes: 12880
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll W,H,N;
	ll result=0;
	cin>>W>>H>>N;
	VVI grid(H,VI(W,1));

	REP(k, N){
		ll x,y,a;
		cin >> x>>y>>a;
		REP(j,H){
			REP(i,W){
				if(a==1){	if (i<x) grid[j][i]=0;}
				if(a==2){	if (i>=x) grid[j][i]=0;}
				if(a==3){	if (j<y) grid[j][i]=0;}
				if(a==4){	if (j>=y) grid[j][i]=0;}
			}
		}
	}
	REP(j,H){REP(i,W) result+=grid[j][i];}
	cout << result << "\n";
	return;
}

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


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  string s;
  cin>>s;
  int ans1=0,ans2=0;
  REP(i,SIZE(s)){
    if(i%2==0){
      if(s[i]!='0'){ans1++;}
    }
    else{
      if(s[i]!='1'){ans1++;}
    }
  }
  REP(i,SIZE(s)){
    if(i%2==1){
      if(s[i]!='0'){ans2++;}
    }
    else{
      if(s[i]!='1'){ans2++;}
    }
  }
  cout<<min(ans1,ans2)<<endl;
  
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,last=0,ans=-1;
	string s;
	cin>>s;
	for (int i=0;i<s.length();i++)
	{
		if (s[i]=='R')   a++;
		else
		{
			ans=max(ans,a);
			a=0;
		}
	}
	cout<<max(ans,a);
	return 0;
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int c=0,bc=1;
	for(int i=0;i<n;i++)
	{
		if(a[i]==bc)
		{
			bc++;
			c++;
		}
	}
	if(c>0)
	cout<<n-c;
	else
	cout<<"-1";
	return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL f(LL n, LL b){
  if(n < b) return n;
  return f(n/b, b) + n%b;
}

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

  LL N, S; cin >> N >> S;
  if(N < S){
	cout << -1 << endl;
	return 0;
  }
  if(N == S){
	cout << N+1 << endl;
	return 0;
  }

  LL ans = 1e15, b;
  for(b=2;b*b<=N;++b){
	if(f(N,b) == S)
	  ans = min(ans, b);
  }
  for(LL p=1;p<b;++p){
	LL q = S - p;
	LL b_ = (N - q) / p;
	if(b<=b_ && f(N,b_) == S)
	  ans = min(ans, b_);
  }
  
  cout << (ans==1e15?-1:ans) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;

ll func(vector<ll>&arr, ll n, ll k){
    vector<vector<ll>>dp(n+1, vector<ll>(k+1, 0));
    vector<vector<ll>>pr(n+1, vector<ll>(k+1, 0));
    for(int i = 0 ; i <= n ; i++){
        dp[i][0] = 1;
        pr[i][0] = 1;
    }
    for(int j = 0 ; j <= k ;j++){
        pr[0][j]=1;
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= k ; j++){
            // for(int p = 0; p <= j && arr[i-1]-p>=0; p++){
            dp[i][j] = (dp[i][j] + pr[i-1][j]-pr[i-1][j-arr[i-1]>=0?j-arr[i-1]:0]+dp[i-1][j-arr[i-1]>=0?j-arr[i-1]:0] + mod)%mod;
            pr[i][j] = (dp[i][j] + pr[i][j-1])%mod;
                // dp[i][j] = (dp[i][j] + dp[i-1][j-p])%mod;
            // }
        }
    }
    // for(int i = 0; i <=n; i++){
    //     for(int j= 0;j<= k; j++){
    //         cout<<pr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    return dp[n][k];
}

int main(){
    ll n, k;
    cin>>n>>k;
    vector<ll>arr(n);
    for(ll i = 0 ; i < n ; i++){
        cin>>arr[i];
        // cout<<arr[i]<<" ";
    }
    sort(arr.begin(), arr.end());
    cout<<func(arr, n, k);
}

Measured memory_bytes: 159088
#include<iostream>
#include<cmath>

int main() {
	signed long long a{}, b{};
	std::cin >> a >> b;
	auto dis = std::abs(b - a) + 1;

	if (a < 0 && 0 < b) { std::cout << "Zero"; }
	else {
		if (0 < a) { std::cout << "Positive"; }
		else {
			//signed res{1};

			if (dis % 2 == 0) {
				std::cout << "Positive";
			}
			else {
				std::cout << "Negative";
			}
		}
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


n = int(input())
p = [x for x in primes(55555) if x % 5 == 1]
print(' '.join(map(str, p[:n])))


Measured memory_bytes: 3572
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
# 大きい順 or 小さい順に揃えていく
ds = [a-b for a,b in zip(As,Bs)]
if sum(ds) > 0:
    print("No")
    exit()
cnt = 0
cnts = []
for d in ds:
    # print(d)
    if d < 0:
        c = -(d//2)
        cnt += c
        d += c * 2
    cnts.append(d)
if cnt >= sum(cnts):
    print("Yes")
else:
    print("No")

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



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n - i - 1; i++) {
		if (s[i] != s[n - i - 1]) {
			cout << "No";
			return 0;
		}
	}
	int len = (n - 1) / 2;
	for (int i = 0; i < len - i - 1; i++) {
		if (s[i] != s[len - i - 1] || s[i + len + 1] != s[n - i - 1]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    int cnt=0;
    vector<int> a(n);
    FOR(i, 0, n){
        cin >> a[i];
        if(i>0){
            if(a[i] == a[i-1]){
                a[i] = 100000;
                cnt++;
            }
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;

const int maxn = 1e5;

int pos[maxn + 11];

int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		pos[x] = i;
	}
	set <int> s;
	set <int> ::iterator itl, itr;
	s.insert(0); s.insert(n + 1);s.insert(n + 2);s.insert(-1);
	ll ans = 0;
	for (int i = n; i >= 1; i--) {
		itl = s.lower_bound(pos[i]); itr = itl--;
		int l = *itl;
		int r = *itr;
		if (l == 0) {
			itr++;
			int R = *itr;
			if (r != n + 1) {
				ans += 1ll * pos[i] * (R - r) * i;
			}
		}
		else if (r == n + 1) {
			itl--;
			int L = *itl;
			ans += 1ll * (l - L) * (n - pos[i] + 1) * i;
		}
		else {
			itl--; itr++;
			int L = *itl; int R = *itr;
			ans += (1ll * (l - L) * (r - pos[i]) + 1ll * (R - r) * (pos[i] - l)) * i;
		}
		s.insert(pos[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 8212
#include <iostream>
#include <vector>
#include <random>

using namespace std;

const int MAXN = 1111;
int p[MAXN];
int x[MAXN];
int d[MAXN];
vector <int> v[MAXN];
int din[MAXN][5 * MAXN];
int n;

void dfs(int k) {

    vector <pair <int, int>> t;
    long long sum = 0;
    for (int to : v[k]) {
        dfs(to);
        t.push_back({d[to], x[to]});
        sum += d[to];
        sum += x[to];
    }
    for (int i = 0; i < v[k].size(); i++) {
        for (int j = 0; j < MAXN * 5; j++) {
            din[i][j] = 0;
        }
    }
    if (v[k].size() == 0) {
        return;
    }
    if (t[0].first < 5 * MAXN) {
        din[0][t[0].first] = 1;
    }
    if (t[0].second < 5 * MAXN) {
        din[0][t[0].second] = 1;
    }
    for (int i = 0; i < (int)v[k].size() - 1; i++) {
        for (int j = 0; j < MAXN * 5; j++) {
            if (din[i][j] && j + t[i + 1].first < 5 * MAXN) {
                din[i + 1][j + t[i + 1].first] = 1;
            }
            if (din[i][j] && j + t[i + 1].second < 5 * MAXN) {
                din[i + 1][j + t[i + 1].second] = 1;
            }
        }
    }
    d[k] = 1e9;
    bool was = 0;
    for (int j = 5 * MAXN - 1; j >= 0; j--) {
        if (din[(int)v[k].size() - 1][j]) {
            if (j <= x[k]) {
                d[k] = sum - j;
                was = 1;
                break;
            }
        }
    }
    if (!was) {
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    }
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> n;
    p[0] = -1;
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        v[p[i]].push_back(i);
    }

    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    dfs(0);
    cout << "POSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#include <ext/pb_ds/assoc_container.hpp> // Used to include policy based data structure 
using namespace __gnu_pbds;  // Only for g++ compiler
using namespace std;

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define max(a, b)  (a > b) ?a :b  // max of 2 elements 
#define min(a, b)  (a < b) ?a :b  // min of 2 elements

//short hand for usual tokens
#define pb              push_back
#define fi              first
#define se              second
#define mp              make_pair
#define mii             map<int,int>
#define pqb             priority_queue<int>   // Max Heap
#define pqs             priority_queue<int,vi,greater<int> >   // Min Heap
#define setbits(x)      __builtin_popcountll(x)   // returns the number of set bits in the binary representation of x
#define zrobits(x)      __builtin_ctzll(x)   // returns the number of zeroes before the first set bit in the binary representation of x       
#define mod             1000000007   // 1e9 + 7   
#define inf             1e18   // pow(10, 18)  
#define mk(arr,n,type)  type *arr=new type[n];   // generates a dynamic array
#define w(x)            int x; cin>>x; while(x--)   // for taking test cases 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());   // used with shuffle

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;   // Used to implement policy-based data structure

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    
    ll n;
    cin>>n;
    ll ans = 0LL;
    for(ll i = 1; i <= n; i++){
        ll temp = n/i;
        ans += (temp*(temp+1)*i)/2 ;    
    }
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int color[800];

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

pair<bool, vector<int>> isBipartite(const Graph &g, int v, int c) {
	bool flag = true;
	vector<int> res(2);

	if(color[v] >= 0) {
		return make_pair(color[v] == c, res);
	}

	color[v] = c;
	res[c]++;
	EACH(i, g[v]) {
		auto r = isBipartite(g, i->to, 1-c);
		flag = flag && r.first;
		res[0] += r.second[0];
		res[1] += r.second[1];
	}

	return make_pair(flag, res);
}

signed main(){
	int N, M;
	cin >> N >> M;
	set<pair<int,int>> st;
	for(int i = 0; i < M; ++i) {
		int A, B;
		cin >> A >> B;
		--A; --B;
		st.insert(make_pair(min(A,B), max(A,B)));
	}

	Graph g(N);
	for(int i = 0; i < N; ++i)  for(int j = i + 1; j < N; ++j) {
		if(st.find(make_pair(i, j)) == st.end()) {
			addUndirectedEdge(g, i, j, 0);
		}
	}

	vector<vector<int>> vs;
	memset(color, -1, sizeof(color));
	for(int i = 0; i < N; ++i) if(color[i] < 0) {
		auto res = isBipartite(g, i, 0);
		if(!res.first) {
			cout << -1 << endl;
			return 0;
		}
		vs.push_back(res.second);
	}

	vector<bool> dp1(N + 1), dp2(N + 1);
	dp1[0] = true;
	EACH(i, vs) {
		//cout << (*i)[0] << "," << (*i)[1] << endl;;
		for(int j = N; j >= 0; --j) {
			for(int k = 0; k < 2; ++k) {
				int a = (*i)[k];
				if (j >= a) {
					dp2[j] = dp2[j] || dp1[j-a];
				}
			}
		}
		dp1.assign(N + 1, false);
		swap(dp1, dp2);
	}

	int res = N * N;
	for(int i = 0; i <= N; ++i) if(dp1[i]) {
		int a = i, b = N - i;
		int tmp = a * (a - 1) / 2 + b * (b - 1) / 2;
		res = min(res, tmp);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 20224
import java.util.*;
    public class Main {
    	public static void main(String[] args){
    	
    		Scanner sc = new Scanner(System.in);
    		
    		  int a = sc.nextInt();
    		  int b = sc.nextInt();
    		  
    		   int c;
    		   
    		   if(a%b==0){
    		   
    		   c=(a/b);
    		   } else{
    		   c=(a/b)+1;
    		   }
    		   
    
    	         
    	         System.out.println(c);
    	       
    	}
    }

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


using namespace std;
double pi=3.14159265358979323846264338;


inline void ex(){cout<<"NO"<<endl;exit(0);}
long long a,b,c,d;
const long long N=1000000007;
long long n;
int main(){
	cin>>n;
	a=1;
	b=1;
	for(int i=0;i<n;i++)a=(a*9)%N;
	for(int i=0;i<n;i++)b=(b*8)%N;
	d=1;
	for(int i=0;i<n;i++)d=(d*10)%N;
	a=a*2%N;
	c=a-b;
	
	if(c<0)c=c+N;
	d=d-c;
	if(d<0)d=d+N;
	cout<<d<<endl;
	return 0;
			
}

Measured memory_bytes: 3600