akhauriyash/Code-Regression huggingface dataset:
line = input().split()
N = int(line[0])
K = int(line[1])

A = list(map(int, input().split()))
i = A.index(min(A))

b = (i+1)
a = (N-i)

if (N-1)%(K-1) != 0:
    print(str((N-1)//(K-1)+1))
else:
    print(str((N-1)//(K-1)))

Measured memory_bytes: 13880
#include <stdio.h>

#define WIDTH_MAX 30
#define HEIGHT_MAX 30

#define next( i ) ( ( ( i ) + 1 ) % ( WIDTH_MAX * HEIGHT_MAX ) )

typedef struct {
	int type;
	int min;
} FIELD;

FIELD field[ WIDTH_MAX * 2 + 1 ][ HEIGHT_MAX * 2 + 1 ] = {};
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int queue[ WIDTH_MAX * HEIGHT_MAX ], front, rear;

int bfs( int, int );

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

	for ( x = 1; x <= WIDTH_MAX * 2 - 1; x += 2 )
		field[ x ][ 0 ].type = 1;
	for ( y = 1; y <= HEIGHT_MAX * 2 - 1; y += 2 )
		field[ 0 ][ y ].type = 1;

	for ( ; scanf( "%d %d", &w, &h ), w; printf( "%d\n", bfs( w, h ) ) ) {
		for ( y = 1; y <= h * 2 - 1; y += 2 )
			for ( x = 1; x <= w * 2 - 1; x += 2 )
				field[ x ][ y ].min = 0;
		for ( x = 1; x <= w * 2 - 1; x += 2 )
			field[ x ][ h * 2 ].type = 1;
		for ( y = 1; y <= h * 2 - 1; y += 2 )
			field[ w * 2 ][ y ].type = 1;

		for ( y = 1; y <= h * 2 - 1; y++ )
			for ( x = y % 2 + 1; x <= w * 2 - 1 ; x += 2 )
				scanf( "%d", &field[ x ][ y ].type );
	}

	return 0;
}

int bfs( int w, int h ) {
	int i, x, y, tmp;

	front = rear = 0;

	queue[ rear ] = h * 2 + 2;
	rear = next( rear );

	field[ 1 ][ 1 ].min = 1;

	while ( rear != front ) {
		tmp = queue[ front ];
		front = next( front );

		x = tmp / ( h * 2 + 1 );
		y = tmp % ( h * 2 + 1 );

		if ( x == w * 2 - 1 && y == h * 2 - 1 )
			break;

		for ( i = 4; i--;  ) {
			int nx1 = x + dx[ i ], ny1 = y + dy[ i ], nx2 = nx1 + dx[ i ], ny2 = ny1 + dy[ i ];

			if ( !field[ nx1 ][ ny1 ].type && !field[ nx2 ][ ny2 ].min ) {
				queue[ rear ] = nx2 * ( h * 2 + 1 ) + ny2;
				rear = next( rear );

				field[ nx2 ][ ny2 ].min = field[ x ][ y ].min + 1;
			}
		}
	}

	return field[ w * 2 - 1 ][ h * 2 - 1 ].min;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	set<string> s;
	int n = next<int>();
	while(n--) s.insert(next<string>());
	cout<<s.size()<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 19276
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
N_list = [0] * N
for _ in range(M):
  A, B = map(int, input().split())
  if H_list[A-1] >= H_list[B-1]:
    N_list[B-1] = 1
  if H_list[A-1] <= H_list[B-1]:
    N_list[A-1] = 1
print(N_list.count(0))

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

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e3;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};



void solve(){
	   int n,wt;
   cin>>n>>wt;

   vector<vi> dp(n+1,vi (wt+1,0));
   vi w(n+1,0),val(n+1,0);

   rep(i,1,n+1){
	     cin>>w[i]>>val[i];	    
	 }

   rep(i,0,n+1){
    rep(j,0,wt+1){
       if(i==0 || j==0)
		  dp[i][j]=0;
	   else if(w[i]<=j)
		  dp[i][j]=max(val[i]+dp[i-1][j-w[i]],dp[i-1][j]);
	   else
		   dp[i][j]=dp[i-1][j];
		 }
	   }

  cout<<dp[n][wt]<<endl;
 // rep(i,0,n+1){
   // rep(j,0,wt+1)
	//	 cout<<dp[i][j]<<" ";
	 //cout<<endl;
 // }
	   
  

}



int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	   
}


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

int main() {
  int N;cin>>N;
  if(N<3){cout<<0<<endl;exit (0);}
  vector<ll> V(N);
  for(int i=0;i<N;i++)cin>>V.at(i);
  sort(V.begin(),V.end());
  ll ans=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(V[i]+V[j]>V[k]&&V[i]<V[j]&&V[j]<V[k])ans++;
      }
    }
  }cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
