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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
typedef pair<li, li> PI;


vector<li> edge[2020];
li n, k;


// rootから距離lim以内のノードの数を数える（ただしrootからparent側に向かうものは除外）
inline li calc(li root, li parent, li lim) {
    stack<pair<PI, li>> stk;
    li cnt = 0;
    stk.push({{root, parent}, 0});
    while (!stk.empty()) {
        li now = stk.top().first.first;
        li from = stk.top().first.second;
        li now_d = stk.top().second;
        stk.pop();
        cnt++;
        if (now_d >= lim)continue;
        for (auto next : edge[now]) {
            if (next == from)continue;
            stk.push({{next, now}, now_d + 1});
        }
    }
    return cnt;
}

inline li solve_node() {
    li res = n;
    rep(i, n) {
        res = min(res, n - calc(i, -1, k / 2));
    }
    return res;
}

inline li solve_link() {
    li res = n;
    rep(i, n) {
        for (auto to : edge[i]) {
            res = min(res, n - calc(i, to, k / 2) - calc(to, i, k / 2));
        }
    }
    return res;
}

int main(void)
{
    cin >> n >> k;
    rep(i, n - 1) {
        li a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    if (k % 2 == 0) {
        cout << solve_node() << endl;
    } else {
        cout << solve_link() << endl;
    }


    return 0;
}

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

int main(){
    long long h, w;
    cin >> h >> w;
    
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    if(h*w % 2 == 0){
        cout << h*w/2 << endl;
    }
    else{
        cout << (h*w)/2 + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3572
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
point = 0
for i in range(61):
    now = 0
    for j in a:
        now += (j >> i&1)
    now *= n-now
    now %= mod
    for k in range(i):
        now *= 2
        now %= mod
    point += now
    point %= mod
print(point)


Measured memory_bytes: 122936
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

int A, B;
string S;
int flag = 0;

int main()
{
	scanf("%d %d", &A, &B);
	cin >> S;

	if(S[A] == '-')
	{
		// cout << "True";
		for(int i = 0; i < A; i++)
		{
			if(S[i] == '0' || S[i] == '1' || S[i] == '2' || S[i] == '3' || S[i] == '4' || S[i] == '5' || S[i] == '6' || S[i] == '7' || S[i] == '8' || S[i] == '9')
			{
				flag = 1;
			}	
			else
			{
				flag = 0;
				break;
			}
		}
		if(flag)
		{
			for(int i = A + 1; i < S.size(); i++)
			{
				if(S[i] == '0' || S[i] == '1' || S[i] == '2' || S[i] == '3' || S[i] == '4' || S[i] == '5' || S[i] == '6' || S[i] == '7' || S[i] == '8' || S[i] == '9')
				{
					flag = 1;
				}	
				else
				{
					flag = 0;
					break;
				}

			}
		}
	}

	if(flag)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    int a[60], b[60];
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];

    }
    //バケット法
    int num[60] = {0};

    for(int i = 1; i <= N; i++){
        for(int j = 0; j < M; j++){
            if(a[j] == i || b[j] == i) ++num[i];
        }
    }
    for(int i = 1; i <= N; i++)
        cout << num[i] << endl;
    return 0;
}

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

int main(){
    int n,i;
    while( cin >> n, n ){
        vector<long> h(n);
        for(i = 0; i < n; i++){
            cin >> h[i];
        }
        sort( h.begin(), h.end() );
        long s = 0;
        for(i = 0; i < n-1; i++){
            s += h[i];
            h[i+1] += h[i];
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1292
def main():
    buf = input()
    N = int(buf)
    table = []
    for i in range(1, 10):
        create_table("", 0, i, table)
    count = 0
    for i in table:
        if i <= N:
            count += 1
        else:
            break
    print(count)

def create_table(num, current_digit, maximum_digit, table):
    if current_digit < maximum_digit:
        create_table(num + "3", current_digit + 1, maximum_digit, table)
        create_table(num + "5", current_digit + 1, maximum_digit, table)
        create_table(num + "7", current_digit + 1, maximum_digit, table)
    else:
        appearance = [0, 0, 0]
        for _, x in enumerate(num):
            if x == "3":
                appearance[0] += 1
            elif x == "5":
                appearance[1] += 1
            elif x == "7":
                appearance[2] += 1
            else:
                return
        if min(appearance) >= 1:
            table.append(int(num))
        return

if __name__ == '__main__':
    main()


Measured memory_bytes: 4184
#include <iostream>
using namespace std;
int main(void){
   // Your code here
   int x;
   for(int i=1;i<=10000 ;i++){
       cin >>x;
     if(x==0)break;
     else{
      cout << "Case";
      cout << " ";
      cout << i;
      cout << ": ";
      cout << x;
      cout << endl;
     }
}
}


Measured memory_bytes: 3044
N = int(input())
items = [list(map(int,input().split())) for i in range(N)]
items.sort(key=lambda x: x[0]+x[1], reverse=True)
taka = sum([items[i][0] for i in range(0,N,2)])
aoki = sum([items[i][1] for i in range(1,N,2)])
print(taka - aoki)

Measured memory_bytes: 32224
#include <bits/stdc++.h>
using namespace std;
string x[200005];
string b[200005];
bool cmp(string a,string b)
{ return a<b;

}
int main()
{   int n;
   cin>>n;
   int max=0;
   int j=0;
  map<string,int>m;
  for(int i=0;i<n;i++)
  {
     cin>>x[i];
     m[x[i]]++;
     if(m[x[i]]>max)max=m[x[i]];
  }
  for(int i=0;i<n;i++)
  {  if(m[x[i]]==max)
     b[j++]=x[i];
  }
  sort(b,b+j,cmp);
  for(int i=0;i<j;i=i+max)
    cout<<b[i]<<endl;
}

Measured memory_bytes: 28288
L, R = map(int, input().split())
ml = L // 2019
mr = R // 2019

for i in range(ml, mr+1):
  if L <= 2019 * i <= R:
    print(0)
    exit()

L %= 2019
R %= 2019
ans = float('inf')
if L > R:
  L, R = R, L
elif L == R:
  R += 2019
if L == 0 or R == 0:
  print(0)
  exit()

for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, (i*j)%2019)

print(ans)



Measured memory_bytes: 40428
#include <bits/stdc++.h>
using namespace std;
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for(i=1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    
}


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

int main( void )
{
	while ( !cin.eof() )
	{
		vector <int> v(5);
		for ( int i = 0; i < 5; i++ )
			cin >> v[i];
		if ( cin.eof() )
			break;

		sort( v.rbegin(), v.rend() );

		for ( int i = 0; i < 5; i++ )
		{
			cout << v[i];
			if ( i < 4 )
				cout << " ";
			else
				cout << endl;
		}

	}
	return 0;
}

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

int main() {
  ll k, n;
  cin >> k >> n;

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

  vector<ll> b(n + 1);
  for (ll i = 0; i < n; i++) {
    b[i] = (a[(i+1)%n] - a[i]) % k;
    if (b[i] < 0) b[i] += k;
  }

  cout << k - *max_element(b.begin(), b.end()) << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ld a, b, x;
  cin >> a >> b >> x;
  ld space = a*a*b - x;
  if (2*space/a/a <= b) {
    cout << fixed << setprecision(7) << 90 - atan((a*a*a)/2/space) * 180/Pi  << '\n';
  }
  else {
    cout << fixed << setprecision(7) << 90 - atan(2*x/a/b/b) * 180/Pi  << '\n';
  }
}

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

#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long MOD=1e9+7;
const long long LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=100050;

ll mpow(ll a,ll n){
	if(a==1||n==0)return 1;
	ll ans=1;
	a%=MOD;
	while(n!=0)
	{
		if(n&1)ans=(ans*a)%MOD;
		n>>=1;
		a=(a*a)%MOD;
	}
	return ans%MOD;
}
void solve(int T){
	ll n;
	scanf("%lld",&n);
	ll ans=(mpow(10,n)+mpow(8,n))%MOD;
	ans=(ans-2*mpow(9,n)+2*MOD)%MOD;
	printf("%lld",ans);
}
signed main(){
	int t=1;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//scanf("%d",&t); 
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

Measured memory_bytes: 3824
#include<iostream>
#include<cstdio>
#include<algorithm>
#define Maxn 100007
using namespace std;
inline long long read()
{
	long long x=0;char y=getchar();int f=1;
	while(y<'0'||y>'9')
	{
		if(y=='-') f=-1;
		y=getchar();
	}
	while(y<='9'&&y>='0')
	{
		x=10*x+y-'0';
		y=getchar();
	}
	return f*x;
}
long long n,a[Maxn],b[Maxn],c[Maxn],d[Maxn],pos1[Maxn],pos2[Maxn],ans,sum[Maxn];
int main()
{
//	freopen("1.txt","r",stdin);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int i=1;i<=n;i++) c[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for(int i=1;i<=n;i++)
	{
		pos1[i]=upper_bound(b+1,b+n+1,a[i])-b;
	}
	for(int i=1;i<=n;i++)
	{
		pos2[i]=upper_bound(c+1,c+n+1,b[i])-c;
	}
	for(int i=n;i;i--)
	{
		if(pos2[i]<=n)
		{
			sum[i]=sum[i+1]+(n-pos2[i]+1);
		}
	}
	for(int i=1;i<=n;i++)
	{
		ans+=sum[pos1[i]];
	}
	cout<<ans;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, curr;
    cin >> n;
    set <ll> paper;  
    REP(i, n){
        cin >> curr;
        if (paper.find(curr) == paper.end()) paper.insert(curr);
        else paper.erase(curr);
    }
    cout << paper.size() << endl;
}

Measured memory_bytes: 4864
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n;x>=1;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001

ll dp[N+2];

ll fun(ll a[],ll n,ll k)
{
	if(n==0 || n==1)
		return dp[n];
	if(dp[n]!=-1)
		return dp[n];
	ll mi=INT_MAX,i;
	ifr(i,k)
	{
		if(n-i-1<0)
			break;
		mi=min(mi,fun(a,n-i-1,k)+abs(a[n-i-1]-a[n]));
	}
	dp[n]=mi;
	return dp[n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,k,i,j;
    cin>>n>>k;
	ll a[n];
	ifr(i,N) dp[i]=-1;
	ifr(i,n)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	fun(a,n-1,k);
	cout<<dp[n-1]<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int N,M;cin>>N>>M;
  vector<int> city(N,0);
  int a,b;
  for(int i=0; i<M;i++){
    cin>>a>>b;
    city[a-1]++;
    city[b-1]++;
  }
  
  for(int i =0 ;i < N;i++){
    cout<<city[i]<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std ; 
int main (){
int a , b ;
  cin>>a>>b ;
  if (a <= 9 and b <= 9 ) {
   cout<<a*b<<endl;
    return 0 ;
  }
  else {
	cout<<-1<<endl;
    return 0 ;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 998244353;
const double PI = 3.141592653589793;

//階乗、逆元、階乗の逆元 
int main(){
  ll n, m, k;
  cin >> n >> m >> k;
  ll fact[1000000], inv[1000000], fact_inv[1000000];
  fact[1] = inv[1] = fact_inv[1] = 1;
  fact[0] = inv[0] = fact_inv[0] = 1;
  for (int i = 2; i < 1000000; i++) {
      fact[i] = fact[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
  }
  ll u[1000000];
  u[0] = m;
  for(int i = 1; i < 1000000; i++){
    u[i] = u[i-1] * (m-1) % MOD;
  }
  
  ll ans = 0;
  for(int i = 0; i <= k; i++){
    ll tmp = fact[n-1] * fact_inv[i] % MOD;
    tmp = tmp * fact_inv[n-i-1] % MOD;
    tmp = tmp * u[n-i-1] % MOD;
    ans = (tmp + ans)% MOD;
  }
  ans = ans % MOD;
  cout << ans <<endl;
}

Measured memory_bytes: 34872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  rep(i,n){
    int a;
    cin >> a;
    mp[a] ++;
  }
  //case1
  if(mp.size()==1 && mp[0]>0){
    cout << "Yes" << endl;
    return 0;
  }//mp.size()
  if(n%3 != 0){
    cout << "No" << endl;
    return 0;
  }
  //case2
  if(mp.size() == 2){
    int key = 0;
    bool suc1 = 0;
    bool suc2 = 0;
    for(auto p : mp){
      if(key==0 && p.second==n/3){
        suc1 = 1;
      }
      if(key==1 && p.second==2*n/3){
        suc2 = 1;
      }
      key ++;
    }//p
    if(suc1 && suc2){
      cout << "Yes" << endl;
      return 0;
    }
  }//mp.size()
  //case3
  if(mp.size() == 3){
    for(auto p : mp){
      if(p.second != n/3){
        cout << "No" << endl;
        return 0;
      }//p.second
    }//p
    int a,b,c;
    int key = 0;
    for(auto p : mp){
      if(key == 0) a = p.first;
      if(key == 1) b = p.first;
      if(key == 2) c = p.first;
      key ++;
    }//p
    if((a^b) == c){
      cout << "Yes" << endl;
      return 0;
    }//a^b
  }//mp.size()
  cout << "No" << endl;
}

Measured memory_bytes: 7224
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int temp, next;
	vector<int> a;
	cin >> temp;
	a.push_back(temp);

	while (1) {
		if ((temp % 2) == 0) {
			next = temp / 2;
		}
		else {
			next = 3 * temp + 1;
		}
		for (int j = 0; j < a.size(); j++) {
			if (a[j] == next) {
				goto EPI;
			}
		}
		a.push_back(next);
		temp = next;
	}
EPI:
	cout << a.size() + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
for i in range(1,N+2):
  if i*(i-1)//2==N:
    print('Yes')
    ans = [[] for i in range(i)]
    cnt = 0
    p = 0
    q = 1
    while cnt<N:
      cnt += 1
      ans[p].append(cnt)
      ans[q].append(cnt)
      if q==i-1:
        p += 1
        q = p+1
      else:
        q += 1
    print(len(ans))
    for a in ans:
      print(len(a),*a)
    break
else:
  print('No')

Measured memory_bytes: 9376
#include<iostream>
using namespace std;
#include<cstdio>
#include<complex>

typedef double type_n;
typedef complex<type_n> point;

point crosspoint(point &a, point &b, point &c, point &d)
{
    a -= d, b -= d, c -= d;
    point z;
    z = c * (((a * conj(b)).imag()) / (((a - b) * conj(c)).imag()));
    return z + d;
}

inline void show_cp(const point &z){ printf("%.12f %.12f\n", z.real(), z.imag()); }

int main()
{
    point a, b, c, d;
    int i, q;
    type_n a1, a2, b1, b2, c1, c2, d1, d2;

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a1, &a2, &b1, &b2, &c1, &c2, &d1, &d2);
        a.real(a1), a.imag(a2), b.real(b1), b.imag(b2), c.real(c1), c.imag(c2), d.real(d1), d.imag(d2);
        show_cp(crosspoint(a, b, c, d));
    }
    return 0;
}

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

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



Measured memory_bytes: 256
from math import gcd

k = int(input())

res = 0
mul = [0, 1, 3, 6]
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            res += gcd(gcd(a, b), c) * mul[len({a, b, c})]

print(res)


Measured memory_bytes: 9128
/******************************************************************************
 
 Online C++ Compiler.
 Code, Compile, Run and Debug C++ program online.
 Write your code in this editor and press "Run" button to compile and execute it.
 
 *******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    long long int b[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0)
            b[i+1]=a[i];
        else b[i+1]=b[i]+a[i];
        
        
    }
    ll k=0;
    long long int val[n+1][n+1]={0};
    for(ll i=1;i<n;i++)
    {
        
        ll s=1;
        for( ll j=i+1;j<=n;j++)
        {
            val[s][j]=b[j]-b[s-1];
            ll max=0;
            for(ll g=s;g<j;g++)
            {
                
                if(max>=val[s][g]+val[g+1][j])
                    max=val[s][g]+val[g+1][j];
                else if(max==0)max=val[s][g]+val[g+1][j];
                    
                
                
            }
            val[s][j]+=max;
            // cout<<max<<endl;
            s++;
        }
        //k++;
    }
    cout<<val[1][n]<<endl;
    
}

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

using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N + 1);
  rep(i, N) {
    cin >> H.at(i + 1);
  }
  Graph graph(N + 1, vector<int>(0));
  int a, b;
  rep(i, M) {
    cin >> a >> b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }
  vector<bool> list(N + 1, true);

  rep(i, N + 1) {
    if (i == 0) continue;
    if (!list.at(i)) continue;
    auto g = graph.at(i);
    int baseH = H.at(i);
    for (auto j : g) {
      int headH = H.at(j);
      if (headH > baseH) {
        list.at(i) = false;
      }
      if (headH < baseH) {
        list.at(j) = false;
      }
      if (headH == baseH) {
        list.at(i) = false;
        list.at(j) = false;
      }
    }
  }

  int ans = -1;
  for (auto l : list) {
    if (l) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8696
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int N,q;
q=0;
cin>>N;
vector<int> vec(N);
for(int i=0;i<N;i++){
    cin>>vec[i];
}
for(int j=0;j<10000;j++){
    for(int i=0;i<N;i++){
        if(vec[i]%2==1){
        cout<<j<<endl;
        q++;
        break;
        }
        else{
            vec[i]=vec[i]/2;
        }
    

         }
    if(q==1){
        break;
    }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    ll N, K;
    cin >> N >> K;

    N %= K;
    cout << min(N, K - N) << endl;

    return 0;
}


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

using namespace std;

#define pb push_back
#define prr pair<int,int> 
#define int long long
#define fir first
#define sec second
#define double long double
#define ll long long



int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,k;
    cin>>n>>k;
    vector<int> v1(n+1);
    for(int i=1;i<=n;i++){
        cin>>v1[i];
    }

    vector<int> ans;
    int c1=0;
    int a1=1;
    vector<int> m1(n+1,0);
    m1[1]=1;
    ans.pb(1);
    int start=-1;
    for(int i=0;i<n;i++){
        a1=v1[a1];
        c1++;
        if(m1[a1]==1){
            start=a1;
            break;
        }else{
            ans.pb(a1);
            m1[a1]=1;
        }
        
    }
    int l1=ans.size();
    if(k<=l1-1){
        int r1=k%l1;
        // cout<<r1<<"\n";
        cout<<ans[r1];    
        return 0;
    }

    vector<int> ans2;
    for(int i=0;i<l1;i++){
        if(start==ans[i]){
            while(i<l1){
                ans2.pb(ans[i]);
                i++;
            }
        }
    }
    for(int i=0;i<ans2.size();i++){
        // cout<<ans2[i]<<" ";
    }
    int l2=ans2.size();
    k=k-(ans.size()-ans2.size());
    int r1=k%l2;
    cout<<ans2[r1]; 

    // if(s.length()>=1 && s.length()<=10){
    //     if(t.length()==s.length()+1){
    //         cout<<"Yes";
    //     }else{
    //         cout<<"No";
    //     }

    // }else{
    //     cout<<"No";
    // }
}



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

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> list(N);
  vector<int> pen(N);
  int ac = 0;
  int penalty = 0;
  int q;
  string res;
  for (int i = 0; i < M; i++){
    cin >> q >> res;
    if (!list[q - 1] && res == "AC"){
      list[q - 1] = true;
      ac++;
    }
    if (!list[q - 1] && res == "WA"){
      pen[q - 1]++;
    }
  }
  for (int i = 0; i < N; i++){
    if (list[i]){
      penalty+= pen[i];
    }
  }
  cout << ac << " " << penalty << endl;
}


Measured memory_bytes: 640
import itertools
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
count = 0
ans = list(itertools.combinations(l, 3))
for i in ans:
    if i[0] + i[1] > i[2]:
        if len(i) == len(set(i)):
            count += 1

print(count)

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

int main(void)
{
	char a[1];
	char b[1];

	cin >> a >> b;

	if (a[0] == b[0]) {
		cout << "H" << endl;
	}
	else {
		cout << "D" << endl;
	}
}

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

using ll = long long;
const int INF = INT_MAX;//2147483647
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


int main() {

	int n,k;
	cin >> n >> k;
	vector<int> h(n+1,0);
	repeq(i,n){
		cin >> h[i];
	}

	vector<int> dp(n+1,0);
	dp[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		int minval=INF;
		for(int j=1; j<=k && i-j>=1; j++){
			chmin(minval,dp[i-j]+abs(h[i]-h[i-j]));
		}
		dp[i]=minval;
	}
	p(dp[n]);
	return 0;
}



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,d;
  cin >> n;
  int mx = -1e9;
  int mn = 1e9;
  ll sum = 0;
  rep(i,n){
    cin >> d;
    mx = max(mx,d);
    mn = min(mn,d);
    sum += d;
  }
  cout << mn << ' ' << mx << ' ' << sum << endl;
}



Measured memory_bytes: 3116
#include <iostream>
#include <stack>
#include <unordered_set>

using namespace std;

int main() {
    int L;
    cin >> L;

    unordered_set<int> cats;
    stack<int> cave;
    cave.push(0);

    int c, ans = 0;
    for (int i = 1; i <= L; i++) {
        cin >> c;
        if (c < 0) {
            if (cave.top() == -c) {
                cave.pop();
                cats.erase(-c);
            } else {
                ans = i;
                break;
            }
        } else {
            if (cave.top() != c && cats.find(c) == cats.end()) {
                cave.push(c);
                cats.insert(c);
            } else {
                ans = i;
                break;
            }
        }
    }

    cout << (ans ? to_string(ans) : "OK") << endl;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,k;
  cin >> a >> b >> k;
  long long tmp = k - a;
  if (a > k) {
    cout << a-k << " " << b<< endl;
  } else if (b > k-a) {
    cout << 0 << " " << b-k+a << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll dp_x[8010][16010] = {};
ll dp_y[8010][16010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll x,y;
    cin >> s >> x >> y;
    ll N = s.size();
    vector<string> st;
    ll idx = 0;
    rep(i,1,N){
        if(s[i] != s[i-1]){
            st.push_back(s.substr(idx,i-idx));
            idx = i;
        }else if(s[i] == 'T' && s[i-1] == 'T'){
            st.push_back(s.substr(idx,i-idx));
            idx = i;
        }
    }
    st.push_back(s.substr(idx, N-idx));
    ll m = st.size();
    vector<ll> xx, yy;
    ll mode = 0;
    rep(i,0,m){
        if(i == 0 && st[i] != "T"){
            x -= st[i].size();
        }else if(i != 0 && st[i] != "T"){
            if(mode == 0){
                xx.push_back(st[i].size());
            }else{
                yy.push_back(st[i].size());
            }
        }else{
            mode = (mode == 0 ? 1 : 0);
        }
    }
    ll mx = xx.size();
    ll my = yy.size();
    // printa(xx,mx);
    // printa(yy,my);
    dp_x[0][8000] = 1;
    dp_y[0][8000] = 1;
    rep(i,0,mx){
        rep(j,0,16000){
            if(j-xx[i] >= 0 && j-xx[i] <= 16000){
                dp_x[i+1][j] |= dp_x[i][j-xx[i]];
            }
            if(j+xx[i] >= 0 && j + xx[i] <= 16000){
                dp_x[i+1][j] |= dp_x[i][j+xx[i]];
            }
        }
    }
    rep(i,0,my){
        rep(j,0,16000){
            if(j-yy[i] >= 0 && j-yy[i] <= 16000){
                dp_y[i+1][j] |= dp_y[i][j-yy[i]];
            }
            if(j+yy[i] >= 0 && j + yy[i] <= 16000){
                dp_y[i+1][j] |= dp_y[i][j+yy[i]];
            }
        }
    }
    if(dp_x[mx][8000+x] && dp_y[my][8000+y]){
        print("Yes");
    }else{
        print("No");
    }

    
    
}


Measured memory_bytes: 504448
def caesar(enc, n)
  dec = ""
  a = "a".ord

  for ch in enc.split("")
    if /[a-z]/ =~ ch
      dec += ((ch.ord - a + n) % 26 + a).chr
    else
      dec += ch
    end
  end

  dec
end

### main

while (line = gets)
  enc = line.chop

  for n in (0..25)
    dec = caesar(enc, n)
    if /\b(the|this|that)\b/ =~ dec
      puts dec
      break
    end
  end
end

Measured memory_bytes: 6100
#include <stdio.h>
int main(void) {
    int a, b, i, c, d, e, f, g;
    e = 1;
     
     
 
    scanf("%d %d", &a, &b);
    if(a > b) {
        f = a;
        a = b;
        b = f;
    }
    if(b % a == 0) {
       e = a;
        }
    else {
    g = b % a;
 
    for(i = 1; i <= g; i++) {
        if(g % i == 0) {
            c = i;
         
        if(b % i == 0) {
            d = i;
        }
    }
        if(c == d) {
            e = c;
        }
    }
}
 
    printf("%d\n", e);
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ull x;
    cin >> x;
    ull m = 100;
    for(ll y = 1; ; ++y){
        m += m / 100;
        if(m >= x){
            cout << y << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict, deque, Counter
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inpl(): return list(map(int, sys.stdin.readline().split()))


def inpl_str(): return list(sys.stdin.readline().split())


L = inp()
print((L/3)**3)


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int Mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void solve()
{
  string s;
  cin>>s;
  if(s.back()=='s')
    cout<<s<<"es"<<nl;
  else
    cout<<s<<"s\n";
}

int main()
{
    fio;
    solve();
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h> 

int main() {
  int x,i,n;

  scanf("%d",&n);
  
  for(i=1; i<=n; i++) {
    x = i;
    
    if(x %3 == 0) {
      printf(" %d",i);
    } else if(x % 10 == 3) {
      printf(" %d",i);
    } else { 
      while(x != 0) {
	x /=10;
	if(x % 10 == 3) {
	  printf(" %d",i);
	  break;
	}
      }
    }
    
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

enum Currency {
	kJPY = 0,
	kBTC = 1,
};

struct present {
	uint32_t yen;
	double   btc;
	Currency currency;
};

int main()
{
	int n = 0;
	cin >> n;

	vector<present> presents(n);
	for (auto& present : presents) {
		string amount;
		cin >> amount;
		string currency_str;
		cin >> currency_str;

		if (currency_str.compare("JPY") == 0) {
			present.currency = kJPY;
		}
		else if (currency_str.compare("BTC") == 0) {
			present.currency = kBTC;
		}
		else {
			assert(!"bug in currency_str");
		}

		if (present.currency == kJPY) {
			present.yen = stoi(amount);
		}
		else {
			present.btc = stod(amount);
		}
	}

	double sum = 0.0;
	for (const auto&present : presents) {
		if (present.currency == kJPY) {
			sum += present.yen;
		}
		else {
			sum += present.btc * 380000.0;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int b[3][3]={0};
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(a[i][j]==l)
          b[i][j]=1;
      }
    }
  }
    bool ok=false;
    for(int i=0;i<3;i++){
      if(b[i][0]==1 and b[i][1]==1 and b[i][2]==1)
        ok=true;
    }
  for(int i=0;i<3;i++){
      if(b[0][i]==1 and b[1][i]==1 and b[2][i]==1)
        ok=true;
    }
    if(b[0][0]==1 and b[1][1]==1 and b[2][2]==1)
      ok=true;
    if(b[2][0]==1 and b[1][1]==1 and b[0][2]==1)
      ok=true;
    if(ok)
      cout<<"Yes";
    else
      cout<<"No";
  return 0;
}

Measured memory_bytes: 256
# N,M = map(int, input().split())
S = input()

can = "KIHBR"
tar = "AKIHABARA"

N = len(S)
i = 0
for c in S:
    if c == can[i]:
        i += 1
        if i == 5: break
    if not c in tar:
        print("NO")
        exit()

if any(S.count(can[i]) != 1 for i in range(4)):
    print("NO")
    exit()
if not i == 5:
    print("NO")
    exit()
if "AA" in S or "KA" in S or "IA" in S or "AI" in S:
    print("NO")
    exit()
print("YES")
# print("NO")



Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<ll, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main() {
	int n; cin >> n; int k; cin >> k;
	ll a[100000], sum[100001], absum[100001];
	sum[0] = absum[0] = 0;
	rep(i, n) {
		cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
		absum[i + 1] = absum[i] + max((ll)0,a[i]);
	}
	ll ma = 0;
	rep(i, n - k + 1) {
		ll s = sum[i + k] - sum[i];
		ll t = absum[i] + absum[n] - absum[i + k];
		ma = max({ ma, s + t,t });
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cctype>
#include <string>

class Parser {
public:
  std::string str;
  int idx;
  Parser (std::string str):str(str),idx(0)
  {
  }
  int evalas();
  int evalmd();
  int evalexpr();
  int evalnum();
};

int Parser::evalas() {
  int left = evalmd(), right;
  while(true) {
    switch(str[idx]) {
    case '+':
      idx++;
      right = evalmd();
      left = left+right;
      break;
    case '-':
      idx++;
      right = evalmd();
      left = left-right;
      break;
    default:
      goto hoge;
    }
  }
 hoge:
  return left;
}

int Parser::evalmd() {
  int left = evalexpr(),right;
  while(true) {
    switch(str[idx]) {
    case '*':
      idx++;
      right = evalexpr();
      left = left*right;
      break;
    case '/':
      idx++;
      right = evalexpr();
      left = left/right;
      break;
    default:
      goto hoge;
    }
  }
 hoge:
  return left;
}

int Parser::evalexpr() {
  int n;
  if (str[idx] == '(') {
    idx++;
    n = evalas();
    idx++;
  } else {
    n = evalnum();
  }
  return n;
}

int Parser::evalnum() {
  int ans=0;
  char ch;
  while (isdigit(ch=str[idx])) {
    idx++;
    ans = ans*10+(int)ch-(int)'0';
  }
  return ans;
}

int main() {
  int time;
  scanf("%d\n",&time);
  while(time--) {
    char str[100];
    fgets(str,100,stdin);
    printf("%d\n",Parser(std::string(str)).evalas());
  }
}

Measured memory_bytes: 1068
#include <stdio.h>
#include <string.h>
 
int main() {
    char s[101], p[100], r[200];
 
    scanf("%s", s);
    scanf("%s", p);
    strcpy(r,s);
    strcat(r,s);
 
    if (strstr(r,p)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
 
    return 0;
}
 

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int a;
    for (int i = 1; i <= 5; ++i) {
        cin >> a;
        if (a == 0) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(b >= 0 && a <= 0){
    cout << "Zero" << endl;
  }else if(a > 0){
    cout << "Positive" << endl;
  }else if(a < 0){
    if((b - a) % 2){
      cout << "Positive" << endl;
    }else{
      cout << "Negative" << endl;
    }
  }
}


Measured memory_bytes: 256
import sys

def countingSort(A, k):
    Sorted = []
    Cnt = [0] * (k + 1)

    for i in range(len(A)):
        Cnt[A[i]] += 1

    for i in range(len(Cnt)):
        for j in range(Cnt[i]):
            Sorted.append(i)

    print " ".join([str(v) for v in Sorted])

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    countingSort(A, 10000)

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        for (int j = 0; j < 100; j++)
        {
            if (a.at(i) % 2 == 0)
            {
                a.at(i) = a.at(i) / 2;
                ans++;
            }
            else
            {
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int n,l; 
int main(){
	scanf("%d%d",&n,&l);
    priority_queue<string,vector<string>,greater<string> > lex;
    for(int i=0;i<n;i++){
    	string str;
    	cin>>str;
    	lex.push(str);
    }
    vector<string> v;
    while(!lex.empty()){
    	string s=lex.top();
    	lex.pop();
    	cout<<s;
    	v.push_back(s);
    }
    printf("\n");
    return 0;
}

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

const int DIM = 35;

char str[DIM]; 
int frq[DIM];

int main(void) {
	cin >> (str + 1);
	int n = (int) strlen(str + 1);
	if (n < 26) {
		for (int i = 1; i <= n; ++i) {	
			++frq[str[i] - 'a']; }
		for (int i = 0; i < 26; ++i) {
			if (!frq[i]) {
				cout << (str + 1) << ((char) (i + 'a')) << endl;
				return 0; } } }
	else {
		int p = n;
		while (p > 1 and str[p - 1] > str[p]) {
			--p; }
		if (p == 1) {
			cout << -1; }
		else {
			for (int i = p; i <= n; ++i) {
				++frq[str[i] - 'a']; }
			for (int i = 1; i <= p - 2; ++i) {
				cout << str[i]; }	
			for (int i = str[p - 1] - 'a' + 1; i < 26; ++i) {
				if (frq[i]) {
					cout << ((char) (i + 'a'));
					return 0; } } } }
	return 0; }


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

inline int read()
{
	int ret=0,f=1; char c=getchar();
	while(c<48||c>57)
	{
		if(c=='-')f=-1;
	    c=getchar();
	}
	while(c>=48&&c<=57)ret=ret*10+c-48,c=getchar();
	return f*ret;
}

int n,a;
map<long long,int>mp;
long long s,ans;
int main()
{
	n=read();
	++mp[0];
	for(int i=1; i<=n; ++i){
		a=read();
		s+=a;
		ans+=mp[s];
		++mp[s];
	}
	cout<<ans;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
int main() {
  // input
  int n,m,x;cin >> n >> m >> x;
  vector<int> a(m) ;
  vector<int> c(n) ;
  for(int i = 0;i < m; i++) cin >> a[i];
 
  // compute
  int sum = 0;
  int ans = 0;

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

  for(int i = 0; i < x; i++){
    sum += c[i];
     }

  ans = min(sum,m -sum);
 
  // output  
  cout << ans << endl;
  
}

Measured memory_bytes: 3596
def solve(a, b, c):
    l = 0; r = a;
    for t in range(114514):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Measured memory_bytes: 7720
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


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


struct Node {
	int par;
	vector<int> link;
};

vector<Node> nod;

ll MOD = 1e9 + 7;

ll P(ll a, ll b) {
	ll res = 1;
	for (ll x = 0; x < b; ++x) {
		res *= a - x;
		res %= MOD;
	}
	return res;
}

int main() {
	int N, K;
	cin >> N >> K;
	nod.resize(N);
	rep(i, N) nod[i].par = -1;
	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		nod[a].link.push_back(b);
		nod[b].link.push_back(a);
	}
	ll res = 1;
	res *= K;
	res *= P(K - 1, nod[0].link.size());
	res %= MOD;
	queue<int> q;
	for (int i : nod[0].link) {
		nod[i].par = 0;
		q.push(i);
	}
	while (!q.empty()) {
		int idx = q.front(); 
		q.pop();
		res *= P(K - 2, nod[idx].link.size() - 1);
		res %= MOD;
		for (int i : nod[idx].link) {
			if (i == nod[idx].par) continue;
			nod[i].par = idx;
			q.push(i);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 7288
<?php
$n = (int)trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$cnt = 0;
for ($i=0; $i < $n-2; $i++) { 
	if ($s[$i] == "A") {
		if ($s[$i+1] == "B") {
			if ($s[$i+2] == "C") {
				$cnt += 1;
			}
		}
	}
}
echo $cnt;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  
  cin>>N;
  vector<int>x={111,222,333,444,555,666,777,888,999};
  
  int min=999;
  
  int answer;

  for(int i=0;i<9;i++){
    int S=x.at(i)-N;
    
    if(S>=0&&S<min){
      min=S;
      
      answer=x.at(i);
      
    }
    
  }
cout<<answer<<endl;
}


Measured memory_bytes: 256
// In the name of god
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define use_file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;
const ll N = 1e6, inf = 4e18, mod = 1e9 + 7;
ll n, m, t;
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >>  n;
	for(int i = 0; i < n; i++)cout << "ACL" ;
	cout << endl;
}


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



int main(){
  int a,b,c;
  //int i, j, sum = 0;
  
  cin >> a >> b >> c;

  if((a == b) && (a != c)){
    cout <<"Yes" << endl;
  }
  else if((b == c) && (b != a)){
    cout <<"Yes" << endl;
  }
  else if((a == c) && (a != b)){
    cout <<"Yes" << endl;
  }
  else{
    cout <<"No" << endl;
  }
  
  //cout << sum << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
lis = [[] for i in range(n)]
query = []

for num in range(m):
  tp = tuple(map(int,input().split()))
  query.append(tp)
  lis[tp[0]-1].append((tp[1],num))  

ans = [[0,0] for i in range(m)]

for num_p , pref in enumerate(lis):
  pref.sort(key = lambda tp:tp[0])
  for i,tp_city in enumerate(pref):
    ans[tp_city[1]][0] = num_p
    ans[tp_city[1]][1] = i+1

for item in ans:
  print("{:06}{:06}".format(item[0]+1,item[1]))

Measured memory_bytes: 52468
s=list(input())
n=len(s)
ans=0
for i in range(1,n):
  if s[i] == s[i-1]:
    if s[i] == "0":
      s[i] = "1"
    elif s[i] == "1":
      s[i] = "0"
    ans+=1
print(ans)

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] lettrs = scanner.nextLine().toCharArray();
		boolean[] exits = new boolean[26];
		
		for (int i = 0; i < exits.length; i++) {
			exits[i] = false;
		}
		for (int i = 0; i< lettrs.length; i++) {
			exits[lettrs[i]-'a'] = true;
		}
		String ans = "None";
		for (int i = 0; i < exits.length; i++) {
			if (!exits[i]) {
				char c = (char)(i+'a');
				ans = String.valueOf(c);
				break;
			}
		}
		
		System.out.println(ans);
		
		
		scanner.close();

	}

}

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

int knapsack(vector<int> &v, vector<int> &w, int W) {
    const int LIM = accumulate(v.begin(), v.end(), 0);
    vector<int> dp(LIM + 1, W + 1);
    dp[0] = 0;
    for (int i = 0; i < (int)v.size(); ++i) for (int j = LIM; j >= v[i]; --j) {
        dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
    int res = 0;
    for (int i = 0; i <= LIM; ++i) if (dp[i] <= W) res = i;
    return res;
}

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; ++i) {
        cin >> v[i] >> w[i];
    }
    cout << knapsack(v, w, W) << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long
using namespace std;

int main()
{
    ll r, d, x;
    cin >> r >> d >> x;

    ll prev = x;
    for(ll i = 0; i < 10; i ++)
    {
    	cout << r*prev - d << endl;
    	prev = r*prev - d;
    }
}

Measured memory_bytes: 256