akhauriyash/Code-Regression huggingface dataset:
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 998244353;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int A,B,C;cin >> A >> B>> C;
    cout << (A*B) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main() {
	int sum = 0;
	vector<int> v(5,0);
	for (int i = 0;i<5;++i){
		cin >> v[i];
		if (v[i]%10 == 0){
		sum += v[i];
		}else{
			sum = sum + (v[i]/10+1)*10;
		}
	}
	int ans = sum;
	for (int i = 0;i < 5;++i){
		if (v[i]%10 != 0){
			ans = min(ans,sum-(v[i]/10+1)*10 + v[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int x;cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


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

using namespace std;
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(3*n);
    for(int i=0;i<3*n;i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0, cnt = 0;
    for(int i=3*n-2;i>=0;i-=2) {
        ans += a[i];
        cnt++;
        if(cnt >= n) break;
    }
    cout << ans << endl;


}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
  
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        if((i%3 == 0) || (i%5 == 0)) continue;
        ans+=i;
    }
    cout<<ans;
}

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

typedef double ld;
const int XD = 303;
ld dp[ XD ][ XD ][ XD ];
bool czy[ XD ][ XD ][ XD ];
int n, ile[ 4 ];
ld N;

ld oblicz( int a, int b, int c )
{
    ld A = a, B = b, C = c;
    if( a == 0 && b == 0 && c == 0 ) return 0;
    if( a < 0 || b < 0 || c < 0 ) return 0;
    if( czy[ a ][ b ][ c ] ) return dp[ a ][ b ][ c ];
    czy[ a ][ b ][ c ] = true;
    ld x = A + B + C;
    dp[ a ][ b ][ c ] = N/x + oblicz(a-1,b,c)*A/x
                                + oblicz(a+1,b-1,c)*B/x
                                + oblicz(a,b+1,c-1)*C/x;
    return dp[ a ][ b ][ c ];
}
int main()
{
    scanf( "%d", &n );
    N = n;
    while( n-- )
    {
        int a; scanf( "%d", &a ); ile[ a ]++;
    }
    printf( "%.10lf", oblicz( ile[ 1 ], ile[ 2 ], ile[ 3 ] ) );
    return 0;
}


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


int main() {
	int n, l, r,y;
	cin >> n;
	y = 0;
	rep(i, n) {
		
		cin >> l >> r;
		y += (r - l + 1);
		
	}
	cout << y << endl;
	return 0;
}


Measured memory_bytes: 3588
S = list(input())
ls = len(S)

a = [0] * (len(S) + 1)


for i in range(ls):
    if S[i] == "<":
        a[i + 1] = max(a[i + 1], a[i] + 1)
        
for i in range(ls - 1, -1, -1):
    if S[i] == ">":
        a[i] = max(a[i], a[i + 1] + 1)
        
print(sum(a))


Measured memory_bytes: 32472
f()=(x->parse(Int,x)).(split(readline()))
N,K=f()
A=sort(f())
S=0
C=1
M=10^9+7
for k=K:N
	S+=C*(A[k]-A[N+1-k])%M
	C=C*k%M*invmod(k-K+1,M)%M
end
show(S%M)

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  long long N, K; cin >> N >> K;
  long long A[N]; for (long long i = 0; i < N; i++) cin >> A[i];
  COMinit();
  sort(A, A + N);
  
  long long MAX_ = 0, MIN_ = 0;
  for (long long i = 0; i < N; i++){
    if (N - i >= K) MIN_ += COM(N - i - 1, K - 1) * A[i];
    MIN_ %= MOD;
  }
  for (long long i = N - 1; i >= 0; i--){
    if (i >= K - 1) MAX_ += COM(i, K - 1) * A[i];
    MAX_ %= MOD;
  }
  long long ans = MAX_ - MIN_;
  ans %= MOD; ans += MOD; ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 16304
/** 	Author: Apoorva Mittal  **/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define nl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i >= b; i--)
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define init(i, k) memset(i, k, sizeof i)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define inp(a) rep(i, 0, a.size()) cin >> a[i];
#define out(a)                               \
    cout << #a << ": "<<endl;                      \
    rep(i, 0, a.size()) cout << a[i] << " "; \
    cout << endl;
#define out2d(a)                \
    cout << #a << ": " << endl; \
    rep(i, 0, a.size())         \
    {                           \
        rep(j, 0, a[0].size())  \
                cout            \
            << a[i][j] << " ";  \
        cout << endl;           \
    }
#define flush fflush(stdout);
#define lb lower_bound
#define ub upper_bound
#define maxe *max_element
#define mine *min_element
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define pqueue priority_queue
#define precise(x) cout << fixed << showpoint << setprecision(x);
#define setbit(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)
#define deb(x) cout << #x << " " << x << endl;
#define Y "YES"
#define N "NO"
const int mod = 1e9 + 7;
// ====== Useful functions begin ======
inline int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
inline int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
// ====== Useful functions end ======
const int inf = 1e18;
const int maxn = 1e5 + 5;

//--------------------------------------------------------------------------------------------------------------------------------
vector<int>edges[maxn];
int indegree[maxn]; // number of edges going to b
int n,m;
int dist[maxn];
bool vis[maxn];
//--------------------------------------------------------------------------------------------------------------------------------

void dfs(int a)
{
    vis[a]=1;
    for(auto b:edges[a])
    {
        indegree[b]--;
        dist[b] = max(dist[b],dist[a]+1);
        if(!indegree[b])
        {
            dfs(b);
        }
    }
}

void solve()
{
    cin>>n>>m;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        edges[a].pb(b);
        indegree[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0 && indegree[i] == 0)
        {
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,dist[i]);
    }
    cout<<ans<<endl;


}
signed main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    speed;
    int t = 1;
    // cin >> t;

    for (int tt = 1; tt <= t; tt++)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
    }
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define mx 1000000007
#define db double

