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

const int MAX_N = 200010;
int dp[MAX_N][2];
char S[MAX_N];
// dp[i][0] := i文字目まで確定したときに、直前の部分文字列が1文字である場合の最大分割数
// dp[i][1] := i文字目まで確定したときに、直前の部分文字列が2文字である場合の最大分割数
// dp[0][0] = 1, dp[0][1] = 0, dp[1][1] = 1;
// dp[1][0] = (S[1] != S[0]) ? 2: 0;
// (dp[i-1][0]からの遷移)
// if(S[i] != S[i-1]) dp[i][0] = max(dp[i][0], dp[i-1][0] + 1);
// dp[i+1][1] = max(dp[i+1][1], dp[i-1][0] + 1);
// (dp[i-1][1]からの遷移)
// dp[i][0] = max(dp[i][0], dp[i-1][1] + 1);
// if(S[i-2] != S[i] || S[i-1] != S[i+1]) dp[i+1][1] = max(dp[i+1][1], dp[i-1][1] + 1);

int main() {
    scanf("%s",S);
    int n = strlen(S);
    dp[0][0] = 1, dp[1][1] = 1;
    for(int i = 0; i + 1 < n; ++i) {
        if(S[i] != S[i+1]) dp[i+1][0] = max(dp[i+1][0], dp[i][0] + 1);
        if(i+2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][0] + 1);

        dp[i+1][0] = max(dp[i+1][0], dp[i][1] + 1);
        if(i+2 < n && i-1 > 0 && (S[i-1] != S[i+1] || S[i] != S[i+2])) 
            dp[i+2][1] = max(dp[i+2][1], dp[i][1] + 1);
    }
    printf("%d\n", max(dp[n-1][0], dp[n-1][1]));
    return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#define M 1000000000
int MIN(int a,int b){return a<b?a:b;}
int d[30][30],n,min,i,j;
int f(int s,int t){
  int f[50]={0};
  int c[50]={0};
  for(i=0;i<50;i++)c[i]=M;
  for(i=c[s]=0;i<n;i++){
    for(j=f[s]=1;j<=n;j++)c[j]=MIN(c[j],c[s]+d[s][j]);
    min=M;
    for(j=1;j<=n;j++){
      if(f[j]==0&&min>c[j])min=c[s=j];
    }
  }
  return c[t];
}
int main(){
  int m,a,b,c;
  for(a=0;a<30*30;a++)d[a/30][a%30]=M;
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d,%d,",&a,&b);
    scanf("%d,%d",&d[a][b],&d[b][a]);
  }
  scanf("%d,%d,%d,%d",&a,&b,&m,&c);
  printf("%d\n",m-c-f(a,b)-f(b,a));
  return 0;
}

Measured memory_bytes: 604
# ABC119 Synthetic Kadomatsu
わからん=True
INF=1<<30

n,a,b,c=map(int,input().split())
# 8>=n>=3
# 1000>=a>b>c>=1
l=[int(input()) for _ in range(n)]
# 1000>=li>=1

def dfs(j,x,y,z):
    if n==j:
        return abs(a-x)+abs(b-y)+abs(c-z)-30 if min(x,y,z)>0 else INF
        
    t1 = dfs(j+1,x,y,z)
    t2 = dfs(j+1,x+l[j],y,z)+10
    t3 = dfs(j+1,x,y+l[j],z)+10
    t4 = dfs(j+1,x,y,z+l[j])+10
    return min(t1,t2,t3,t4)
    
ans=dfs(0,0,0,0)
print(ans)


Measured memory_bytes: 44124
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
void bubblesort(int A[],int n)
{
	bool flag=true;
	int a;
	for(int i=0;flag;i++)
	{
		flag=false;
		for(int j=n-1;j>=i+1;j--)
		{
			if(A[j]<A[j-1])
			{
				a=A[j];
				A[j]=A[j-1];
				A[j-1]=a;
				flag=true;
			}
		}
	}
}
int main()
{
	int k,n;
	int s[100];
	cin>>k>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	if(n==1)
	{
		cout<<k-1<<endl;
		return 0;
	}
	sort(s,s+n);
	int last=-1;
	for(int i=0;i<k;i++)
	{
		if(s[n-2]==0)
		{
			cout<<s[n-1]-1<<endl;
			return 0;
		}
		for(int j=n-1;j>=0;j--)
		{
			if(last!=j&&s[j]!=0)
			{
				s[j]--;
				last=j;
				break;
			}
		}
		bubblesort(s,n);
	}
	cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < n;i++)
using ll = long long;
const ll M = 1e9 + 7;
int main(){
  ll n,a,sum=0,ans=0; cin >>n;
  while(cin>>a){
    (ans+=a*sum)%=M;
    (sum+=a)%=M;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] ary = new int[n + k + 1];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        long[] dp = new long[n + k + 1];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= k; j++) {
                dp[i + j] = Math.min(dp[i + j], Math.abs(ary[i] - ary[i + j]) + dp[i]);
            }
        }
        System.out.println(dp[n - 1]);
    }
}

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

