akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int P[50];
int N, X, Y, Z;
int mask;
int memo[50][1<<17];
bool visited[50][1<<17];
int f(int p, int q) {
	if (p == N) return 0;
	if (visited[p][q]) return memo[p][q];
	visited[p][q] = true;
	long long res = 0;
	for (int i = 1; i <= 10; ++ i) {
		int qq = (q << i) | 1;
		if ((qq & mask) == mask) {
			res += P[N-1-p];
		} else {
			res += f(p+1, qq & ((1<<17)-1));
		}
	}
	return memo[p][q] = res % mod;
}
int main() {
	cin >> N >> X >> Y >> Z;

	P[0] = 1;
	for (int i = 1; i < 50; ++ i) P[i] = P[i-1] * 10LL % mod;

	mask = (1<<X) | (1<<(X+Y)) | (1<<(X+Y+Z));

	cout << f(0, 1) << endl;
}


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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int x,k,d,ans,x_d,step=0;
	cin >> x >> k >> d;
	x_d = abs(x);

	int a = (x_d)/d;
	x_d -= a*d;
	step = a;

	if(abs(x_d-d)< x_d)
	{
		x_d = abs(x_d-d);
		step++;
	}
	if(k>=step)
	{
		if((k-step)%2 == 0)
			ans = abs(x_d);
		else
			ans = min(x_d+d,abs(x_d-d));
	}
	else
	{	
		x_d = abs(x);
		while(k!=0)
		{
			x_d = x_d - d;
			k--;
		}
		ans = x_d;
	}
	cout << ans << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

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

std::queue<int> cds;