int n;
int i=1;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%3==0||i%10==3||i%10000%1000%100/10==3||i%10000%1000/100==3||i%10000/1000==3){
            printf(" %d",i);
        }


    }
    printf("\n");

        return 0;
}

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

int main() {

    ll k;
    cin >> k;
    vector<ll> a(10);
    iota(a.begin(), a.end(), 0);
    ll last, next;
    for (int i = 1; a.size() <= k; i++) {
        last = a[i] % 10;
        next = a[i] * 10 + last;
        if (last) a.push_back(next - 1);
        a.push_back(next);
        if (last < 9) a.push_back(next + 1);
    }

    cout << a[k] << endl;

    return 0;
}

Measured memory_bytes: 1656
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,T;
  cin >> n >> T;

  vi r;

  rep(i,n)
  {
    int c,t;
    cin >> c >> t;

    if(T >= t)
    {
      r.emplace_back(c);
    }
  }

  vsort(r);

  if(sz(r) == 0)
    cout << "TLE" << endl;
  else  cout << r[0] << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define line puts("")


const int INF = 1e9+7;
const ll INFLL = 1e17;
const double EPS = 1e-6;

using namespace std;

int al[30];
int main(){
	string s;
	cin>>s;
	
	int n=  s.size();
	
	rep(k,0,n)al[s[k] - 'a']++;
	
	ll ret = 0;
	rep(k,0,30)rep(i,k+1,30)ret += (ll)al[k]*al[i];
	cout<<ret+1<<endl;
	
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	LL n,k;
    cin>>n>>k;
    vl a(n);
    FOR(i,0,n){
        cin>>a[i];
    }
    cmbset(101010);
    sort(a.begin(),a.end());
    LL ans=0;
    FOR(i,k-1,n){
        ans=add(ans,mul(a[i],cmb(i,k-1)));
    }
    FOR(i,0,n-k+1){
        int j=n-i-1;
        ans=sub(ans,mul(a[i],cmb(j,k-1)));
    }
    cout<<ans<<endl;
}


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

const string YES = "Yes";
const string NO = "No";

auto solve(long long N){
    stringstream ss;
    ss << N;
    auto s = ss.str();
    return equal(begin(s), end(s), rbegin(s)) ? YES : NO;
}

int main(){
    long long N;
    scanf("%lld",&N);
    auto result = solve(N);
    cout << result << endl;
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<long long> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    long long mi, ma;
    if(n % 2){
        mi = A[n / 2];
        ma = B[n / 2];
    } else {
        mi = (A[n / 2] + A[n / 2 - 1]);
        ma = (B[n / 2] + B[n / 2 - 1]);
    }

    cout << ma - mi + 1 << endl;

    return 0;
}

Measured memory_bytes: 6364
#include<stdio.h>