using namespace std;

db dp[301][301][301]={0},n;

db solve(int c1,int c2,int c3){
    if(dp[c1][c2][c3]!=0)
        return dp[c1][c2][c3];
    if(c1==0 && c2==0 && c3==0)
        return dp[c1][c2][c3]=0;
    db j=0,k=0,l=0,sum=c1+c2+c3;
    if(c1!=0){
        j=(c1/sum)*solve(c1-1,c2,c3);
    }
    if(c2!=0){
        k=(c2/sum)*solve(c1+1,c2-1,c3);
    }
    if(c3!=0){
        l=(c3/sum)*solve(c1,c2+1,c3-1);
    }
    dp[c1][c2][c3]=(n/(sum)) + j+ k +l;
    return dp[c1][c2][c3];

}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int c1=0,c2=0,c3=0;
	int sz;
	cin>> sz ;
	n=sz;
	int p[sz+1];
	for(int i=1;i<=sz;++i){
        cin>> p[i] ;
        if(p[i]==1)
            ++c1;
        if(p[i]==2)
            ++c2;
        if(p[i]==3)
            ++c3;
    }
    cout << fixed << setprecision(15) << solve(c1,c2,c3) ;
	return 0;
}


Measured memory_bytes: 111200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,k;
ll dp[66666][111];
vector<int>v;
int main()
{
    scanf("%d%d",&n,&k);
    int l=1,r=1;
    while(r+1<=n)
    {
        v.push_back(r);
        l=r+1;r=n/(n/l);
    }
    v.push_back(r);
    sort(v.begin(),v.end());
    dp[0][1]=v[0];
    for(int i=1;i<v.size();i++)
        dp[i][1]=v[i]-v[i-1];
    ll ans=0;
    for(int i=2;i<k;i++)
    {
        int r=v.size()-1;
        ll now=0;
        for(int j=0;j<v.size();j++)
        {
           now=(now+dp[j][i-1])%mod;
           while(v[r]>=n/v[j]&&r>=0)
           {
               dp[r][i]=now*(r==0?v[r]:v[r]-v[r-1])%mod;
               r--;
           }
        }
    }
    for(int i=0;i<v.size();i++)
    {
        if(i==0) ans+=dp[i][k-1]*(n/v[i])%mod;
        else ans+=dp[i][k-1]*(n/v[i])%mod;
    }
    printf("%lld\n",ans%mod);
}


Measured memory_bytes: 55932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