int gcd(int a, int b) {
    int tmp;
    while(a % b != 0) {
        tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

void commDiv(int arr[], int size) {
    cds.push(1);
    std::sort(arr, arr+size);
    int n = gcd(arr[0], arr[1]);
    for (int i = 1; i < size-1; i++) {
        n = std::min(n, gcd(arr[i], arr[i+1]));
    }
    if (n > 1) {
        for (int i = 2; i <= n / 2; i++) {
            if (n % i == 0) {
                cds.push(i);
            }
        }
        cds.push(n);
    }
}

int main()
{
    int size;
    std::scanf("%d", &size);
    int arr[size];
    for (int i = 0; i < size; i++) {
        std::scanf("%d", &arr[i]);
    }
    commDiv(arr, size);
    while( !cds.empty() ) {
        std::printf("%d\n", cds.front());
        cds.pop();
    }
    return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	vector<ll> vec;
	ll n, a;
	cin >> n;
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		cin >> a;
		vec.push_back(a);
		if (i == 0)vec[0] = a;
		else vec[i] = a + vec[i - 1];
		mp[vec[i]]++;
	}
	mp[0]++;
	ll ans = 0;
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i = 0; i<vec.size(); ++i) {
		if (mp[vec[i]] == 0)continue;
		ans += (mp[vec[i]] - 1) * mp[vec[i]] / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14320
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(((a + b) % 2) == 0) {
      System.out.println((a + b) / 2);
    } else {
      System.out.println("IMPOSSIBLE");
    }
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  int n,ans=0;
  cin>>n;
  string a,b,c;
  cin>>a>>b>>c;
  for(int i=0;i<n;i++){
    char ai=a[i],bi=b[i],ci=c[i];
    if(ai==bi&&bi==ci) continue;
    else if(ai==bi||bi==ci||ci==ai) ans++;
    else ans+=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
L, R = list(map(int,input().split()))

if(R - L) >= 2019:
    print(0)
    exit()
 
ans = float('inf')
for i in range(L, R):
    for j in range(i+1, R+1):
        t = i*j%2019
        ans = min(ans,t)
print(ans)

Measured memory_bytes: 3060
from collections import deque
N,M=map(int,input().split())

G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G[a-1]+=[b-1]
  G[b-1]+=[a-1]
que=deque([0])
visited=[-1 for i in range(N)]
visited[0]=0
dokokara=[0 for i in range(N)]
while len(que)>0:
  v=que.popleft()
  for i in G[v]:
    if visited[i]!=-1:
      continue
    else:
      visited[i]+=1
      dokokara[i]=v
      que.append(i)


print("Yes")
for i in range(1,N):
  print(dokokara[i]+1)

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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  vector<vector<P> > a(n);
  rep(i,n) {
    int num;
    cin >> num;
    rep(_,num) {
      int x, y;
      cin >> x >> y;
      x--;
      a[i].emplace_back(P(x,y));
    }
  }
  int ans = 0;
  for (int bit = 0; bit < 1<<n; ++bit) {
    bool ok = true;
    rep(i,n) {
      if (bit & (1<<i)) {
        for (auto p : a[i]) {
          int x = p.first, y = p.second;
          if (y == 0 && (bit & (1<<x))) { 
            ok = false; break;
          }
          if (y == 1 && !(bit & (1<<x))) { 
            ok = false; break;
          }
        }
        if (!ok) break;
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(bit));
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int A,B;
	cin>>A>>B;
	
	double K=(double)(A+B)/2;
	long long int k=(A+B)/2;

	if(K==k)
		cout<<k;
	else
		cout<<"IMPOSSIBLE";
	
	return 0;
}

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

using namespace std;

int main(void) {
  int h, i, sum;
  cin >> h >> i;
  sum = 0;
  for(int j=0; j<i; j++){
    int a;
    cin >> a;
    sum += a;
    if(h <= sum) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char [] data = sc.next().toCharArray();
			long count = 0;
			long sum = 0;
			for(int i = data.length-1; i >= 0; i--){
				if(data[i] =='W'){
					count++;
				}
				else {
					sum += count;
				}
			}
			System.out.println(sum);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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


int main(){
  int a,b;
  cin >> a>>b;
  
  if((a+b)%2==1)
  cout << (a+b)/2+1;
  else
    cout << (a+b)/2;
 }



Measured memory_bytes: 256
from itertools import product

h, w, k = map(int, input().split())

h_kumiawase = list(product([1, 0], repeat=h))
w_kumiawase = list(product([1, 0], repeat=w))

C = [list(input()) for _ in range(h)]
# C[h][w]


def calc(h_kumi, w_kumi):
    cnt = 0
    for i in range(h):
        if h_kumi[i] == 1:
            continue
        for j in range(w):
            if w_kumi[j] == 1:
                continue
            if C[i][j] == ".":
                continue
            cnt += 1
    return cnt


ans = 0
for i in range(1 << h):
    h_kumi = h_kumiawase[i]
    for j in range(1 << w):
        w_kumi = w_kumiawase[j]

        if calc(h_kumi, w_kumi) == k:
            ans += 1

print(ans)


Measured memory_bytes: 68712
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    string s;
    cin>>s;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            cout<<s[i];
        }
    }
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    var s : MutableList<Char> = mutableListOf()
    var S = readLine()!!.toList()
    S.map{x->
        when(x){
            '1' -> s.add(x)
            '0' -> s.add(x)
            else -> {
                if(s.size == 0) null
                else s.removeAt(s.size-1)
            }
        }
    }
    println(s.joinToString(""))
    
}


Measured memory_bytes: 33736
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
ll mod = 1000000007;


int main() {
    int H,W;
    cin >> H >> W;
    char ch;
    int cnt;
    REP(i,0,H){
        REP(j,0,W){
            string s;
            cin >> s;
            if(s == "snuke"){
                ch = (char) (j + 'A');
                cnt = 1 + i;
            }
        }
    }
    cout << ch << cnt << endl;

    return 0;

}


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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h,vector<char>(w));
  
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> c.at(i).at(j);
    }
  }
  long long ans = 0;
  vector<vector<char>> buf(h,vector<char>(w));
  vector<vector<char>> buf2(h,vector<char>(w));
  for (int tmp = 0; tmp < (1 << h); tmp++) {
    bitset<6> s(tmp);  // 最大20個なので20ビットのビット列として扱う
 
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    buf = c;
    for (int i = 0; i < h; i++) {
      if (s.test(i)) {
        if(i != h){
          for(int j = 0;j < w;j++){
            buf.at(i).at(j) = '.';
          }
        }
      }
    }
    for (int tmp2 = 0; tmp2 < (1 << w); tmp2++){
      bitset<6> s2(tmp2);
      buf2 = buf;
      int sum = 0;
      
      //cout << 2 << endl;
      for (int i = 0; i < w; i++) {
        if (s2.test(i)) {
          if(i != w){
            for(int j = 0;j < h;j++){
              buf2.at(j).at(i) = '.';
            }
          }
        }
      }
      for(int l = 0;l < h;l++){
          for(int m = 0;m < w;m ++){
            if(buf2.at(l).at(m) == '#'){
              sum ++;
            }
            //cout << buf2.at(l).at(m);
          }
        //cout << endl;
        }
        if (sum == k) {
          ans++;
        }
    }
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 3648
arr1 = input().split()
n,x = int(arr1[0]),int(arr1[1])

arr2 = input().split()

d = 0
count = 1
for i in range(1, n + 1):
  d += int(arr2[i-1])
  if d <= x:
    count +=1
    
print(count)
  

Measured memory_bytes: 9048
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a=0,b=0,c=0,d=0,e,l,m,n,o=0,p,q,x,y,z,max1=0,ans,r,g;
    string s,t,u;
    
    cin>>s;
    for(ll i=0;i<s.size();i++){
    if(s[i]=='o')o++;
    }
    if(o+15-s.size()>7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>

struct P{
  int key;
  struct P *prev,*next;
};
typedef struct P* node;
node F,L;

void insert(int x) {
  node z=F->next;
  node v=malloc(sizeof(struct P));
  v->key=x;
  F->next=v;
  v->prev=F;
  v->next=z;
  z->prev=v;
}

void delete(int x) {
  node z=F;
  while(z->key!=x && z!=L) z=z->next;
  node l=z->prev,r=z->next;
  l->next=r;
  r->prev=l;
}

void deleteF() {
  node z=F->next->next;
  F->next=z;
  z->prev=F;
}

void deleteL() {
  node z=L->prev->prev;
  L->prev=z;
  z->next=L;
}

int main() {
  int n;
  scanf("%d",&n);
  char c[10];
  int x;
  F=malloc(sizeof(struct P));
  L=malloc(sizeof(struct P));
  F->next=L;F->prev=F;
  L->prev=F;L->next=L;
  while(n--) {
    scanf("%s",c);
    if(c[0]=='i') {
      scanf("%d",&x);
      insert(x);
    } else if(c[6]=='F') deleteF();
    else if(c[6]=='L') deleteL();
    else {
      scanf("%d",&x);
      delete(x);
    }
  }
  node z=F->next;
  while(z!=L) {
    if(z!=F->next) printf(" ");
    printf("%d",z->key);
    z=z->next;
  }
  printf("\n");
  return 0;
}


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

ll gcd(ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}

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

ll f(ll a, ll b, ll c) {
  return a - a/b - a/c + a/(lcm(b,c));
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << f(b,c,d) - f(a-1,c,d) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

set<int> s;

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

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

	for (int i = 0; i < N; i++) {
		s.insert(vec[i]);
	}

	cout << s.size();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    int A, P;
    cin >> A >> P;

    cout << (3 * A + P) / 2 << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
int main()
{
	int n,k;cin>>n>>k;
	int sum=0;
	while(n!=0)
	{
		n/=k;
		sum++;
	}
	cout<<sum<<endl;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

double cal(int now,int goal,double p){
    if(now >= goal) return p;
    return cal(now*2,goal,p/2);
}

int main()
{
    int N,K;
    cin >> N >> K;
    double ans = 0;
    _rep(i,1,N){
        ans += cal(i,K,1/(double)N);
    }

    printf("%.12lf",ans);
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    deque<int> a;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==0)
        {
            cin>>q;
            if(q==0)
            {
                cin>>q;
                a.push_front(q);
            }else
            {
                cin>>q;
                a.push_back(q);
            }
        }else if(q==2)
        {
            cin>>q;
            if(q==0)
            {
                a.pop_front();
            }else
            {
                a.pop_back();
            }
        }else
        {
            cin>>q;
            cout<< a[q] <<endl;
        }
    }
    return 0;

}


Measured memory_bytes: 4584
#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
#define int long long
const long long inf = 2147483647;
int dat[280000];
int a[100005];
int N; 
void init(int n_) {
	N = 1;
	while (N < n_)N *= 2;
	for (int i = 0; i < 2 * N - 1; i++) {
		dat[i] = inf;
	}
}
void update(int k, int a) {
	k += N - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}
int query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return inf;
	if (a <= l&&r <= b)return dat[k];
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
signed main() {
	int n,q;
	cin >> n>>q;
	init(n);
	for (int i = 0; i < q; i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com) {
			cout << query(x, y + 1, 0, 0, N) << endl;
		}
		else update(x, y);
	}
}


Measured memory_bytes: 5136
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
    double w;
    while(true){
        cin>>w;
        if (cin.eof())break;
        if(w<=48.00){
            cout<<"light"<<" "<<"fly"<<endl;
        }
        if(48.00<w&&w<=51.00){
            cout<<"fly"<<endl;
        }
        if(51.00<w&&w<=54.00){
            cout<<"bantam"<<endl;
        }
        if(54.00<w&&w<=57.00){
            cout<<"feather"<<endl;
        }
        if(57.00<w&&w<=60.00){
            cout<<"light"<<endl;
        }
        if(60.00<w&&w<=64.00){
            cout<<"light"<<" "<<"welter"<<endl;
        }
        if(64.00<w&&w<=69.00){
            cout<<"welter"<<endl;
        }
        if(69.00<w&&w<=75.00){
            cout<<"light"<<" "<<"middle"<<endl;
        }
        if(75.00<w&&w<=81.00){
            cout<<"middle"<<endl;
        }
        if(81.00<w&&w<=91.00){
            cout<<"light"<<" "<<"heavy"<<endl;
        }
        if(91.00<w){
            cout<<"heavy"<<endl;
        }
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl s(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    s[i + 1] = s[i] + a;
  }
  ll ans = 1e18;
  rep(i, n - 1) {
    ll now = abs(s[n] - 2 * s[i + 1]);
    ans = min(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4756
INF = 10**18

V, E = map(int, raw_input().split())
cost = [[INF]*V for i in xrange(V)]
for i in xrange(E):
    s, t, d = map(int, raw_input().split())
    cost[s][t] = d
for i in xrange(V):
    cost[i][i] = 0

for k in xrange(V):
    for i in xrange(V):
        for j in xrange(V):
            if cost[i][k]!=INF and cost[k][j]!=INF:
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
if any(cost[i][i]<0 for i in xrange(V)):
    print "NEGATIVE CYCLE"
else:
    print "\n".join(" ".join(map(lambda e: str(e) if e<INF else "INF", e)) for e in cost)

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

using namespace std;

int main() {

  string n, m, u;
  int a, b;
  cin >> n >> m >> a >> b >> u;
  if(u == n){
    a--;
  }
  if(u == m){
    b--;
  }
  cout << a << ' '<< b;
  return 0;
}


Measured memory_bytes: 3600
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(H, K):
    N = len(H)
    INF = 10**9
    dp = np.full(N + K, INF, np.int32)
    dp[0] = 0
    for n in range(N):
        for k in range(1, K + 1):
            dp[n + k] = min(dp[n + k], dp[n] + abs(H[n] - H[n + k]))
    return dp[N - 1]

signature = '(i4[:],i4)'
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

N, K = map(int, readline().split())
H = np.array(read().split(), np.int32)

print(main(H, K))

Measured memory_bytes: 33460
import math
import sys
a,v=(int(x) for x in input().split())
b,w=(int(x) for x in input().split())
t = int(input())

e1=pow(-10, 9)
e2=pow(10, 9)

if (a<e1)or(e2<a)or(b<e1)or(e2<b)or(v<1)or(e2<v)or(w<1)or(e2<w)or(t<1)or(e2<t)or(a==b):
    sys.exit(0)

ab = abs(b-a)/t+w-v

if ab<=0:
    print("YES")
else :
    print("NO")


Measured memory_bytes: 9160
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
// #define a first
// #define b second

vector < vi > v(100010);
stack <int > st;
int dp[100010];

void dfs(int u){
    dp[u] = true;
    for(auto i:v[u])
        if(!dp[i])
            dfs(i);
    st.push(u);
}

int f(int u){
    if(dp[u] != -1) return dp[u];

    int ans = 0;
    for(auto i:v[u]){
        ans = max(ans, 1 + f(i));
    }
    return dp[u] = ans;
}


int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);	
    
    int n, m, a, b;
    cin >> n >> m;
    memset(dp, 0, sizeof dp);
    forn(i, m){
        cin >> a >> b;
        v[a].pb(b);
    }
    rep(i, 1, n + 1){
        if(!dp[i])
            dfs(i);
    }
    memset(dp, -1, sizeof dp);
    int ans = -1;
    while(!st.empty()){
        if(dp[st.top()] == -1)
            ans = max(ans, f(st.top()));
        st.pop();
    }
    cout << ans << endl;

    return 0;
}

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


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vii  = vector<ii>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ar array

// no change 

//const int MxN = 1e9+5;
void solve(){
	ll n;
	cin >> n;
	string s = "";
	while(n){
		n-=1;
		int r = n%26;
		s+=char(r+'a');
		n = n/26;
	}
	reverse(s.begin(),s.end());
	cout << s;




}
int main() {
	FASTER;
	int T=1;
	//cin >> T;
	while(T--)solve();	
	#ifdef LOCAL
	Time();
	#endif
}


Measured memory_bytes: 3664
#include<stdio.h>
#define min(a,b) (a<b?a:b)
#define INF 10000000
int g[16][16],n,i,j,k,v,e,f,t,c;
int dp[1<<17][16];
int main()
{
	scanf("%d%d",&v,&e);
	for(i=0;i<(1<<16);i++)
		for(j=0;j<v;j++)
			i<v?(g[i][j]=dp[i][j]=INF):(dp[i][j]=INF);
	dp[0][0]=0;
	for(i=0;i<e;g[f][t]=c,i++)
		scanf("%d%d%d",&f,&t,&c);
	for(i=0;i<(1<<v);i++)
		for(j=0;j<v;j++)
			for(k=0;k<v;k++)
				if(!(i>>k&1))
					dp[i|(1<<k)][k]=min(dp[i+(1<<k)][k],dp[i][j]+g[j][k]);
	printf("%d\n",dp[(1<<v)-1][0]==INF?-1:dp[(1<<v)-1][0]);
	return 0;
}

Measured memory_bytes: 6740
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

int L[11111] ; 

int main()
{
    int N ; 
    scanf("%d", &N) ; 
    for(int i = 0 ; i != N*2 ; i++)
        scanf("%d", L+i) ; 
    sort(L, L+N*2) ; 
    int ans = 0 ; 
    for(int i = 0 ; i != N*2 ; i += 2)
        ans += L[i] ; 
    printf("%d\n", ans) ; 
    return 0 ; 
}


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

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << (1000 - (n % 1000)) % 1000;

}

Measured memory_bytes: 3592
import bisect
import collections
import heapq
import math
import operator as op
from collections import Counter
from functools import reduce

import numpy as np


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    S = get_input()
    T = get_input()
    if len(T) == len(S) + 1 and T[:-1] == S:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()


Measured memory_bytes: 27092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int fac[1010101],ifac[1010101];
int fpow(int x,int y)
{
	if(y==0)
		return 1;
	int ret=fpow(x,y>>1);
	ret=(long long)ret*ret%mod;
	if(y&1)
		ret=(long long)ret*x%mod;
	return ret;
}
int C(int n,int m)
{
	return (long long)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
	int n,m,k,nn,h,ans=0,l,r,nl,nr,now,now1;
	scanf("%d%d%d",&n,&m,&k);
	nn=n+m+k;
	fac[0]=1;
	for(int i=1;i<=nn;i++)
		fac[i]=(long long)fac[i-1]*i%mod;
	ifac[0]=ifac[1]=1;
	for(int i=2;i<=nn;i++)
		ifac[i]=(long long)(mod-mod/i)*ifac[mod%i]%mod;
	for(int i=2;i<=nn;i++)
		ifac[i]=(long long)ifac[i-1]*ifac[i]%mod;
	now=fpow(3,m+k);
	now1=fpow(3,mod-2);
	for(int i=0;i<=m+k;i++)
	{
		if(i==0)
		{
			h=1;
			l=0;
			r=0;
		}
		else
		{
			nl=max(i-k,0);
			nr=min(m,i);
			(h*=2)%=mod;
			(h+=mod-C(i-1,l))%=mod;
			(h+=mod-C(i-1,r))%=mod;
			l++;
			while(l>nl)
			{
				l--;
				h+=C(i,l);
			}
			while(r<nr)
			{
				r++;
				h+=C(i,r);
			}
		}
		ans=((long long)h*C(n+i-1,i)%mod*now+ans)%mod;
		now=(long long)now*now1%mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7680
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    ans = max(a - 2 * b, 0);
    cout << ans << endl;
    return 0;
}


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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

long long stoi(string str) {
	long long ret;
	stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b) {
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}
void solve() {
	int n;
	cin >> n;
	int maxi = -1;
	vector<int> v;
	rep(i, n) {
		int a;
		cin >> a;
		maxi = max(maxi, a);
		v.push_back(a);
	}
	int r = -1;
	rep(i, n) {
		if (v[i] != maxi) {
			int mini = min(maxi - v[i], v[i]);
			int rmini = min(maxi - r, r);
			if (rmini < mini) {
				r = v[i];
			}
		}
	}
	cout << maxi << " " << r << endl;
}

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


Measured memory_bytes: 892
#include <stdio.h>
int uruu(int year);
int daycount(int y,int m,int d);
int main()
{
    int y1,m1,d1,y2,m2,d2;
    scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2);
    while(y1 > 0 && m1 > 0 && d1 > 0 && y2 > 0 && m2 > 0 && d2 > 0){
        printf("%d\n",daycount(y2,m2,d2) - daycount(y1,m1,d1));
        scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2);
    }
    return 0;
}