int main() {
  int n;
  string s, ans = "Yes";
  cin >> n >> s;
  if(n % 2 != 0) ans = "No";
  else {
    rep(i, n/2) {
      if(s.at(i) != s.at(n/2+i)) ans = "No";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
    int n,d;
    scanf("%d%d", &n, &d);

    int count = 0;

    for(int i=0; i<n; i++){
        int x,y;
        scanf("%d%d", &x, &y);
        if((long)x*x+(long)y*y<=(long)d*d)count++;
    }

    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int M,K; cin >> M >> K;
    if(K >= (1<<M)){
        cout << -1 << endl;
        return 0;
    }
    if(M == 0){
        cout << 0 << " " << 0 << endl;
        return 0;
    }
    if(M == 1){
        if(K == 0){
            cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }
    rep(i,1<<M){
        if(i != K) cout << i << " ";
    }
    cout << K << " ";
    for(int i = (1<<M)-1; i >= 0; i--){
        if(i != K) cout << i << " ";
    }
    cout << K << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

int main(){
    ull N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    ull min_v;
    min_v = min(A, B);
    min_v = min(min_v, C);
    min_v = min(min_v, D);
    min_v = min(min_v, E);

    ull ans = N / min_v;
    if (N % min_v != 0) ans++;

    ans += 4;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ok(f):
        bb=[a%f for a in aa]
        bb.sort()
        i,j=0,n-1
        s=t=0
        while i<=j:
            if s>t:
                t+=f-bb[j]
                j-=1
            else:
                s+=bb[i]
                i += 1
        return s<=k

    n,k=MI()
    aa=LI()
    s=sum(aa)
    ff=[]
    for d in range(1,s+1):
        if d**2>s:break
        if s%d==0:
            ff.append(d)
            ff.append(s//d)
    if ff[-1]==ff[-2]:ff.pop()
    ff.sort(reverse=True)
    for f in ff:
        if ok(f):
            print(f)
            break

main()

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   int a[100001],aa[100001],N,cnt=0;
   cin >> N;
  for(int i=0;i<100001;i++)
    aa[i]=0;
   for(int i=0;i<N;i++)
     cin >> a[i];   
  for(int i=0;i<N;i++)
    aa[a[i]]++;
  for(int i=0;i<99999;i++){
     cnt = max(cnt,aa[i]+aa[i+1]+aa[i+2]);
   }
  cout << cnt << endl;

}

Measured memory_bytes: 1024
/*
    If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

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

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b)
{
    a+=b; a%=MOD;
    if(a<0) a+=MOD;
    return a;
}
ll mult(ll a, ll b)
{
    if(a>MOD) a%=MOD;
    if(b>MOD) b%=MOD;
    ll ans=(a*b)%MOD;
    if(ans<0) ans+=MOD;
    return ans;
}
ll pw(ll a, ll b)
{
    ll r=1;
    while(b){
        if(b&1) r=mult(r,a);
        a=mult(a,a);
        b>>=1;
    }
    return r;
}

void solve(){
    string s;
    cin>>s;
    map<char, int> m;
    for(int i=0;i<s.length();i++){
        m[s[i]]++;
        if(m[s[i]]>1){cout<<"no";return;}
    }
    cout<<"yes"<<endl;
}

int main(){
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}



Measured memory_bytes: 3648
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int cnt = 0;
    int temp =0;
    for(int i = 1; i <= N ; i+=2){
      for(int j = 1; j<=i ; j++){
        if(i%j == 0){
          temp++;
        }
      }
      if(temp==8){
        cnt++;
      }
      temp=0;
    }
    System.out.println(cnt);
  }
}



Measured memory_bytes: 35860
// Best practice

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// #include <functional> // for less

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
// using namespace __gnu_pbds;

// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// #define fbo find_by_order
// #define ook order_of_key

// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vi a(n + 1), ind(n + 1);
	map<int, int> sum;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		int diff = i - a[i];
		ans += sum[diff];
		// cout << diff << " " << sum[diff] << " " << i << " " << a[i] << endl;
		sum[a[i] + i]++;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 29004
#include "cstdio"

int main (){
    int h,w;

    for(;;){
        scanf("%d%d",&h,&w);
        if(h==0&&w==0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}

Measured memory_bytes: 2676
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

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

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=50;

int main(){
    
    ll n,a,b;
    vector<ll> v;
    vector<vector<ll>> comb(maxn+1);
    
    cin >> n>>a>>b;
    
    rep(i,n){
        ll x;
        cin >> x;
        v.push_back(x);
    }
    
    sort(all(v));
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0||j==i)comb[i].push_back(1);
            else comb[i].push_back(comb[i-1][j-1]+comb[i-1][j]);
        }
    }
    
    
    ll least=0;
    ll sum=0;
    
    rep(i,a){
        sum+=v[n-1-i];
        least = v[n-1-i];
    }
    
    ll cnt1=0,cnt2=0;
    rep(i,n){
        if(least==v[i])cnt1++;
        if(least==v[i]&&i>=n-a)cnt2++;
    }
    
    cout.precision(20);
    cout << (double)sum/(double)a<<endl;
    
    if(least!=v[n-1]){
        cout <<comb[cnt1][cnt2]<<endl;
    }else{
        ll ans=0;
        for(int i=a;i<=min(cnt1,b);i++){
            ans+=comb[cnt1][i];
        }
        cout << ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    var (N,W) = readLine()!!.split(" ").map{it.toInt()}

    var maxVal = 100001

    var dp = Array(N){LongArray(maxVal+1){ Long.MAX_VALUE/2}}
    var w = LongArray(N)
    var v = IntArray(N)

    for(i in 0 until N){
        val(wi,vi) = readLine()!!.split(" ")
        w[i] = wi.toLong()
        v[i] = vi.toInt()
    }

    for(j in 0..v[0]){
        dp[0][j] = w[0]

    }
    var ans = 0

    for(i in 1 until N){
        for(j in 0..maxVal){

            if(v[i] >= j) {
                dp[i][j] = Math.min(dp[i-1][j],w[i])
            } else {
                dp[i][j] = Math.min(dp[i-1][j],dp[i-1][j-v[i]] + w[i])
            }



        }

    }
    for(i in 0 until N){
        for(j in 0 until maxVal+1){
            if(dp[i][j] <= W){
                ans = Math.max(ans,j)
            }
        }

    }

    println(ans)

}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef vector<int> vi;
typedef vector<long long int> vl;
#define pb push_back
#define mp make_pair

ll expm(ll x, ll y, ll mod){
	ll ans = 1;
	while(y>0){
		if(y%2==1) ans*=x, ans%=mod, y--;
		else x*=x, x%=mod, y/=2;
	}
	return ans%mod;
}

ll exp(ll x, ll y){
	return expm(x,y,LLONG_MAX);
}

void shift(vector<long long int>& dp1, vector<long long int>& dp2){
	for(int i = 0; i < dp2.size(); i++) {
		dp2[i] = dp1[i];
	}
}

long long int sum(vector<long long int>& v){
	long long int sum = 0;
	for(auto it : v) 
		sum += it;
	return sum;
}

long long int findMaxValue(long long int n, long long int w, vector<long long int>& weights, vector<long long int>& value) {
	// dp[v][n] -> min weight we can get, if we have v value and n objects remaining
	// dp[v][n] = min(dp[v - value[n]][n-1] + weight[n], dp[v][n-1])
	// ans = max_i (dp[i][n]) st dp[i][n] <= w;

	long long int v = sum(value);

	vector<long long int> dp1(v+1, INT_MAX), dp2(v+1,0);
	dp1[0] = 0;

	for(long long int i = 0; i < n; i++){
		for(int target_val = 1; target_val <= v; target_val++){
			long long weight_leaving_cur = dp1[target_val];
			long long weight_taking_cur = INT_MAX;
			if(target_val >= value[i]) 
				weight_taking_cur = dp1[target_val - value[i]] + weights[i];
			
			dp2[target_val] = min(weight_leaving_cur, weight_taking_cur);
			// cout << i << " " << target_val << " " << dp2[target_val] << endl;
		}

		shift(dp2, dp1); //copies dp2 to dp1
		// for(int i=0;i<=v;i++) cout << dp1[i] << " ";
		// cout << endl;
	}

	long long int ans = 0;
	for(int i = 0; i < dp1.size(); i++){
		if(w >= dp1[i]) 
			ans = i;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);

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

	cout << findMaxValue(n, w, weights, value) << endl;
	return 0;
}



Measured memory_bytes: 4716
import sys
input = sys.stdin.readline

import numpy as np

N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = np.zeros(N, dtype=int)
h = np.array(h)

for i in range(1, N):
  start = max(0, i-K)
  dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[N-1])    

Measured memory_bytes: 22804
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int n,m;cin>>n>>m;
  cout << (n==m ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	REP(i, n) cin>>a[i];
	vector<int> dp(n + 1);
	dp[0] = -1;
	FOR(i, 1, n + 1) {
		dp[i] = INF;
	}
	FOR(i, 1, n + 1) {
		vector<int>::iterator ite = lower_bound(ALL(dp), a[i - 1]);
		if(ite != a.end()) *ite = a[i - 1];
	}
	int res = 0;
	REP(i, n + 1) {
		if(dp[i] != INF) res = i;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int card[255][14]={{0}};

int main(void){
   int n,i,num;
   cin >> n;
   for(i=0;i<n;i++){
       char c;
       cin >> c >> num;
       card[(int)c][num]=1;
   }
   for(i=1;i<=13;i++){
       if(card[(int)'S'][i]==0){
           cout << "S" << " " << i << endl;
       }
   }
   for(i=1;i<=13;i++){
       if(card[(int)'H'][i]==0){
           cout << "H" << " " << i << endl;
       }
   }
   for(i=1;i<=13;i++){
       if(card[(int)'C'][i]==0){
           cout << "C" << " " << i << endl;
       }
   }
   for(i=1;i<=13;i++){
       if(card[(int)'D'][i]==0){
           cout << "D" << " " << i << endl;
       }
   }
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>

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

using namespace std;

typedef long long ll;

int main(){
  int a,b,c;
  int max_v,min_v,mid_v;
  int K;
  cin >> a >> b >> c;;
  cin >> K;
  max_v = max(a,max(b,c));
  min_v = min(a,max(b,c));
  mid_v = a+b+c-max_v-min_v;
  REP(i,K) max_v *= 2;
  cout << max_v+min_v+mid_v << endl;

  return 0;
}


Measured memory_bytes: 256
str = gets.chomp.split("")
str << nil
previous = nil
str = str.map { |c|
  if c == previous
    nil
  else
    output = previous
    previous = c
    output
  end
}.compact

if str.size == 1
  puts 0
elsif str.size == 2
  puts 1
else # str.size >= 3
  # Wについて
  w_count = str.count("W")
  w_edge  = (str[0] + str[-1]).count "W"
  w_pattern = w_count * 2 - w_edge

  # Bについて
  b_count = str.count("B")
  b_edge  = (str[0] + str[-1]).count "B"
  b_pattern = b_count * 2 - b_edge

  puts [w_pattern, b_pattern].min
end


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n;
	cin >> n;
	vec(a,n);
	REP(i,n){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	cout << a[n-1]-a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def factorize(M):
  res=defaultdict(int)
  for i in range(2,int(M**0.5)+1):
    if M==1:
      break
    while M%i==0:
      M//=i
      res[i]+=1  
  if M!=1:
    res[M]=1
  return res

N=int(input())
fact=factorize(N)
#print(fact)

def times(n):
  s=0
  for i in range(1,10**9):
    s+=i
    if n<s:
      return i-1
    
answer=0
for v in fact.values():  
  #print(v,times(v))
  answer+=times(v)
  
print(answer)

Measured memory_bytes: 9720
#include<cstdio>
int main(void){int n,m,l,a[101][101],b[101][101],i,j,k;unsigned long long int c=0;scanf("%d%d%d",&n,&m,&l);for(i=0;i<n;++i){for(j=0;j<m;++j){scanf("%d",a[i]+j);}}for(i=0;i<m;++i){for(j=0;j<l;++j){scanf("%d",b[i]+j);}}for(i=0;i<n;++i){for(j=0;j<l;++j){for(c=0,k=0;k<m;++k){c+=a[i][k]*b[k][j];}printf("%lld%s",c,(j!=l-1)?" ":"");}puts("");}return(0);}


Measured memory_bytes: 2768
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 100010
int n,k;
int a[maxn];
int ans[maxn];
int main()
{
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<" ";
	}
	return 0;
 } 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,a,b;
	cin>>n>>m;
	int mx=1,mn=n;
	rep(i,m){
		cin>>a>>b;
		chmax(mx,a);
		chmin(mn,b);
	}
	cout<<(max(0,mn-mx+1))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x-a) > abs(x-b)) puts("B");
	else puts("A");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,k;
    cin>>x>>k;

    if(k&1) cout<<"No\n";
    else
    {
        if(k>=2*x && k<=4*x)    cout<<"Yes\n";
        else                    cout<<"No\n";
    }
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1e18;

const int N = 15;
ll dist[N][2][1 << N];

ll xs[N];
ll ys[N];
ll ps[N];

ll res[N+1];

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

	// Optimal to put straight through at least one city
	//	PROOF: assume not, assume two use same railway, move it towards the more populous using side

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) cin >> xs[i] >> ys[i] >> ps[i];

	for (int a = 0; a < n; ++a) {
		ll base = ps[a] * min(abs(xs[a]), abs(ys[a]));
		for (int m = 0; m < (1 << n); ++m) {
			dist[a][0][m] = base;
			dist[a][1][m] = base;
			for (int b = 0; b < n; ++b) {
				if (m & (1 << b)) {
					dist[a][0][m] = min(dist[a][0][m], ps[a] * abs(xs[a] - xs[b]));
					dist[a][1][m] = min(dist[a][1][m], ps[a] * abs(ys[a] - ys[b]));
				}
			}
		}
	}

	for (int i = 0; i <= n; ++i) res[i] = INF;
	
	for (int m = 0; m < (1 << n); ++m) {
		ll off = INF;
		for (int k = m;; k = (k-1) & m) {
			ll cur = 0;
			for (int a = 0; a < n; ++a) {
				cur += min(dist[a][0][m & k], dist[a][1][m & (~k)]);
			}
			off = min(off, cur);

			if (k == 0) break;
		}
		int i = __builtin_popcount(m);
		res[i] = min(res[i], off);
	}
	for (int i = 0; i <= n; ++i) cout << res[i] << ' '; cout << '\n';
}


Measured memory_bytes: 11292
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    map<char,int> point;
    point['r']=p;
    point['s']=r;
    point['p']=s;
    int ans=0;
    char pre=' ';
    rep(i,k){
        int a=i;
        while(a<n){
            if(t[a]==pre){
                a+=k;
                pre=' ';
                continue;
            }
            ans+=point[t[a]];
            pre=t[a];
            a+=k;
        }
        pre=' ';
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

long gcd(long x, long y) {
    return x % y ? gcd(y, x%y) : y;
}

void main() {
    long a,b,c,d;
    readf("%d %d %d %d\n",&a,&b,&c,&d);
    long cd = c * d;

    long count(long x) {
        if (x == 0) return 0L;
        return x - x/c - x/d + x / (c / gcd(c,d) * d);
    }
    long x = count(b);
    long y = count(a - 1);
    debug writeln(x, " ", y);
    writeln(x - y);
}


Measured memory_bytes: 256
/*
ID: arthurc4
TASK: test
LANG: C++11
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<bool> vb;
typedef vector<vb> vvb;

typedef map<string,int> msi;
typedef map<int,int> mii;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll; // note 'single' ls

typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)

#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); f--)

#define pb \
push_back

#define ff \
first

#define ss \
second

// LL OR INT ???
// DELETED IFSTREAM ???
int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	int n;
	cin >> n;

	int operations = 0;

	REP(i, 1, n)
	{
		int a;
		cin >> a;

		while(a%2 == 0)
		{
			operations+=1;
			a/=2;
		}
	}

	cout << operations << endl;

	return 0;
}

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

int main() {
	int i, j, k, n, d, x, maxx, p[11][11], curp, nextp;

	cin >> n >> d >> x;
	for (i = 0; i < d; i++) {
		for (j = 0; j < n; j++) {
			cin >> p[i][j];
		}
	}

	for (i = 0; i < d - 1; i++) {
		int dp[100000] = {};
		for (j = 0; j < n; j++) {
			if (1.0 * p[i + 1][j] / p[i][j] <= 1.0)continue;
			curp = p[i][j];
			nextp = p[i + 1][j];
			k = 0;
			while (k + curp <= x) {
				dp[k + curp] = max(dp[k + curp], dp[k] + nextp);
				k++;
			}
		}
		maxx = x;
		for (k = 0; k <= x; k++) {
			maxx = max(maxx, dp[k] + x - k);
		}
		x = maxx;
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int n;
vector<vector<ll>> a(16, vector<ll>(16));
vector<ll> dp(1 << 16);
vector<bool> used(1 << 16);
ll f(int s) {
    if (used[s])
        return dp[s];
    used[s] = true;
    rep(i, 0, n) rep(j, i + 1, n) {
        if ((s & (1 << i)) && (s & (1 << j)))
            dp[s] += a[i][j];
    }
    for (int t = (s - 1) & s; t > 0; t = (t - 1) & s) {
        dp[s] = max(dp[s], f(t) + f(s ^ t));
    }

    return dp[s];
}

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

    cin >> n;
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
    cout << f((1 << n) - 1) << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//おしりから見てく。Nが1ならNに1個いれないといけない
//いれたら約数に＋１してく
int main(){
  ll N; cin>>N;
  vector<ll> base(N+1,0), W(N+1,0), ans(N+1,0);
  for(int i=1; i<=N; i++){
    ll a; cin>>a; base[i]=a;
  }
  for(int i=N; i>0; i--){
    if(base[i]^W[i]==1){
      ans[i]++;
      for(int j=1; j<=i/j; j++){
        if(i%j==0){
          (W[j]=W[j]+1)%=2;
          if(i!=j*j)
            (W[i/j]=W[i/j]+1)%=2;
        }
      }
    }
  }
  //check
  ll n=0,cnt=0;
  for(int i=1; i<=N; i++){
    if(base[i]^W[i]==1){
      cout<<-1<<endl;
      return 0;
    }
    if(ans[i]==1)
      n=i, cnt++;
  }
  cout<<cnt<<endl;
  for(int i=1; i<=n; i++){
    if(ans[i]){
      cout<<i;
      if(i<n) cout<<" ";
    }
  }
}

Measured memory_bytes: 5504
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_D
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i < n; i++){
    cin >> a[i];
  }
  int min = a[0], max = a[0];
  long sum = 0;
  for(int i=0; i < n; i++){
    if(min > a[i]){
      min = a[i];
    }
    if(max < a[i]){
      max = a[i];
    }
    sum += a[i];
  }
  cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 1200
N = int(input())
a = [int(e) for e in input().split()]

ans = 0
time = 1

for i in range(N):
    if time%2 == 1:
        if a[i]%2 == 1:
            ans += 1
            time += 1
        else:
          time += 1
    else:
        time += 1
print(ans)

Measured memory_bytes: 9172
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A_modify = [A[j] - j - 1 for j in range(N)]
    A_modify.sort()

    mid1 = A_modify[N//2]
    A_modify1 = [abs(elm - mid1) for elm in A_modify]
    print(sum(A_modify1))


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

/*
const int INF   = 1 << 29;
const int MAX_N = 1000001;

// Segment Tree
// (数列のサイズ N に対してSegment Treeの頂点は 2*N-1 となる)
struct Seg_tree{
	int n;
	vector<int> dat;
	// コンストラクタで初期化
	Seg_tree(int n_){
		// 簡単のために要素数を2のべき乗にする 
		n = 1;
		while( n < n_ ) n *= 2;
		// すべての頂点の値を -INF にする
		for(int i = 0; i < 2 * n - 1; i++){
			dat.push_back(-INF);
		}
	}
	// k 番目の値 (0-indexed) を a に更新
	void update(int k, int a){
		k += n - 1;
		dat[k] = a;
		// 登りながら更新
		while( k > 0 ){
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// [a,b)の最小値を求める
	int query(int a, int b, int k=0, int l=0, int r=-INF){
		// 初回呼び出し時
		if( k == 0 && l == 0 && r == -INF ) r = n;
		
		// [a,b) と [l,r) が交差しないとき
		if( r <= a || b <= l ) return -INF;
		
		// [a,b) が [l,r) を完全に含んでいるとき
		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 max(vl, vr);
		}
	}
};
*/

// s[k] := k匹釣った人の集合
set<int> s[100001];
// id[k] := 番号 k の人が釣った数
int id[1000000] = {0};

int main(){
	int n, q, x = 0, y = 0;
	cin >> n >> q;
	
	for(int i = 0; i < n; i++) s[0].insert(i);
	
	for(int i = 0; i < q; i++){
		int a, v;
		cin >> a >> v;
		a--;
		int prev = id[a];
		int next = id[a] + v;
		x = min(x, next);
		y = max(y, next);
		s[prev].erase(a);
		s[next].insert(a);
		for(int k = y; k >= x; k--){
			if( s[k].size() ){
				cout << ((*s[k].begin()) + 1) << " " << k << endl;
				break;
			}else{
				y = k;
			}
		}

		id[a] = next;
	}
}

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

int main() {
    int A, B;
    cin >> A >> B;
    string s;
    cin >> s;
    if (count(s.begin(), s.end(), '-') != 1 || s[A] != '-') {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	cin >> s;
	string t;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'B') {
			if(t.size()) t.pop_back();
		}
		else t += s[i];
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    if op=='?': break
    a = int(a)
    b = int(b)
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    else:
        print(a//b)




Measured memory_bytes: 5596
x1,y1,x2,y2 = map(int, input().split())
x3 = x2 + y1 -y2
y3 = y2 + x2 - x1
x4 = x1 + y1 - y2
y4 = y1 + x2 - x1
print(x3,y3,x4,y4)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)

int n;
string s;
int main(){
    cin >> s;
    REP(i,s.size()-1) if(s[i] != s[i+1]) ++n; 
    cout << n << endl;
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin >> n >> k;
	vector<int> nums(n); for(auto &e : nums) cin >> e;
	sort(nums.begin(), nums.end());
	int sm = 0;
	for(int i = 0; i < k; i++) sm += nums[i];
	cout << sm << endl;
}


Measured memory_bytes: 3640
import sys
n=int(input())
p=n
a=[]
cnt=0

if n<=26:
    print(chr(n+96))
    sys.exit()
while p>0:
    p=p//26
    cnt+=1


#print(n)
for i in range(cnt-1):
    q,r=divmod(n,26**(cnt-i-1))
    a.append(q)
    n=r
if n<=25:
    a.append(n)
    
    
#print(cnt,a)
for i in range(len(a)-1,0,-1):
    if a[i]<=0:
        a[i]+=26
        a[i-1]-=1
#print(a)

flag=True
j=0
while flag:
    if a[j]==0:
        j+=1
    else:
        flag=False
a=a[j:]
        
eigo=[chr(i) for i in range(97,123)]    
for i in a:
    print(eigo[i-1],end="")

Measured memory_bytes: 61996
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define out(s) cout<<(s)<<endl;
using ll = long long;
int main()
{
	int N, K;
	cin >> N >> K;
	ll ans = K;
	N--;
	K--;
	for (size_t i = 0; i < N; i++)
	{
		ans *= K;
	}
	out(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(){
  long n,mid;
  long a[200005];
  long sum=0;
  long ave = 0;
  long ans = 0;
  cin >> n;
  for(long i=0;i<n;++i){
    cin >> a[i];
    a[i] = a[i]-i-1;
  }
  sort(a,a+n);
  if(n%2){
    mid = a[n/2];
  }else{
    mid = (a[n/2]+a[n/2-1])/2;
  }
  for(int i=0;i<n;++i){
    ans += abs(a[i]-mid);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 1792
N=int(input())
A=list(map(int,input().split()))

SUM=0
A=sorted(A)
COUNT=N-1

if COUNT==0:
    print(SUM)
    exit()

SUM+=A[-1]
del A[-1]
COUNT-=1

if COUNT==0:
    print(SUM)
    exit()

while True:
    for i in range(2):
        SUM+=A[-1]
        COUNT-=1
        if COUNT==0:
            print(SUM)
            exit()
    del A[-1]



Measured memory_bytes: 94180
a, b, c, d = gets.split.map(&:to_i)
alice = (a..b).to_a
bob = (c..d).to_a
count = 0


alice.each do |i|
  if bob.include?(i)
    count += 1
  end
end

if count > 0
  count -= 1
end

puts count

Measured memory_bytes: 1788
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun main(args: Array<String>) {
    val n = readInt()
    var a = readIntList()

    var count = 0
    while(a.all { it % 2 == 0 }) {
        a = a.map { it / 2 }
        count++
    }
    println(count)
}

Measured memory_bytes: 37996
#include <stdio.h>

int main (void){
    char s[1005];
    char t[1005];
    int match=0;
    int max_match=0;
    
    int size=0;
    int size2 = 0;
    
        scanf("%s",s);
        scanf("%s",t);
    for(int i=0;s[i]!='\0';i++){
        size++;
    }
    
    for(int i=0;t[i]!='\0';i++){
        size2++;
    }
    for(int i=0;i<=size-size2;i++){
        for(int j=0;j<size2;j++){
            if(s[i+j] == t[j])match ++;
        }
        if(match>max_match)max_match=match;
        match=0;
    }
    printf("%d",size2-max_match);
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ( A == 1 && B == 2 ) cout << 3 << endl;
  else if ( A == 1 && B == 3 ) cout << 2 << endl;
  else if ( A == 2 && B == 1 ) cout << 3 << endl;
  else if ( A == 2 && B == 3 ) cout << 1 << endl;
  else if ( A == 3 && B == 1 ) cout << 2 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>

#define R register
int main()
{
	R int H, W, h, w; scanf("%d%d%d%d", &H, &W, &h, &w);
	if (H % h == 0 && W % w == 0) puts("No");
	else
	{
		puts("Yes");
		for (R int i = 1; i <= H; ++i, puts(""))
			for (R int j = 1; j <= W; ++j)
				if (i % h == 0 && j % w == 0)
					printf("%d ", -1000 * (h * w - 1) - 1);
				else printf("%d ", 1000);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, a, b;
	cin >> k >> a >> b;
	bool ok = false;
	for (int i = a; i <= b; ++i) {
		if (i % k == 0) ok = true;
	}
	if (ok) cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
}


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

using namespace std;

#define intt long long

int f (int n) {
	int ans = 0;
	while (ans * (ans + 1) / 2 <= n) {
		ans ++;
	}
	return ans - 1;
}

int main() {

	intt n;
	cin >> n;
	int ans = 0;
	for (int i = 2; 1LL * i * i <= n; i ++) {
		if (n % i == 0) {
			int cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt ++;
			}
			ans += f(cnt);
		}
	}
	if (n != 1) ans ++; 
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3640
a = int(input())
A = list(map(int, input().split()))

N = [0]*len(A)

for i in range(a):
    n = A[i]
    while n % 2 == 0:
        if n % 2 == 0:
            n /= 2
            N[i] += 1

print(min(N))


Measured memory_bytes: 9084
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n;
	while(cin >> n){
		int counter = 0;
		for(int a = 0; a <= 9; a++){
			for(int b = 0; b <= 9; b++){
				for(int c = 0; c <= 9; c++){
					for(int d = 0; d <= 9; d++){
						if(a + b + c + d == n)counter++;
					}
				}
			}
		}
		cout << counter << endl;
	}
}


Measured memory_bytes: 3092
/*************************************************************************
  >         File: C.cc
  >       Author: Riho.Yoshioka
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 28 Aug 2016 08:00:43 PM CST
*************************************************************************/
#include <bits/stdc++.h>
using LL = long long;
const int N = 55;
LL dp[N][N][N * N];
int a[N];

int main() {
  std::ios::sync_with_stdio(0);
  
  int n, m;
  std::cin >> n >> m;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) std::cin >> a[i];
  for (int itr = 0; itr < n; itr++) {
    for (int cnt = 0; cnt < n; cnt++) {
      for (int sum = 0; sum < N * N; sum++) {
        dp[itr + 1][cnt][sum] += dp[itr][cnt][sum];
        dp[itr + 1][cnt + 1][sum + a[itr]] += dp[itr][cnt][sum];
      }
    }
  }
  LL answer = 0;
  for (int i = 0; i < n; i++) {
    answer += dp[n][i + 1][(i + 1) * m];
  }
  std::cout << answer << std::endl;
  return 0;
}


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

int main(){
    long long A,B,N;
    cin>>A>>B>>N;
    //int x=min(B-1,N);
    if(B-1<N)
        cout<<A*(B-1)/B<<endl;
    else
        cout<<A*N/B<<endl;

    return 0;
}

Measured memory_bytes: 3524
import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self,l):
        nb = bin(len(l))[2:]
        b = sum([int(d) for d in nb])
        if b == 1:
            self.end_leaves = pow(2,len(nb)-1)
        else:
            self.end_leaves = pow(2,len(nb))
        self.tree = [set() for _ in range(self.end_leaves*2)]
        
        for i in range(len(l)):
            self.tree[self.end_leaves+i].add(l[i])
            
    def union(self,a):
        if a >= self.end_leaves // 2:
            self.tree[a] = self.tree[a*2] | self.tree[a*2+1]
            return self.tree[a]
        else:
            self.tree[a] = self.union(a*2) | self.union(a*2+1)
            return self.tree[a]
    def update(self,a,s):
        x = a + self.end_leaves
        if s not in self.tree[x]:
            self.tree[x] = set(s)
            while x > 1:
                x //= 2
                self.tree[x] = self.tree[x*2] | self.tree[x*2+1]
    def query(self,l,r):
        x = l + self.end_leaves
        y = r + self.end_leaves
        tl = set()
        tr = set()
        while y - x > 1:
            if x % 2 == 1:
                tl = tl | self.tree[x]
                x += 1
            if y % 2 == 0:
                tr = self.tree[y] | tr
                y -= 1
            x >>= 1
            y >>= 1
        if y - x == 0:
            print(len(tl|tr|self.tree[x]))
        else:
            print(len(tl|tr|self.tree[x]|self.tree[y]))
            
            

N = int(input())
S = list(input())
st = SegmentTree(S)
st.union(1)
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        st.update(int(q[1])-1,q[2])
    else:
        st.query(int(q[1])-1,int(q[2])-1)

Measured memory_bytes: 370004
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b;
int dp[4005][4005];

int main(void){
	dp[0][0]=1;
	for(int i=0;i<=4000;i++){
		dp[i][0]=1;
		dp[i][i]=1;
		for(int j=1;j<=i;j++){
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD;
		}
	}
	scanf("%d%d",&a,&b);
	ll ans=a+1;
	for(int i=1;i<b;i++){
		for(int l=1;l<=b-i;l++){
			ll t=(ll)dp[b-1][i-1]*dp[b-i-1][l-1]%MOD;
			if(a-(b-i)-(b-i-l)+2>=2)ans+=(ll)t*dp[a-(b-i)-(b-i-l)+2][2]%MOD;
			ans%=MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

bool isPrime (int n)
{
    if (n == 1) return false;
    if (n == 2) return true;

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }

    return true;
}
int main()
{
    int n;
    cin >> n;

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt += isPrime(a);
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3088
def main():
  import collections
  N, *W = open(0).read().split()
  N = int(N)

  if max(collections.Counter(W).values()) != 1:
    print("No")
    exit()
  else:
    for i in range(len(W)-1):
      if W[i][-1] != W[i+1][0]:
        print("No")
        exit()
    print("Yes")
  
if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define pb push_back
#define ff first
#define ss second
#define SIZE 10000001
#define INF int(2e9 + 9)
#define BIG_INF ll(1e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)



//#pragma GCC optimize("Ofast")



ll T = 1, n, m, k;

vector<ll> a, b;


int get_kol(int x)
{
    int res = 0;
    for(ll i = 1; i * i <= x; i++)
    {
        if(x % i == 0)
            res++;

        if(x / i != i) res++;
    }

    return res;
}

ll d[SIZE];

ll calc(ll x)
{
    ll div = 0;
    vector<ll> divs;
    while(x != 1)
    {
        div = d[x];
        int st = 0;
        while(x % div == 0)
        {
            st++;
            x /= div;
        }
        divs.pb(st);
    }
    if(x > 1)
    {
        divs.pb(1);
    }
    ll res = 1;
    for(ll lol: divs)
    {
        res *= (lol + 1);
    }

    return res;


}

void solve()
{

    for(ll i = 1; i < 1e7 + 1; i++)
    {
        for(ll j = i; j < 1e7 + 1; j+=i)
        {
            d[j]++;
        }
    }


    cin >> n;
    ll ans = 0;
//    cout << calc(100) << "\n";
    for(int i = 1; i <= n; i++)
    {
        ans += i * d[i];
    }
    cout << ans;
    return;

}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    while(T--)
    {
        solve();
    }




    return 0;
}


Measured memory_bytes: 81736
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,t;cin>>n>>t;
	vector<pair<int,int>> a(n);
	int x,y;
	for(int i = 0; i < n; i++) {
		cin>>x>>y;
		a[i] = mp(x,y);
	}
	sort(ALL(a));
	vector<vector<int>> dp(n + 1,vector<int>(t + 1,0));
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= t - 1; j++) {
			dp[i][j] = dp[i - 1][j];
			ans = max(dp[i][j] + a[i - 1].sc,ans);
			if (a[i - 1].fs > j){
				dp[i][j] = dp[i - 1][j];
			}
			else{
				dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - a[i - 1].fs] + a[i - 1].sc);
			}
		}


	}

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

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


def main():
    n = int(input())
    w = list(map(int, input().split()))
    ans = float('inf')

    for i in range(1, n):
        ans = min(ans, abs(sum(w[:i]) - sum(w[i:])))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940