akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <random>
using namespace std;
int n,m;
int main(){
	random_device rd;
	mt19937 mt(rd());
	cin>>n>>m;
	vector<string>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int qq=0;qq<100000;qq++){
		vector<vector<bool> >b(m,vector<bool>(m,1));
		for(int j1=0;j1<m;j1++)
			for(int j2=j1;j2<m;j2++)
				for(int i=0;i<n;i++)
					if(a[i][j1]!=a[n-1-i][j2])b[j1][j2]=0;
		vector<bool>dp(1<<m);
		dp[0]=1;
		for(int s=0;s<1<<m;s++){
			if(dp[s]){
				for(int j1=0;j1<m;j1++)
					for(int j2=j1+1;j2<m;j2++){
						if(!(s>>j1&1)&&!(s>>j2&1)&&b[j1][j2]){
							dp[s|1<<j1|1<<j2]=1;
						}
					}
			}
		}
		bool flg=0;
		if(m%2==0)flg=dp.back();
		else{
			for(int j=0;j<m;j++)if(dp[(1<<m)-1-(1<<j)]&&b[j][j])flg=1;
		}
		if(flg){
			cout<<"YES\n";
			return 0;
		}
		shuffle(a.begin(),a.end(),mt);
	}
	cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

  string s;   cin >> s;
  for(int i = 0 ; i < s.length() ; i += 2) cout << s[i];
  cout << endl;

  return 0;
}


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

int N, K;
int l[50];

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> l[i];
    sort(l, l+N, greater<int>());

    int sum = 0;
    for(int i = 0; i < K; i++) sum += l[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

s, w = input_a
if w >= s
  puts "unsafe"
else
  puts "safe"
end


Measured memory_bytes: 14308
N,x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
count = 0
if a[1] > x:
    difference = x-a[1]
    count += difference
    a[1] -= difference
     
for i in range(N-1):
    difference = x - (a[i] + a[i+1])
    if difference < 0:
        count += abs(difference)
        a[i+1] += difference
        if a[i+1] < 0:
            a[i] += a[i]
            a[i+1] = 0 


print(count)

Measured memory_bytes: 14068
function main(input) {
  input = input.trim().split("\n");
  const [n, k] = input[0].split(" ").map(a => Number(a));
  const abs = input.slice(1).map(a => a.split(" ").map(b => Number(b)));
  const map = {};
  for (let i = 0; i < n; i++) {
    const [a, b] = abs[i];
    if (!map[a]) {
      map[a] = b;
    } else {
      map[a] += b;
    }
  }
  const keys = Object.keys(map).sort((a, b) => Number(a) - Number(b));
  let result = keys[keys.length - 1];
  let num = k;
  for (let i = 0; i < keys.length; i++) {
    const key = keys[i];
    const cnt = map[key];
    if (num <= cnt) {
      result = key;
      break;
    }
    num -= cnt;
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 56252
#include <iostream>
#include <algorithm>

using namespace std;

const int NMAX = 100000 + 5;
const int MMAX = 3 * NMAX;

inline int lsb(int node) {
    return node & (-node);
}

int N, M;
int aib[NMAX];

void update(int where, int val) {
    for (; where <= N; where += lsb(where))
        aib[where] += val;
}

int query(int where) {
    int ans = 0;
    for (; where; where -= lsb(where))
        ans += aib[where];
    return ans;
}

struct Query {
    int time;
    int type;
    int pos;
    int where;

    friend bool operator<(const Query &a, const Query &b) {
        if (a.time != b.time)
            return a.time < b.time;
        else
            return a.type < b.type;
    }
};

vector <Query> queries;

void addQr(int l, int r, int pos) {
    if (r > N)
        r = N;
    if (l > r)
        return ;

    Query qr;
    qr.time = r;

    //First
    qr.type = 1;
    qr.pos = pos;
    qr.where = l - 1;
    queries.push_back(qr);

    //Second
    qr.type = 2;
    qr.pos = pos;
    qr.where = r;
    queries.push_back(qr);
}

int ans[NMAX];

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

    cin >> M >> N;

    for (int i = 1; i <= M; ++ i) {
        int l, r;
        cin >> l >> r;

        Query qr;
        qr.type = 0;
        qr.time = r;
        qr.where = l;
        queries.push_back(qr);
    }

    for (int i = 1; i <= N; ++ i) {
        addQr(1, i - 1, i);
        for (int mult = i; mult <= N; mult += i)
            addQr(mult + 1, mult + i - 1, i);
    }

    sort(queries.begin(), queries.end());

    for (auto it: queries)
        if (it.type == 0)
            update(it.where, 1);
        else {
            int mult = it.type;
            if (mult == 2)
                mult = -1;

            ans[it.pos] += mult * query(it.where);
        }

    for (int i = 1; i <= N; ++ i)
        cout << M + ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 65888
import java.util.Scanner;

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

	int[] sunuke = new int[N];
	for(int i=0;i<K;i++){
	    int d = sc.nextInt();
	    for(int j=0;j<d;j++){
		sunuke[sc.nextInt()-1]++;
	    }
	}
	int count=0;
	for(int i=0;i<N;i++){
	    if(sunuke[i] == 0) count++;
	}
	System.out.print(count);
    }
}


Measured memory_bytes: 46384
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
} //good night.

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	char a;
	cin >>a;
	if ((a>='a')&&(a<='z'))
		cout <<'a' <<endl;
	else
		cout <<'A' <<endl;
	return 0;
}