int uruu(int year){
    int resist = 0;
    if(year % 4 == 0 && year % 100 != 0)resist = 1;
    if(year % 400 == 0)resist = 1;
    return resist;
}

int daycount(int y,int m,int d){
	int resist=0;
    int i;
	for(i = 1;i < y;i++){
		resist+=365;
        if(uruu(i)) resist+=1;
	}
	for(i = 1;i < m;i++){
		resist+=31;
		if(i==4||i==6||i==9||i==11) resist--;
		if(i==2){
            resist-=3;
            if(uruu(y))resist++;
        }
	}
	for(i = 1;i < d;i++){
		resist+=1;
	}
	return resist;
}

Measured memory_bytes: 592
using CompLib.Util;
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int x = sc.NextInt();
        int y = sc.NextInt();
        int z = sc.NextInt();

        Console.WriteLine((x - z) / (y + z));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1LL<<60

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

pair<ll, ll> dfs(ll from, vector<ll>& edge, int d, vector<ll>& dist) {
    if(dist[from] == -1) {
        dist[from] = d;
    }
    if(dist[edge[from]] >= 0) {
        return make_pair(edge[from], dist[from] + 1 - dist[edge[from]]);
    }
    
    return dfs(edge[from], edge, dist[from]+1, dist);
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }
    vector<ll> dist(N, -1);
    // map<ll, ll> dist_to_v;
    vector<ll> dist_to_v(2*N);
    dist[0] = 0;

    pair<ll, ll> loop_start = dfs(0, A, 0, dist);
    for(ll i = 0; i < N; i++) {
        if(dist[i] >= 0)
            dist_to_v[dist[i]] = i;
    }
    // cerr << loop_start.first << " " << loop_start.second  << " " << dist[1] << endl;
    ll ans = 0;
    if(K < dist[loop_start.first]) {
        cout << dist_to_v[K] + 1 << endl;
        return 0;
    }
    if(loop_start.first == 0) {
        K %= loop_start.second;
        cout << dist_to_v[K] + 1 << endl;
    } else {
        K -= dist[loop_start.first];
        K %= loop_start.second;
        // cerr << "dist: " << K + dist[loop_start.first] << endl;
        cout << dist_to_v[K + dist[loop_start.first]] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 9580
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int num = 0;
		if(a > b){
			num = b;
			b = a;
			a = num;
		}
		if((a+b) % 2 == 0){
			num = (b - a)/2;
			System.out.println(num + a);
		} else {
			System.out.println("IMPOSSIBLE");
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124
#include <cmath>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <vector>
const double kEpsilon = 1e-10;
inline bool equals(double a, double b)
{
    return fabs(a - b) < kEpsilon;
}

class Point
{
  public:
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y)
    {
    }

    Point operator+(const Point &p)
    {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point &p)
    {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(const double k)
    {
        return Point(x * k, y * k);
    }

    double SquaredNorm()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(this->SquaredNorm());
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator==(const Point &p) const
    {
        return fabs(x - p.x) < kEpsilon && fabs(y - p.y) < kEpsilon;
    }

    double dot(const Point &p) const
    {
        return x * p.x + y * p.y;
    }
    double cross(const Point &p) const
    {
        return x * p.y - y * p.x;
    }
};

double dot(const Point &p1, const Point &p2)
{
    return p1.x * p2.x + p1.y * p2.y;
}
double cross(const Point &p1, const Point &p2)
{
    return p1.x * p2.y - p1.y * p2.x;
}

using Vector = Point;

struct Segment
{
    Point p1, p2;

    Segment() = default;
    Segment(Point p1, Point p2) : p1(p1), p2(p2)
    {
    }
};

Point crossPoint(Segment &s1, Segment &s2)
{
    auto base = s2.p2 - s2.p1;

    auto d1 = fabs(base.cross(s1.p1 - s2.p1)) / base.abs();
    auto d2 = fabs(base.cross(s1.p2 - s2.p2)) / base.abs();

    auto t = d1 / (d1 + d2);

    return s1.p1 + (s1.p2 - s1.p1) * t;
}

int main()
{
    Segment s1, s2;
    int q;
    std::cin >> q;

    for (size_t i = 0; i < q; ++i)
    {
        std::cin >> s1.p1.x >> s1.p1.y;
        std::cin >> s1.p2.x >> s1.p2.y;
        std::cin >> s2.p1.x >> s2.p1.y;
        std::cin >> s2.p2.x >> s2.p2.y;

        std::cout << std::setprecision(20);
        auto p = crossPoint(s1, s2);

        std::cout << p.x << " " << p.y << std::endl;
    }
}



Measured memory_bytes: 3300
#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 ll mx=1000010;
const ll mod=1e9+7;

vector<int> ip(mx,0);
bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
void ipset(int x){ for(int i=2; i<x; i++){ ip[i]=(int)isprime(i);} }


int main(){
  ll a;
  cin >> a;
  ipset(1000010);
  priority_queue<ll,vector<ll>,greater<ll>> q;
  for(ll i=2; i<1000010; i++)if(ip[i]){
    q.emplace(i);
  }
  ll ans = 0;
  while(a!=1 && !q.empty()){
    ll p = q.top(); q.pop();
    if(a%p==0){
      a/=p;
      ans++;
      ll tmp = p*p;
      while(a%tmp==0){
        ans++;
        a/=tmp;
        tmp *= p;
      }
    }
  }
  if(a>1000000){ ans+=1; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8312
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val as = List.fill(n)(sc.nextInt)

    println(as.filter(_ % 2 == 0).map(divsBy2).sum)
  }
  def divsBy2(i: Int): Int = {
    if(i == 0 || i % 2 != 0) 0
    else 1 + divsBy2(i / 2)
  }
}


Measured memory_bytes: 38204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Koto Distance
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		words = br.readLine().split(" ");
		int N, W, H;
		N = parseInt(words[0]);
		W = parseInt(words[1]);
		H = parseInt(words[2]);

		int[] xs = new int[W];
		int[] ys = new int[H];

		for (int i = 0; i < N; i++) {
			words = br.readLine().split(" ");
			int x, y, w;
			x = parseInt(words[0]);
			y = parseInt(words[1]);
			w = parseInt(words[2]);

			//
			if (0 <= x - w) {
				xs[x - w]++;
			} else {
				xs[0]++;
			}
			if (x + w < W) {
				xs[x + w]--;
			}
			//
			if (0 <= y - w) {
				ys[y - w]++;
			} else {
				ys[0]++;
			}
			if (y + w < H) {
				ys[y + w]--;
			}
		}

		boolean fillW = true, fillH = true;
		//
		for (int i = 0; i < xs.length; i++) {
			if (0 < i) {
				xs[i] += xs[i - 1];
			}
			if (xs[i] == 0) {
				fillW = false;
				break;
			}
		}
		//
		for (int i = 0; i < ys.length; i++) {
			if (0 < i) {
				ys[i] += ys[i - 1];
			}
			if (ys[i] == 0) {
				fillH = false;
				break;
			}
		}
		if (fillW | fillH) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	} //end main
}

