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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 105 A / Link: http://abc105.contest.atcoder.jp/tasks/abc105_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N, K; cin >> N >> K;
	ans = !!(N%K);
	
	
	cout << ans << "\n";

	return 0;
}


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

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

typedef long long LL;

int main(){
  LL n,m;
  cin >> n >> m;
  vector<list<int>> e(n);
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    e[--a].push_back(--b);
    e[b].push_back(a);
  }
  vector<int> color(n,-1);
  queue<int> q;
  q.push(0);
  color[0]=0;
  int now;
  bool nibu=true;
  while(!q.empty()){
    now=q.front();
    q.pop();
    for(auto i:e[now]){
      if(color[i]<0){
        color[i]=1-color[now];
        q.push(i);
      }else{
        if(color[i]==color[now]) nibu=false;
      }
    }
  }
  if(nibu){
    LL white=0;
    for(int i=0;i<n;i++) if(color[i]) white++;
    cout << white*(n-white)-m << endl;
  }else{
    cout << n*(n-1)/2-m << endl;
  }
  return 0;
}


Measured memory_bytes: 8448
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int n = cast(int)s.length;
    auto es = new int[n];

    int e = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') e++;
        es[i] = e;
    }

    // p 番目までの W の累積和
    int ws(int p) { return p + 1 - es[p]; }

    int ans = int.max;
    for (int i = 0; i < n; i++) { // i がリーダー
        // リーダーの左側で W を向いている人数
        int leftWs = i > 0 ? ws(i - 1) : 0;
        // リーダーの右側で E を向いている人数
        int rightEs = i == n-1 ? 0 : es[n - 1] - es[i];
        ans = min(ans, leftWs + rightEs);
    }
    return ans;
}

void main() {
    readint;
    auto s = readln.chomp;
    auto ans = calc(s);
    writeln(ans);
}

Measured memory_bytes: 3796
#include <iostream>
#include<cstdio>
using namespace std;
#define MAX 100
long long A[MAX][MAX];
long long  INF = 1LL << 32;

void warshallFloyd(int v){
    for(int k = 0;k < v;++k){
        for(int i = 0;i < v;++i){
            if(A[i][k] == INF) continue;
            for(int j = 0;j < v;++j){
                if(A[k][j] == INF) continue;
                A[i][j] = min(A[i][j],A[i][k] + A[k][j]);
            }
        }
    }
}
int main(void){
    int v,e,s,t,d;
    for(int i = 0;i < MAX;++i){
        for(int j = 0;j < MAX;++j){
            A[i][j] = (i == j) ? 0:INF;
        }
    }
    scanf("%d %d",&v,&e);
    for(int i = 0;i < e;++i){
        scanf("%d %d %d",&s,&t,&d);
        A[s][t] = d;
    }
    warshallFloyd(v);
    for(int i = 0;i < v;++i){
        if((A[i][i] < 0)){
            printf("NEGATIVE CYCLE\n");
            return 0;
        }
    }
    for(int i = 0;i < v;++i){
        for(int j = 0;j < v;++j){
            if((A[i][j] != INF)){
                printf((j != v-1) ? "%lld " : "%lld",A[i][j]);
            } else{
                printf((j != v-1) ?"INF ":"INF");
            }
        }
        printf("\n");
    }
    
}




Measured memory_bytes: 3300
#include<bits/stdc++.h>
const unsigned int M = 1000000007; 
#define all(v) (v).begin(), (v).end()
#define rall(v) v.rbegin(),v.rend()
#define  pb push_back
#define int  long long
#define N 998244353
#define endl "\n"
#define fr(i,n) for(int i=0;i<n;i++)
int power(int x,int y){int res=1;while(y>0){if(y&1)res=x*res; y=y>>1;x=x*x;}return res;}
int power(int x,int y,int mod){int res=1;while(y>0){if(y&1)res=x*res%mod; y=y>>1;x=x*x%mod;}return res;}

using namespace std;

void nik()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

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


#define F first
#define S second

#define PI 3.141592653589793238



 signed main()
{
//nik();

int test=1;
//cin>>test;

while(test--)
{	
int n,sm=0;
cin>>n;
for(int i=1;i<=n;i++)
{
	for(int j=1;j<=n;j++)
	{
		for(int k=1;k<=n;k++)
		{
			int x=__gcd(j,k);
			sm+=__gcd(x,i);
		}
	}
}
cout<<sm;

}
 return 0;
}



Measured memory_bytes: 3552
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
    
	ll x,y;
	cin >> x >> y;

	ll cnt = 0;

	while(x <= y){
        cnt++;
        x *= 2;
	}

    P(cnt);
	
	return  0;
}

