akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn get_possible_matches(a: &Vec<char>, b: &Vec<char>, first_only: bool) -> Vec<Vec<char>> {
    let mut ans = vec![];
    for i in 0..a.len() + 1 {
        if (0..b.len())
            .any(|j| i + j < a.len() && a[i + j] != b[j] && a[i + j] != '?' && b[j] != '?')
        {
            continue;
        }
        let mut temp = vec![];
        for j in 0..i {
            temp.push(a[j]);
        }
        for j in i..a.len() {
            if a[j] != '?' {
                temp.push(a[j]);
            } else if j - i < b.len() && b[j - i] != '?' {
                temp.push(b[j - i]);
            } else {
                temp.push('?');
            }
        }
        if b.len() + i > a.len() {
            for j in 0..b.len() + i - a.len() {
                temp.push(b[j + a.len() - i]);
            }
        }
        ans.push(temp);
        if first_only {
            break;
        }
        if ans.len() > 50 {
            break;
        }
    }
    ans
}

fn main() {
    let a = read::<String>().chars().collect::<Vec<_>>();
    let b = read::<String>().chars().collect::<Vec<_>>();
    let c = read::<String>().chars().collect::<Vec<_>>();

    // try a->b  b->a
    let mut ans = a.len() + b.len() + c.len();

    for &(ref a, ref b, ref c) in &[
        (&a, &b, &c),
        (&b, &a, &c),
        (&a, &c, &b),
        (&c, &a, &b),
        (&b, &c, &a),
        (&c, &b, &a),
    ] {
        for matched in get_possible_matches(&a, &b, false) {
            ans = min(get_possible_matches(&matched, &c, true)[0].len(), ans);
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4476
import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<String> list = new ArrayDeque<String>();
		
		int n = Integer.parseInt(r.readLine());
		
		for (int i = 0; i < n; i++) {
			String[] s = r.readLine().split(" ");
			if (s[0].equals("delete")) {
				list.remove(s[1]);
			}else if (s[0].equals("insert")) {
				list.addFirst(s[1]);
			}else if (s[0].equals("deleteFirst")) {
				list.removeFirst();
			}else if (s[0].equals("deleteLast")) {
				list.removeLast();
			}
		}
		
		System.out.print(list.remove());
		while (list.isEmpty() == false) {
			System.out.print(" " + list.remove());
		}
		System.out.println();
		
		
	}
}


Measured memory_bytes: 230060
n = int(input())
S = input()
ans = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i)) + 1:]
        for j in range(10):
            if str(j) in T:
                U = T[T.index(str(j)) + 1:]
                for k in range(10):
                    if str(k) in U:
                        ans += 1
print(ans)

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