Measured memory_bytes: 64796
N = int(input())
dic = {1:0,2:0,4:0}
List = list(map(int,input().split()))
for item in List:
  if item%4 == 0:
    dic[4] += 1
  elif item %2 == 0:
    dic[2] += 1
  else:
    dic[1] += 1
Answer = 'No'
if dic[4] != 0 and dic[4]+1 >= dic[1]+dic[2]:
  Answer = 'Yes'
elif dic[4]>=dic[1]:
  Answer = 'Yes'
print(Answer)

Measured memory_bytes: 14252
var s:string;
    i,k,j:integer;
    
begin
    read(s);
     

            
                  if ((s[1]=s[2]) and (s[3]=s[4]) and (s[1]<>s[3])) 
                  or ((s[1]=s[3]) and (s[2]=s[4]) and (s[2]<>s[3]))
                  or ((s[1]=s[4]) and (s[3]=s[2]) and (s[1]<>s[2]))
                  then write('Yes') else write('No');
              
                   
        
  
      readln;readln;
end.     

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		VVI G( n, VI() );

		REP( i, 0, m )
		{
			int a, b;
			cin >> a >> b;

			a--;
			b--;

			G[a].PB( b );
			G[b].PB( a );
		}

		VI dist( n, INT_MAX );

		priority_queue< PII, vector< PII >, greater< PII > > que;
		que.push( MP( 0, 0 ) );

		while ( !que.empty() )
		{
			auto cur = que.top();
			que.pop();

			if ( dist[ cur.snd ] <= cur.fst )
			{
				continue;
			}

			dist[ cur.snd ] = cur.fst;

			REP( i, 0, G[ cur.snd ].size() )
			{
				que.push( MP( cur.fst + 1, G[ cur.snd ][i] ) );
			}
		}

		cout << count_if( dist.begin() + 1, dist.end(), []( int a ){ return a <= 2; } ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1636
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] sList = sc.next().split("");

        for (int i = 1; i <= sList.length; i++) {
            if (i % 2 == 0) {
                if ("R".equals(sList[i-1])) {
                    System.out.println("No");
                    return;
                }
            } else {
                if ("L".equals(sList[i-1])) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
# include <iostream>
using namespace std;
int h,*a;
void maxHeapify(int i)
{
	int l = 2*i, r = 2*i+1,largest;
	if(l <= h && a[l] > a[i]) largest = l;
	else largest = i;
	if(r <= h && a[r] > a[largest]) largest = r;
	
	if(largest != i)
	{
		swap(a[i],a[largest]);
		maxHeapify(largest);
	}
}
int main(void)
{
	scanf("%d",&h);
	a = new int [4*h+1];
	for(int i = 1;i <= h;i++) scanf("%d",&a[i]);
	for(int i = h/2;i >= 1;i--) maxHeapify(i);
	for(int i = 1;i <= h;i++) printf(" %d",a[i]);
	printf("\n");
	return 0;
}  


Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   long long n;
   cin >> n;
   if(n==1) {
       cout << 1 << endl;
       return 0;
   }
   long long m = -1;
   for(int i = 1;i < n;i++) {
       for(int j = 2;j < sqrt(n)+1;j++) {
           long long ans = pow(i, j);
        //    cout << "i:" << i << " j:" << j << " " << ans << endl;
           if(ans <= n) {
             m = max(m, ans);   
           }
       }
   }
   cout << m << endl;
}

//    if(floor(sqrt(i))==sqrt(i)) {
//        cout << i << endl;
//        return 0;
//    }

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b;
    string s;
    cin >> s; 
    rep(i,3){
        if(s[i] == '9'){   // "9" とするとうまく動作しない。 
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
  int N; cin>>N;
  vector<int>S(N);
  for(int i=0; i<N;i++){
    cin>>S.at(i);
  }

  sort(S.begin(),S.end());
 cout<<S.at(N-1)-S.at(0)<<endl;
}

Measured memory_bytes: 3608