Measured memory_bytes: 256
object Main extends App {
  val S = scala.io.StdIn.readLine()
  val list = S.toList

  val oddList: List[Char] = list.zipWithIndex.filter(tt => tt._2 % 2 == 0).unzip._1
  val evenList: List[Char] = list.zipWithIndex.filter(tt => tt._2 % 2 != 0).unzip._1

  val startWithZeroCount = oddList.count(_ == '1') + evenList.count(_ == '0')
  val startWithOneCount = oddList.count(_ == '0') + evenList.count(_ == '1')

  println(startWithZeroCount.min(startWithOneCount))
}

Measured memory_bytes: 53912
#include<iostream>
#include<string>
using namespace std;
int main(){
	int h=0; //??????
	int w=0; //??????
	int a[10000];
	int b[10000];
	int i=0;
	int x=0;
	int y=0;
	int z=0;
	while(1){
		cin>>w>>h;
		if(w==0&&h==0){
			break;
		}
		a[i]=w;
		b[i]=h;
		i++;
	}
	for(x=0;x<i;x++){
		for(y=0;y<a[x];y++){
			for(z=0;z<b[x];z++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

ll n, in, ans, mon = 1;
bool uku[100005];
int main() {
	cin >> n;
	vector<pair<ll, ll>>v;

	for (int i = 1; i <= n; ++i) {
		cin >> in;
		uku[i] = 1;
		v.push_back(make_pair(in, i));
	}

	sort(all(v));
	ans = ((v[0].first == 0) ? 0 : 1);

	for (int i = 0; i < v.size(); ++i) {
		auto ushi = v[i].second;
		uku[ushi] = 0;
		--mon;
		if (uku[ushi - 1]) { ++mon; }
		if (uku[ushi + 1]) { ++mon; }
		if (i == v.size() - 1 || v[i].first != v[i + 1].first) { ans = max(ans, mon); }
	}

	cout << ans << endl;
}



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

using namespace std;

int main()
{
	long long x,y;
	cin >> x >> y;
	
	long long now = x;
	int ans = 0;
	while(now <= y)
	{
		ans++;
		now *= 2;
	}
	
	cout << ans << endl;
	return 0;
}

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

vector<pair<int, string> > v;

void dfs(int now, int deep){
  for(int i = 0; i < v.size(); i++){
    if(now == v[i].first){
      cout << string(deep, '.') << v[i].second << "\n";
      dfs(i, deep + 1);
    }
  }
}

int main(){
  int n;
  cin >> n;
  v.resize(n);
  for(int i = 0; i < n; i++){
    int root;
    string str;
    cin >> root;
    cin >> str;
    v[i] = make_pair(root - 1, str);
  }
  dfs(-1, 0);
  return 0;
}

Measured memory_bytes: 1396
# def f(As, M):
#     prev = None
#     c = 0
#
#     for i, A in enumerate(As):
#         A %= M
#         if i == 0:
#             prev = {A: 1}
#             if A == 0:
#                 c += 1
#             continue
#
#         ccc = {A: 1}
#         for k in prev.keys():
#             v = prev[k]
#             newv = (k + A) % M
#             if newv in ccc:
#                 ccc[newv] += v
#             else:
#                 ccc[newv] = v
#         c += ccc[0] if 0 in ccc else 0
#         prev = ccc
#     return c
def f(As, M):
    totals = [As[0] % M]
    res = 1 if As[0] % M == 0 else 0
    for A in As[1:]:
        l = (totals[-1] + A) % M
        if l == 0:
            res += 1
        totals.append(l)

    # N = len(As)

    ddd = {}
    for t in totals:
        if t not in ddd:
            ddd[t] = 0
        res += ddd[t]
        ddd[t] += 1

    # for i in range(N):
    #     ii = totals[N - 1 - i]
    #     if ii == 0:
    #         res += 1
    #     for j in range(i + 1, N):
    #         jj = totals[N - 1 - j]
    #
    #         if jj == ii:
    #             res += 1
    return res


def main():
    N, M = [int(a) for a in input().split()]
    As = [int(a) for a in input().split()]
    print(f(As, M))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl;
#define all(x) x.begin(), x.end()
#define endl "\n"
const int mx = 1e5 + 1;

void swap(ll &a, ll &b)
{
    ll t = a;
    a = b;
    b = t;
}

ll Min(ll a, ll b, ll c)
{
    return min(a, min(b, c));
}

void printvec(vi &vec)
{
    for (int x : vec)
    {
        cout << x << " ";
    }
    cout << endl;
}

int sum(int a)
{
    int ans = 0;
    while (a)
    {
        ans += (a % 10);
        a = a / 10;
    }
    return ans;
}
void print(vi & mp)
{
    for(auto x : mp)
    {
        cout<<x;
    }
    cout<<endl;
}
void solve()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
    IOS;

    string s,t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int mi = INT_MAX;
    for(int i=0;i<=n-m;i++){
        int val = 0;
        for(int j=0;j<m;j++){
            if(s[i+j] != t[j]) val++;
        }
        mi = min(mi,val);
    }
    cout << mi << endl;
    return 0;    
}

Measured memory_bytes: 3612
def check_use_count(X, Y):
    a = (2 * X - Y) // 3
    b = X - 2 * a

    return a, b


def factorial(x, mod):
    if x == 0:
        return 1

    x %= mod

    for i in range(x-1, 0, -1):
        x *= i
        x %= mod

    return x


def main():
    mod = 10**9 + 7
    X, Y = [int(x) for x in input().split()]

    # 必ず3で割り切れる
    if (X + Y) % 3 != 0:
        print(0)
        exit()

    a, b = check_use_count(X, Y)

    # 0だったら行けない
    if a < 0 or b < 0:
        print(0)
        exit()

    # 移動パターンの計算
    # !(a + b) / !a * !b
    up = factorial(a + b, mod)
    fact_a = factorial(a, mod)
    fact_b = factorial(b, mod)

    down = fact_a * fact_b % mod

    result = up * pow(down, mod - 2, mod) % mod
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
typedef long long ll;
const int mod=924844033,g=5;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return (ll)a*b%mod;}
int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/*math*/
typedef vector<int> Poly;
int rev[N];
void DFT(int *t,int n,int type){
	int l=0;while(1<<l<n)++l;
	for(int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	for(int i=0;i<n;i++)if(rev[i]>i)swap(t[rev[i]],t[i]);
	for(int step=1;step<n;step<<=1){
		int wn=qpow(g,(mod-1)/(step<<1));
		for(int i=0;i<n;i+=step<<1){
			int w=1;
			for(int k=0;k<step;k++,w=mul(w,wn)){
				int x=t[i+k],y=mul(t[i+k+step],w);
				t[i+k]=add(x,y),t[i+k+step]=sub(x,y);
			}
		}
	}
	if(type==1)return;
	for(int i=1;i<n-i;i++)swap(t[i],t[n-i]);
	int inv=qpow(n,mod-2);
	for(int i=0;i<n;i++)t[i]=mul(t[i],inv);
}
Poly NTT(Poly A,int n,Poly B,int m){
	static Poly res,PolA,PolB;
	PolA=A,PolB=B;
	int len=1;while(len < n+m)len<<=1;
	res.resize(len);
	PolA.resize(len),PolB.resize(len);
	DFT(&PolA[0],len,1);DFT(&PolB[0],len,1);
	for(int i=0;i<len;i++) res[i]= mul(PolA[i],PolB[i]);
	DFT(&res[0],len,-1);
	res.resize(n+m-1);
	return res;
}
Poly NTT(Poly A,Poly B){return NTT(A,A.size(),B,B.size());}
Poly A,B,C;
int hed[N],to[N],nxt[N],cnt;
int n;
inline void adde(int u,int v){++cnt;to[cnt]=v,nxt[cnt]=hed[u];hed[u]=cnt;}
int sz[N];
int fac[N],ifac[N];
inline void dfs(int x,int pre){
	sz[x]=1;
	for(int i=hed[x];i;i=nxt[i]){
		int v=to[i];if(v==pre)continue;
		dfs(v,x);
		sz[x]+=sz[v];
	}
	if(n-sz[x]>0)A[sz[x]]=add(A[sz[x]],fac[sz[x]]);
	if(n-sz[x]>0)A[n-sz[x]]=add(A[n-sz[x]],fac[n-sz[x]]);
}
void init(){
	fac[0]=ifac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int comb(int x,int y){
	return mul(fac[x],mul(ifac[y],ifac[x-y])); 
}

int main()
{
	scanf("%d",&n);
	for(int u,v,i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		adde(u,v),adde(v,u);
	}
	init();
	A.resize(n+1);
	B.resize(n+1);
	dfs(1,0);
	for(int i=0;i<=n;i++){
		int id=n-i;
		B[id]=ifac[i];
	}
	C=NTT(A,B);
	for(int i=1;i<=n;i++){
		int id=n+i;
		int tmp=0;
		tmp=mul(C[id],ifac[i]);
//		cout<<mul(i,comb(n,i))<<endl;
		printf("%d\n", sub( mul(n,comb(n,i)) ,tmp));
	}
}

Measured memory_bytes: 40040
#include <bits/stdc++.h>
// #include <atcoder/mincostflow>
// using namespace atcoder;
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
ll  LINF = 1e18;



int main(){
	int n;
	ll a,b,c,d;cin >> n >> a >> b >> c >> d;
	--n;
	bool flag = false;
	for(int i = 0;2*i <= n;i++){
		ll diff1 = abs(b-a) - i*abs(c-d);
		ll diff2 = abs(b-a) + i*abs(c-d);
		ll step = ll(n-2*i);
		if(diff1>=c*step &&diff1 <= d*step) flag = true;
		if(diff2>=c*step &&diff2 <= d*step) flag = true;
	}
	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, m; cin >> n;
    int cnt;
    m = n;
    while (m != 0){
        cnt += m % 10;
        m /= 10;
    }
    cout << (n % cnt == 0 ? "Yes" : "No") << '\n';
}

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

int main(){
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> L(k), R(k);
  int i=0;
  int num = 0;
  while (i < n) {
    if (s[i] == 'o') {
      if (num > k) return 0;
      L[num++] = i + 1;
      i += c;
    }
    i++;
  }
  i = n-1;
  num = k - 1;
  while (i >= 0) {
    if (s[i] == 'o') {
      if (num < 0) return 0;
      R[num--] = i + 1;
      i -= c;
    }

    i--;
  }

  for (int j=0; j<k; j++) {
    if (R[j] == L[j]) cout << R[j] << endl;
  }

  return 0;
}

Measured memory_bytes: 3332
#include<iostream>
#include<string>
#include<algorithm>
typedef long long ll;
using namespace std;
int main(void){
   int w,h,n;
   cin >> w >> h >> n;
   int ansx1=0,ansx2=w,ansy1=0,ansy2=h;
   for(int i=0;i<n;++i){
   	  int x,y,ewsn;
   	  cin >> x >> y >>ewsn;
   	  switch(ewsn){
   	  	case 1:
   	  		if(ansx1<=x){
   	  			ansx1 = x;
   	  		}
   	  		break;
   	  	case 2:
   	  		if(ansx2>=x){
   	  			ansx2 = x;
   	  		}
   	  		break;
   	  	case 3:
   	  		if(ansy1<=y){
   	  			ansy1 = y;
   	  		}
   	  		break;
   	  	case 4:
   	  		if(ansy2>=y){
   	  			ansy2 = y;
   	  		}
   	  		break;
   	  }
   	}
   	  if(ansx2-ansx1<0 || ansy2-ansy1<0){
   	 	cout << 0; 	
   	  }else{
   	  	cout << (ansx2-ansx1)*(ansy2-ansy1);
   	  }
return 0;
}


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

int main(void){
  int A, P;
  cin >> A >> P;
  int piece = A * 3 + P;
  cout << piece / 2 << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i; i<n; i++){
    cin>>s.at(i);
  }
  int m;
  cin >> m;
  vector<string> t(m);
  for(int i; i<m; i++){
    cin>>t.at(i);
  }
  int flag,top=0;
  for(int i=0; i<n; i++){
    flag=0;
    for(int j=0;j<n; j++){
      if(s.at(i)==s.at(j))
        flag++;
    }
    for(int j=0; j<m; j++){
      if(s.at(i)==t.at(j))
        flag--;
    }
    if(flag>top)
      top=flag;
  }
  cout<<top<<endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define vi vector<int>
#define ll long long
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define MOD 998244353
#define endL << '\n'
#define ii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define endL << '\n'
#define vii vector<ii>
#define pb push_back

/*
ll powmod(ll x, ll y, ll mod){
	ll res = 1;
	while (y > 0){
		if (y%2) res = (res*x) % mod;
		x = (x*x) % mod;
		y /= 2;
	}
	return res;
}
*/

/*const int N = 1000000;
int lp[N+1];
vector<ll> pr;

void sieve(){
	for (int i=2; i<=N; ++i) {
	    if (lp[i] == 0) {
	        lp[i] = i;
	        pr.push_back (i);
	    }
	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
	        lp[i * pr[j]] = pr[j];
	}
}*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1; //cin >> t;
	while(t--){
		int n; cin >> n;
		vll h(n); for (int i = 0; i < n; i++) cin >> h[i];
		vll dp(n, -1); dp[0] = 0;
		for (int i = 1; i < n; i++){
			dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
			if (i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
		}
		cout << dp[n-1];
	}
}

Measured memory_bytes: 1792
/*C*/
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define lint long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
/*******source code below********/

int main(void) {

	int N; cin >> N;
	string S; cin >> S;

	vector<int> w1(N);
	vector<int> b1(N);

	for (int i = 0; i < N; i++) {
		w1.at(i) = 0;
		b1.at(i) = 0;
	}

	if (S.at(0) == '.') w1.at(0) = 1;
	else b1.at(0) = 1;
	for (int i = 1; i < N; i++)
	{
		if (S.at(i) == '.') {
			w1.at(i) = w1.at(i - 1) + 1;
			b1.at(i) = b1.at(i - 1);
		}
		else {
			b1.at(i) = b1.at(i - 1) + 1;
			w1.at(i) = w1.at(i - 1);
		}
	}
	int countmax = b1.at(N - 1);
	for (int i = 1; i < N; i++)
	{
		int count = w1.at(i - 1) + (b1.at(N - 1) - b1.at(i - 1));
		if (count > countmax) countmax = count;

	}
	if (w1.at(N - 1) > countmax) countmax = w1.at(N - 1);

		cout << N - countmax << endl;


	return 0;
}

Measured memory_bytes: 2180
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    A.sort()
    answer = "YES"
    for i in range(N - 1):
        if A[i] == A[i + 1]:
            answer = "NO"
            break
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 26808
import sys
import numpy as np

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func()
    top_str = input_raw.strip().split()
    [a, b] = [top_str[0], top_str[1]]
    if a == 'H':
        TopCoDeer = b
    else:
        if b == 'H':
            TopCoDeer = 'D'
        else:
            TopCoDeer = 'H'
    print TopCoDeer

if __name__ == '__main__':
    main()


Measured memory_bytes: 19052
#include <iostream>

using namespace std;

int main(void)
{
    int K, S, i, j, ans=0, xy;

    cin >> K >> S;

    for(i=0; i<=S; i++){ // z
        for(j=0; j<=S-i; j++){
            if(i<=K && j<=K && S-i-j<=K){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

const int inf = 1e9;

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

int main() {
    int h, w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> maze(h);
    for(int i = 0; i < h; i++) {
        cin >> maze[i];
    }
    deque<pair<pair<int, int>, int>> que;
    vector<vector<int>> dis(h, vector<int>(w, inf));
    dis[ch][cw] = 0;
    que.push_back({{ch, cw}, 0});
    while(que.size()) {
        auto p = que.front();
        que.pop_front();
        int nx = p.first.first;
        int ny = p.first.second;
        int d = p.second;
        if(d > dis[nx][ny]) continue;
        for(int i = -2; i <= 2; i++) {
            for(int j = -2; j <= 2; j++) {
                int ni = nx + i;
                int nj = ny + j;
                if(i == 0 && j == 0) continue;
                if(0 <= ni && ni < h && 0 <= nj && nj < w && maze[ni][nj] == '.') {
                    if(abs(i) + abs(j) == 1 && dis[ni][nj] > d) {
                        dis[ni][nj] = d;
                        que.push_front({{ni, nj}, d});
                    } else if(dis[ni][nj] > d + 1){
                        dis[ni][nj] = d + 1;
                        que.push_back({{ni, nj}, d + 1});
                    }
                }
            }
        }
    }

    if(dis[dh][dw] == inf) {
        cout << -1 << endl;
    } else {
        cout << dis[dh][dw] << endl;
    }

}


Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N;
	int money[4]={10,50,100,500};
	bool flag=false;
	while(cin>>N,N){
		int a[4],ans[4]={0};
		int sum=0;
		REP(i,0,4){
			cin>>a[i];
			sum+=a[i]*money[i];
		}
		sum-=N;//paid
		for(int i=3;i>=0;i--){//unused
			ans[i]+=sum/money[i];
			ans[i]=a[i]-ans[i];
			sum-=sum/money[i]*money[i];
		}
		if(flag)	cout<<endl;
		REP(i,0,4){
			if(ans[i]>0){
				cout<<money[i]<<" "<<ans[i]<<endl;
				flag=true;
			}
		}

	}
	return 0;
}

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

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

    long long ans;
    if(N!=100){
        ans = round(pow(100, D))*N;
    }else{
        ans = round(pow(100, D))*(N+1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e5;
const int PLS = 3e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e16;


ll n, a[N], d, dp[10010][110];
string s;


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++)
        a[i] = s[i] - '0';
    cin >> d;
    dp[0][0] = 1;
    for (int i = 0; i <= 9; i++)
        dp[1][i % d]++;
    for (int i = 2; i <= n; i++)
        for (int j = 0; j < d; j++)
            for (int k = 0; k <= 9; k++)
                dp[i][j] = (dp[i][j] + dp[i - 1][((j - k) % d + 2 * d) % d]) % mod;
    ll ans = dp[n - 1][0], len = n, x = 0;
    for (int i = 0; i < n; i++) {
        ll start;
        if (i == 0)
            start = 1;
        else
            start = 0;
        for (int j = start; j < a[i]; j++)
            ans = (ans + dp[len - 1][((x - j) % d + 2 * d) % d]);
        len--;
        x = ((x - a[i]) % d + 2 * d) % d;
    }
    ll sm = 0;
    for (int i = 0; i < n; i++)
        sm += a[i];
    if (sm % d == 0)
        ans = (ans + 1) % mod;
    cout << ((ans - 1) % mod + 2 * mod) % mod;
}

Measured memory_bytes: 10624
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
As = list(map(int, input().split()))

def solve(As, first_target):
    ret = 0
    for i, a in enumerate(As):
        if i == 0:
            ret += abs(a - first_target)
            prev_sum = first_target
        else:
            curr_sum = prev_sum + a
            if prev_sum > 0 and curr_sum >= 0:
                ret += abs(curr_sum - (-1))
                curr_sum = -1
            elif prev_sum < 0 and curr_sum <= 0:
                ret += abs(curr_sum - 1)
                curr_sum = 1
            prev_sum = curr_sum
#            print("i, a, ret, curr_sum  = ", i, a, ret, curr_sum)
    return ret

ans1 = solve(As, 1)
ans2 = solve(As, -1)
ans3 = solve(As, As[0])
print(min(ans1, ans2, ans3))


Measured memory_bytes: 14468
#include <stdio.h>
#include <string.h>
 
int main(void)
{
	//変数の宣言
	char numchar[11];
	int num[11];
	int y[12];
	int i,j,k,l;
	int len;
	long temp=0;
	long sum=0;
	long ans=0;
	
	//データの読み込み
	scanf("%s",&numchar);
	
	
//	for(i=0;i<len;i++){
//		scanf("%d %d",&x[i],&y[i]);
//	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
	len=strlen(numchar);
	for(i=0;i<len;i++){
		num[i]=numchar[i]-48;
	}
	
	for(i=0;i<(1<<len-1);i++){
		temp=num[0];
		for(j=0;j<len-1;j++){
			if(i&1<<j){
				temp=temp*10+num[j+1];
			}else{
				sum=sum+temp;
				temp=num[j+1];
			}
		}
		
		sum=sum+temp;
		ans=ans+sum;
//		printf("i=%d,sum=%d\n",i,sum);
		sum=0;
		temp=0;
	}
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
		printf("%ld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
from collections import deque

N = int(input())
A = [ deque() for _ in range(N) ]

for i in range(N):
  for aa in list(map(int,input().split())):
    aa -= 1
    A[i].append(aa)

def check(i):
  if len(A[i])==0: return
  j = A[i][0]
  if len(A[j])==0: return

  if A[j][0] == i:
    if j<i: i,j = j,i
    q.add((i,j))

q = set()
for i in range(N):
  check(i)

ans = 0
while q:
  ans += 1

  prevq = q
  q = set()
  for p in prevq:
    i,j = p
    A[i].popleft()
    A[j].popleft()

  for p in prevq:
    i,j = p
    check(i)
    check(j)

for i in range(N):
  if len(A[i]) != 0:
    print(-1)
    exit()

print(ans)


Measured memory_bytes: 101380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int x, a, b;cin >> x >> a >> b;
  if(abs(x-a) > abs(x-b)) cout << "B" << endl;
  else cout << "A" << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
a.extend(np.cumsum(A, dtype="int64"))
b.extend(np.cumsum(B, dtype="int64"))

best = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:

        j -= 1
    best = max(best, i + j)

print(best)


Measured memory_bytes: 62420
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int H, W; cin >> H >> W;
  int A, B; cin >> A >> B;

  int a[W] = {};
  rep(i,A) a[i] = 1;

  rep(row, H){
    rep(col, W){
      if (row<B) cout << a[col];
      else cout << 1 - a[col];
    }
    cout << endl;
  }
  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<string> s(N);rep(i,N)cin >> s[i];
    int M;cin >> M;
    vector<string> t(M);rep(i,M)cin >> t[i];
    map<string,int> m;

    rep(i,N)m[s[i]]++;
    rep(i,M)m[t[i]]--;

    int ans = 0;
    for(auto c : m){
        chmax(ans,c.S);  
    }


    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define ll long long
using namespace std;

int main() {
	int n;
	cin >> n;
	map<int, int> a;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
		if (a.find(x) == a.end()) {
			a[x] = 1;
		}
		else {
			a[x]++;
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		//replace
		int b, c;
		cin >> b >> c;
		if (a.find(b) != a.end()) {
			if (a.find(c) != a.end()) {
				sum += (c - b) * a[b];
				a[c] += a[b];
				a[b] = 0;
			}
			else {
				sum += (c - b) * a[b];
				a[c] = a[b];
				a[b] = 0;
			}
		}
		cout << sum << '\n';
	}
}

Measured memory_bytes: 7328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string A, B, C;
	cin >> A >> B >> C;

	int kotae = 0;
	rep(i, N) {
		int kari = 0;
		if (A[i] == B[i]) kari++;
		if (B[i] == C[i]) kari++;
		if (C[i] == A[i]) kari++;

		if (kari == 0) kotae += 2;
		if (kari == 1) kotae += 1;
		if (kari == 3) kotae += 0;
	}

	co(kotae);

	Would you please return 0;
}

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

int main() {
 int N , K , A ;
  A = 0 ;
  cin >> N >> K ;
  vector<int> vec(N);
    for (int j=0;j<N;j++){
      cin >> vec.at(j) ;
      if (vec.at(j)>=K){
        A++;
      }
    }
  cout << A ;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    ll n;
    cin >> n;
    rep(i, 1000000)
    {
        ll k = (i+2);
        if((k*(k-1)/2) >= n )ANS(k-1);
    }

}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

const int INF = 1000000005;
int dp[1000005][2];

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';

  int n = s.size();

  for (int i = 0; i < n + 1; ++i) {
    for (int j = 0; j < 2; ++j)
      dp[i][j] = INF;
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      int d = s[i] - '0' + j;
      dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + d);
      dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 1 + (9 - d));
    }
  }

  cout << dp[n][0]  << endl;
  return 0;
}



Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,W;
  cin>>N>>W;
  VI A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  VVI X(4);
  ll tmp=A[0];
  rep(i,N) X[A[i]-tmp].pb(B[i]);
  rep(i,4) sort(all(X[i]),greater<int>());
  rep(i,4) rep(j,X[i].size()) if(j) X[i][j]+=X[i][j-1];
  ll ans=0;
  rep(i,X[0].size()+1){
    rep(j,X[1].size()+1){
      rep(k,X[2].size()+1){
        rep(l,X[3].size()+1){
          if((i+j+k+l)*tmp+j+k*2+l*3>W) continue;
          ll sum=0;
          if(i) sum+=X[0][i-1];
          if(j) sum+=X[1][j-1];
          if(k) sum+=X[2][k-1];
          if(l) sum+=X[3][l-1];
          ans=max(ans,sum);
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

   	cout << max(max(a * c, b * d), max(a * d, c * b));

    return 0;
}

/*

*/

Measured memory_bytes: 3648
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D) << endl;

	return(0);
}

Measured memory_bytes: 256
dp = [999999999 for i in range(100002)]
n = int(input())
hs = list(map(int, input().split()))

dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(hs[i-1] - hs[i]))
    if i > 1 :
        dp[i] = min(dp[i], dp[i-2] + abs(hs[i-2] - hs[i]))

print(dp[n-1])

Measured memory_bytes: 15024
/*  ex7_3
    supercomputerjoi    */

#include <stdio.h>
#include <stdlib.h>

int main(void){

    int height, width;
    char **map;
    int i = 0, j = 0, k = 0;
    char isBlank;

    // input H W
    scanf("%d %d", &height, &width);

    // secure memory
    map = (char**)calloc(height+1, sizeof(char*));
    if(map == NULL){
        exit(1);
    }
    for(i = 0; i < height+1; i++){
        map[i] = (char*)calloc(width+1, sizeof(char));
        if(map[i] == NULL){
            exit(1);
        }
    }

    // input a
    for(i = 0; i < height; i++){
        scanf("%s", map[i]);
    }

    // check blank row
    for(i = 0; i < height; i++){
        isBlank = 'y';
        for(j = 0; j < width; j++){
            if(map[i][j] == '#'){
                isBlank = 'n';
                break;
            }
        }
        // if row is blank
        if(isBlank == 'y'){
            // delete row and slide
            for(k = i; k < height; k++){
                for(j = 0; j < width; j++){
                    map[k][j] = map[k+1][j];
                }
            }
            i--;
            height--;
        }
    }

    // check blank col
    for(j = 0; j < width; j++){
        isBlank = 'y';
        for(i = 0; i < height; i++){
            if(map[i][j] == '#'){
                isBlank = 'n';
                break;
            }
        }
        // if col is blank
        if(isBlank == 'y'){
            // delete col and slide
            for(k = j; k < width; k++){
                for(i = 0; i < height; i++){
                    map[i][k] = map[i][k+1];
                }
            }
            j--;
            width--;
        }
    }

    // output answer
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            printf("%c", map[i][j]);
        }
        printf("\n");
    }

    // free memory
    for(i = 0; i < height; i++){
        free(map[i]);
    }
    free(map);

    return 0;
}


Measured memory_bytes: 1628
def gcd(m, n):
    while n:  # nが0になるまで続ける
        m, n = n, m % n
    return m


N = int(input())  # モンスターの数

A = list(map(int, input().split()))  # モンスターのそれぞれの体力のリスト

g = gcd(A[0], A[1])

for i in range(2, N):
    g = gcd(g, A[i])

print(g)


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

int main(){
  int N;
  string brackets;
  cin >> N >> brackets;
  
  int cumsum= 0;
  int min_neg= 0;
  for(auto c:brackets){
    if(c=='('){
      cumsum++;
    }
    else{
      cumsum--;
      min_neg= min(min_neg, cumsum);
    }
  }
  
  string prefix= string(abs(min_neg), '(');
  string suffix= string(cumsum- min_neg, ')');

  string ans= prefix + brackets + suffix; 

  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(list)
chars = ["M", "A", "R", "C", "H"]

for s in S:
    c = s[0]
    for cc in chars:
        if c == cc:
            d[c].append(s)
            break
len_list = []
for c in chars:
    l = d[c]
    len_list.append(len(l))

ans = 0
n_arr = [0, 0, 0, 0, 0]
for i in range(1, 32):
    n = i
    count = 0
    for j in range(0, 5):
        if n % 2 > 0:
            count += 1
            n_arr[j] = 1
        else:
            n_arr[j] = 0
        n = n // 2
    if count != 3:
        continue
    c = 1
    for j in range(0, 5):
        if n_arr[j] > 0:
            c *= len_list[j] * n_arr[j]
    ans += c
print(ans)

Measured memory_bytes: 11120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()
	n := scanInt()
	memo := map[int]int{}
	for i:= 0; i<n-1; i++{
		take := scanInt()
		if _,ok := memo[take]; !ok {
			memo[take] = 0
		}
		memo[take] += 1
	}
	for i:= 1; i<=n; i++ {
		fmt.Println(memo[i])
	}
}

var sc = bufio.NewScanner(os.Stdin)
func scanInit () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}

Measured memory_bytes: 13084
#abc092 b
n=int(input())
d,x=map(int,input().split())
a=[]
for i in range(n):
    z=int(input())
    a.append(z)

def eat(c):
    cnt=0
    z=1
    while d>=z:
        cnt+=1
        z=cnt*c+1
    return cnt
ans=0
for i in a:
    ans+=eat(i)
print(ans+x)


Measured memory_bytes: 3060
/*
* 挑战程序设计竞赛2 第四章 第二题 queue
* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B
*/

# include <cstdio>

static const int maxn = 100000 + 5;
int Q[maxn], n, q, head, tail;

struct Job {
	char name[15];
	int time;
} job[maxn];

void dequeue() {
	head = (head+1) % maxn;
}

void enqueue(int x) {
	Q[tail] = x;
	tail = (tail+1) % maxn;
}

int main() {
	// 输入输出重定向
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	
	scanf("%d%d", &n, &q); 
	for (int i = 0; i < n; i++) {
		scanf("%s%d", job[i].name, &job[i].time);
		Q[i] = i;
	}
	head = 0; tail = n; // 初始化队列的头和尾
	int p, t = 0; // p是正在操作的任务，t是目前的时间
	while (head != tail) {
		// printf("head is %d, tail is %d\n", head, tail);
		p = Q[head];
		dequeue();
		if (job[p].time <= q) {
			t += job[p].time;
			printf("%s %d\n", job[p].name, t);
		}
		else {
			t += q;
			job[p].time -= q;
			enqueue(p);	
		}
	}
	return 0;
}


Measured memory_bytes: 3948
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9 for i in range(N + K)]
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[N - 1])


Measured memory_bytes: 56544