akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int N,X;
    int D,ans;
    cin >> N >> D >> X;
    vector<int>A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    ans = X;
    for(int i = 0; i < N; i++){
        int tmp = (D - 1)/A[i] + 1;
        ans += tmp;  
    }
    cout << ans << endl;         
}

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

long long int N, dp[1919810][2], i, ans, con;

static inline long long dpt(int b){
    return ((b - 3 >= 0) ? dp[b - 3][1] + N - b + 1 : N - 1) % 1000000007;
}

int main(){
    scanf("%lld", &N);
    ans = con = (N - 1) * (N - 1) % 1000000007;
    dp[0][0] = N;
    dp[0][1] = N;
    for(i = 1; i <= N; ++i){
        dp[i][0] = (dp[i - 1][0] + con + dpt(i)) % 1000000007;
        dp[i][1] = (dp[i - 1][1] + dp[i][0]) % 1000000007;
    }
    cout << dp[N - 1][0] << endl;
    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,sum[10][10]={},ans=0;
	string s;
	stringstream ss;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%10==0)continue;
		ss<<i;
		ss>>s;
		sum[s[0]-'0'][s[s.length()-1]-'0']++;
		ss.clear();
	}
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			if(i==j&&sum[i][j]<=1)ans+=sum[i][j];
			else if(i==j&&sum[i][j]>1)ans+=sum[i][j]*sum[i][j];
			else ans+=sum[i][j]*sum[j][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1412
//******************************************************************************
// File Name: E.cpp
// Author: Shili_Xu
// E-Mail: shili_xu@qq.com
// Created Time: Sat 29 Sep 2018 08:57:19 PM CST
//******************************************************************************

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int MAXN = 1e5 + 5;

char s[MAXN];

int main()
{
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    bool flag = true;
    if (s[1] == '0' || s[n] == '1') flag = false;
    for (int i = 1; i <= n - 1 && flag; i++)
        if (s[i] != s[n - i]) flag = false;
    if (!flag) {
        printf("-1\n");
        return 0;
    }
    else {
        int now = 2;
        printf("1 2\n");
        for (int i = 2; i < n; i++) {
            if (s[i] == '1') {
                printf("%d %d\n", now, i + 1);
                now = i + 1;
            }
            else {
                printf("%d %d\n", now, i + 1);
            }
        }
    }
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  Vi AC(n+2);
  AC[0] = 0;
  
  rep(i,0,n){
    if(s[i]=='A' && s[i+1]=='C') AC[i+1]++;
    AC[i+2] = AC[i+1];
  }
  
  int l,r;
  rep(i,0,q){
    cin >> l >> r;
    cout << AC[r-1] - AC[l-1] << endl;
  }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
constexpr int INF = 1<<21;
enum Color { WHITE = 0, GRAY, BLACK };
int n;
vv(int, M, MAX, MAX, INF);
inline int prim() {
	vi d(n, INF), t(n, -1), color(n, WHITE);
	d[0] = 0;
	int minv, u;
	while(true) {
		minv = INF;
		u = -1;
		rep(i, 0, n) {
			if(minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		rep(v, 0, n) {
			if(color[v] != BLACK && d[v] > M[u][v]) {
				d[v] = M[u][v];
				t[v] = u;
				color[v] = GRAY;
			}
		}
	}
	return accumulate(all(d), 0);
;
}
int main() {
	cin >> n;
	int e;
	rep(i, 0, n) {
		rep(j, 0, n) {
			cin >> e;
			if(e != -1) M[i][j] = e;
		}
	}
	P(prim());
	return 0;
}

Measured memory_bytes: 3172
#include <stdio.h>

int main()
{
   int smallA;
   int bigB;
   int calcResult;
   int s;

   s = scanf("%d %d", &smallA, &bigB);
   if (s == EOF)
   {
      printf("Error!\n");
   }

   if (bigB % smallA == 0)
   {
      calcResult = smallA + bigB;
   }
   else
   {
      calcResult = bigB - smallA;
   }

   printf("%d", calcResult);

   return 0;
}

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

#define ll long long 
int main() {
  ll N;
  cin >> N;
  
  ll ans = 0;
  ll n = 5;
  if (N % 2) {
    cout << 0 << endl;
    return 0;

  } else {
    while (n <= N) {
      ans += N / (n*2);
      n *= 5;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,ans=0; cin>>N;
  int a=0,b=0,c=0;
  rep(_,0,N){
    string S; cin>>S;
    rep(i,1,S.size()){
      if(S[i]=='B'&&S[i-1]=='A')
        ans++;
    }
    if(S[S.size()-1]=='A'){
      if(S[0]=='B')
        c++;
      a++;
    }
    if(S[0]=='B')
      b++;
  }
  int K=min(a,b);
  if(a==b&&b==c)
    K--;
  K=max(K,0LL);
  cout<<ans+K<<endl;
  }




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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())
#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

char ch;

int
main()
{
  cin >> ch;

  if ('A' <= ch && ch <= 'Z') {
    cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }

  return 0;
}

/*
4, 1, 10, 2, 16, 3, 22, 

8, f(8), f(f(8)), 
8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 
7, f(7), f(f(7)), 
7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1
*/


Measured memory_bytes: 3504
# C - Prison
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]
new_L = []
new_R = []
for i in range(M):
    new_L.append(L[i][0])
    new_R.append(L[i][1])
if min(new_R) - max(new_L) >= 0:
    ans = min(new_R) - max(new_L) + 1
else:
    ans = 0
print(ans)


Measured memory_bytes: 29088
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();

    if (n%k != 0) {
      System.out.println("1");
    } else {
      System.out.println("0");
    }
  }
}


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

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

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

    bool isRule = true;
    for(int i = 0; i < n-1; i++){
        if(s[i].back() != s[i+1].front()){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] == s[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    mina = min(A)
    maxa = max(A)
    cost = float('inf')
    for y in range(mina, maxa + 1):
        c = 0
        for x in A:
            c += (x - y) ** 2
        cost = min(cost, c)

    print(cost)

main()


Measured memory_bytes: 3060
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int go[4] = {};

int find(State &a) {
	if (*a == '[') {
		a++;
		int b = 0;
		if (*a == '+') {
			b = 0;
		}
		else if (*a == '*') {
			b = 1;
		}
		else if (*a == '^') {
			b = 2;
		}
		a++;
		int c = find(a);
		int d = find(a);
		if (b == 0) {
			c |= d;
		}
		else if (b == 1) {
			c &= d;
		}
		else {
			c ^= d;
		}
		a++;
		return c;
	}
	else {
		int hoge = go[*a - 'a'];
		a++;
		return hoge;
	}
}

void solve(){
	while (true) {
		string a;
		cin >> a;
		if (a == ".") return;
		int ans[10000] = {};
		for (int i = 0; i < 10000; ++i) {
			int now = i;
			REP(q, 4) {
				go[3-q] = now % 10;
				now /= 10;
			}
			State b = a.begin();
			ans[i] = find(b);
		}
		int b;
		cin >> b;
		int cnt = 0;
		REP(q, 10000) {
			if (ans[b] == ans[q]) cnt++;
		}
		cout << ans[b] << " " << cnt << endl;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3280
#include <iostream>
#include <vector>
 
using namespace std;
 
vector<int> factorize(int n) {
	vector<int> ps;

	while (n % 2 == 0) {
		ps.push_back(2);
		n /= 2;
	}
	for (int i = 3; i * i <= n; i += 2) {
		while (n % i == 0) {
			ps.push_back(i);
			n /= i;
		}
	}
	if (n != 1) ps.push_back(n);

	return ps;
}
 
int main()
{
    int n;
    cin >> n;
 
    vector<int> ps = factorize(n);
    cout << n << ':';
    for (vector<int>::iterator it = ps.begin(); it != ps.end(); ++it) {
        cout << ' ' << *it;
    }
    cout << endl;
 
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int count = n;
  int m,t;
  for(int i=0;i<=n;i++){
    m = 0;
    t = i;
    while(t>0){
      m += t%6;
      t /= 6;
    }
    t = n - i;
    while(t>0){
      m += t%9;
      t /= 9;
    }
    count = min(count,m);

  }
  cout << count << endl;
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using ll = long long;

int main() {
    FAST;

    ll n, i, p = 1, sum = 0, now;
    cin >> n;

    string s = "";
    while (sum < n) {
        sum += ll(round(pow(26, p++)));
        s += 'z';
    }
    --p;

    for (i = 1; i <= p; ++i) {
        now = ll(round(pow(26, p-i)));
        while (sum-now >= n) {
            sum -= now;
            --s[i-1];
        }
    }

    cout << s;

    return 0;
}


Measured memory_bytes: 4052
#include<iostream>
using namespace std;
struct Card { char suit, value; };

void bubbleSort(struct Card A[],int N){
	for(int i=0;i<N;i++){
		for(int j=N-1;j>i;j--){
			if( A[j].value < A[j-1].value ){
				Card t = A[j];A[j] = A[j-1];A[j-1] = t;
			}
		}
	}
}

void selectionSort(struct Card A[],int N){
	for(int i=0;i<N;i++){
		int minj=i;
		for(int j=i;j<N;j++){
			if( A[minj].value > A[j].value ) minj = j;
		}
		if(minj != i){
			Card t = A[i];A[i] = A[minj];A[minj] = t;
		}
	}
}

void print(struct Card A[],int N){
	for(int i=0;i<N;i++){
		if(i) cout<<" ";
		cout<<A[i].suit<<A[i].value;
	}
	cout<<endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
	for(int i=0;i<N;i++){
		if(C1[i].suit != C2[i].suit) return false;
	}
	return true;
}

int main(){
	int N;
	cin>>N;
	Card C1[36],C2[36];
	for(int i=0;i<N;i++){
		cin>>C1[i].suit>>C1[i].value;
	}	
	for(int i=0;i<N;i++){
		C2[i] = C1[i];
	}
	
	bubbleSort(C1,N);
	print(C1,N);
	cout<<"Stable"<<endl;
	selectionSort(C2,N);
	print(C2,N);
	if(isStable(C1,C2,N)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
A[1000][1000],I[1000],u[999];i,j;d;F=2;main(N){for(scanf("%d",&N);i<N;++i)for(j=0;j<N-1;)scanf("%d",A[j++]+i);for(;F&2;i=N)for(++d,F=1;i--;)u[i]<d&&(j=A[I[i]][i])&&u[F&=2,--j]<d&&A[I[j]][j]==i+1&&++I[u[i]=u[j]=d,++I[i],F=2,j];printf("%d",F*d-1);}

Measured memory_bytes: 4096
def counting_sort(a, b, k):
	c = [0] * (k + 1)
	for i in range(len(a)):
		c[a[i]] += 1

	for i in range(1, k+1):
		c[i] = c[i] + c[i - 1]

	for i in range(len(a) - 1, -1, -1):
		c[a[i]] -= 1
		b[c[a[i]]] = a[i]

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
counting_sort(a, b, max(a))
print(b[0], end='')
for i in range(1, n):
	print(' ' +  str(b[i]), end='')
print()



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

int difficulty[100000]={0};
int main()
{
    int i=0,N;

    cin>>N;
    for(i=0;i<N;i++)
    {
        cin>>difficulty[i];
    }

    sort(difficulty, difficulty+N);
    cout<<difficulty[N/2]-difficulty[N/2-1]<<endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define MAXNUM 222222
typedef long long ll;
struct node{
    int posl,posr,lnum,rnum;
    bool operator<(const node &nn)
    {
        return posl<nn.posl;
    }
};
int k,n;
ll cal(vector<node> &tmp)
{
    ll sum=0,res=0;
    for(int i=k-1,j=0;i<tmp.size();i++,j++)
    {
        sum+=tmp[j].lnum;
        res+=sum*tmp[i].rnum;
    }
    return res;
}
int allx[MAXNUM],xsize,num[MAXNUM];
vector<node> pos[MAXNUM];
int main()
{
    scanf("%d%d",&n,&k);
    rep(i,1,n+1)scanf("%d",&num[i]),allx[++xsize]=num[i];
    sort(allx+1,allx+xsize+1);
    xsize=unique(allx+1,allx+xsize+1)-allx-1;
    rep(i,1,n+1)pos[lower_bound(allx+1,allx+xsize+1,num[i])-allx].push_back({i,i,1,1});
    int nowx=1,nownum=allx[1];
    vector<node> vnow,vx;
    ll res=0;
    while(1)
    {
        if(nowx>xsize&&vnow.empty())break;
        if(vnow.empty())nownum=allx[nowx];
        if(nowx<=xsize&&nownum==allx[nowx])
        {
            vx.clear();vx.resize(vnow.size()+pos[nowx].size());
            merge(vnow.begin(),vnow.end(),pos[nowx].begin(),pos[nowx].end(),vx.begin());
            nowx++;
        }
        else vx=vnow;
        vnow.clear();
        vector<node> vv,vv2;
        rep(i,0,vx.size())
        {
            vv.push_back(vx[i]);
            if(i==vx.size()-1||vx[i].posr!=vx[i+1].posl-1)
            {
                vv2.clear();
                res+=cal(vv);
                int kk=vv.size()/k;
                vv2.resize(kk,{n+2,-1,0,0});int minpos=n+2,maxpos=-1;
                rep(i,0,vv.size())
                {
                    int rpos=(i+1)/k,lpos=kk-(vv.size()-i)/k;
                    if(rpos)vv2[rpos-1].rnum+=vv[i].rnum;
                    if(lpos!=kk)vv2[lpos].lnum+=vv[i].lnum;
                    minpos=min(minpos,vv[i].posl),maxpos=max(maxpos,vv[i].posr);
                }
                rep(i,0,kk)vv2[i].posl=vv2[i].posr=minpos+i;
                if(kk)vv2[kk-1].posr=maxpos;
                res-=cal(vv2);
                for(node &nn:vv2)vnow.push_back(nn);
                vv.clear();
            }
        }
        nownum++;
    }
    printf("%lld\n",res+n);
}

Measured memory_bytes: 20076
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


vector<bool> sieve;
vector<int> primes;
void prime_list(int sz){
    sieve.resize(sz);
    for(int i=0;i<sz;i++)sieve[i]=true;
    sieve[0]=sieve[1]=false;
    for(long long i=2;i<sz;i++){
        if(sieve[i]){
            primes.push_back((int)i);
            for(long long j=i*i;j<sz;j+=i)sieve[j]=false;
        }
    }
}

ll counter(ll a){
    ll res=1;
    REP(i,primes.size()){
        int cnt=0;
        while(a%primes[i]==0){
            cnt++;
            a/=primes[i];
        }
        if(cnt==1)res*=(primes[i]*primes[i]);
        if(cnt==2)res*=primes[i];
        if(a==1||a<primes[i])break;
    }
    if(a!=1){
        ll inv=sqrt(a+0.01);
        if(a==inv*inv)res*=inv;
        else res*=a*a;
    }
    return res;
}

int main(){
    
    prime_list(10100);
    
    int N; cin>>N;
    vector<ll> norm(N);
    REP(i,N)cin>>norm[i];
    REP(i,N){
        for(int j=0;j<primes.size();j++){
            ll cube=primes[j]*primes[j]*primes[j];
            if(cube>norm[i])goto nextf;
            while(norm[i]%cube==0)norm[i]/=cube;
        }
    nextf:;
    }
    
    ll ans=0;
    map<ll,ll> cnt,part;
    REP(i,N){
        if(norm[i]==1){
            ans=1;
            continue;
        }else{
            ll p=counter(norm[i]);
            if(cnt.find(norm[i])==cnt.end()){
                cnt[norm[i]]=1;
                part[norm[i]]=p;
            }else{
                cnt[norm[i]]++;
                part[norm[i]]=p;
            }
        }
    }
    
    for(auto itr=cnt.begin();itr!=cnt.end();itr++){
        if(part.find(itr->first)!=part.end()){
            ans+=max(cnt[itr->first],cnt[part[itr->first]]);
            cnt[itr->first]=0;
            cnt[part[itr->first]]=0;
        }else{
            ans+=cnt[itr->first];
        }
    }
    
    cout<<ans<<endl;
   
    return 0;
}


Measured memory_bytes: 19840
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}

int main(){

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

    cin >> N;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
    }
    ll minv=A[0];
    ll cnt = 0;
    rep(ni,N){
        if(minv>=A[ni]) cnt++;
        minv = llmin(minv,A[ni]);
    }
    cout << cnt << endl;



    

}

Measured memory_bytes: 5324
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.pb(mp(x, i+1));
    }
    sort(all(v));
    for(int i = 0; i < n; i++){
        cout << v[i].second << " ";
    }
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int64_t FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
// Tao luyện kỹ thuật trong 8 năm mày luyện kỹ thuật trong buồng tắm nam
const int MAXN = (int) 2e5 + 2;
const int INF = numeric_limits<int>::max() >> 1;
const int MOD = (int) 998244353;

signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n, x, m;
  cin >> n >> x >> m;
  vector<int> rm;
  rm.push_back(x);
  map<int, int> mp;
  mp[x] = 0;
  int leap, from;
  while(true){
    int pr = rm.back();
    pr *= pr;
    pr %= m;
    if(mp.count(pr)){
      from = mp[pr];
      leap = rm.size() - from;
      break;
    }
    mp[pr] = rm.size();
    rm.push_back(pr);
  }
  n --;
  if(n < from){
    int sum = 0;
    for(int i = 0; i <= n; i ++) sum += rm[i];
    cout << sum;
    return 0;
  }
  int sum = 0;
  for(int i = 0; i < from ; i ++) sum += rm[i];
  int jump = 0;
  for(int i = from; i < rm.size(); i ++) jump += rm[i];
  n -= from;
  n ++;
  int leap_req = n/leap;
  sum += leap_req*jump;
  n %= leap;
  for(int i = 0; i < n; i ++){
    sum += rm[i + from];
  }
  cout << sum;
}

Measured memory_bytes: 6720
#include <iostream>

using namespace std;

int main (void) {
    int N;
    cin >> N;

    char s;
    string ans = "Three";
    for ( int i=0; i<N; i++ ) {
        cin >> s;
        if ( s == 'Y' ) {
            ans = "Four";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll yueshu1(ll x){
	ll ans=0;
	for(ll i=1;i*i<=x;++i){
		if(x%i==0){
			if(i*i==x) ++ans;
			else ans+=2;
		}
	}
	return ans;
}
ll find(ll x){
	ll ans=0;
	for(ll i=2;i*i<=x;++i){
		if(x%i==0){
			if(i*i==x){
				ll tmp=x;
				while(tmp%i==0) tmp/=i;
				if(tmp%i==1) ++ans;
			}
			else{
				ll tmp=x,j=x/i;
				while(tmp%i==0) tmp/=i;
				if(tmp%i==1) ++ans;
				tmp=x;
				while(tmp%j==0) tmp/=j;
				if(tmp%j==1) ++ans;
			}
		}
	}
	return ans+1;
}
ll n,tot;
int main()
{
	scanf("%lld",&n);
	tot=yueshu1(n-1)-1+find(n);
	printf("%lld",tot);
}

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

const int maxn = 1e5 + 10;

int n;
int x[maxn], y[maxn], t[maxn];

bool solve() {
	for(int i = 1; i <= n; ++i) {
		int dx = abs(x[i] - x[i - 1]);
		int dy = abs(y[i] - y[i - 1]);

		if(dx + dy > t[i] - t[i - 1]) return false;
		if(((t[i] - t[i - 1]) - (dx + dy)) % 2) return false;
	}

	return true;
}

int main() {
	cin.sync_with_stdio(false);
	
	cin >> n;
	
	for(int i = 1; i <= n; ++i)
		cin >> t[i] >> x[i] >> y[i];
	
	if(solve()) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 1408
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	putStrLn $ which "Possible" "Impossible" $ any ( ( == 0 ) . ( `mod` 3 ) ) [ a, b, a + b ]


Measured memory_bytes: 508
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	var (
		sunny  = "Sunny"
		cloudy = "Cloudy"
		rainy  = "Rainy"
	)

	s := getString()
	if s == sunny {
		s = cloudy
	} else if s == cloudy {
		s = rainy
	} else {
		s = sunny
	}

	fmt.Fprintln(wr, s)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


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

// 
int main() {
    string N;
    cin >> N;
    int tmp = 0;
    int num;
    for (long long i = 0; i < N.size(); i++) {
        num = stoi(N.substr(i, 1));
        if (tmp + num < 9) {
            tmp = tmp + num;
        } else {
            tmp = (tmp + num) - 9;
        }
        // cout << tmp << endl; // debug
    }
    if (tmp == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int K = scan.nextInt();
        long A = scan.nextLong();
        long B = scan.nextLong();
        if (B <= A) {
            System.out.println(K+1);
            return;
        }
        int count = 0;
        long current_cookie = 1;
        if (current_cookie < A) {
            count += A - current_cookie;
            current_cookie = A;
        }
        long times = (K - count) / 2;
        current_cookie += (B - A) * times;
        long remain = K - count - 2 * times;
        current_cookie += remain;
        current_cookie = Math.max(current_cookie, K + 1);
        System.out.println(current_cookie);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n;
  cin >> n;
  vi a(4);
  rep(i, 4) {
    a[i] = n % 10;
    n /= 10;
  }
  rep(i, 1 << 3) {
    int num = a[3];
    rep(j, 3) num += (i & 1 << j) ? a[j] : -1 * a[j];
    if(num == 7) {
      cout << a[3];
      rep(j, 3) cout << ((i & 1 << 2 - j) ? '+' : '-') << a[2 - j];
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  int a,b,c,d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cout << min(a,b) + min(c,d) << endl;
  return 0;
}

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

map<int, int> oo, tt;
vector< pair<int, int> > v1, v2;
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n/2;i++){
        int aa, bb;
        scanf("%d%d", &aa, &bb);
        oo[aa]++; tt[bb]++;
    }
    oo[-1] = 0; tt[-1] = 0;
    for(auto &elem: oo){
        v1.push_back({elem.second, elem.first});
    }
    for(auto &elem: tt){
        v2.push_back({elem.second, elem.first});
    }
    sort(v1.begin(), v1.end(), greater< pair<int, int> >());
    sort(v2.begin(), v2.end(), greater< pair<int, int> >());
    int mx = 0;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(v1[i].second == v2[j].second) continue;
            mx = max(mx, v1[i].first + v2[j].first);
        }
    }
    printf("%d\n", n-mx);
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int i;
    for(i = 0; i < n; i++){
        cin >> a.at(i);
    }
    vector<int> b(n);
    for(i = 0; i < n; i++){
        b.at(i) = a.at(i);
    }
    int max = 0, max2 = 0;
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    max = b.at(0);
    max2 = b.at(1);
    for(i = 0; i < n; i++){
        if(a.at(i) == max){
            cout << max2 << endl;
        }
        else{
            cout << max << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,A,B)for(int i=int(A),i##_len=(B);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(C)C.begin(),C.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    array<ll, 31> pow3 = { 1 };
    rep(i, 30) pow3[i + 1] = pow3[i] * 3;

    int Q;
    cin >> Q;
    vector<ll> A(Q), B(Q), C(Q), D(Q);
    rep(i, Q) cin >> A[i] >> B[i] >> C[i] >> D[i];

    rep(i, Q) {
        A[i]--; B[i]--; C[i]--; D[i]--;
        if (A[i] > C[i]) A[i] = pow3[30] - 1 - A[i], C[i] = pow3[30] - 1 - C[i];
        if (B[i] > D[i]) B[i] = pow3[30] - 1 - B[i], D[i] = pow3[30] - 1 - D[i];
        int xl = -1, yl = -1;
        ll ans = (C[i] - A[i]) + (D[i] - B[i]);
        for (int j = 29; j >= 0; --j) {
            ll a = A[i] / pow3[j], b = B[i] / pow3[j], c = C[i] / pow3[j], d = D[i] / pow3[j];
            if (a != c) xl = j;
            if (b != d) yl = j;
            if (xl != -1 && yl != -1) break;
            else if (xl != -1 && b % 3 == 1 && c - a > 1) {
                ans += 2 * min(B[i] % pow3[j] + 1, pow3[j] - D[i] % pow3[j]);
                break;
            }
            else if (yl != -1 && a % 3 == 1 && d - b > 1) {
                ans += 2 * min(A[i] % pow3[j] + 1, pow3[j] - C[i] % pow3[j]);
                break;
            }
        }
        write(ans);
    }
}

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

using namespace std;
typedef long long ll;

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

  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //cout.setf(ios::fixed), cout.precision(20);

  ll n;
  cin >> n;
  ll arr[n][3];
  ll dp[n][3];
  for(int j=0;j<n;j++)
    cin >> arr[j][0] >> arr[j][1] >> arr[j][2];

  dp[n-1][0]=arr[n-1][0];
  dp[n-1][1]=arr[n-1][1];
  dp[n-1][2]=arr[n-1][2];

  
  for(int j=n-2;j>=0;j--)
    {
      dp[j][0]=max(arr[j][0]+dp[j+1][1],arr[j][0]+dp[j+1][2]);
      dp[j][1]=max(arr[j][1]+dp[j+1][0],arr[j][1]+dp[j+1][2]);
      dp[j][2]=max(arr[j][2]+dp[j+1][0],arr[j][2]+dp[j+1][1]);
    }
  cout<<max(max(dp[0][0],dp[0][1]),dp[0][2])<<" ";
  return 0;
}



Measured memory_bytes: 4992
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from itertools import product
from heapq import heappop, heappush
def resolve():
    n = int(input())
    S = [None] * n
    C = [None] * n
    for i in range(n):
        S[i], C[i] = input().split()
        C[i] = int(C[i])
    for i in range(n):
        S.append(S[i][::-1])
        C.append(C[i])

    # id[i][j] : index of S[i][-j:]
    id = [[] for _ in range(2 * n)]
    N = 1
    for i in range(2 * n):
        for j in range(len(S[i])):
            id[i].append(N)
            N += 1

    # make graph
    E = [[] for _ in range(N)]
    for i, ni in product(range(2 * n), repeat = 2):
        if i // n == ni // n:
            continue
        for j in range(len(S[i])):
            now = S[i][j:]
            edge = S[ni]
            l = min(len(now), len(edge))
            if now[:l] != edge[:l]:
                continue
            c = C[ni]
            v = id[i][j]
            nv = None
            if len(now) > len(edge):
                E[id[i][j]].append((id[i][j + len(edge)], c))
            elif len(now) < len(edge):
                E[id[i][j]].append((id[ni][len(now)], c))
            else:
                E[id[i][j]].append((0, c))

    # Dijkstra
    dist = [INF] * N
    queue = []
    for i, c in enumerate(C):
        dist[id[i][0]] = c
        heappush(queue, (c, id[i][0]))
    while queue:
        d, v = heappop(queue)
        if d != dist[v]:
            continue
        for nv, w in E[v]:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                heappush(queue, (dist[nv], nv))

    ans = dist[0]
    for i in range(2 * n):
        for j in range(len(S[i])):
            T = S[i][j:]
            if T == T[::-1]:
                ans = min(ans, dist[id[i][j]])

    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 74832
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
constexpr long long mod=1000000007;
constexpr long long inf=1ll<<61;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
modint<mod> kj[200006];

void setkj(){
    int mx=200000;
    kj[0]=1;
    for(int i=1;i<=mx;i++)kj[i]=kj[i-1]*i;
}

modint<mod> modpow(int a,int x){
    modint<mod> res=1;
    while(x){
        if(x&1)res*=a;
        x>>=1;
        a=a*a%mod;
    }
    return res;
}

modint<mod> comb(int r,int c){
    return kj[r]/(kj[c]*kj[r-c]);
}

signed main(){
    int b,w;cin>>b>>w;
    setkj();
    
    if(b>=w){
        rep(i,w)cout<<modpow(2,mod-2).a<<endl;
        modint<mod> l=modpow(2,mod-w-1);
        for(int i=w+1;i<=b;i++){
            modint<mod>ans=1;ans-=l;ans/=2;ans+=l;
            cout<<ans.a<<endl;
            l+=modpow(2,mod-1-i)*comb(i-1,i-w);
        }
        modint<mod> r=modpow(2,mod-b-1);
        for(int i=b+1;i<=b+w;i++){
            modint<mod>ans=1;ans-=l+r;ans/=2;ans+=l;
            cout<<ans.a<<endl;
            l+=modpow(2,mod-1-i)*comb(i-1,i-w);
            r+=modpow(2,mod-1-i)*comb(i-1,i-b);
        }
    }
    else{
        rep(i,b)cout<<modpow(2,mod-2).a<<endl;
        modint<mod>l=modpow(2,mod-b-1);
        for(int i=b+1;i<=w;i++){
            modint<mod>ans=1;ans-=l;ans/=2;
            cout<<ans.a<<endl;
            l+=modpow(2,mod-1-i)*comb(i-1,i-b);
        }
        modint<mod>r=modpow(2,mod-w-1);
        for(int i=w+1;i<=b+w;i++){
            modint<mod>ans=1;ans-=l+r;ans/=2;ans+=r;
            cout<<ans.a<<endl;
            l+=modpow(2,mod-i-1)*comb(i-1,i-b);
            r+=modpow(2,mod-1-i)*comb(i-1,i-w);
        }
    }
}

Measured memory_bytes: 5160
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-03 17:29:11
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int cur = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == cur) {
            cur++;
        }
    }

    int ans;
    if (cur > 1) {
        ans = n - cur + 1;
    } else {
        ans = -1;
    }

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


Measured memory_bytes: 1024
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

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

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int32 N;
    cin >> N;

    int32 max = -1;
    int32 maxCnt = -1;
    for(int32 i=1; i<=N; i++){
        int32 tmp = i;
        int32 cnt = 0;
        while(1){
            if(tmp%2 == 0){
                cnt++;
                tmp = tmp/2;
            }else{
                if(maxCnt <= cnt){
                    maxCnt = cnt;
                    max = i;
                }
                break;
            }
        }
    }

    cout << max << endl;

    return;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
vector<int>visited(100005,-1);
int dfs(int parent , int&ans)
{
    if(visited[parent]==-1)
    {
     visited[parent] = 0;
    }
    int a = 0;
    int cnt=0;
    for(auto x: adj[parent])
    {
        cnt++;
        int b=0;
        if(visited[x]!=-1)
        {
            b= visited[x];
            a = max(a,b);
            
            
        }
        else
        {
           b =  dfs(x,ans);
           a = max(a,b);
        }
    }
    if(cnt>0)
   a+=1;

    ans = max(ans,a);
    visited[parent] = a;
    return a;

   
}
int main()
{
   int n,m;
   cin>>n>>m;
   for(int i=0;i<m;i++)
   {
       int a,b;
       cin>>a>>b;
       adj[a].push_back(b);
   }
   int ans=0;

   for(int i=1;i<=n;i++)
   {
      if(visited[i]==-1)
      {
         int a =  dfs(i,ans);
         ans = max(a,ans);
      }
   }

   cout<<ans<<endl;
   
}

Measured memory_bytes: 11740
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int ans[1000001];
#define f first
#define s second
#define mk make_pair
int main(){
	int a,b,c,n;
	while(cin>>a>>b>>c,a){
		cin>>n;
		r(i,a+b+c+1)ans[i]=2;
		pair<pair<int,int>,pair<int,int> >p[n];
		r(i,n)cin>>p[i].f.s>>p[i].s.f>>p[i].s.s>>p[i].f.f;
		sort(p,p+n);
		for(int i=n-1;i>=0;i--){
			if(p[i].f.f){
				ans[p[i].f.s]=1;
				ans[p[i].s.s]=1;
				ans[p[i].s.f]=1;
			}else{
				if(ans[p[i].f.s]==2&&ans[p[i].s.s]==1&&ans[p[i].s.f]==1)ans[p[i].f.s]=0;
				if(ans[p[i].f.s]==1&&ans[p[i].s.s]==2&&ans[p[i].s.f]==1)ans[p[i].s.s]=0;
				if(ans[p[i].f.s]==1&&ans[p[i].s.s]==1&&ans[p[i].s.f]==2)ans[p[i].s.f]=0;
			}
		}
		r(i,a+b+c)cout<<ans[i+1]<<endl;
	}
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "No"; return;}

void solve() {
    int n; cin >> n;
    cout << n * n * n;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
s = input()
t = [0] * (n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2]=='AC' else 0)
for i in range(q):
    l,r = map(int,input().split())
    print(t[r-1] - t[l-1])


Measured memory_bytes: 7916
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C
{
    public class Program

    {
        class Shop
        {
            public long UnitPrice { get; set; }
            public long Stock { get; set; }
            public Shop(int[] v) { UnitPrice = v[0]; Stock = v[1]; }
        }


        public static void Main(string[] args)
        {
            int[] nm = RIntAr();
            int n = nm[0];
            int m = nm[1];

            Shop[] shops = new Shop[n];
            for (int i = 0 ; i < n ; i++)
            {
                shops[i] = new Shop(RIntAr());
            }

            long cost = 0;
            long cnt = 0;
            foreach (var shop in shops.OrderBy(x => x.UnitPrice))
            {

                if (cnt + shop.Stock <= m)
                {
                    cost += shop.UnitPrice * shop.Stock;
                    cnt += shop.Stock;
                }
                else
                {
                    cost += shop.UnitPrice * (m - cnt);
                    break;
                }             
            }
            Console.WriteLine(cost);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


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

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back

int mod = 1e9 + 7;
vector<int> fib(112345, -1);

int fibf(int n)
{
    if(n < 2) return 1;
    if(fib[n] > -1) return fib[n];
    fib[n] = (fibf(n - 1) + fibf(n - 2)) % mod;
    return fib[n];
}

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

    int current, prev = -1;
    vector<int> dist;
    for(int i = 0; i < m; i++)
    {
        cin >> current;
        if(prev == current - 1 && prev)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            dist.pb((current - 1) - (prev + 1));
            prev = current;
        }
    }
    dist.pb(n - (prev + 1));

    long long res = 1;
    for(int in : dist)
    {
        res = (1LL * res * fibf(in)) % mod;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std;

long long n;
vector<vector<pair<long long, long long> > > g;
set<pair<long long, long long> > st;

void dijkstra(long long s){
    vector<int> d (n, 1e9),  p(n, -1);
    d[s] = 0;
    set < pair<int,int> > q;
    q.insert (make_pair (d[s], s));
    while (!q.empty()) {
        int v = q.begin()->second;
        q.erase (q.begin());

        for (size_t j=0; j<g[v].size(); ++j) {
            int to = g[v][j].first,
                len = g[v][j].second;
            if (d[v] + len < d[to]) {
                q.erase (make_pair (d[to], to));
                d[to] = d[v] + len;
                p[to] = v;
                q.insert(make_pair (d[to], to));
            }
        }
    }
    for(int i = 0; i < n; ++i){
        if(p[i] == -1) continue;
        long long a = max(i, p[i]), b = min(i, p[i]);
        st.insert({a, b});
    }
}

int main(){
    long long m;
    cin >> n >> m;
    g.resize(n);
    for(int i = 0; i < m; ++i){
        long long fr, to, w;
        cin >> fr >> to >> w;
        fr--, to--;
        g[fr].push_back({to, w});
        g[to].push_back({fr, w});
    }

    for(int i = 0; i < n; ++i) dijkstra(i);

    //for(auto i = st.begin(); i != st.end(); ++i) cout << i->first << " " << i->second << endl;
    cout << m - st.size();
    
}


Measured memory_bytes: 256