int main(){
    ll N; cin >> N;
    ll ans=0;

    rep(i,N-1){
        ans += i+1;
    }

    cout << ans <<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b; cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    ll a,b;
    cin >> a >> b;
    a--;
    vector<ll> c_a(64),c_b(64),c_c(64);
    ll tmpa,tmpb;
    ll tmp = 1;
    rep(i,60){
        tmp = 2;
        tmp = (tmp << i);
        c_a[i] = a / (tmp);
        if(c_a[i] > 0){
            c_a[i] *= (1LL << i);
        }
        c_a[i] += max(0LL ,(a % tmp)  + 1LL - tmp/2);
        
        c_b[i] = b / (tmp);
        if(c_b[i] > 0){
            c_b[i] *= (1LL << i);
        }
        
        c_b[i] += max(0LL ,(b % tmp)  + 1LL - tmp/2);
        c_c[i] = c_b[i]-c_a[i];
    }

    ll ans = 0;

    rep(i,60){
        if(c_c[i] % 2 == 1){
            ans += (1LL << i);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		long long ans = 0;
		int x,y,h,w;

		rep(i,n)
		{
			cin >> x >> y >> h >> w;

			int a = x + y + h;
			
			if(a <= 60 && w <= 2) ans += 600;
			else if(a <= 80 && w <= 5) ans += 800;
			else if(a <= 100 && w <= 10) ans += 1000;
			else if(a <= 120 && w <= 15) ans += 1200;
			else if(a <= 140 && w <= 20) ans += 1400;
			else if(a <= 160 && w <= 25) ans += 1600;	
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,count;
  count=0;
  cin >> n;
  int s[n];
  for (int i=0;i<n;i++){
    cin >>s[i];
  }
  while (true){
    bool end=false;
  for (int i=0;i<n;i++){
   if (s[i]%2!=0){
      end=true;
   }
  }
    if (end) break;
    for (int i=0;i<n;i++){
      s[i]=s[i]/2;
    }
    count=count+1;
  }
  cout << count <<endl;
}


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

vector<int> a;
vector<vector<int>> g;
vector<bool> win;
vector<bool> used;

bool dfs(int v) {
        used[v] = true;
        if (g[v].size() == 0) return win[v] = false;
        bool lose = true;
        for (int u : g[v]) lose &= dfs(u);
        return win[v] = !lose;
}

int main() {
        int n;
        cin >> n;
        a.resize(n);
        g.resize(n);
        win.resize(n);
        used.resize(n, false);
        for (int i = 0; i < n; i ++) cin >> a[i];
        for (int i = 0; i < n - 1; i ++) {
                int u, v;
                cin >> u >> v;
                u --, v --;
                if (a[u] == a[v]) continue;
                if (a[u] > a[v]) g[u].push_back(v);
                else g[v].push_back(u);
        }
        for (int i = 0; i < n; i ++) if (!used[i]) dfs(i);
        for (int i = 0; i < n; i ++) if (win[i]) cout << i + 1 << ' ';
        return 0;
}


Measured memory_bytes: 384
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque

    h, w = map(int, readline().split())
    grid = [["!"] * (w + 2)]
    for _ in range(h):
        s = ["!"] + list(input()) + ["!"]
        grid.append(s)
    grid.append(["!"] * (w + 2))

    ans = 0
    for row in range(1, h + 1):
        for col in range(1, w + 1):
            if grid[row][col] != "!":
                black, white = 0, 0
                que = deque()
                que.append((row, col))
                while que:
                    cr, cc = que.popleft()
                    if grid[cr][cc] == "#":
                        black += 1
                        if grid[cr + 1][cc] == ".":
                            que.append((cr + 1, cc))
                        if grid[cr - 1][cc] == ".":
                            que.append((cr - 1, cc))
                        if grid[cr][cc + 1] == ".":
                            que.append((cr, cc + 1))
                        if grid[cr][cc - 1] == ".":
                            que.append((cr, cc - 1))
                    elif grid[cr][cc] == ".":
                        white += 1
                        if grid[cr + 1][cc] == "#":
                            que.append((cr + 1, cc))
                        if grid[cr - 1][cc] == "#":
                            que.append((cr - 1, cc))
                        if grid[cr][cc + 1] == "#":
                            que.append((cr, cc + 1))
                        if grid[cr][cc - 1] == "#":
                            que.append((cr, cc - 1))
                    grid[cr][cc] = "!"

                ans += white * black
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83328
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

# List of ints
def LI(): return list(map(int, sys.stdin.readline().split()))

# Single int
def I(): return int(sys.stdin.readline())

# List, which contains Lists of chars (not strings)
def LS():return list(map(list, sys.stdin.readline().split()))

# Single List of chars (not strings)
def S(): return list(sys.stdin.readline())[:-1]

# List of "n" integers from "n" lines.
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
# List of "n" Lists of integers
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l


# Runtime Complexity: O(?)
# Space Complexity: O(?)
# Solution
N, blue, red = LI()

blue_red_count = N // (blue + red)
blue_balls = blue_red_count * blue

remaining = N - blue_red_count * (blue + red)
blue_balls += min(remaining, blue)
print(blue_balls)

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

using namespace std;

map<long long, char> ma;
int main() {
    int n, m;
    string s1, s2;
    cin >> n >> m >> s1 >> s2;
    long long ans = 1LL * n * m / __gcd(n, m);
    for(int i = 0; i < n; i++){
        ma[ans / n * i] = s1[i];
    }
    for(int i = 0; i < m; i++){
        if (ma.find(ans / m * i) != ma.end() && ma[ans / m * i] != s2[i]){
            cout << "-1";
            return 0;
        }
    }
    cout << ans;
}


Measured memory_bytes: 6144
#include<stdio.h>   
#include<string.h>   
int main()  
{  
    int n;
    int s=0,x;
    scanf("%d",&n);
    x=n;
    while(n)
    {
    	s+=n%10;
    	n/=10;
	}
	if(x%s==0)
	printf("Yes\n");
	else
	printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        //input
        String[] input = br.readLine().split(" ");
        int N = Integer.parseInt(input[0]);
        int M = Integer.parseInt(input[1]);

        //for algorithm & input
        boolean[] answer = new boolean[N+1];
        int[] wrong = new int[N+1];
      
        Arrays.fill(answer, false);
        Arrays.fill(wrong, 0);
        int pena = 0;
        int result = 0;

        for(int i = 0; i < M; i++){
          String[] in = br.readLine().split(" ");
          int num = Integer.parseInt(in[0]);
         
          if(answer[num] == false){
            if(in[1].equals("AC")){
              answer[num] = true;
              result++;
              pena += wrong[num];
            }else{
              wrong[num] += 1;
            }
          }else{
            continue;
          }
        }

        System.out.println(result + " " + pena);

      }
    }
}


Measured memory_bytes: 45504
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#define int long long
using namespace std;

map<int, int>b;
signed main() {
	int a; cin >> a;
	for (int c = 0; c < a; c++) {
		int d; cin >> d;
		b[d]++;
	}
	vector<int>V;
	for (auto i : b) {
		if (i.second >= 2) {
			V.push_back(i.first);
		}
		if (i.second >= 4) {
			V.push_back(i.first);
		}
	}
	reverse(V.begin(), V.end());
	if (V.size() < 2)puts("0");
	else cout << V[0] * V[1] << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using boost::string_ref;

using namespace std;

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

    size_t k;
    string s;
    cin >> s >> k;
    
    set<string_ref> substrs;
    
    for(size_t i = 0; i < s.size(); ++i)
    {
        for(size_t l = 1; l <= s.size() - i; ++l)
        {
            const auto ss = string_ref(&s[i], l);
            //cout << '(' << i << ',' << l << ')' << ' ' << ss << '\n';
            if(substrs.size() < k)
            {
                substrs.insert(ss);                
            }
            else if(ss < *--end(substrs))
            {
                substrs.insert(ss);
                if(substrs.size() > k)
                {
                    substrs.erase(--end(substrs));
                }
            }
            else
            {
                break;
            }
            //copy(begin(substrs), end(substrs), ostream_iterator<string>(std::cout, " ")); cout << endl;
        }
    }
    
    cout << *next(begin(substrs), k-1) << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string N; int dp[1000005];
int main() {
  cin >> N; N.insert(0, "0");
  int lng = N.size()-1, d = 0;
  for(int i = 1; i <= lng; ++i) {
    int n = N.at(lng-i+1)-'0'+d, nn = N.at(lng-i)-'0';
    if(n > 5 || n == 5 && nn > 4) dp[i] += dp[i-1]+10-n, d = 1;
    else dp[i] += dp[i-1]+n, d = 0;
  }
  cout << dp[lng]+d << endl;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int D;
int C[26];
int S[400][26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D;
	FOR(i,26) cin>>C[i];
	FOR(i,D) {
		FOR(j,26) cin>>S[i][j];
		cout<<(rand()%26+1)<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3696
N, Q = map(int, input().split())
S = input()
cumsum = [0]*(N+1)
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        cumsum[i+1] = cumsum[i] + 1
    else:
        cumsum[i+1] = cumsum[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(cumsum[r]-cumsum[l])


Measured memory_bytes: 6140
s = input()
a = "Yes"

odd = ["R","U","D"]
even =  ["L","U","D"]


for i in range(len(s)):
    if i%2==0 and s[i] in odd:
        a=a
    elif i%2==1 and s[i] in even:
        a=a
    else:
        a="No"
        break

print(a)

Measured memory_bytes: 3060
#include<stdio.h>
 
int main()
{
	int a, b, c, d, n, i, j, p, q, r, s;
	scanf("%d %d %d %d", &a, &b, &c, &d);

    if (a > d || c > b) {
        printf("0\n");
        return 0;
    }
    
	p = b - a;
	q = b - c;
	r = d - a;
	s = d - c;
    
	if(p > q){
		if(r > s){
			if(q > s){
				printf("%d\n",s);
			}else{
				printf("%d\n",q);
			}
		}else{
			if(q > r){
				printf("%d\n",r);
			}else{
				printf("%d\n",q);
			}
		}
	}else{
		if(r > s){
			if(p > s){
				printf("%d\n",s);
			}else{
				printf("%d\n",p);
			}
		}else{
			if(p > r){
				printf("%d\n",r);
			}else{
				printf("%d\n",p);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>
#include <sstream>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

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

	int N;
	while (cin >> N) {
		vector<int>ans;
		while (N != 0) {
			if (N - 512 >= 0) {
				N -= 512;
				ans.push_back(512);
			} else if (N - 256 >= 0) {
				N -= 256;
				ans.push_back(256);
			} else if (N - 128 >= 0) {
				N -= 128;
				ans.push_back(128);
			} else if (N - 64 >= 0) {
				N -= 64;
				ans.push_back(64);
			} else if (N - 32 >= 0) {
				N -= 32;
				ans.push_back(32);
			} else if (N - 16 >= 0) {
				N -= 16;
				ans.push_back(16);
			} else if (N - 8 >= 0) {
				N -= 8;
				ans.push_back(8);
			} else if (N - 4 >= 0) {
				N -= 4;
				ans.push_back(4);
			} else if (N - 2 >= 0) {
				N -= 2;
				ans.push_back(2);
			} else {
				N--;
				ans.push_back(1);
			}
		}

		SORT(ans);
		cout << ans[0];
		REP2(i, 1, ans.size()) {
			cout << ' ' << ans[i];
		}
		cout << "\n";
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  while(n-->0) {
    int map[5][5];
    
    for(int i=0; i<5; i++) {
      for(int j=0; j<5; j++) {
        cin >> map[j][i];
      }
    }
    int ans = 0;
    for(int x=0; x<5; x++) {
      for(int y=0; y<5; y++) {
        for(int dx=1; dx<=5-x; dx++) {
          for(int dy=1; dy<=5-y; dy++) {
            int f = 0;
            int px, py;
            for(px=0; px<dx; px++) {
              for(py=0; py<dy; py++){
                if (map[x+px][y+py]==0) {
                  f = 1;
                  break;
                }
              }
              if (f == 1) break;
            }
            if (px == dx && py == dy) {
              // printf("x,y,dx,dy = %d,%d,%d,%d\n", x,y,dx,dy);
              ans = max(ans, dx*dy);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
n = int(input())

# a進法でのnの桁和
def func(n,a):
    res = 0
    while n > 0:
        res += n%a
        n //= a
    return res

mini = n

for i in range(n+1):
    tmp = func(i,6) + func(n-i,9)
    mini = min(mini,tmp)
print(mini)

Measured memory_bytes: 73576
#include<bits/stdc++.h>
using namespace std;
char arr[4005];
int main()
{
    int n,R=0,G=0,B=0;
    long long ans=0,ans2=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        switch(arr[i])
        {
        case 'R':
            R++;
            ans2+=G*B;
            break;
        case 'G':
            G++;
            ans2+=R*B;
            break;
        case 'B':
            B++;
            ans2+=R*G;
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i-1;j>=0&&(2*i-j)<n;j--)
        {
            if(arr[i]!=arr[j]&&arr[i]!=arr[2*i-j]&&arr[j]!=arr[2*i-j])ans++;
        }
    }
    cout<<ans2-ans<<endl;
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

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

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	vs s{ "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

	string t; cin >> t;
	rep(i, 7) {
		if (s[i] == t) {
			cout << 7 - i << endl;
			return 0;
		}
	}
} 

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <iterator>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n)
    cin >> v[i];
    if (n == 1)
    {
        cout << "1\n1\n0\n"
             << v[0] << endl;
        return 0;
    }
    for (int i = 0; (1 << (i + 1)) - 1 < n; i++)
        g.push_back((1 << (i + 1)) - 1);
    reverse(g.begin(), g.end());
    cout << g.size() << endl;
    REP(i, g.size() - 1)
    cout << g[i] << ' ';
    cout << g.back() << endl;
    int cnt = 0;
    for (auto k : g)
    {
        rep(i, k, n)
        {
            int d = v[i];
            int j = i - k;
            while (j >= 0 && d < v[j])
            {
                cnt++;
                v[j + k] = v[j];
                j -= k;
            }
            v[j + k] = d;
        }
    }
    cout << cnt << endl;
    for (auto i : v)
    {
        cout << i << endl;
    }
}


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

	


int main(){
  int n; cin >>n;
  vector<int> v(n); 
  for(int i=0;i<n;i++){cin>>v[i];}
  int a=0; for(int i=0;i<n;i++){a+=v[i];}//aは総和
  int ans=100000;
  int b=0;
  int c=100000;
  for(int i=0;i<n-1;i++){
    b+=v[i];
    c=b-(a-b);
    if(c<0){c*=-1;}
    //cout<<a<<" "<<b<<" "<<c<<" ";
    ans=min(ans,c);
    //cout<<ans<<endl;
  }
  cout << ans << endl;
}

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

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

const ll mod = 1e9+7;

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

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

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

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


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

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



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

    int n; cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a; cin >> a;
        mp[a]++;
        if(mp[a] == 2) { cout << "NO" << endl; return 0; }
    }
    cout << "YES" << endl;
    
    return 0;
}

Measured memory_bytes: 9600
N = int(input())
S = [input() for _ in range(N)]

ans = 0
_A = 0
B_ = 0
B_A = 0

for s in S:
    for i in range(len(S)-1):
        if s[i:i+2] == "AB":
            ans += 1
    if s[0] == "B" and s[-1] == "A":
        B_A += 1
    elif s[0] == "B":
        B_ += 1
    elif s[-1] == "A":
        _A += 1

if B_A>=2:
    ans+=B_A-1
    B_A=1

if B_A==1 and B_>0:
    ans += 1
    B_A -= 1

if B_A==1 and _A>0:
    ans += 1
    B_A -= 1

if _A>0 and B_>0:
    ans += min(_A,B_)

print(ans)


Measured memory_bytes: 47884
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <stack>
using namespace std;

int N,M;
const int maxn = 100000+5;
const int WHITE = 0;
vector<int> G[maxn];
vector<int> nodeColor;

void DFS(int u,int color){
    stack<int> nodeStack;
    nodeStack.push(u);
    while(!nodeStack.empty()){
        int u = nodeStack.top();
        nodeStack.pop();
        nodeColor[u] = color;
        for(int i = 0;i<G[u].size();i++){
            int v = G[u][i];
            if(nodeColor[v]==0) nodeStack.push(v);
        }
    }
}

int main(){
    //freopen("data2.txt","r",stdin);
    cin >> N >> M;
    nodeColor.resize(N,0);
    int u,v;
    for(int i = 0;i<M;i++){
        scanf("%d %d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int color = 1;
    for(int i = 0;i<N;i++) if(nodeColor[i]==0) DFS(i,color++);
    int q;
    scanf("%d",&q);
    for(int i = 0;i<q;i++){
        scanf("%d %d",&u,&v);
        if(nodeColor[u]==nodeColor[v]) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}





Measured memory_bytes: 8728
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cmath>
#include <tuple>
using namespace std;
#define fio ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N,M,K;
pii inp[100005];

ll p[100005],siz[100005];

int find(int a){
	if(a==p[a]) return a;
	return p[a]=find(p[a]);
}
ll total;

bool merge(int a, int b){
	a=find(a),b=find(b);
	if(a==b) return 0;
	p[a]=b;
	total+=siz[a]*(siz[a]-1)/2;
	total+=siz[b]*(siz[b]-1)/2;
	siz[b]+=siz[a];
	total-=siz[b]*(siz[b]-1)/2;
	return 1;
}

ll ans[100005];
int main(){
	scanf("%d %d",&N,&M);
	for(int i=1;i<=N;i++){
		p[i]=i;
		siz[i]=1;
	}
	for(int i=0;i<M;i++){
		int a,b; scanf("%d %d",&a,&b);
		inp[i]={a,b};
	}
	total=(ll)N*(N-1)/2;
	for(int i=M-1;i>=0;i--){
		ans[i]=total;
		merge(inp[i].first,inp[i].second);
	}
	for(int i=0;i<M;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
const int MOD = 1e9 + 7;
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vector<ll> x(n+1), y(m+1);
	for (int i = 1; i <= n;i++) cin >> x[i];
	for (int i = 1; i <= m; i++) cin >> y[i];
	ll X = 0, Y = 0;
	for (int k = 1; k <= n;k++) {
		X += ((k - 1)*x[k] - (n - k)*x[k]) % MOD;
		X %= MOD;
	}
	for (int k = 1;k <= m;k++) {
		Y += ((k - 1)*y[k] - (m - k)*y[k]) % MOD;
		Y %= MOD;
	}
	ll ans = (X*Y) % MOD;
	cout << ans << endl;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int n, m;
vector <int> graph[ N ];
int cost[ N ];
int path[ N ];

void bfs() {
  queue <int> q;
  memset(cost, -1, sizeof(cost));
  cost[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int f = q.front(); q.pop();
    for (auto x: graph[f]) {
      if (cost[x] == -1 || cost[x] > cost[f] + 1) {
        cost[x] = cost[f] + 1; path[x] = f; q.push(x);
      }
    }
  }
}

void solve() {
  cin >> n >> m;

  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bfs();

  bool f = true;
  for (int i = 2; i <= n; i++) f &= (cost[i] != -1);

  if (!f) {
    cout << "No" << endl;
    return;
  }

  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) cout << path[i] << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int t = 1;
  for (int tc = 1; tc <= t; tc++) solve();
  return 0;
}



Measured memory_bytes: 10916
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
ll ans(ll n)
{
    if(n==0)
    return 1;
    return 2* + ans(n/2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    cout<< ans(n) - 1;

	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  ll L;
  cin >> L;
  vector<ll> a(N);
  for(int i = 0;i < N;i++)cin >> a[i];

  bool flag = false;

  int b = 0;
  for(int i = 0;i < N-1;i++){
    if(a[i] + a[i+1] >= L){
      flag = true;
      b = i + 1;
      break;
    }
  }

  if(!flag)cout << "Impossible" << endl;
  else{
    cout << "Possible" << endl;
    for(int i = 1;i < N;i++){
      if(i != b)cout << i << endl;
      else break;
    }

    for(int i = N-1;i >= 1;i--){
      if(i != b)cout << i << endl;
      else break;
    }

    cout << b << endl;
  }

}


Measured memory_bytes: 1664
#!/usr/bin/env python
N = int(input())

ans = 0
c = 0
for i in range(1, N+1, 2):
    for j in range(1, i+1):
        if i%j == 0:
            c += 1
    if c == 8:
        ans += 1
    c = 0

print(ans)
    

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const int MAX = 200002;

int N = 0;
ll n = 0;
char ti[10] = {'M','A','R','C','H'};

ll a[10] = {0};
ll b[10] = {0},bi = 0;
int main()
{
    cin>>N;
    for(int i = 1;i<=N;i++){
        char temp[100];
        cin>>temp;
        for(int j = 0;j<5;j++){
            if(temp[0]==ti[j]){
                a[j]++;
            }
        }
    }


    for(int i = 0;i<5;i++){
        if(a[i]!=0){
            b[bi] = a[i];
            bi++;
        }
    }

    if(bi<3){
        cout<<0<<endl;
        return 0;
    }

    for(int i = 0;i <= bi -3;i++ ){
        for(int j = i+1;j <= bi-2;j++){
            for(int k = j+1;k <= bi-1;k++){
                n += b[i]*b[j]*b[k];
            }
        }
    }
    cout<<n<<endl;


    return 0;
}


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

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a==b && b==c){
    cout << 1 << endl;
  }
  else if(a==b || a==c || b==c){
    cout << 2 << endl;
  }
 
  else{
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

ll digit(ll u){
    ll ct=0;
    while(u>0){
        u/=10;
        ct++;
    }
    return ct;
}

int main() {
    ll N;cin >> N;
    ll ans=digit(N);
    for(ll i=1;i*i<=N;i++){
        if(N%i==0) ans=min(ans,max(digit(i),digit(N/i)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
info = []
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    info.append([a, b])
info.sort()
tmp = []
for i, j in enumerate(info):
    if i == 0:
        tmp.append(j[1])
    elif j[0] > tmp[-1]-1:
        tmp.append(j[1])
    else:
        if j[1] < tmp[-1]:
            tmp[-1] = j[1]
print(len(tmp))

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 20005;
const ll mod=1e9+7;
ll qp(ll t1,ll t2) { ll s=1;for (;t2;t1=t1*t1%mod,t2>>=1) if (t2&1) s=s*t1%mod; return s;}
ll num[30];
ll ans[30];
int main()
{
    int n;
    string str;
    cin>>n;
    cin>>str;

    for (int q=0;q<str.length();q++)
    {
        int x=str[q]-'a';
        num[x]++;
    }

    int t=0;
    ans[0]=1;
    for (int q=0;q<26;q++)
    {
        if (num[q]>0)
        {
            t++;
            for (int w=t;w>=1;w--)
            {
                ans[w]=(ans[w]+ans[w-1]*num[q]%mod)%mod;
            }
        }
    }

    ll sum=0;
    for (int q=1;q<=26;q++)
    sum=(sum+ans[q])%mod;

    cout<<sum<<endl;
 

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void p(){ cout << "pairwise coprime" << endl;}
void s(){ cout << "setwise coprime" << endl;}
void no(){ cout << "not coprime" << endl;}

//-----------------------------------------
vector<ll> prime_table(ll n){
  vector<bool> flag(n + 1, true);
  vector<ll> res(n + 1);
  for(ll i = 0; i < n + 1; i++) res[i] = i;

  flag[0] = flag[1] = false;
  res[0] = 0; res[1] = 1;

  for(ll i = 2; i * i <= n; i++){
    if(flag[i]){
      for(ll j = i + i; j <= n; j += i){
        flag[j] = false;
        res[j] = i;
      }
    }
  }
  return res;
}
//-----------------------------------------

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  vll a(n);
  REP(i,n) cin >> a[i];
  ll tmp = gcd(a[0], a[1]);
  for(ll i = 2; i < n; i++){
    tmp = gcd(tmp, a[i]);
  }
  if(tmp != 1){
    no();
    return 0;
  }

  vll pt = prime_table(1000000);
  vector<bool> cnt(1000000 + 1, false);

  for(ll i = 0; i < n; i++){
    ll x = a[i];
    while(x > 1){
      ll k = pt[x];
      if(cnt[k]){
        s(); return 0;
      }
      cnt[k] = true;
      while(x % k == 0) x /= k;
    }
  }
  p();
    
  return 0;
}



Measured memory_bytes: 19096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long lsum[][] = new long[n][n]; // local sum:部分和
		for ( int c = 0; c < n; c++ ) {
			lsum[c][c] = in.nextInt();
			for ( int r = 0; r < c; r++ ) {
				lsum[r][c] = lsum[r][c - 1] + lsum[c][c];
			}
		}

		long cost[][] = new long[n][n]; // 累積コスト
		for ( int p = 1; p < n; p++ ) {
			for ( int r = 0, c = p; c < n; r++, c++ ) {
				Long min = Long.MAX_VALUE;
				for ( int i = r; i <= c - 1; i++ ) {
					if(min > cost[r][i] + cost[i + 1][c]) {
						min = cost[r][i] + cost[i + 1][c];
					}
				}
				cost[r][c] = min + lsum[r][c];
			}
		}

		System.out.println(cost[0][n - 1]);
		in.close();
	}
}


Measured memory_bytes: 92372
while(1):
    [X,Y]=[int(x) for x in raw_input().split()]
    if X==0:
        break
    else:
        F=[]
        for i in range(Y):
            F.append([0]+[int(x) for x in raw_input().split()]+[0])
        F.append([3 for x in range(X+2)])
        F.append([4 for x in range(X+2)])        
        S=[[0 for x in range(X+2)] for y in range(Y+2)] #F,S[y][x]
        #initilizing
        for i in range(1,X+1):
            S[0][i]=1-F[0][i]
        for j in range(Y+2):
            for i in range(1,X+1):
                if F[j][i]==2:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]
                    S[j+2][i]=S[j+2][i]+S[j][i]
                elif F[j][i]==1:
                    S[j][i]=0
                elif F[j][i]==3:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]
                elif F[j][i]==4:
                    S[j][i]=S[j][i]+S[j-1][i]                    
                else:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]+(1-F[j-1][i-1]/2)*S[j-1][i-1]+(1-F[j-1][i+1]/2)*S[j-1][i+1]
        print sum(S[Y+1])
        

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;

const bool DEBUG = false;
const long long MAX_VAL = (long long)(pow(10, 10));

void warshall_floyd(Graph& graph) {
  const int N = graph.size();
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (graph[i][j] > (graph[i][k] + graph[k][j]))
          graph[i][j] = graph[i][k] + graph[k][j];
      }
    }
  }
}

int main(int argc, char const* argv[]) {
  int N, M;
  long long L;
  cin >> N >> M >> L;

  int A, B;
  long long C;
  Graph graph(N, vector<long long>(N, MAX_VAL));
  // if (DEBUG) cout << "start: " << N << ", " << M << ", " << L << endl;
  for (int i = 0; i < M; i++) {
    cin >> A >> B >> C;
    // if (DEBUG) cout << A << ", " << B << ", " << C << endl;
    graph[A - 1][B - 1] = min(graph[A - 1][B - 1], C);
    graph[B - 1][A - 1] = min(graph[B - 1][A - 1], C);
  }
  warshall_floyd(graph);
  Graph movable(N, vector<long long>(N, MAX_VAL));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (graph[i][j] <= L) movable[i][j] = 1;
    }
  }
  warshall_floyd(movable);

  int Q;
  cin >> Q;
  int s, t;
  vector<int> S(Q);
  vector<int> T(Q);
  long long num_charge;
  // if (DEBUG) cout << "query: " << Q << endl;
  for (int i = 0; i < Q; i++) {
    cin >> s >> t;
    S[i] = s;
    T[i] = t;
  }

  for (int i = 0; i < Q; i++) {
    s = S[i];
    t = T[i];
    num_charge = movable[s - 1][t - 1];
    if (num_charge == MAX_VAL) {
      cout << "-1" << endl;
    } else {
      cout << num_charge - 1 << endl;
    }
  }

  // if (DEBUG) cout << "finish " << endl;

  // if (DEBUG) {
  //   for (int i = 0; i < N; i++) {
  //     for (int j = 0; j < N; j++) {
  //       cout << movable[i][j] << ", ";
  //     }
  //     cout << endl;
  //   }
  // }

  return 0;
}


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

using namespace std;

int main()
{
    int a[]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    //sort(a,a+32);
    int k;
    scanf("%d",&k);
    printf("%d\n",a[k]);
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int N,D,A; cin>>N; cin>>D;cin>>A;
  vector<pair<int,int> > vp;
  for (int i = 0; i < N; i++)
  {
    int X,H;cin>>X>>H;
    vp.emplace_back(X,H);
  }
  sort(ALL(vp));
  vector<int> X (N,0);
  vector<int> H (N,0);
  for (int i = 0; i < N; i++)
  {
    X[i] = vp[i].first;
    H[i] = vp[i].second;
  }
  int res = 0;
  int p = 0;
  vector<int> H2(N+1,0);
  int aD = 0;
  while(p < N)
  {
    aD += H2[p];
    // DEBUG(aD,H2[p],H[p]);
    if(H[p] - aD <= 0)
    {
      p++;
      continue;
      DEBUG("call");
    }
    int damage = A*((H[p] -aD)/A + ((H[p]-aD)%A > 0));
    // int damage = A*(ceil(double(H[p]-aD)/double(A)));
    res +=((H[p] -aD)/A + ((H[p]-aD)%A > 0));
    int q = distance(X.begin(),upper_bound(ALL(X),2*D+X[p]));
    
    aD += damage;
    H2[q] -=damage;
    p++;
    // DEBUG(res,aD,"\n");
    // DEBUG(H2);
  }
  cout<<res<<endl;


  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;
	double d, t, s;
	cin >> d >> t >> s;
	double ans = d / s;
	if (ans <= t)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s.length()==1)
  {
    cout<<"YES"<<endl;
    return 0;
  }
  vector<int>a(3);
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='a')a[0]++;
    if(s[i]=='b')a[1]++;
    if(s[i]=='c')a[2]++;
  }
  sort(a.begin(),a.end());
  a[1]-=a[0];
  a[2]-=a[0];
  a[0]=0;
 
  if((a[1]==1 || a[1]==0) && (a[2]==0 ||a[2]==1))
  {
    cout<<"YES"<<endl;
    return 0;
  }
  else cout<<"NO"<<endl;
  
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
using namespace std;
typedef long long ll;
 
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
 
int fact[maxn], ifact[maxn];
 
void addmod(int & a, int b){
	a += b;
	if (a >= mod) a -= mod;
	if (a < 0) a += mod;
}
 
int power(int a, int b){
	if (b == 0) return 1;
	int res = power(a, b/2);
	if (b&1) return 1ll * res * res % mod * a % mod;
	return 1ll * res * res % mod;
}
 
int nCk(int n, int k){
	if (k > n) return 0;
	return 1ll * fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}
 
void precalc(void){
	fact[0] = 1;
	for (int i=1; i<=maxn-5; ++i)
		fact[i] = 1ll * fact[i-1] * i % mod;
	ifact[maxn-5] = power(fact[maxn-5], mod-2);
	for (int i=maxn-6; i>=0; --i)
		ifact[i] = 1ll * ifact[i+1] * (i+1) % mod;
}
 
signed main(void){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	precalc();
	int x, y;
	cin >> x >> y;
	if ( (x + y) % 3){
		cout << 0;
		return 0;
	}
	int m = x - (x + y) / 3;
	int n = x - 2 * m;
	if (n < 0 || m < 0){
      cout << 0;
      return 0;
    }
	cout << nCk (n+m, n) << '\n';	
}

Measured memory_bytes: 8064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int a,b,x;
    cin>>a>>b>>x;
    if(a+b<x)
    {
        cout<<"NO";
    }else
    if(a>x)
    {
        cout<<"NO";
    }else
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll idx, ans;
string s, t;
vvll pos;

int main() {
    fast_io; cout_precision;
    cin >> s >> t;
    pos.assign(26, vll());
    for (ll i = 0; i < (ll) s.length(); i++) {
        pos[s[i] - 'a'].push_back(i);
    }
    for (ll i = 0; i < 26; i++) {
        sort(pos[i].begin(), pos[i].end());
    }
    idx = -1, ans = 0;
    for (ll i = 0, c; i < (ll) t.length(); i++) {
        c = t[i] - 'a';
        if (pos[c].empty()) {
            cout << -1 << endl;
            return 0;
        }
        auto it = upper_bound(pos[c].begin(), pos[c].end(), idx);
        if (it == pos[c].end()) {
            ans += s.length();
            it = pos[c].begin();
        }
        idx = *it;
    }
    cout << ans + idx + 1 << endl;
}

Measured memory_bytes: 1736
<?php
$n = fgets(STDIN);
$a = explode(' ', fgets(STDIN));
$min = 30;
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $a[$i] % 2 == 0; $j++) {
        $a[$i] /= 2;
    }
    $min = min($j, $min);
}
echo $min;
?>

Measured memory_bytes: 4604