int main(void)
{
int N,i,g;

        scanf("%d",&N);

        double x[9],goukei=0.0;

        for(i=0; i<N; i++){

        char u[3]={};

           scanf("%lf",&x[i]);
           scanf("%s",&u);

        if(u[0] == 'J')
              goukei = goukei + x[i] * 1.0;

        else if (u[0] == 'B')
              goukei = goukei + (x[i] * 380000.0);

        }

        printf("%lf\n",goukei);

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
string find(int n)
{
    string ans="";
    while(n>0)
    {
        ans+=n%10+'0';
        n/=10;
    }
    int cnt=ans.size();
    cnt=3-cnt;
    while(cnt--)
    {
        ans+='0';
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string str;
cin>>str;
int ans=0;
for(int i=0;i<1000;i++)
{
    string val=find(i);
    int dp[3]={};
    for(int j=0;j<n;j++)
    {
        for(int k=2;k>=0;k--)
        {
            if(val[k]==str[j])
                {
                    if(k!=0)
                        dp[k]+=dp[k-1];
                    else
                        dp[k]+=1;
                }
        }
    }
   if(dp[2])
    ans++;
}
cout<<ans<<endl;


    return 0;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    ll ans;
    rep(i, n){
        if(i == 0){
            ans = (ll)k;
            continue;
        }
        ans *= (ll)(k-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h> 
#include <bits/types/stack_t.h>
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  

int main() 
{ 
    FIO
    ll t;
    //cin >> t;
    t=1;
    while(t--)
    {
        int n;
        cin >> n;

        int a[n];

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

        map<int,int> mp1,mp2;
        for(int i=0;i<n;i++)
        {
            mp1[i+1-a[i]]++;
            mp2[a[i]+i+1]++;
        }

        ll ans = 0;
        for(auto i=mp1.begin();i!=mp1.end();i++)
        {
            ll m1 = i->second;
            auto fi = mp2.find(i->first);
            
            if(fi!=mp2.end())
            {
                ll m2 = fi->second;
                ans += m1*m2;
            }
        }

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


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n, k;
    cin >> n >> k;
    vector<intpair> v(n);
    rep(i,n){
        int a, b;
        cin >> a >> b;
        v[i] = {a,b};
    }
    
    sort(ALL(v));
    int ans = -1;
    for(auto p : v){
        k -= p.second;
        if(k <= 0){
            ans = p.first;
            break;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    ans = 0
    for i in range(1,N+1):
        if i % 3 == 0 and i % 5 == 0:
            continue
        elif i % 3 == 0:
            continue
        elif i % 5 == 0:
            continue
        else:
            ans += i
    print(ans)



if __name__ == "__main__":
    main()

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

int main() {
    int x, y;
    cin >> x >> y;
    vector<int> a(205);
    a[0] = 300000;
    a[1] = 200000;
    a[2] = 100000;


    if (x == 1 && y == 1) {
        cout << a[x - 1] * 2 + 400000 << endl; 
    } else {
        cout << a[x - 1] + a[y - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3576
A,B,K=map(int,input().split())
X=[]
if A<=B :
    for a in range(A):
        if A%(a+1)==0 and B%(a+1)==0:
            X.append(a+1)
        else:
            continue

else :
    for b in range(B):
        if A%(b+1)==0 and B%(b+1)==0:
            X.append(b+1)
        else:
            continue
print(X[-K])


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

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k; cin >> n >> k;
	vi h(n);
	rep(i, 0, n) cin >> h[i];
	cout << count_if(all(h), [k](auto x) {return x >= k; }) << endl;
	return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;

int main(){
  const int m=10000,g=5000,s=1000;
  int N,Y,z=0,p=0;

  cin>>N>>Y;
  //x=10,000 y=5,000 z=1,000


  REP(x,0,N){
    REP(y,0,(N-x)){
      z=N-(x+y);
      if(!p && (x*m + y*g + z*s)==Y){
        cout<<x<<" "<<y<<" "<<z<<endl;
        p++;
        break;
      }
    }
  }
  cout<<(p?"":"-1 -1 -1\n");
}


Measured memory_bytes: 384
# coding: utf-8
# 計数ソート


def countingSort(A, B, k):
    global n

    C = [0] * k

    for i in range(n):
        C[A[i]] += 1

    for j in range(1, k):
        C[j] = C[j] + C[j - 1]

    for l in reversed(A):
        B[C[l] - 1] = l
        C[l] -= 1


if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]

    B = [0] * n

    countingSort(A, B, max(A) + 1)
    print(' '.join(map(str, B)))



Measured memory_bytes: 240608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  int n,W;
  cin>>n>>W;
  vector<long> w(n),v(n);
  rep(i,n){
    cin >> w.at(i)>>v.at(i);
  }
  vector<vector<long>>dp(n+1,vector<long>(W+1));
  rep(i,n){
    rep(j,W+1){
      if(j<w[i]){
        dp[i+1][j]=dp[i][j];
      }
      else{
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }
    }
  }
  cout<<dp[n][W]<<endl;
}

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

const int M = 1000000007;
long long a[2001], b[2001];
int n, k;

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

	a[0] = 1, b[0] = 1;

	for (int i = 1; i <= n; i++) {
		a[i] = (a[i - 1] * i) % M;

		long long c[30];

		c[0] = a[i], b[i] = a[i];

		for (int j = 1; j < 30; j++)
			c[j] = (c[j - 1] * c[j - 1]) % M;

		for (int j = 1; j < 30; j++)
			if ((1 << j) & (M - 2))
				b[i] = (b[i] * c[j]) % M;
	}

	for (int i = 1; i <= k; i++) {
		long long t = ((a[k - 1] * b[i - 1] % M) * b[k - i]) % M;
		long long u;
		if (i <= n - k + 1)
			u = ((a[n - k + 1] * b[i] % M) * b[n - k - i + 1]) % M;
		else
			u = 0;

		cout << t * u % M <<  endl;
	}

  return 0;
}

Measured memory_bytes: 256
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int n, m;
vector<pair<int, int> > bridges;
vector<int> starts;
vector<int> dp;

int num(int s){
    if(dp[s] != -1) return dp[s];
    int count = 0;
    bool eda = false;
    int start = lower_bound(starts.begin(), starts.end(), s) - starts.begin();
    int end = upper_bound(starts.begin(), starts.end(), s) - starts.begin();
    for(int i = start; i < end; i++){
        eda = true;
        int endd = bridges[i].second;
        int now = num(endd);
        if(now > count){
            count = now;
            //cout << "count update: " << count << endl;
        }
    }
    if(eda) count++;
    dp[s] = count;
    //cout << "dp[" << s << "]:" << dp[s] << endl;
    return dp[s];
}


int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        bridges.push_back(make_pair(a, b));
    }

    sort(bridges.begin(), bridges.end());
    for(int i = 0; i < m; i++){
        starts.push_back(bridges[i].first);
        //cout << bridges[i].first << " " << bridges[i].second << endl;
    }

    for(int i = 0; i <= n; i++){
        dp.push_back(-1);
    }

    int result = 0;
    for(int i = 0; i < n; i++){
        if(num(i+1) > result) result = dp[i+1];
    }



    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N, K; cin >> N >> K;
    vector<ll> a(N, 0), cum(N+1, 0);
    rep(i, N) cin >> a[i];
    rep(i, N) cum[i+1] = cum[i] + a[i];
    
    ll ans = 0; map<ll, ll> mp;

    rep(i, N+1) {
        if (i>=K) mp[(cum[i-K]-(i-K))%K]--;
        ans += mp[(cum[i]-i)%K];
        mp[(cum[i]-i)%K]++;
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    p.at(i).first=a.at(i);
    p.at(i).second=i+1;
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<N;i++){
    if(a.at(p.at(i).first-1)==p.at(i).second){
      ans++;
    }
  }
  cout<<ans/2<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c;
  string s,ss;
  cin>>a;
  bool flag[4]={};
  for(int i=0;i<a;i++){
    char d;cin>>d;
    if(d=='G')flag[0]=true;
    else if(d=='W')flag[1]=true;
    else if(d=='Y')flag[2]=true;
    else flag[3]=true;
  }
  int cnt=0;
  for(int i=0;i<4;i++)
    if(flag[i])cnt++;
  if(cnt==3)
    cout<<"Three"<<endl;
  else
    cout<<"Four"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;

string replaceA(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'a';
    }
  }
  return s;
}

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  string candidates = "";
  for (int i = S.size()-T.size(); i >= 0; i--) {
    bool replacable = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i+j] == '?') {
        continue;
      }
      if (S[i+j] != T[j]) {
        replacable =false;
        break;
      }
    }
    if (replacable) {
      string newCandidate = replaceA( S.substr(0, i) + T + S.substr(i + T.size()) );
      candidates = newCandidate;
      break;
    }
  }

  if (candidates.size() < 1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << candidates << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
X = input()
tmp = sum(X[i] == '1' for i in range(N))

for_zero = tmp + 1
for_one = tmp - 1
zero_S = 0
one_S = 0


numbers = [0] * N
counts = [1] * N

if tmp == 1:
    for i in range(N):
        if X[i] == '1':
            counts[i] = 0
    # =====================first sweep
    tmp_zero = 1
    for i in range(N):
        if X[-i - 1] == '1':
            zero_S += tmp_zero
            zero_S %= for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero

    # =====================second sweep
    tmp_zero = 1
    for i in range(N):
        if X[-i - 1] == '1':
            pass
        else:
            numbers[-i - 1] = (zero_S + tmp_zero) % for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero

else:
    # =====================first sweep
    tmp_zero = 1
    tmp_one = 1
    for i in range(N):
        if X[-i - 1] == '1':
            one_S += tmp_one
            one_S %= for_one
            zero_S += tmp_zero
            zero_S %= for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero
        tmp_one *= 2
        tmp_one %= for_one

    # =====================second sweep
    tmp_zero = 1
    tmp_one = 1
    for i in range(N):
        if X[-i - 1] == '1':
            numbers[-i - 1] = (one_S - tmp_one) % for_one
        else:
            numbers[-i - 1] = (zero_S + tmp_zero) % for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero
        tmp_one *= 2
        tmp_one %= for_one




def solution(number):
    loop = 0
    while number != 0:
        popcount = 0
        for i in range(30):
            if (1 << i) & number:
                popcount += 1
        number %= popcount
        loop += 1
    return loop

for i in range(N):
    counts[i] += solution(numbers[i])

print(*counts, sep='\n')

Measured memory_bytes: 85072
#include "bits/stdc++.h"
using namespace std;
#include "string"
#define int long long
#define pi pair <int, int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'

class SequenceSum {
private:
	int n, x, m;
	map < int, int > mp, id;

public:
	SequenceSum(int _n, int _x, int _m) {
		n = _n;
		x = _x;
		m = _m;
	}

	int solve() {
		int cur = x, cnt = 1, ans = 0;
		mp[0] = 0;
		while(cnt <= n) {
			if(cur <= 1) {
				ans += (n - cnt + 1)*cur;
				break;
			} 
			if(mp.find(cur) != mp.end()) {
				int tmp = ans;
				n -= (cnt - 1);
				ans += (n / (cnt - mp[cur]))*(tmp - id[mp[cur] - 1]);
				n %= (cnt - mp[cur]);
				ans += id[mp[cur] + n - 1] - id[mp[cur] - 1];
				break;
			}
			ans += cur;
			mp[cur] = cnt;
			id[cnt] = ans;
			cnt++;
			cur = (cur * cur ) % m;
		}
		return ans;
	}
};

int32_t main() {
	boost;
	int n, x, m;
	cin >>  n >> x >> m;
	SequenceSum ss(n, x, m);
	cout << ss.solve() << endl;
}

Measured memory_bytes: 9816
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
 
ll dp[401][401];
 
ll prefix[401];
 
ll v[401];
 
ll solve( int i, int j){
 
    if(i>=j){
        return 0;
 
    }
    
  
 
    if(dp[i][j]!=-1){
        return dp[i][j];
 
    }
 
 
    ll ans=LLONG_MAX;
    ll s;
     if(i>0){
        s=prefix[j]-prefix[i-1];
 
    }else{
        s=prefix[j];
 
    }
 
    for(int k=i;k<j;k++){
 
        ll left;
        ll right;
        if(dp[i][k]!=-1){
            left=dp[i][k];
 
        }else{
            left=solve(i,k);
            dp[i][k]=left;
 
        }
 
        if(dp[k+1][j]!=-1){
            right=dp[k+1][j];
            
        }else{
            right=solve(k+1,j);
            dp[k+1][j]=right;
 
        }
 
 
        ll temp=s+left+right;
 
        ans=min(ans,temp);
 
    }
 
 
    return dp[i][j]=ans;
 
 
 
}
 
int main(){
    
   int n;
   cin>>n;
   
   
   memset(dp,-1,sizeof(dp));
 
   
 
   for(int i=0;i<n;i++){
       cin>>v[i];
   }
   
 
   prefix[0]=v[0];
 
   for(int i=1;i<n;i++){
       prefix[i]=prefix[i-1]+v[i];
 
   }
 
 
 
   cout<<solve(0,n-1);
 
 
 
}

Measured memory_bytes: 4880
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x-r<0 || y-r<0 || x+r>W||y+r>H)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
		
	return 0;
}


Measured memory_bytes: 3084
import sys
input = sys.stdin.buffer.readline
import fractions
from functools import reduce

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
            
    def lcm(x,y):
        return((x*y)//fractions.gcd(x,y))
        
    l = reduce(lcm,a)
    ans = 0
    for num in a:
        ans += l//num
    
    print(ans%MOD)

if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-15;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

bool check(const string &s, const string &t, int sindex, int tindex, int len) {
  for (int i = 0; i < len; i++) {
    if (s[sindex + i] == t[tindex + i]) continue;
    if (s[sindex + i] == '?' || t[tindex + i] == '?') continue;
    return false;
  }
  return true;
}

int solve(string a, string b, string c) {
  int alen = a.size(), blen = b.size(), clen = c.size();
  // aの相対位置で何番目ならok
  unordered_map<int, int> ab, ac, bc;
  ab[-blen] = 1;
  ab[alen] = 1;
  for (int i = -blen + 1; i <= alen - 1; i++) {
    int aindex = max(0, i);
    int bindex = max(-i, 0);
    int len = min(alen - aindex, blen - bindex);
    if (check(a, b, aindex, bindex, len)) ab[i] = 1;
  }
  ac[-clen] = 1;
  ac[alen] = 1;
  for (int i = -clen + 1; i <= alen - 1; i++) {
    int aindex = max(0, i);
    int cindex = max(-i, 0);
    int len = min(alen - aindex, clen - cindex);
    if (check(a, c, aindex, cindex, len)) ac[i] = 1;
  }
  bc[-clen] = 1;
  bc[blen] = 1;
  for (int i = -clen + 1; i <= blen - 1; i++) {
    int bindex = max(0, i);
    int cindex = max(-i, 0);
    int len = min(blen - bindex, clen - cindex);
    if (check(b, c, bindex, cindex, len)) bc[i] = 1;
  }
  int ret = INF;
  for (int i = -blen; i <= alen; i++) {
    for (int j = -clen; j <= alen; j++) {
      int diff = j - i;
      int ma = max({alen - 1, i + blen - 1, j + clen - 1});
      int mi = min({0, i, j});
      if (ab[i] && ac[j]) {
        if (diff < -clen || blen < diff || bc[diff]) {
          ret = min(ret, ma - mi + 1);
        }
      }
    }
  }
  return ret;
}

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

  string a, b, c;
  cin >> a >> b >> c;
  int ret = min({solve(a, b, c), solve(b, a, c), solve(c, a, b)});
  cout << ret << endl;
}


Measured memory_bytes: 904
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n) for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main()
{
    
    

    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;
        
        VVI vvi;

        REP(i, 0, n) {
            vvi.push_back( vector<int>() );
            int sum = 0;
            
            REP(j, 0, n) {
                int in;
                std::cin >> in;
                vvi[i].push_back(in);
                sum += in;
            }
            vvi[i].push_back(sum);
        }

        vvi.push_back( vector<int>() );
        REP(i, 0, n + 1) {
            int sum = 0;
            
            REP(j, 0, n) {
                sum += vvi[j][i];
            }
            
            vvi[n].push_back(sum);
        }
        
        
        REP(i, 0, vvi.size()) {
            REP(j, 0, vvi[i].size()) {
                std::cout << std::setw(5) << vvi[i][j];
            }
            std::cout << std::endl;
        }
    }
    return 0;
}

    

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define fir first
#define sec second
#define db double
#define ll long long
#define ev eg[i].v
#define pb push_back
#define INF 1000000007
#define pir pair<int,int>
#define Rep(i,l,r) for(int i=(l);i<=(r);++i)
#define RepD(i,r,l) for(int i=(r);i>=(l);--i)
#define RepG(i,x) for(int i=hd[x];i;i=eg[i].nxt)
using namespace std;