/* a と b の最小公倍数を求める */
long long LCM(long long a, long long b)
{
    long long g = GCD(a, b);
    return a / g * b;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    // std::ifstream in("04.txt");
    // std::cin.rdbuf(in.rdbuf());

    int N, M;
    cin >> N >> M;

    vi A(N);
    REP(i, N)
    {
        cin >> A.at(i);
        A.at(i) /= 2;
    }
    int llcm;
    if (N > 1)
        llcm = LCM(A.at(0), A.at(1));
    else
        llcm = A.at(0);

    REP(i, N)
    {
        if (llcm > M)
        {
            cout << 0 << endl;
            return 0;
        }
        llcm = LCM(llcm, A.at(i));
        if (llcm > M)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    REP(i, N)
    {
        int tmp = llcm / A.at(i);
        if (tmp % 2 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = 0;
    int ii = 0;

    while (true)
    {
        int tmp = llcm * (2 * ii + 1);
        if (tmp <= M)
            ans++;
        else
            break;
        ii++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define x first
#define y second
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int n, k;

int main()
{
	fastio;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		if (x == k + 1)
			k++;
	}
	
	cout << (k == 0 ? -1 : n - k) << '\n';
}

Measured memory_bytes: 256
h, w = map(int, input().split())

a = []
for _ in range(h):
    row = list(input())
    if not all([c == '.' for c in row]):
        a.append(row)

all_whites = []
for j in range(w):
    if all([a[i][j] == '.' for i in range(len(a))]):
        all_whites.append(j)

for row in a:
    removed_row = [row[j] for j in range(w) if j not in all_whites]
    print(''.join(removed_row))


Measured memory_bytes: 3064
S = input()
k = int(input())

if len(set(S)) == 1:
    print(len(S)*k//2)
else:
    ans = 0
    cnt = 1
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    if cnt > 1:
        ans += cnt//2
    ans = ans * k
    if S[0] == S[-1]:
        f, b = 0, 0
        for s in S:
            if s == S[0]:
                f += 1
            else:
                break
        for s in S[::-1]:
            if s == S[0]:
                b += 1
            else:
                break
        ans -= (f//2 + b//2 - (f+b)//2) * (k-1)
    print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int N = scan.nextInt();
        int D[] = new int[N];
        int num_length[] = new int[N];
        int max_length = 0;
        
        boolean bad_input = false;
        
        long cnt = 1;
        
        //標準入力-----------------------
        if( N != 1 )
        for( int i = 0 ; i < N ; i++ ){
          D[i] = scan.nextInt();
          
          if( N-1 <  D[i] ){
            //exception
            bad_input = true;
            cnt = 0;
            break;
          }
          num_length[ D[i] ] += 1;
          
          if(max_length < D[i])max_length=D[i];
        }
        //-------------------------------
        if( D[0] != 0 ){
          cnt = 0;
        }
        else if( num_length[0] != 1 ){
          cnt = 0;
        }
        else if(!bad_input){
          for( int i = 1 ; i < max_length ; i++ ){
            //powだと数字がでかい時にエラーになる
            //cnt *= (long)Math.pow( num_length[i] , num_length[i+1]  );
            for( int j = 0 ; j < num_length[i+1] ; j++){
              cnt = (long)cnt * (long)num_length[i];
              cnt = cnt % (long)998244353;
            }
          }
        }
         
        //cnt = (long)998244354 * (long)3;
        //cnt = (long)Math.pow( 998244354 , 2  );
            
        //System.out.println(cnt % (long)998244353);
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 57180
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    StringBuilder output = new StringBuilder();
    String crlf = System.getProperty("line.separator");
    boolean[][] cards = new boolean[4][13];
    int num = in.nextInt();
    char suit;
    int rank;
    
    if (num == 52) return;
    while (num != 0) {
      suit = in.next().charAt(0);
      rank = in.nextInt() - 1;
      
      switch (suit) {
        case 'S': cards[0][rank] = true; break; 
        case 'H': cards[1][rank] = true; break; 
        case 'C': cards[2][rank] = true; break; 
        case 'D': cards[3][rank] = true; break; 
      }
      num--;
    }
    
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 13; j++) {
        if (cards[i][j] == false) {
          switch (i) {
            case 0: output.append("S").append(" ").append(j + 1).append(crlf); break;
            case 1: output.append("H").append(" ").append(j + 1).append(crlf); break;
            case 2: output.append("C").append(" ").append(j + 1).append(crlf); break;
            case 3: output.append("D").append(" ").append(j + 1).append(crlf); break;
          }
        }
      }
    }
    output.delete(output.length() - 1, output.length());
    System.out.println(output.toString());
  }
}

Measured memory_bytes: 17192
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int cnt = 0;
    for (int i = 0; i < 101;i++){
        if(A<=i&&i<B&&C<=i&&i<D)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:3
*Problem:Small Multiply
*Date:2017-11-18
*Algorithm:Teacher's deque
*Stats:Unknown*/

bool debug=false;

template<typename T> struct pq_small{
	priority_queue<T,vector<T>,greater<T> > pq;
	void push(T x){
		pq.push(x);
	}

	void pop(){
		pq.pop();
	}

	int size(){
		return pq.size();
	}

	bool empty(){
		return pq.empty();
	}

	T top(){
		return pq.top();
	}
};

int dis[100005];
int main(int argc,char* argv[]){
	int k;
	cin>>k;
	deque<int> dq;
	for(int i=0;i<=k;i++) dis[i]=1e9;
	dis[1]=1;
	dq.push_front(1);
	while(!dq.empty()){
		int last=dq.front();
		dq.pop_front();
		
		if(dis[last*10%k]>dis[last]){
			dis[last*10%k]=dis[last];
			dq.push_front(last*10%k);
		}
		if(dis[(last+1)%k]>dis[last]+1){
			dis[(last+1)%k]=dis[last]+1;
			dq.push_back((last+1)%k);
		}
	}
	
	cout<<dis[0];
	return 0;
}



Measured memory_bytes: 896
n = int(input())
a = list(map(int,input().split()))

c = [a[i]-i-1 for i in range(n)]
ans = 0
c.sort()
#print(c)
if n%2 == 1:
    b = c[n//2]
    for i in range(n):
        ans += abs(c[i]-b)
else:
    b = (c[n//2]+c[n//2-1])//2
    #print(b)
    for i in range(n):
        ans += abs(c[i]-b)
print(ans) 




Measured memory_bytes: 99668
# -*- coding: utf-8 -*-
"""
C - Average Length
https://atcoder.jp/contests/abc145/tasks/abc145_c

"""
import sys


from itertools import permutations
from statistics import mean

def solve(N, points):
    dists = []
    for p in permutations(points):
        x = 0.0
        for a, b in zip(p, p[1:]):
            x += ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
        dists.append(x)
    return mean(dists)


def main(args):
    N = int(input())
    points = [list(map(int, input().split())) for _ in range(N)]
    ans = solve(N, points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 6552
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			LinkedList<Integer> list = new LinkedList<Integer>();
			
			for(int i = 0; i < n; i++){
				list.add(sc.nextInt());
			}
			
			Collections.sort(list);
			Collections.reverse(list);

			int cost = 0;
			
			while(list.size() >= m){
				for(int i = 0; i < (m - 1); i++){
					cost += list.poll();
				}
				list.poll();
			}
			
			if(!list.isEmpty()){
				for(int i : list){
					cost += i;
				}
			}
			
			System.out.println(cost);
		}
		
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_NV = 100010;
int v[MAX_NV],even[MAX_NV],odd[MAX_NV];
P evenP[MAX_NV+1],oddP[MAX_NV+1];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		if (i % 2 == 0) cin >> even[i/2];
		else cin >> odd[i/2];
	}

	/*
	for (int i = 0; i < n/2; ++i)
	{
		cout << even[i] << " ";
	}

	cout << endl;

	for (int i = 0; i < n/2; ++i)
	{
		cout << odd[i] << " ";
	}
	cout << endl;
	*/

	sort(even,even+n/2);
	sort(odd,odd+n/2);
	for (int i = 0; i <= MAX_NV; ++i)
	{
		evenP[i] = P(lower_bound(even,even+n/2,i) - upper_bound(even,even+n/2,i), i);
		oddP[i] = P(lower_bound(odd,odd+n/2,i) - upper_bound(odd,odd+n/2,i), i);
	}
	sort(evenP,evenP+MAX_NV+1);
	sort(oddP,oddP+MAX_NV+1);
	if (evenP[0].second != oddP[0].second)
	{
		//cout << evenP[0].second << " " << oddP[0].second << endl;;
		//cout << evenP[0].first << " a " << oddP[0].first << endl;
		cout << n + evenP[0].first + oddP[0].first << endl;
	}
	else if (evenP[1].first + oddP[0].first < evenP[0].first + oddP[1].first)
	{
		//cout << evenP[1].first << " b " << oddP[0].first << endl;
		cout << n + evenP[1].first + oddP[0].first << endl;
	}
	else
	{
		//cout << evenP[0].first << " c " << oddP[1].first << endl;
		cout << n + evenP[0].first + oddP[1].first << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
n,d=map(int,input().split())
l1=[]
for a in range(n):
    l=list(map(int,input().split()))
    l1.append(l)
count=0
for i in range(n-1):
    for j in range(i+1,n):
        sum2 = 0
        for k in range(d):
            sum2+=(l1[i][k]-l1[j][k])**2
        if (sum2**0.5)%1==0:
            count+=1
print(count)

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

typedef long long int ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
const int lt=100005;
ll mod=1000000007;

void printv(vector <ll> a){
	for(int i=0;i<a.size();i++)
		cout << a[i] << " ";
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin >> n;
	vector <ll> a;
	for(int i=0;i<n;i++){
		ll k;
		cin >> k;
		a.pb(k);
	}
	ll mx = 0;
	ll ans = 0;
	for(int i=0;i<n;i++){
		if(a[i]<mx)
			ans+=mx-a[i];
		else
			mx = a[i];
		// cout << mx << " ";
	}
	// cout << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ll long long

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

	vector<int> card(n + 1, 0);

	rep(i, m)
	{
		int l, r;
		cin >> l >> r;
		l--; r--;

		card[l]++;
		card[r + 1]--;
	}

	rep(i, n)
	{
		card[i + 1] += card[i];
	}

	int ans = 0;
	rep(i, n + 1)
	{
		if (card[i] == m)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
// You either die a hero, or you live long enough to see yourself become the villain.

/**
 *   author:  Blind_is_love
 *   created: 12.10.2019, 16:41
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

#define endl "\n"
#define vll vector<int>
#define max_heap priority_queue<int>
#define min_heap priority_queue<int , vector<int>, greater<int> >
#define pb push_back
#define all(container) container.begin(), container.end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define printArr(name,from,to) for(int x = from; x < to; x++) {cout << name[x] << " ";} cout << endl;
#define fi first
#define se second
#define mp make_pair
#define prime1 304933
#define prime2 15486277 
#define mod2 179424691
#define int ll

typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

const ll MOD = 1000000007;
const ll MAX = 1005;
const double PI = 3.1415926;
const ll INF = 1e18;
const double EPS = 1e-5;

int h,w;
char matrix[MAX][MAX];
int dp[MAX][MAX];
bool seen[MAX][MAX];

int solve(int i, int j){
	if (i >= h || i < 0 || j >= w || j < 0) return 0;
	if (matrix[i][j] == '#') return 0;
	if (i == h-1 && j == w-1) return 1;
	if (seen[i][j]) return dp[i][j];
	seen[i][j] = true;
	return dp[i][j] = (solve(i+1, j) + solve(i, j+1))%MOD;
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	clock_t t1, t2;
	t1 = clock();
	cin >> h >> w;
	for(int i = 0 ; i < h; ++i){
		for	(int j = 0 ; j < w; ++j){
			cin >> matrix[i][j];
		}
	}
	cout << solve(0,0) << endl;
	t2 = clock(); cerr << "time taken: " << (t2-t1)/(long double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 10240
N = parse(Int, readline())
A = map(x->parse(Int, x), split(readline()))

count = Dict()

for a in A
    count[a] = get(count, a, 0) + 1
end

count = sort([x for x in count], by = x->x.first)

ans = 0

if length(count) == 1
    ans = max(ans, count[1].second)
end

if length(count) == 2
    if abs(count[1].first - count[2].first) == 1
        ans = max(ans, count[1].second + count[2].second)
    else
        ans = max(ans, count[1].second, count[2].second)
    end
end

if length(count) >= 3
    for i = 1:length(count) - 2
        if count[i].first + 1 == count[i + 1].first == count[i + 2].first - 1
            global ans = max(ans, count[i].second + count[i + 1].second + count[i + 2].second)
        elseif count[i].first + 1 == count[i + 1].first
            global ans = max(ans, count[i].second + count[i + 1].second)
        elseif count[i + 1].first + 1 == count[i + 2].first
            global ans = max(ans, count[i + 1].second + count[i + 2].second)
        else
            global ans = max(ans, count[i ].second, count[i + 1].second, count[i + 2].second)
        end
    end
end

println(ans)

Measured memory_bytes: 175488
#include<stdio.h>
#include<vector>
using namespace std;

vector<int>lis[100005];

class solution {
private:
	int n, m;
	int dp[100005];
	int serc(int x) {
		if (dp[x] != -1) return dp[x];
		dp[x] = 0;
		for (int i = 0; i < lis[x].size(); i++) {
			dp[x] = max(dp[x], 1 + serc(lis[x][i]));
		}
		return dp[x];
	}
	int max(int a, int b) {
		if (a > b) return a;
		return b;
	}
	void reset() {
		for (int i = 0; i <= n; i++) {
			dp[i] = -1;
		}
	}
public:
	solution() {
		scanf("%d %d", &n, &m);
		for (int i = 0; i < m; i++) {
			int a, b;
			scanf("%d %d", &a, &b);
			lis[a].push_back(b);
		}
		reset();
		int ans = 0;
		for (int i = 0; i <= n; i++) {
			if (dp[i] == -1) ans = max(ans, serc(i));
		}
		printf("%d\n", ans);
	}
};

#ifndef L0C4L
int main() {
	solution();
	return 0;
}
#endif

Measured memory_bytes: 7680
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	int a,h,b;
	cin>>a>>b>>h;
	cout<<(a+b)*(h/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto x : v) cerr << x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int i = 0; i < (n); ++i) cerr << a[i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int A[200005];
int main() {
	int N;
	scanf("%d", &N);
	int p = 0;
	int x = 0;
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%d", &A[i]);
		while (x & A[i]) {
			x ^= A[p];
			++p;
		}
		ans += i - p + 1;
		x |= A[i];
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node {
	int key;
	struct Node* parent;
	struct Node* left;
	struct Node* right;
	struct Node* sibling;
	int degree;
	int depth;
	int height;
	char type[15]; 
};
typedef struct Node * NodePointer;


void serach_depth (NodePointer ,int );

int main (){
	int n;
	scanf("%d\n",&n);
	
	//setting part
	NodePointer array [n];
	for (int i = 0; i < n;i++)
	{
		array[i] = (NodePointer) malloc (sizeof(struct Node));
		array[i]->parent = NULL;
		array[i]->sibling = NULL;
		array[i]->left = NULL;
		array[i]->right = NULL;
		array[i]->degree = 0;
		strcpy(array[i]->type,"internal node");
	}
	
	//input part
	for (int i = 0; i < n;i++)
	{
		int id ,left_id,right_id;
		scanf("%d %d %d\n",&id,&left_id,&right_id);
		
		array[id]->key = id;
		if (left_id != -1){
			array[id]->left = array[left_id];
			array[left_id]->parent =  array[id];
			array[id]->degree++;
		}
		if (right_id != -1){
			array[id]->right = array[right_id];
			array[right_id]->parent =  array[id];
			array[id]->degree++;
		}
		if (left_id != -1 && right_id != -1){
			array[left_id]->sibling =  array[right_id];
			array[right_id]->sibling =  array[left_id];
		}
		if (left_id == -1 && right_id == -1){
			strcpy(array[id]->type ,"leaf");
		}
	}
	
	//search part
		for (int i = 0; i < n;i++)
	{
		if(array[i]->parent == NULL) {
			strcpy(array[i]->type ,"root");
			serach_depth(array[i],0); break;
		}
	}
	
	//print part
	for (int i=0; i<n ;i++){
		printf("node %d: ",i);
		if (array[i] -> parent != NULL){
		printf("parent = %d, ",array[i]->parent->key);
		}else {
			printf("parent = -1, ");
		}if (array[i] -> sibling != NULL){
		printf("sibling = %d, ",array[i]->sibling->key);
		}else {
			printf("sibling = -1, ");
		}
		printf("degree = %d, depth = %d, height = %d, %s\n",array[i]->degree,array[i]->depth,array[i]->height,array[i]->type );
	}
	
	return 0;
}

void serach_depth (NodePointer tag,int dep){
	tag->depth = dep;
	if(tag->left == NULL && tag->right == NULL){tag->height = 0; return;}
	if ( tag->left != NULL){serach_depth(tag->left , dep+1);}
	if ( tag->right != NULL){serach_depth(tag->right , dep+1);}
	if ( tag->left == NULL ){
		tag->height = tag->right->height + 1;
	}
	if ( tag->right == NULL){
		tag->height = tag->left->height + 1;
	}
	if ( tag->left != NULL && tag->right != NULL){
		if ( tag->left->height > tag->right->height){
			tag->height = tag->left->height + 1;
		}else {
			tag->height = tag->right->height + 1;
		}
	}
}



Measured memory_bytes: 2104
S = input()

ans = len(S)

abc = "abcdefghijklmnopqrstuvwxyz"

def do(x,c):
    if len(x)==1 or x.count(c)==len(x):
        return 0
    res = ""
    for i in range(len(x) - 1):
        if (x[i]==c or x[i+1]==c):
            res += c
        else:
            res += x[i]
    return 1+do(res,c)

for c in abc:
    ans = min(ans,do(S,c))

print(ans)

Measured memory_bytes: 76468
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int A, B, K;
   cin >> A >> B >> K;
   int r_1,r_2,r_3;
   if(B >= A)
   {
       r_1 = B;
       r_2 = A;
       while(r_1 % r_2 != 0)
       {
           r_3 = r_1 % r_2;
           r_1 = r_2;
           r_2 = r_3;
       }
   }
    else
   {
       r_1 = A;
       r_2 = B;
       while(r_1 % r_2 != 0)
       {
           r_3 = r_1 % r_2;
           r_1 = r_2;
           r_2 = r_3;
       }
   }
   vector<int> G;
   for(int i = 1; i <= r_2; i++)
   {
       if(r_2 % i == 0)
       {
           G.push_back(r_2 / i);
       }
   }
   cout << G.at(K-1) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        double a = sc.nextDouble();
        int[] h = new int[n];
        int flag = 1;
        double[] t_ave = new double[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            t_ave[i] = t - h[i] * 0.006;
        }
        double min = Math.abs(a - t_ave[0]);
        for (int i = 1; i < n; i++) {
            if (min > Math.abs(a - t_ave[i])) {
                min = Math.abs(a - t_ave[i]);
                flag = i + 1;
            }
        }
        System.out.println(flag);
    }
}

Measured memory_bytes: 25300
#include "stdio.h"
#include "string.h"

int main()
{
    char S[10], T[10], U[10];
    int nS, nT;
    scanf("%s %s", &S, &T);
    scanf("%d %d", &nS, &nT);
    scanf("%s", &U);

    if(!strcmp(U, S))
    {
        nS--;
    }
    else if(!strcmp(U, T))
    {
        nT--;
    }

    printf("%d %d\n", nS, nT);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s; cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N,i,t,ans,h;
  ans=1;
  scanf("%d",&N);
  int H[N];
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  for(i=1;i<N;i++){
    h=1;
    for(t=i-1;t>=0;t--){
      if(H[i]<H[t]){
        h=0;
        break;}
    }
    if(h==1){
      ans=ans+1;
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for i in range(n,n+10**6):
    if is_prime(i):
        print(i)
        break

Measured memory_bytes: 66028
from collections import deque

class Car:
  def __init__(self, rem, ind):
    self.ind = ind
    self.rem = rem
 
class Part:
  def __init__(self, i):
    self.ind = i
    self.top = None
    self.und = None
    self.sta = 0
    self.rem = -1
  
  def prog(self, time):
    if self.top != None:
      self.top.rem -= time
    if self.und != None:
      self.und.rem -= time
    if self.sta != 0:
      self.rem -= time

  def out(self):
    if self.sta == 2:
      if self.und.rem <= 0 and self.top.rem <= 0:
        outs = [self.und.ind, self.top.ind]
        self.und = None
        self.top = None
        self.sta = 0
        self.rem = -1
        return outs
      if self.und.rem <= 0:
        outs =  [self.und.ind]
        self.und = None
        self.sta = 1
        self.rem = self.top.rem
        return outs
    
    if self.sta == 1:
      if self.top.rem <= 0:
        outs = [self.top.ind]
        self.top = None
        self.sta = 0
        self.rem = -1
        return outs
    return []

  def into(self, rem, ind):
    if self.sta == 0:
      self.top = Car(rem, ind)
      self.sta = 1
      self.rem = rem
    elif self.sta == 1:
      self.und = Car(rem, ind)
      self.sta = 2
      self.rem = rem


class Parking:
  def __init__(self, length):
    self.length = length
    self.max_space = length * 2
    self.space = length * 2
    self.body = [Part(i) for i in range(length)]

  def prog(self, time):
    for part in self.body:
      part.prog(time)

  def out(self):
    outs = []
    for part in self.body:
      if part.sta >= 1 and part.rem <= 0:
        outs.append(part.out())
    ret = []
    for out in outs:
      ret += out
    self.space += len(ret)
    return ret

  def into(self, rem, ind):
    self.space -= 1
    for part in self.body:
      if part.sta == 0:
        part.into(rem, ind)
        return
    
    rem_lst = []
    for part in self.body:
      if part.sta == 1:
        rem_lst.append((part.rem, part.ind))
    rem_lst.sort()
    
    for r, i in rem_lst:
      if r >= rem:
        self.body[i].into(rem, ind)
        return
    
    max_r = r
    for r, i in rem_lst:
      if r == max_r:
        self.body[i].into(rem, ind)
        return

while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  parking = Parking(m)
  que = deque()
  ans = []
  for t in range(n * 120 - 1):
    parking.prog(1)
    ans += parking.out()
    if t <= (n - 1) * 10 and t % 10 == 0:
      r = int(input())
      que.append((r, t // 10 + 1))

    for i in range(min(parking.space, len(que))):
      rem, ind = que.popleft()
      parking.into(rem, ind)
  print(*ans)




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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, k;
  cin >> n >> k;

  int a = 1;
  re(i, n) {
    a = min(a * 2, a + k);
  }
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{   long long int h,w,a,b;   cin>>h>>w;if(h==1 || w==1){cout<<1;return 0;}   if(w%2==0)   {     a=h*(w/2);   }   else   {     if(h%2==0)     {       a=(h*w)/2;     }     else     {       b=((w+1)/2);       a=b+(((h-1)/2)*w);     }   }   cout<<a<<endl;
}

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

int main(){
  int N, Ai;
  int times_i, times=30;
  
  cin >> N;
  
  for (int i=0;i<N;i++){
    cin >> Ai;
    times_i=0;
    
    while ( Ai%2==0 ){
      Ai /= 2;
      times_i++;
    }
    
    if ( times_i < times )
      times = times_i;
  }
  
  cout << times << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("No"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

bool can(string s, int a, int b) {
  srep(i,a,b) {
    if (s[i] == '#' && s[i+1] == '#') return false;
  }
  return true;
}
bool swcan(string s, int a, int b) {
  srep(i,a,b-1) {
    if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') return true;
  }
  return false;
}

int main() {
  int n,a,b,c,d;
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  string s;
  cin>>s;
  s = "#"+s;
  // if (a > b) swap(a,b), swap(c,d);
  if (!can(s,a,c)) dame;
  if (!can(s,b,d)) dame;
  if (c > d) {
    if (!swcan(s,b-1,d+1)) dame;
  }
  puts("Yes");
  return 0;
}






















Measured memory_bytes: 772
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N;
V<int> v;
std::deque<int> q;

int main(){
    INIT;
    cin >> N;
    v.resize(N);
    REP(i,N) cin >> v[i];
    std::sort(ALL(v));
    REP(i,N) q.push_back(v[i]);
    V<PII> ans;
    while(q.size() > 1) {
        int l = q.front(), r = q.back();
        q.pop_front(); q.pop_back();
        if(q.empty()) {
            q.push_back(std::max(l-r,r-l));
            ans.push_back(((l-r>r-l) ? PII(l,r) : PII(r,l)));
            break;
        }
        /*if(r-l == 0) {
            cout << r;
            return 0;
        }*/
        if(l >= 0) {
            q.push_front(l-r);
            ans.push_back(PII(l,r));
        } else 
        if(r <= 0) {
            q.push_back(r-l); 
            ans.push_back(PII(r,l));
        } else {
            int nl = q.front(), nr = q.back();
            if(nl <= 0 && nr <= 0) {
                q.push_back(r-l);
                ans.push_back(PII(r,l));
            } else
            if(nl >= 0 && nr >= 0) {
                q.push_front(l-r);
                ans.push_back(PII(l,r));
            }
            else {
                if(nr-(l-r) > (r-l)-nl) {
                    q.push_front(l-r);
                    ans.push_back(PII(l,r));
                } else {
                    q.push_back(r-l);
                    ans.push_back(PII(r,l));
                }
            }
        }
    }
    cout << q.front() << "\n";
    REP(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  long n,k;
  cin>>n>>k;
  vector<bool>ans(n);
  rep(i,k){
    int d;
    cin>>d;
    vector<int>a(d);
    rep(j,d){
      cin>>a.at(j);
      a.at(j)--;
      ans.at(a.at(j))=true;
    }
  }
  int co=0;
  rep(i,n){
    if(!ans.at(i)){
      co++;
    }
  }
  cout<<co<<endl;
}



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

int main()
{
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << endl;
	return 0;
}

Measured memory_bytes: 3592