Measured memory_bytes: 3636
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

H, N = LI()
A = LI()
if sum(A) >= H:
    print("Yes")
else:
    print("No")


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];


void solve()
{

	cin >> n;
	n--;

	string ans = "";
	bool f =  1;
	while (n >= 0)
	{
		if (!n) f = 0;
		int x = n % 26;
		ans = (char)('a' + x ) + ans;
		n /= 26;
		n--;
	}

	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

const int maxn = 5000;
ll dp[maxn][maxn+1];
ll inf = 1e18;

ll solve(vi &c, int k){
    int n = c.size();
    int mxj = min(n, k);
    int i,j;
    ll sm = 0;
    for(j=1;j<=mxj;j++){
        for(i=0;i<n;i++){
            if(j == 1){
                dp[i][j] = c[i];
                sm += c[i];
            }else{
                ll tmp = dp[(i+1)%n][j-1] + c[i];
                dp[i][j] = max(dp[i][j-1], tmp);
            }
        }
    }
    ll ans = -inf;
    for(i=0;i<n;i++){
        ans = max(ans , dp[i][mxj]);
        if(k > n && sm > 0){
            ll q = k/n;
            ll tmp = q*sm - c[i] + dp[i][k - q*n + 1];
            ans = max(ans , tmp);
            if(q > 1){
                tmp = (q-1)*sm - c[i] + dp[i][mxj];
                ans = max(ans, tmp);
            }
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, i, j;
    cin >> n >> k;
    vi p(n), c(n);
    cin >> p;
    cin >> c;
    vb used(n);
    vi newC;
    ll ans = -inf;
    for(i=0;i<n;i++){
        if(used[i]) continue;
        newC.clear();
        j = i;
        while(!used[j]){
            newC.push_back(c[j]);
            used[j] = true;
            j = p[j] - 1;
        }
        ll cr = solve(newC, k);
        ans = max(ans , cr);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 199048
using System;

namespace C___Switches
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = read[0];
            var M = read[1];
            var bulbs = new int[M];
            for(int i = 0 ; i < M ; i++)
            {
                read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
                for(int j = 1 ; j < read.Length ; j++)
                {
                    bulbs[i] += 1<<read[j]-1;
                }
            }
            var Pi = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var allOnCount = 0;

            for(int switches = 0 ; switches < 1<<N ; switches++)
            {
                bool allOn = true;
                for(int i = 0 ; i < M ; i++)
                {
                    var checker = switches & bulbs[i];
                    var lightup = 0;
                    while(checker != 0)
                    {
                        lightup += checker % 2;
                        checker /= 2;
                    }
                    if(lightup % 2 != Pi[i])
                    {
                        allOn = false;
                        break;
                    } 
                }
                if(allOn) allOnCount++;
            }

            Console.WriteLine(allOnCount);
        }
    }
}


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

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/* ***************************************
Author        :Scau.ion
Created Time  :2016/09/21 11:26:33 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=100010;
const int maxm=1000010;

map<int,VI> node[maxn];
VI edge[maxm];
VI newg[maxn*3];
int dis[maxn*3];
int last[maxn];

void dfs(int u,int color,int tot)
{
    last[u]=color;
    newg[u].PB(tot);
    newg[tot].PB(u);
    map<int,VI>::iterator it=node[u].find(color);
    for (int j=0;j<it->Y.size();++j)
    {
        int v=it->Y[j];
        if (last[v]<color) dfs(v,color,tot);
    }
    return;
}

int main()
{
	IOS;
    int n,m;
    cin>>n>>m;
    for (int j=1;j<=m;++j)
    {
        int p,q,c;
        cin>>p>>q>>c;
        node[p][c].PB(q);
        node[q][c].PB(p);
        edge[c].PB(p);
        edge[c].PB(q);
    }
    int tot=n;
    for (int color=1;color<maxm;++color)
    {
        for (int j=0;j<edge[color].size();++j)
        {
            int v=edge[color][j];
            if (last[v]==color) continue;
            ++tot;
            dfs(v,color,tot);
        }
    }
    queue<int> que;
    while (!que.empty()) que.pop();
    memset(dis,-1,sizeof dis);
    dis[1]=0;
    que.push(1);
    while (!que.empty())
    {
        int u=que.front();
        que.pop();
        for (int j=0;j<newg[u].size();++j)
        {
            int v=newg[u][j];
            if (dis[v]==-1)
            {
                dis[v]=dis[u]+1;
                que.push(v);
            }
        }
    }
    if (dis[n]!=-1) dis[n]/=2;
    cout<<dis[n]<<endl;
	return 0;
}


Measured memory_bytes: 96768
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxm = maxn*10;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int n,a[1<<18],b[1<<18],ans,cnt;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i = 0;i<(1<<n);++i) cin>>a[i];
    for(int i = 0;i<n;i++) 
        for(int j = 0;j<(1<<n);j++)
            if((j>>i)&1)
                if(a[j] > a[j^(1<<i)]) b[j] = max(b[j],a[j^(1<<i)]);
                else {
                    b[j] = max(a[j],b[j^(1<<i)]);
                    a[j] = a[j^(1<<i)];
                }
    int ans = 0;
    for(int i = 1;i<(1<<n);i++) {
        ans = max(ans,a[i] + b[i]);
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int W,H,K,i,j,k,l;
inline ll calc(int n,int m){
	static int v1[N],v2[N];ll ans=0;
	for(i=1;i<m;++i){
		int lm1,lm2;
		for(j=1;j<n;++j){
			v1[j]=(m+1)*(j+1)-(i+1)*(j+1)+3;
			if(v1[j]+2*i-(m+1)>K*2+m*2)break;
		}
		lm1=j;
		for(j=1;j<n;++j){
			v2[j]=(m+1)*j-(m-i+1)*(j+1);
			if(v2[j]>K*2+m*2)break;
		}
		lm2=j;
		for(j=1,k=lm2-1;j<lm1;++j){
			for(;k>1 && v1[j]+v2[k]>K*2;--k);
			ans+=k-1;
			int vv=v1[j]-__gcd(j,i);
			for(l=0;vv+v2[k+l]-m-(m-i)<=K*2 && k+l<lm2;++l)ans+=vv+v2[k+l]-__gcd(k+l,m-i)-__gcd(abs(j-k-l),m)<=K*2;
		}
	}
	return ans;
}
int main(){
	scanf("%d%d%d",&W,&H,&K);
	printf("%lld\n",calc(W,H)+calc(H,W)<<1);
}

Measured memory_bytes: 4616
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string a,b;
    cin >> a >> b;

    if(a.size()>b.size()){
        cout << "GREATER" << endl;
        return 0;
    }else if(a.size()<b.size()){
        cout << "LESS" << endl;
        return 0;
    }else{
        for(int i=0;i<a.size();i++){
            if(a[i]<b[i]){
                cout << "LESS" << endl;
                return 0;
            }else if(a[i]>b[i]){
                cout << "GREATER" << endl;
                return 0;
            }
        }
    }

    cout << "EQUAL" << endl;

    return 0;
}


Measured memory_bytes: 3600
x = int(input())

# 約数のリストを作る
# sortはされてないのできをつけよう
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if(n%i == 0):
            divisors.append(i)
            if(i!= n//i):
                divisors.append(n//i)

    return  divisors

while(True):
    tmp = make_divisors(x)
    if(len(tmp) == 2):
        break
    x += 1

print(x)

Measured memory_bytes: 38640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;


int main() {
    int cube[6][6] = {{0, 3, 5, 2, 4, 0},
                      {4, 0, 1, 6, 0, 3},
                      {2, 6, 0, 0, 1, 5},
                      {5, 1, 0, 0, 6, 2},
                      {3, 0, 6, 1, 0, 4},
                      {0, 4, 2, 5, 3, 0}};
    
    int n[6];
    for(int i = 0; i < 6; i++){
        cin >> n[i];
    }

    int q;
    cin >> q;

    for(int i = 0; i < q; i++){
        int a, b;
        cin >> a >> b;
        for(int j = 0; j < 6; j++){
            if(n[j] == a) a = j;
            if(n[j] == b) b = j;

        }
        cout << n[cube[a][b]-1] << endl;
    }


    
}


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

int main() {
  int a,b,mul;
  cin >> a >> b;
  mul = a * b;
  if (mul%2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define pb	push_back
#define f	first
#define s	second

using namespace std;

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

const int N = 100007;
const ll mod = 1e9 + 7;
const ll oo = 1e18;

int n, O[N], F[N];
long long dp[N], S[N], A, B, sum[N];

int getL(int i){
	int lo = 1, hi = i, ret = i;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		if((S[i] - S[mid]) >= A){
			ret = mid;
			lo = mid + 1;
		}
		else hi = mid - 1;
	}
	return ret;
}

int getR(int i){
	int lo = 1, hi = i, ret = i + 1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		if((F[i] - F[mid-1]) == (i - mid + 1)){
			ret = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	return max(1, ret-2);
}

void init(){
	S[0] = -oo, S[n+1] = +oo;
	repn(i, n){
		O[i] += O[i-1];
		F[i] += F[i-1];;
		if((S[i+1] - S[i-1]) >= B) O[i]++;
		if((S[i+0] - S[i-1]) >= B) F[i]++;
	}
}

long long calc(){
	for(int i=1;i<=n;i++){
		sum[i] = sum[i-1];
		if(O[i] == O[i-1]) continue;
		if(F[i-1] == i - 1) dp[i] += 1, dp[i] %= mod;
		int S1 = getL(i), S2 = getR(i-1);
		if(S2 > S1 || S1 == i){
			sum[i] += dp[i];
			sum[i] %= mod;
			continue;
		}
		dp[i] += sum[S1] - sum[S2-1];
		dp[i] %= mod;
		sum[i] += dp[i];
		sum[i] %= mod;
	}
	long long ret = dp[n];
	for(int i=1;i<n;i++){
		if((F[n] - F[i+1]) == n - i - 1){
			ret += dp[i];
			ret %= mod;
		}
	}
	if(F[n] == n) ret = (ret + 1) % mod;
	if(ret < 0) ret += mod;
	assert(ret >= 0 && ret < mod);
	return ret;
}

int main(){
	scanf("%d %lld %lld", &n, &A, &B);
	repn(i, n) scanf("%lld", &S[i]);
	if(n <= 25){
		int ret = 0;
		for(int mask=0;mask<(1<<n);mask++){
			long long p1 = -oo, p2 = -oo, flag = 1;
			rep(i, n){
				if(mask & (1 << i)){
					if((S[i+1] - p1) < A){
						flag = 0;
					}
					p1 = S[i+1];
				}
				else{
					if((S[i+1] - p2) < B) flag = 0;
					p2 = S[i+1];
				}
			}
			if(flag) ret++;
		}
		cout << ret << endl;
		return 0;
	}
	if(B > A) swap(A, B);
	init();
	long long ret = calc();
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3328
class Dice:
    def __init__(self, a, b, c, d, e, f):
        self.top = a
        self.front = b
        self.right = c
        self.left = d
        self.behind = e
        self.bottom = f

    def S(self):
        self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self.front

    def N(self):
        self.behind, self.top, self.bottom, self.front = self.top, self.front, self.behind, self.bottom

    def E(self):
        self.top, self.bottom, self.left, self.right = self.left, self.right, self.bottom, self.top

    def W(self):
        self.left, self.right, self.bottom, self.top = self.top, self.bottom, self.left, self.right


dice=Dice(*[int(i) for i in input().split(" ")])
for s in input():
    if s=="S":
        dice.S()
    if s=="E":
        dice.E()
    if s=="N":
        dice.N()
    if s=="W":
        dice.W()
print(dice.top)



Measured memory_bytes: 5612
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    ll N;
    cin >> N;
    map<ll, ll> mp;
    rep(x, 1, 101){
        rep(y, 1, 101){
            rep(z, 1, 101){
                ll M = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
                if (M > 10000) continue;
                else{
                    if (mp.count(M)) mp[M]++;
                    else mp[M] = 1;
                }
            }
        }
    }
    rep(i, 1, N + 1){
        if(mp.count(i)) cout << mp[i] << endl;
        else cout << 0 << endl;
    }
}

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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

bool prime[1001];
vl pr;

void sieve(int n)
{
    mem(prime, true);
    prime[0]=false;
    prime[1]=false;
    for(int i=4; i<=n; i+=2)
    {
        prime[i]=false;
    }
    for (int p=3; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    pr.pb(2);
    for (int p=3; p<=n; p+=2)
        if (prime[p] == true)
            pr.pb(p);

}

int main()
{
    su;
    ll n,ans=1,c,p;
    cin>>n;
    sieve(n);
    for(auto i:pr)
    {
        c=1;
        p=i;
        while(p<=n)
        {
            c+=(n/p);
            c%=MOD;
            p*=i;
        }
        ans*=c;
        ans%=MOD;
    }
    cout<<ans%MOD<<nl;
    return 0;
}


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

void solve()
{
    int c = 1;
    int mx = 0;
    for (int i = 0; dp[i] <= n; i++)
    {
        for (int j = 0; j < i + 1; j++)
        {
            ans[j].push_back(c);
            ans[i + 1].push_back(c);
            c++;
            mx = max(mx, i + 1);
        }
    }
    cout << mx + 1 << endl;
    for (int i = 0; i < 10000; i++)
    {
        if (ans[i].empty())
        {
            continue;
        }
        cout << ans[i].size() << ' ';
        rep(j, ans[i].size())
                cout
            << ans[i][j] << ' ';
        cout << endl;
    }
}
int main()
{
    dp.push_back(1);
    for (int i = 2; dp[i - 2] + i <= 1000000; i++)
    {
        dp.push_back(dp[i - 2] + i);
    }
    cin >> n;
    if (n == *lower_bound(dp.begin(), dp.end(), n))
    {
        cout << "Yes" << endl;
        solve();
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main(){
	int m,n,cnt=0,prev,ans=0;	cin>>m>>n;
	if(m==2){
		int ans1=0,ans2=0;
		for(int i=0;i<n;i++){
			int x;	cin>>x;
			
			if((i%2 +1 !=x)){
				ans1++;
			}else ans2++;
		}

		ans=min(ans1,ans2);
	}else{
		for(int i=0;i<n;i++){
			int x;	cin>>x;

			if(x==prev)cnt++;
			else{
				ans+=cnt/2;

				cnt=1;
				prev=x;
			}
		}
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	return 0;
}



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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}
//you don't know math, unless you can do math!
int OO = 1e7;

int main() {

    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    int a,b,c; cin>>a>>b>>c;
    if(b - a == c - b)
        cout<<"YES";
    else
        cout<<"NO";

}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			if( (n|k) == 0 ) break;
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = Integer.parseInt(sc.next());
			int sum = 0;
			int max = 0;
			for(int i=0;i<k;i++) sum += a[i];
			max = sum;
			for(int i=k;i<n;i++) {
				sum += a[i] - a[i-k];
				max = max(max, sum);
			}
			System.out.println(max);
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

int main(){
 int n, k, MIN = 0 , x ,y;
 cin>>n>>k;
list<int>fruits;
for(int i = 0; i < n; i++){
    cin>>x;
    fruits.push_back(x);
 }
for(int j = 0; j < k; j++){
list<int>:: iterator y =min_element(fruits.begin(),fruits.end());
MIN += *y;
fruits.erase(y);
}
cout<<MIN<<endl;
    return 0;
}



Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<random>

//#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define ALL(v) (v).begin() , (v).end()
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

void solve(){

	int n;
	cin>>n;
	vector<pair<int,int>> a(n+1);
	for(int i = 1 ; i <= n ; ++i){
		cin>>a[i].ff;
		a[i].ss = i;
	}

	sort(a.begin()+1,a.end() , greater<pair<int,int>>());

	debug(a);

	int dp[n+1][n+1];
	memset(dp , 0 , sizeof dp);

	for(int i = 1 ; i <= n ; ++i){

		int x = a[i].ff;
		int pos = a[i].ss;
		for(int j = 0 ; j <= i ; ++j){

			int val = 0;
			if(j > 0)
				val = dp[i-1][j-1] + x*abs(pos - j);

			if(j!=i)
				val = max(val , dp[i-1][j] + x*abs(n - (i - j - 1)-pos));

			dp[i][j] = val;

			//debug(dp[i][j] , i , j);
		}
	}

	int ans = *max_element(dp[n] , dp[n]+n+1);

	cout<<ans<<endl;

}

signed main(){

    fast;
    //freopen("output.txt" , "w" , stdout);
    int t = 1;
   // cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 34952
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
string a;
map<string,int> id = {{"Male", 0}, {"Female", 1}};

int main(){
    readi(n);
    cout <<0 <<endl;
    cin >>a;
    if(a == "Vacant") return 0;
    int even = id[a];

    int l = 0, r = n-1;
    while(l < r){
        int mid = (l + r) / 2 + 1;
        cout <<mid <<endl;
        cin >>a;
        if(a == "Vacant") return 0;
        bool ok = (mid % 2 == 0) and id[a] == even;
        ok |= (mid & 1) and id[a] != even;
        if(ok) l = mid;
        else r = mid - 1;
    }
    assert(false);
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 852
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
const int dx[8] = {0,1,1,1,0,-1,-1,-1};
const int dy[8] = {1,1,0,-1,-1,-1,0,1};
int w,h,grid[51][51];
void s(int x, int y){
  grid[y][x] = 0;
  REP(r,8){
    if(x+dx[r]>=0&&x+dx[r]<w&&y+dy[r]>=0&&y+dy[r]<h&&grid[y+dy[r]][x+dx[r]]){
      s(x+dx[r],y+dy[r]);
    }
  }
} 


int main(void){
  while(cin>>w>>h){
    if(w==0) break;
    REP(y,h)
      REP(x,w)
        cin>>grid[y][x];
    int c = 0;
    REP(y,h)
      REP(x,w)
        if(grid[y][x]){
          c++;
          s(x,y);
        }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vu64 bank = {1, 6, 6*6, 6*6*6, 6*6*6*6, 6*6*6*6*6, 6*6*6*6*6*6, 6*6*6*6*6*6*6,
                9, 9*9, 9*9*9, 9*9*9*9, 9*9*9*9*9, 9*9*9*9*9*9};

vu64 dp;

u64 solve(int x)
{
    u64 ret = 1e6;
    rep (i, bank.size())
    {
        if (x >= bank[i])
        {
            ret = MIN(ret, dp[x - bank[i]] + 1);
        }
    }
    return ret;
}

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

    int N;
    cin >> N;
    dp.resize(N + 1, 0);

    for (int i = 1; i <= N; ++i)
    {
        dp[i] = solve(i);
    }
    cout << dp[N] << "\n";
    return 0;
}



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

int main(){
    int n;
    string s;
    bool ok = false;
    cin >> n >> s;
    if(s.length() % 2 == 0){
        ok = true;
        rep(i,s.length()/2){
            if(s[i] != s[s.length()/2+i]){
                ok = false;
            }
        }
    }
    if(ok) cout << "Yes" << endl;
    if(!ok) cout << "No" << endl;
}

Measured memory_bytes: 256
N=int(input())
A= list(map(int,input().split()))
sum_A=sum(A)
B= list(map(int,input().split()))
ans=0
if sum_A < sum(B):
   print(-1)
   exit()
l=[]
S=0
for i in range(N):
   if A[i]<B[i]:
      ans+=1
      S+=B[i]-A[i]
   elif A[i]>=B[i]:
      l.append(A[i]-B[i])
l.sort(reverse=True)
cnt=0
for i in l:
   if S>0:
      S-=i
      cnt+=1
print(ans+cnt)

Measured memory_bytes: 18356
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
//int a[1000000];
int a,b;
int ans;
int bb;
int main()
{
	bb=100000;
	cin>>n;
	//rep(i,n)cin>>a[i];
	rep2(i,1,n)
	{
		ans=0;
		a=i;
		b=n-i;
		while(a!=0)
		{
			ans+=(a%10);
			a/=10;
		}
		while(b!=0)
		{
			ans+=(b%10);
			b/=10;
		}
		if(bb>ans)bb=ans;
	}
	cout<<bb<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long Int;




Int n, a[1080];
Int cnt[2], sum[2];
vector<Int> ans;

void go(int x){
	ans.push_back(x+1);
	if(x == 0){
		for(int i = 0;i < n-1;i++)a[i] = a[i+1];
		n--;
		return;
	}
	if(x == n-1){
		n--;
		return;
	}
	a[x-1] += a[x+1];
	for(int i = x;i < n-2;i++){
		a[i] = a[i+2];
	}
	n-=2;
}
int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		cnt[i%2] += a[i] >= 0;
		sum[i%2] += max(a[i], 0LL);
	}
	if(cnt[0] == 0 && cnt[1] == 0){
		int tmp = 0;
		for(int i = 0;i < n;i++){
			if(a[tmp] < a[i])tmp = i;
		}

		cout << a[tmp] << endl;
		cout << n-1 << endl;
		for(int i = n-1;i > tmp;i--)cout << i + 1 << endl;
		for(int i = 0;i < tmp;i++)cout << 1 << endl;
		return 0;
	}
	int maxsum = max(sum[0], sum[1]);
	if(sum[1] > sum[0])go(0);
	while(n>1){
		if(n > 2 && a[0] < 0){
			go(0);
			go(0);
		}
		else if(n > 2 && a[2] < 0){
			go(2);
		}
		else{
			go(1);
		}
	}

	cout << a[0] << endl;
	cout << ans.size() << endl;
	for(int i = 0;i < ans.size();i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N, D, A;
	cin >> N >> D >> A;

	vector<P> xh(N);
	ll xMax = 0;
	ll xMin = INF;
	ll hMax = 0;
	for (ll i = 0; i < N; ++i)
	{
		cin >> xh[i].first >> xh[i].second;
		xMax = max(xMax, xh[i].first);
		hMax = max(hMax, xh[i].second);
		xMin = min(xMin, xh[i].first);
	}

	if (xMax - xMin <= D * 2)
	{
		ll num_exec = hMax / A;
		if (hMax % A != 0) num_exec++;

		cout << num_exec << endl;

		system("pause");

		return 0;
	}

	sort(xh.begin(), xh.end());

	ll ans = 0;

	for (ll i = 0; i < N; ++i)
	{
		if (xh[i].second <= 0) continue;

		ll num_exec = xh[i].second / A;
		if (xh[i].second % A != 0) num_exec++;
		ll damage = num_exec * A;

		ll r_end = xh[i].first + 2 * D;

		for (ll j = i; j < N; ++j)
		{
			if (xh[j].first <= r_end)
			{
				xh[j].second -= damage;
			}
			else
			{
				break;
			}
		}

		ans += num_exec;
	}
		

	cout << ans << endl;

	system("pause");
}


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

#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define ps(x) printf("%s\n", x)

#define INF 100000000000
#define M 1000000007

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int main() {
	long H, W;
	char S[16];
	long i, j;
	long ans = 0;
	
	sl(H); sl(W);
	for(i=0;i<H;i++) {
		for(j=0;j<W;j++) {
			ss(S);
			if(strcmp("snuke", S) == 0) {
				printf("%c%ld\n", (char)('A' + j), i + 1);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    ll a,b,c,d;cin >>a>>b>>c>>d;
    ll ans=max({a*c,a*d,b*c,b*d});
    cout <<ans <<endl;
}



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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
signed main() {
    cin >> N >> M;
    if (N == 1 && M == 1) { fin(1); }
    if (N == 1) { fin(M - 2); }
    if (M == 1) { fin(N - 2); }
    cout << (N - 2) * (M - 2) << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
kosuu=Hash.new
kosuu.default=0
a.each{|item|
    kosuu[item]+=1
}
sum = Hash.new
sum.default = 0
kosuu.each{|key,value|
        sum[key]=value*(value-1)/2
}
wa = 0
sum.each_value{|v|
    wa += v
}
a.each{|item|
    puts wa+(sum[item]*(kosuu[item]-2)/kosuu[item])-sum[item]
}

Measured memory_bytes: 38156
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] nl = new int[n];
        Arrays.fill(nl,k-q);
        for(int i = 0; i < q; i++){
            int a = sc.nextInt()-1;
            nl[a]++;
        }
        for(int i = 0; i < n; i++){
            if(nl[i] > 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}

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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n;
	cin >> n;
	vector<int> d(n);
	for (auto &x : d)
		cin >> x;
	int ans = 0;
	sort(d.begin(), d.end());
	for (int i = 1; i <= d[n - 1]; ++i)
	{
		int cnt = upper_bound(d.begin(), d.end(), i) - d.begin();
		if (cnt == n / 2)
			ans++;
	}
	cout << ans;
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

bool isrevolve(string s){
  int N = s.size();
  for(int i=0;i<N/2;i++){
    if(s[i]!=s[N-i-1]){
      return false;
    }
  }
  return true;
}

int main(){
  string s;
  cin>>s;
  int N = s.size();
  string s_first=s.substr(0,(N-1)/2);
  string s_last=s.substr((N+3)/2-1);
  if(isrevolve(s)&&isrevolve(s_first)&&isrevolve(s_last)){
    cout<<"Yes";
  }
  else cout<<"No";
}
    
  

Measured memory_bytes: 256
#include<cstdio>
#define max_n 20

int n, A[max_n], q, m_i;

bool solve(int i, int m){
	if(m == 0) return true;
	if(i >= n) return false;
	bool res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

int main(void){
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &A[i]);
	scanf("%d", &q);
	for(int i = 0; i < q; i++){
		scanf("%d", &m_i);
		if(solve(0, m_i) == true) printf("yes\n");
		else printf("no\n");
	}

	return 0;
}

Measured memory_bytes: 2600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9
#define LINF = 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")
#define PI 3.141592653589793

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    YES(b-a == c-b) << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
	char S[3];
	scanf("%s", S);
	if (S[0] == 'a'){
		if (S[1] == 'a'){
			printf("No");
		}
		else if (S[1] == 'b'){
			if (S[2] == 'c'){
				printf("Yes");
			}
			else printf("No");
		}
		else if (S[1] == 'c'){
			if (S[2] == 'b'){
				printf("Yes");
			}
			else printf("No");
		}
	}
	else if (S[0] == 'b'){
		if (S[1] == 'a'){
			if (S[2] == 'c'){
				printf("Yes");
			}
			else printf("No");
		}
		else if (S[1] == 'b'){
			printf("No");
		}
		else if (S[1] == 'c'){
			if (S[2] == 'a'){
				printf("Yes");
			}
			else printf("No");
		}
	}
	else if (S[0] == 'c'){
		if (S[1] == 'a'){
			if (S[2] == 'b'){
				printf("Yes");
			}
			else printf("No");
		}
		else if (S[1] == 'c'){
			printf("No");
		}
		else if (S[1] == 'b'){
			if (S[2] == 'a'){
				printf("Yes");
			}
			else printf("No");
		}
	}
	return (0);
}

Measured memory_bytes: 128