const int N=1e5+5;

ll a[N],b[N],p[N];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n,m,s,ans=0;
	scanf("%lld%lld",&n,&s);
	Rep(i,1,n) scanf("%lld%lld",&a[i],&b[i]);
	ll l=1,r=n;
	while(l<=r)
		if(s<=a[l]) while(l<=r) p[++m]=r--;
		else if(s>=a[r]) while(l<=r) p[++m]=l++;
		else{
			if(b[l]>=b[r]) b[l]+=b[r],p[++m]=r--;
			else b[r]+=b[l],p[++m]=l++;	
		}
	ans=abs(s-a[p[n]]);
	RepD(i,n,2) ans+=abs(a[p[i]]-a[p[i-1]]);
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 2688
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	a := make([]int, N)
	for i := range a {
		fmt.Scanf("%d", &a[i])
	}
	fmt.Println(solve(N, a))
}

func solve(n int, a []int) float64 {
	ones, twos, threes := 0, 0, 0
	for _, num := range a {
		switch num {
		case 1:
			ones++
		case 2:
			twos++
		case 3:
			threes++
		}
	}
	max_ones := ones + twos + threes
	max_twos := twos + threes
	max_threes := threes
	//
	dp := make([][][]float64, n+1)
	for i := range dp {
		dp[i] = make([][]float64, n+1)
		for j := range dp[i] {
			dp[i][j] = make([]float64, n+1)
		}
	}
	//
	var i, j, k int
	var sum float64
	for k = 0; k <= max_threes; k++ {
		for j = 0; j <= max_twos-k; j++ {
			for i = 0; i <= max_ones-j-k; i++ {
				if i+j+k == 0 {
					continue
				}
				sum = float64(i + j + k)
				dp[i][j][k] = float64(n) / sum
				if i > 0 {
					dp[i][j][k] += (dp[i-1][j][k] * float64(i)) / sum
				}
				if j > 0 {
					dp[i][j][k] += (dp[i+1][j-1][k] * float64(j)) / sum
				}
				if k > 0 {
					dp[i][j][k] += (dp[i][j+1][k-1] * float64(k)) / sum
				}
			}
		}
	}
	return dp[i-1][j-1][k-1]
}


Measured memory_bytes: 256492
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Sequence solver = new Sequence();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}


	static class Sequence {
		private int n;
		private long a[];

		private long output;
		private Scanner scanner;

		public Sequence() {
			this.scanner = new Scanner(System.in);
		}

		public void readInput() {
			n = Integer.parseInt(scanner.next());
			a = new long[n];
			for(int i=0; i<n; i++) {
				a[i] = Integer.parseInt(scanner.next());
			}
		}

		private long count(int sign) {
			long count=0;
			long sum=0;
			for(int i=0; i<n; i++) {
				sum += a[i];
				if(i%2==sign) {
					// a[i]までの合計を正にするとき
					if(sum<=0) {
						count += 1-sum;
						sum = 1;
					}
				} else {
					// a[i]までの合計を負にするとき
					if(0<=sum) {
						count += 1+sum;
						sum = -1;
					}
				}
			}
			return count;
		}

		public void solve() {
			long count1 = 	count(0);
			long count2 = count(1);
			output = Math.min(count1,count2);
		}




		public void writeOutput() {
			System.out.println(output);
		}
	}

}

Measured memory_bytes: 50176
# -*- coding: utf-8 -*-


def main():
    from itertools import permutations

    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))
    a = 0
    b = 0

    ps = sorted((permutations(range(1, n + 1))))

    for index, pi in enumerate(ps, 1):
        if pi == p:
            a = index
        if pi == q:
            b = index

    print(abs(a - b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;

int main(){
    long long N, X;
    cin >> N >> X;
    vector<long long> x(N), y(N+1, 0);
    for(long long i=0; i<N; i++)
        cin >> x[i];
    reverse(x.begin(), x.end());

    for(long long i=1; i<=N; i++)
        y[i] = y[i-1] + x[i-1];

    vector<long long> fac(N);
    fac[0] = 5;
    for(long long i=1; i<N; i++)
        fac[i] = 3+2*i;

    long long ans = 1LL<<60;
    for(long long k=1; k<=N; k++){
        long long tmp = (N+k)*X;
        for(long long j=0; j<=N/k; j++){
            long long l = j*k;
            long long r = min(N, (j+1)*k);
            if(l >= r) continue;
            tmp += fac[j] * (y[r] - y[l]);
            if(tmp > 1LL<<60) break;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    left = min(a[i], b[i])
    ans += left
    right = min(a[i + 1], b[i] - left)
    ans +=  right
    a[i + 1] -= right

print(ans)

Measured memory_bytes: 18324
def edu_dp_e_knapsack2():
    n, c = map(int, input().split())
    w, v = [0], [0]
    for _ in range(n):
        a, b = map(int, input().split())
        w.append(a)
        v.append(b)
    dp = [[float('inf')] * 100001 for _ in range(n + 1)]
    dp[0][0] = 0
    for i in range(1, n + 1):
        for j in range(0, 100001):
            dp[i][j] = dp[i - 1][j]
            if j >= v[i]:
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i])
    ans = 100000
    while dp[n][ans] > c: ans -= 1
    print(ans)
edu_dp_e_knapsack2()

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

int main(){
    int A, B, C;
    int X;
    cin >> A >> B >> C >> X;

    int res =0;
    for(int a=0; a<=A; a++){
        for(int b=0; b<=B; b++){
            for(int c=0; c<=C; c++){
                int total = 500*a + 100*b + 50*c;
                if(total == X)res++;
            }
        }
    } 
    cout << res << endl;
}




Measured memory_bytes: 256
n,k=[int(j) for j in input().split()]
a=[int(j) for j in input().split()]
from itertools import accumulate
l=[0]+list(accumulate(a))
ll=[]
for i in range(n+1):
    ll.append((i-l[i])%k)
import collections
c=collections.Counter()
ans=0
for i in range(n+1):
    ans+=c[ll[i]]
    c[ll[i]]+=1
    if i>=k-1:
        c[ll[i-k+1]]-=1
print(ans)

Measured memory_bytes: 50340
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

class Main {

	public static void main(String[] args) {
		Set<Long> set = new TreeSet<Long>();
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			for (int i=0; i<times; i++) set.add(sc.nextLong());
			times = sc.nextInt();
			for (int i=0; i<times; i++) set.add(sc.nextLong());
			ArrayList<Long>  a = new ArrayList<Long>(set);
			for (int i=0; i<a.size(); i++) System.out.println(a.get(i));
		}
	}
}


Measured memory_bytes: 193312
#include<stdio.h>
int main(void){
  int n,i,count=0;
  scanf("%d",&n);
  long a;
  for(i=0;i<n;i++){
    scanf("%ld",&a);
    while(a%2==0){
      a/=2;
      count ++;
    }
  }
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  ld ans = n*2*M_PI;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	bool f = true;
	int N, M; cin >> N >> M;
	vi a(N, -1);

	rep(i, M) {
		int s, c; cin >> s >> c;
		s--;
		// db(s); dbl(c);
		if (a.at(s) == -1) { // 数字未指定
			a.at(s) = c;
		} else if (a.at(s) != c) { // 違う数が指定済み
			f = false;
		}
	}

	if (N > 1 && a.at(0) == 0) f = false; // 2桁以上かつ最上位が0
		
	if (!f) {
		cout << -1 << endl;
	} else {
		rep(i, N) {
			if (a.at(i) == -1) { // 未指定
				if (N > 1 && i == 0) { // 2桁以上かつ最上位の場合
					cout << 1;
				} else {
					cout << 0;
				}
			} else {
				cout << a.at(i);
			}
		}
		cout << endl;
	}
}

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

int main() {
    long long N;
    std::cin >> N;

    std::vector<long> primes;
    // 8 -> [(2, 3)]
    // 24 -> [(2, 3), (3, 1)] -> (_^1 * _^2) * (3^1)
    for (long long i=2; i*i<=N; i++) {
        if (i > N) break;
        long long count = 0;
        while (N%i == 0) {
            N /= i;
            count++;
        }
        if (count > 0) {
            primes.push_back(count);
        }
    }
    if (N != 1) {
        primes.push_back(1);
    }
    long long result = 0;
    for (auto const& e : primes) {
        // l*(l+1)/2 <= e < (l+1)*(l+2)/2 となるようなl
        long long l = 1;
        while (true) {
            auto flag = l*(l+1) <= 2*e && 2*e < (l+1)*(l+2);
            if (flag) {
                break;
            }
            l++;
        }
        result += l;
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll n; cin >> n;
    vector<ll> p(n); for(auto& in:p) cin >> in;
    for(int i = 1; i < n-1; i++){
        if(max(p[i-1],p[i+1]) > p[i] && p[i] > min(p[i-1],p[i+1])) res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
  int x;
  ci >> x;

  if(x == 3 || x == 5 || x == 7) co << "YES" << en;
  else co << "NO" << en;
  
  return 0;
}


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

int main(){
	int N, L;
	cin>>N>>L;
	vector<string> s(N);
	for(int i = 0; i < N; i++){
		cin>>s[i];
	}
	sort(s.begin(), s.end());
	for(int i = 0; i < N; i++){
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256