akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define mer make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;
typedef pair<int,pair<int,int> > ipii;
typedef pair<pii,pii> pi4;
const int vbi=999999999;
int main(){
	//my new name is Veex
	//clock_t start1=clock();
	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World";
	}
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
	//cout<<endl<<((double)(clock()-start1)/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  double a;
  int X , Y;
  cin >> X >> Y;
  a = 2 * X - Y / 2;

  if(a < 0 || Y % 2 != 0 || a > X){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

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

int base = 1e9 + 7;

ll invmod(ll p, ll q) {
  ll r = 1;
  while (q) {
    if (q&1) r = (r*p) % base;
    p = p*p % base;
    q >>= 1;
  }
  return r;
}

ll combimod(ll n, ll m, vector<ll> inv) {
  ll t = 1;
  while (m) {
    t = t * n % base;
    t = t * inv[m] % base;
    n--; m--;
  }
  return t;
}

int main() {
  ll n, k; cin >> n >> k;
  vector<ll> inv(n);
  for (int i = 0; i < n; ++i) inv[i] = invmod(i, base-2);
  
  int N = min(n-1, k);
  int m = n;
  ll total = 0, combi1 = 1, combi2 = 1;
  for (int i = 0; i <= N; ++i) {
    ll t = combi1 * combi2 % base;
    total = (total + t) % base;
    
    combi1 = combi1 * m % base * inv[i+1] % base;
    combi2 = combi2 * (m-1) % base * inv[i+1] % base;
    m--;
  }
  
  cout << total << endl;
}

Measured memory_bytes: 1792
import sys
N=int(input())
flag=True
for k in range(1000):
    s=(k*(k+1))//2
    if N==s:
        flag=False
        break
if flag:
    print('No')
    sys.exit()
table=[[0]*(k+1) for i in range(k+1)]
s=1
for j in range(k+1):
    for i in range(j):
        table[j][i]=table[i][j]
    for i in range(j+1,k+1):
        table[j][i]=s
        s+=1
print('Yes')
print(k+1)
for i in range(k+1):
    print(k,end="")
    for s in table[i]:
        if s==0:
            continue
        print('',s,end='')
    print('')

Measured memory_bytes: 57688
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    long k = N / K;
    if (K % 2 == 0) {
      if (N < K / 2) {
        System.out.println(0);
        return;
      }
      long l = (N - K / 2) / K + 1;
      System.out.println(k * k * k + l * l * l);
    } else {
      System.out.println(k * k * k);
    }
  }
}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define MAX_V 10100
struct edge{
	int to;
	ll cap;
	int rev;
};
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,ll cap){
	G[from].pb((edge){to,cap,G[to].size()});
	G[to].pb((edge){from,0,G[from].size()-1});	
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0ll&&level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
ll dfs(int v,int t,ll f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			ll d = dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
ll max_flow(int s,int t){
	ll flow=0;
	for(;;){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		ll f;
		while((f=dfs(s,t,INF))>0)flow+=f;
	}
}
int N,S,T;
ll a[105];
int main(){
	cin >> N;
	for(int i=1;i<=N;i++)cin >> a[i];
	S = 0, T = N+1;
	ll base = 0ll;
	for(int i=1;i<=N;i++){
		if(a[i]>=0){
			base += a[i];
			add_edge(S,i,a[i]);
			add_edge(i,T,0ll);
		}else{
			add_edge(S,i,0ll);
			add_edge(i,T,-a[i]);
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=i*2;j<=N;j+=i){
			add_edge(j,i,LLINF);
		}
	}
	cout << base-max_flow(S,T) << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define st string
#define b begin
#define e end
#define sr sort
#define sz size
#define lt length
using namespace std;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b>c*d)
        cout<<a*b;
    else
        cout<<c*d;
}


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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		//t sq = sqrt(i) ;
		long ans = 0;
		long temp = 0;
		for (int j = 1;; j++)
		{
			if (j * j > i)
				break;
			for (int k = 1;; k++)
			{
				if ((k * k + j * j + k * j) > i)
					break;
				for (int z = 1;; z++)
				{
					temp = j * j + k * k + z * z + j * k + j * z + k * z;
					if (temp == i)
						ans++;
					if (temp > i)
						break;
				}
			}

		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 3544
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)

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

int num[110] = { 0 };

int main(void) {
	int n, d, ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> d;
		num[d]++;
	}
	for (int i = 1;i <= 100;i++) {
		if (num[i] > 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
    // insert code here...
    
    int a;
    cin >> a;
    if(a==7 || a==5 || a==3){
        cout << "YES" <<endl;
    }else{
        cout << "NO" << endl;
     }
    
    return 0;
}


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

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

  // 文字列
  string str; // 文字列変数を宣言

  cin>>str; //文字(char)の列を代入
  
  cin>>K;
  
  char A;
  
  A = str.at(K-1);
  
  for (int i = 0; i < N; i++) {
   if(str.at(i) == A){
     cout << A;
   }
    else{
      cout <<"*";
    }
}
  cout << endl;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[N - 1])

Measured memory_bytes: 13928
import math
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
x,a,b =iim()

if abs(x-a) > abs(x-b):
    print('B')
else:
    print('A')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++) cin >> a[i];
    ll sum = 0;
    rep(i,n-1){
        if(a[i] > a[i+1]){
            ll diff = a[i] - a[i+1];
            a[i+1] += diff;
            sum += diff;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 5156
#include <stdio.h>
#include <string.h>

int main()
{   char s[200001];
    scanf("%s",s);
    char t[200001];
    scanf("%s",t);
    int l=strlen(s);
    int a[26],b[26];
    for(int i=0;i<26;i++){
        a[i]=-1;
        b[i]=-1;
    }
    for(int i=0;i<l;i++){
        if(a[s[i]-'a']>0||b[t[i]-'a']>0){
            if(a[s[i]-'a']!=t[i]-'a'||b[t[i]-'a']!=s[i]-'a'){
                printf("No");
                return 0;
            }
        }else{
        a[s[i]-'a']=t[i]-'a';
        b[t[i]-'a']=s[i]-'a';
        }
    }
    printf("Yes");

    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    String ans = "No";

    for (int i = 0; i<a+1; i++){
      if((n-i)%500!=0){
        continue;
      }
      else{
        ans="Yes";
        break;
      }
    }
    System.out.println(ans);
  }


}

Measured memory_bytes: 25300
from collections import Counter

mod = 10**9+7
rng = 100002
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<=0 or k<0 or n<k:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod

n = int(input())
a = list(map(int,input().split()))
same = []
c = Counter(a)
x = c.most_common()[0][0]
for i in range(n+1):
  if a[i] == x:
    same.append(i+1)
y = same[1]-same[0]+1
print(n)
for k in range(2,n+2):
  print((cmb(n+1,k)-cmb(n+1-y,k-1))%mod)


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

// Union-Find
struct union_find{
	vector<int> par, rank;
	
	// コンストラクタで初期化
	union_find(int n){
		vector<int> v(n);
		par = v;
		rank = v;
		for(int i=0 ; i < n ; i++ ){
			par[i] = i;
			rank[i] = 0;
		}
	}
	// x の root を返す
	int find(int x){
		return ( par[x] == x )? x : (par[x] = find(par[x]) ) ;
	}
	// x と y の属する集合を併合する
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if( x == y ) return;
		
		if( rank[x] < rank[y] ){
			par[x] = y;
		}else{
			par[y] = x;
			if( rank[x] == rank[y] )
				rank[x]++;
		}
	}
	// x と y が同じ集合に属するかどうか
	bool same(int x, int y){
		return ( find(x) == find(y) );
	}
};

struct edge{
	int u,v,cost;
	edge(int u_, int v_, int cost_){
		u = u_;
		v = v_;
		cost = cost_;
	}
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

// 辺集合
vector<edge> es;
// 頂点数
int V;

// 初期化
void init(int n){
	V = n;
	es.clear();
}

// 最小全域木を求める (クラスカル法)
int kruskal(){
	// コストの小さい順にソート
	sort( es.begin() , es.end() , comp );
	// 頂点数で初期化
	union_find uf( V );
	int res = 0;
	for(int i = 0 ; i < es.size() ; i++ ){
		edge e = es[i];
		if( !uf.same( e.u , e.v ) ){
			uf.unite( e.u , e.v );
			res += e.cost;
		}
	}
	return res;
}

// 重み cost の辺(u,v)の追加
void add_edge(int u, int v, int cost){
	edge e(u,v,cost);
	es.push_back( e );
}

int main(){
	int n,m;
	while( cin >> n >> m , n || m ){
		// 初期化
		init( n );
		for(int i = 0 ; i < m ; i++ ){
			int u, v, c ;
			cin >> u >> v >> c;
			add_edge( u , v , c );
		}
		cout << kruskal() << endl;
	}
}

Measured memory_bytes: 0
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(long[]);
    auto ps = new long[](n + 1);
    foreach (i ; 1 .. n + 1) {
        ps[i] = ps[i-1] + a[i-1];
    }

    long ans = 10L^^18;

    foreach (mid ; 2 .. n - 1) {
        auto left = nibutan(n, ps, 0, mid);
        auto right = nibutan(n, ps, mid, n);
        long p = ps[left] - ps[0];
        long q = ps[mid] - ps[left];
        long r = ps[right] - ps[mid];
        long s = ps[n] - ps[right];
        debug {
            writefln("left = %d, right = %d", left, right);
            writefln("%d, %d, %d, %d", p, q, r, s);
        }
        long mm = max(p, q, r, s);
        long mi = min(p, q, r, s);
        ans = min(ans, mm - mi);
    }

    writeln(ans);
}

int nibutan(int n, long[] ps, int btm, int top) {
    long W = ps[top] - ps[btm];

    long calc(int k) {
        return abs(ps[top] - ps[k] - (ps[k] - ps[btm]));
    }

    bool check(int k) {
        return calc(k + 1) >= calc(k);
    }

    int bb = btm, tt = top;

    while (tt - bb > 1) {
        int mid = (bb + tt) / 2;

        debug {
            writefln("%d, %d", mid, calc(mid));
            writefln("%d, %d", mid + 1, calc(mid + 1));
        }
        if (check(mid)) {
            tt = mid;
        }
        else {
            bb = mid;
        }
    }

    return tt;
}







































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 11656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool v[100005];
stack <ll> v2;
ll ans;
int main(void){
	int N,K;
	cin >> N >> K;
	vector<pair<ll,ll>> s(N);
	for(int i=0;i<N;i++){
		int t,d;
		cin >> t >> d;
		s[i] = make_pair(d,t);
	}
	sort(s.begin(),s.end(),greater<>());
	ll sum = 0,type = 0;
	for(int i=0;i<K;i++){
		sum +=s[i].first;
		if(!v[s[i].second]){
			type++;
			v[s[i].second]=1;
		}else{
			v2.push(s[i].first);
		}
	}
	ans = sum + type*type;
	for(int i=K;i<N;i++){
		sum += s[i].first;
		if(!v[s[i].second]){
			type++;
			v[s[i].second] = 1;
		}
		else v2.push(s[i].first);
		if(v2.empty())break;
		sum -= v2.top();
		v2.pop();
		ans = max(ans,(sum + type*type));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint h, w;
    cin >> h >> w;

    char s[h+2][w+2];
    fill(&s[0][0], &s[h+2][0], '#');
    for(lint i = 1; i <= h; i++) {
        for(lint j = 1; j <= w; j++) {
            cin >> s[i][j];
        }
    }

    lint dp[h+2][w+2][4];
    fill(&dp[0][0][0], &dp[h+2][0][0], 0);

    for(lint i = 1; i <= h; i++) {
        for(lint j = 1; j <= w; j++) {
            if(s[i][j] == '#')  continue;
            dp[i][j][0] = dp[i-1][j][0] + 1;
            dp[i][j][2] = dp[i][j-1][2] + 1;
        }
    }

    for(lint i = h; i >= 1; i--) {
        for(lint j = w; j >= 1; j--) {
            if(s[i][j] == '#')  continue;
            dp[i][j][1] = dp[i+1][j][1] + 1;
            dp[i][j][3] = dp[i][j+1][3] + 1;
        }
    }

    lint ans = 0;
    for(lint i = 1; i <= h; i++) {
        for(lint j = 1; j <= w; j++) {
            ans = max(accumulate(&dp[i][j][0], &dp[i][j][4], 0LL), ans);
        }
    }
    cout << ans-3 << endl;
}

Measured memory_bytes: 129408
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////

void solve(){
  ini(N , Q);
  vi a(N); in(a);
  sort(all(a));
  rep(_ , Q){
    ini(l , r);
    auto il = lower_bound(all(a) , l);
    auto ir = upper_bound(all(a) , r);
    out((int)(ir - il));
  }
}


Measured memory_bytes: 3360
#include<cstdio>

int main()
{
    int x;
    while(~scanf("%d",&x))
    {
        printf("%d\n",x*x*x);
    }
    return 0;
}


/*
#include<cstdio>
#include<cmath>
#define mid ((left+right)>>1)
#define lson rt<<1,left,mid
#define rson rt<<1|1,mid+1,right
#define INF 2147483647

int min(int x,int y)
{
    return x>y?y:x;
}

int n,q;
int node[8<<1-1];

void init(int n_)
{
    for(int i=0;i<=n_*2;i++) node[i]=INF;
}

void print_tree(int n_)
{
    for(int i=1;i<=log(n_);i++)
    {
        int temp=1;
        int temp_=1;
        for(int j=0;j<i;j++) temp*=2;
        for(int j=0;j<log(n_);j++) temp_*=2;
        for(int j=0;j<temp_;j++) printf(" ");
        for(int j=1;j<=temp;j++)
        {
            printf("%d ",node);
        }
        printf("\n");
    }
}

int query(int rt,int left,int right,int L,int R)
{


}

void update(int rt,int left,int right,int target,int value)
{
    node[target+n-1]=value;
    int temp = target+n-1;
    while(1){
        temp=(temp-1)/2;
        if(temp<0) break;
        node[temp]=min(node[2*temp+1],node[2*temp+2]);
    }
}

int main()
{
    while(~scanf("%d%d",&n,&q))
    {
        init(n);
        for(int i=0;i<q;i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);

            printf("dsa");
            if(a==1) printf("%d\n",query(1,1,n,b,c));
            else update(1,1,n,b,c);
            //print_tree(n);
        }
    }
    return 0;
}


3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

*/

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <limits>

struct Item {
	unsigned int a;
	unsigned int b;
	size_t price;

	Item() = default;

	Item(unsigned int a, unsigned int b, size_t p) : a(a), b(b), price(p) {}
};

void traverse(size_t& min_price, const size_t N, const size_t Ma, const size_t Mb, const std::vector<Item>&,
              size_t next_min_item, size_t now_price, int a, int b);

int main() {
	size_t N, Ma, Mb;
	std::cin >> N >> Ma >> Mb;

	std::vector<Item> items;
	items.reserve(N);

	for (size_t i = 0; i < N; ++i) {
		unsigned int a, b, price;
		std::cin >> a >> b >> price;
		items.emplace_back(a, b, price);
	}

	size_t min_price = std::numeric_limits<size_t>::max();
	traverse(min_price, N, Ma, Mb, items, 0, 0, 0, 0);
	if (min_price == std::numeric_limits<size_t>::max()) {
		std::cout << -1 << std::endl;
	} else {
		std::cout << min_price << std::endl;
	}
}

void traverse(size_t& min_price, const size_t N, const size_t Ma, const size_t Mb, const std::vector<Item>& items,
              size_t next_min_item, size_t now_price, int a, int b) {
#if 0
	std::cerr << min_price << ',' << now_price << ',' << next_min_item << ',' << now_price << ',' << a << ',' << b
			  << std::endl;
#endif
	if (min_price <= now_price) {
		return;
	} else if (a != 0 && b != 0 && a % Ma == 0 && b % Mb == 0 && a / Ma == b / Mb) {
		min_price = now_price;
		return;
	} else if (next_min_item == N) {
		return;
	}

	traverse(min_price, N, Ma, Mb, items, next_min_item + 1, now_price, a, b);
	const Item& item = items[next_min_item];
	traverse(min_price, N, Ma, Mb, items, next_min_item + 1, now_price + item.price, a + item.a, b + item.b);
}


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

int cntday(int m, int d);
void disp(int n);

int main(){
	int month, day, n;
	while(cin >>month >>day){
		if(month == 0) break;
		n = cntday(month, day);
		disp(n);
	}
	return 0;
}

int cntday(int m, int d){
	int ans = d, month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	for(int i = 0; i < m - 1; i++){
		ans += month[i];
	}
	return ans;
}

void disp(int n){
	int cnt = n % 7;
	switch(cnt){
		case 0:
			cout <<"Wednesday" <<endl;
			break;
		case 1:
			cout <<"Thursday" <<endl;
			break;
		case 2:
			cout <<"Friday" <<endl;
			break;
		case 3:
			cout <<"Saturday" <<endl;
			break;
		case 4:
			cout <<"Sunday" <<endl;
			break;
		case 5:
			cout <<"Monday" <<endl;
			break;
		case 6:
			cout <<"Tuesday" <<endl;
	}
}

Measured memory_bytes: 0
/* ***************************************************
 *	Author        :mutinner
 *	Created Time  :2018年11月04日 星期日 20时49分20秒
 *	File Name     :20:49:20.cpp
 *************************************************** */

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

int main() {
	int a, b;
	while ( cin >> a >> b ) { cout << a + b / 2 << endl; }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n; char s[maxn];
queue<int> q;
int dp[maxn],lst;
ll ans;
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%s",s+1); n=strlen(s+1);
	for (int i=n;i>=1;i--) {
		if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') dp[i]=dp[i+3]+1;
		if (s[i]=='B'&&s[i+1]=='C') dp[i]=dp[i+2]+1;
		if (s[i]=='A'&&s[i+1]=='A') dp[i]=dp[i+1];
		if (s[i]=='A') ans+=dp[i];
	}
	printf("%lld\n",ans);
	return 0; ans=0;
	for (int i=1;i+2<=n;i++)
		if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') q.push(i);
	while (!q.empty()) {
		int u=q.front(); q.pop(); ans++;
		s[u]='B'; s[u+1]='C'; s[u+2]='A';
		if (s[u+3]=='B'&&s[u+4]=='C') q.push(u+2);
		if (s[u-1]=='A') q.push(u-1);
	} printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
long long val[4000][4000];
long long dp[3001][3001][4];
long long max_val(long long r,long long c, long long cnt)
{
	if(r<0 || c<0)
		return 0;
	if(dp[r][c][cnt]!=-1)
		return dp[r][c][cnt];
	long long c1=0, c2=0;
	if(cnt>0)
		c1 = max(max_val(r-1,c,3),max_val(r,c-1,cnt-1)) + val[r][c];

	c2 = max(max_val(r-1,c,3),max_val(r,c-1,cnt));
	dp[r][c][cnt] = max(c1,c2);
	return dp[r][c][cnt];
}
int main()
{
	long long r,c,k;
	cin>>r>>c>>k;
	for (int i = 0; i <= r; ++i)
	{
		for(int j = 0; j <= c ;j++)
		{
			for (int h = 0; h < 4; ++h)
			{
				dp[i][j][h] = -1;
			}
		}
	}
	for (long long i = 0; i < k; ++i)
	{
		long long x,y,v;
		cin>>x>>y>>v;
		val[x-1][y-1] = v;
	}

	cout<<max_val(r-1,c-1,3)<<endl;

	
	return 0;
}

Measured memory_bytes: 365500
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}

int main() {
    ll n;
    cin >> n;
    ll che [n][3];
    for(int i=0;i<n;i++){
        cin >> che[i][0]>>che[i][1]>>che[i][2];
    }
    ll dp[n+1][3];
    for(int i=0;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){                
                if(j==k)continue;
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]+che[i][j]);
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<3;i++){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;
}
    



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

using namespace std;

int main(void) {

    int N;
    cin >> N;

    long long a[3*N];
    for(int i = 0; i < 3*N; i++)
        cin >> a[i];

    sort(a, a+3*N, greater<int>());

    long long ans = 0;
    for(int i = 0; i <= 2*N; i++)
        if(i % 2 == 1)
            ans += a[i];

    cout << ans << endl;

    return 0;
}

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

int calc(long long int a,long long int b,long long int p);
int main(){
	const int MAX=100002;
	int n,W;
	int a[MAX],b[MAX]={};
	int one=INF,two=INF;
	cin>>n;
	for(int i=0;i<n+1;i++){
		cin>>a[i];
		b[a[i]]++;
		if(b[a[i]]==2){
			W=a[i];
		}
	}
	for(int i=0;i<n+1;i++){
		if(a[i]==W){
			if(one==INF)
				one=i;
			else
				two=i;
		}
	}
	//階乗の表
	ll kaijou[MAX],gyaku[MAX];
	for(int i=0;i<MAX;i++){
		kaijou[i]=i;
	}
	for(int i=2;i<MAX;i++){
		kaijou[i]=kaijou[i-1]*kaijou[i]%MOD;
		//cout<<kaijou[i]<<endl;
	}
	kaijou[0]=1;
	//逆元の表
	for(int i=1;i<MAX;i++){
		gyaku[i]=calc(kaijou[i],MOD-2,MOD);
		//cout<<gyaku[i]<<endl;
	}
	gyaku[0]=1;
	//処理
	for(int k=1;k<=n+1;k++){
		ll pata=0,patb=0;
		pata=kaijou[n+1]*gyaku[k]%MOD*gyaku[n+1-k]%MOD;
		if(n+one-two<k-1){
			patb=0;
		}
		else{
			patb=kaijou[n+one-two]*gyaku[k-1]%MOD*gyaku[n+1+one-two-k]%MOD;
		}
		//cout<<patb<<endl;
		cout<<(pata+MOD-patb)%MOD<<endl;
	}

	return 0;
}

 
int calc(long long int a,long long int b,long long int p){
	if(!b) return 1;
	else if(!(b%2)){
		long long int d=calc(a,b/2,p);
		return (d*d)%p;
	}else return (a*calc(a,b-1,p))%p;
}

Measured memory_bytes: 3584
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    def prime_factor(n):
        lst = []
        while n%2 == 0:
            n //= 2
            lst.append(2)
        f = 3
        while f**2 <= n:
            if n%f == 0:
                n //= f
                lst.append(f)
            else:
                f += 2
        if n != 1:
            lst.append(n)
        return lst


    a, b = LI()
    g = math.gcd(a, b)

    prm = prime_factor(g)

    ans = len(set(prm)) + 1

    print(ans)

main()


Measured memory_bytes: 10116
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int hulf,len,dis=0;
    string in;
    cin>>in;
    len=in.size();
    if(in.size()%2==0){
        hulf = in.size()/2;
    }else{
        hulf = in.size()/2+1;
    }
    for(int i=0;i<hulf;i++){
        if(in[i]!=in[len-1-i]){
            ++dis;
        }
    }
    cout<<dis;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
#include <ctime>
#include <unordered_set>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
const int N = 2e5 + 11, K = 20;
const int mod = 1e9 + 7;
int arr[N];
int main()
{
#ifndef ONLINE_JUDGE
	//freopen("inp.txt", "r", stdin);
#endif
	int n , m; cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i);
		sum += arr[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (arr[i] * (4 * m)  >= sum)
		{
			cnt++;
		}
	}
	if (cnt >= m)
		puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sz(x) (sizeof(x)/sizeof(*x))
#define F first
#define S second


int main(){
    //ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    double a,b,t,sum=0;
    cin>>a>>b>>t;
    
    cout<<int((t+0.5)/a)*b<<endl;
//    system("pause");
    return 0;
}

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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

signed main()
{
    int n, k;
    
    static int a[100010], sum[100010];

    while (cin >> n >> k, n) {
        rep(i, n) cin >> a[i];

        for (int i = 0; i < n; ++i) sum[i + 1] = a[i] + sum[i];

        int ma = -1e9;

        rep(i, n - k + 1) {
            ma = max(ma, sum[i + k] - sum[i]);
        }

        cout << ma << endl;
    }
}

Measured memory_bytes: 3740
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	e := -1 << 50
	dp := make([][3]int, n+5)
	for i := 1; i < n+5; i++ {
		for j := 0; j < 3; j++ {
			dp[i][j] = e
		}
	}
	dp[1][0] = a[0]
	a = append(a, e, e, e, e, e)
	for i := 0; i < n; i++ {
		dp[i+2][0] = max(dp[i+2][0], dp[i][0]+a[i+1])
		dp[i+3][1] = max(dp[i+3][0], dp[i][0]+a[i+2])
		dp[i+4][2] = max(dp[i+4][0], dp[i][0]+a[i+3])
		dp[i+2][1] = max(dp[i+2][1], dp[i][1]+a[i+1])
		dp[i+3][2] = max(dp[i+3][2], dp[i][1]+a[i+2])
		dp[i+2][2] = max(dp[i+2][2], dp[i][2]+a[i+1])
	}

	if n&1 == 1 {
		fmt.Fprintln(wr, max(dp[n-2][0], max(dp[n-1][1], dp[n][2])))
	} else {
		fmt.Fprintln(wr, max(dp[n-1][0], dp[n][1]))
	}

}


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

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b  %a, a);
}

ll lcm(ll a, ll b){
	return (a*b) / gcd(a, b);
}

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

	ll n,k,i,j;

	cin >> n >> k;
	vector <ll> v(n);

	for(i=0;i<n;i++)
	{
		cin >> v[i];
	}

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

	ll sum = 0;

	for(i=0;i<k;i++)
		sum += v[i];

	cout << sum << endl;

}

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

int A, B, X;

int main()
{
  scanf("%d%d%d", &A, &B, &X);
  
  bool isok = X >= A && X <= A + B;
  
  if (isok) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 1660
def main():
    N, D = map(int, input().split())
    count = 0
    for n in range(N):
        X, Y = map(int, input().split())

        if X**2 + Y**2 <= D**2:
            count += 1
    
    print(count)


if __name__ == '__main__':
    main()

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

typedef unsigned long long ull;
typedef long long ll;

const int M = (int)2e5;
const int N = (int)5e5;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;
const double eps = 1e-6;

int n, a[M + 5];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    ll sum = 0, ans = 0;
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), sum = (sum + a[i]) % mod;
    for(int i = 1; i <= n; ++i)
    {
        sum = (sum - a[i]) % mod;
        ans = (ans + sum * a[i] % mod) % mod;
    }
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4536
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,ans=0;
    bool s=0;
    cin>>n>>m;
    for(int i=n;i<=m;i++){
        if(i<0)
            ans++;
        if(i==0)
            s=1;
    }
    if(s)
        cout<<"Zero"<<endl;
    else{
        if(ans%2==0)
            cout<<"Positive"<<endl;
        else
            cout<<"Negative"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var t1 = n / 3600;
        var t2 = (n - t1 * 3600) / 60;
        var t3 = (n - t1 * 3600 - t2 * 60);
        Console.WriteLine("{0}:{1}:{2}", t1, t2, t3);
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

ll modPow(int a,int n,int mod){
    if(n==1)return (a%mod);
    if(n%2==1) return (a*modPow(a,n-1,mod))%mod;
    ll t=modPow(a,n/2,mod);
    return (t*t)%mod;
}

int main(){
    int m,n;
    cin>>m>>n;
    cout<<modPow(m,n,INF)<<endl;
    return 0;
}

//a=97,z=122


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

using namespace std;

int main(){
    long N, M, C;
    cin>>N>>M>>C;

    vector<long> B(M);
    for(int i=0; i<M; ++i){
        cin>>B[i];
    }

    int ans=0;
    int sum;
    int A;
    for(int i=0; i<N; ++i){
        sum = C;
        for(int j=0; j<M; ++j){
            cin>>A;
            sum += A * B[j];
        }
        if(sum>0){
            ans+=1;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

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

    string s = "";
    rep(i,n) s += "0";
    int ll = 0, rr = 100000;
    rep(i,m) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        ll = max(ll,l);
        rr = min(rr,r);
    }

    if (rr >= ll)
        cout << rr - ll + 1<< endl;
    else
        cout << 0 << endl;

    return 0;
}


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

using namespace std;
#define rep(j,n) for(int j=0;j<(n);j++)

using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main(int, char**)
{
  int n;
  cin >> n;

  ll ans = 0;
  for (ll j = 1; j <= n; j++) {
    ll nn = n / j;
    ans += j * nn * (nn+1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL N;
    LL W;
    cin >> N >> W;
    vector<LL> w(N);
    vector<LL> v(N);
    for(LL i=0; i<N; i++){
        cin >> w[i] >> v[i];
    }
    vector<vector<vector<LL>>> dp(3*N+1, vector<vector<LL>>(N+1, vector<LL>(N+1, 0)));
    for(LL i=1; i<=N; i++){
        for(LL j=1; j<=i; j++){
            for(LL k=0; k<=3*N; k++){
                dp[k][j][i]=dp[k][j][i-1];
                if(w[i-1]-w[0]>k){
                    continue;
                }
                if(j*w[0]+k>W){
                    continue;
                }
                dp[k][j][i]=max(dp[k][j][i], dp[k-(w[i-1]-w[0])][j-1][i-1]+v[i-1]);
                //if(i==2){
                //    cout << v[i] << " " << dp[k][j][i] << endl;
                //}
            }
        }
    }

    LL ans=0;
    for(LL i=0; i<=N; i++){
        for(LL j=0; j<=3*N; j++){
            ans=max(ans, dp[j][i][N]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] cost = new int[M];
    int[] keys = new int[M];
    for (int i = 0; i < M; i++) {
      cost[i] = scanner.nextInt();
      int b = scanner.nextInt();
      for (int j = 0; j < b; j++) keys[i] |= 1 << scanner.nextInt() - 1;
    }

    int INF = 1000_000_000;
    int[] dp = new int[1 << N];
    Arrays.fill(dp, INF);
    dp[0] = 0;
    for (int i = 0; i < 1 << N; i++)
      if (dp[i] < INF)
        for (int j = 0; j < M; j++)
          dp[i | keys[j]] = Math.min(dp[i | keys[j]], dp[i] + cost[j]);
    if (dp[(1 << N) - 1] >= INF) System.out.println(-1);
    else System.out.println(dp[(1 << N) - 1]);
  }
}


Measured memory_bytes: 31720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String o = sc.next();
		String e = sc.next();

		for (int i = 0; i < o.length(); i++) {
			System.out.print("" + o.charAt(i) + (i < e.length() ? e.charAt(i) : ""));
		}
		System.out.println();
		sc.close();
	}

}


Measured memory_bytes: 21588
K, X = list(map(int, input().split()))
minimum = X - (K-1)
MAXIMUM = X + (K-1)
if minimum < -1000000:
  minimum = -1000000
if MAXIMUM > 1000000:
  MAXIMUM = 1000000
  
for x in range(minimum,MAXIMUM+1):
  print(str(x), end=" ")
  
print()

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

int n;
int ans = 0; 

int main(){
  cin >> n;
  vector<int> v(n), c(n);
  rep(i, n) cin >> v.at(i);
  rep(i, n) cin >> c.at(i);
  rep(i, n){
    if(v.at(i) - c.at(i) > 0) ans += (v.at(i)-c.at(i));
  }
  
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,a[n],now;
    map<lli,lli> mp;
    lli sum=0;
    
    for(i=0;i<n;i++) cin>>a[i], mp[a[i]]++, sum+=a[i];
    
    lli q;
    cin>>q;
    while(q--)
    {
        lli b,c;
        cin>>b>>c;
        
        now=mp[b];
        mp[b]=0;
        mp[c]+=now;
        
        sum+=(now*(c-b));
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 10308
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
                break;
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
}


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

const int len = 393;
int main(){
  int n;
  cin >> n;
  vector<int> dp(len+1,-1);
  dp[0] = 0;

  rep(i,n){
    int s,l,p;
    cin >> s >> l >> p;
    rep(j,len+1){
      for(int t=s;t<=l;t++){
	if(j+t<=len){
	  dp[j+t] = max(dp[j+t], dp[j] + p);
	}
      }
    }
  }

  int m;
  cin >> m;
  vector<int> ans(m);
  rep(i,m){
    int w;
    cin >> w;
    if(dp[w]<0){
      cout << -1 << endl;
      return 0;
    }
    ans[i] = dp[w];
  }
  rep(i,m)cout << ans[i] << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

vector<int> unlock[1000000];
int neednum[1000000];

int main() {
    int n;
    cin >> n;
    fill(neednum, neednum + 1000000, 0);
    rep(i, n) {
        int before;
        cin >> before;
        before--;
        rep(j, n - 2) {
            int a;
            cin >> a;
            a--;
            int x = min(i, before);
            int y = max(i, before);
            int z = min(i, a);
            int w = max(i, a);
            unlock[x * 1000 + y].push_back(z * 1000 + w);
            neednum[z * 1000 + w]++;
            before = a;
        }
    }

    set<int> ok;
    rep(i, n) {
        for(int j = i + 1; j < n; j++) {
            if(neednum[i * 1000 + j] == 0) ok.insert(i * 1000 + j);
        }
    }

    int ans = 0;
    int nokori = n * (n - 1) / 2;
    while(nokori > 0) {
        ans++;
        set<int> used;
        vector<int> usd;
        vector<int> unl;
        if(ok.empty()) {
            cout << -1 << endl;
            return 0;
        }
        for(int x : ok) {
            int a = x / 1000;
            int b = x % 1000;
            if(used.find(a) != used.end() || used.find(b) != used.end()) continue;
            nokori--;
            usd.push_back(x);
            used.insert(a);
            used.insert(b);
            for(int y : unlock[x]) {
                neednum[y]--;
                if(neednum[y] == 0) unl.push_back(y);
            }
        }
        for(int x : usd) {
            ok.erase(x);
        }
        for(int x : unl) {
            ok.insert(x);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 43264
#include <iostream>

using namespace std;
long long x,ans = 0;
int main(){
    int i,n,res = 0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x;
        if(res && x){
            x--; res--; ans++;
        }
        res = 0;
        ans += x/2;
        if(x&1) res = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
l = []
for i in range(Q):
  l.append(list(map(int, input().split())))

A_N = [[i] for i in range(1, M+1)]
for i in range(N-1):
  a = []
  for j in range(len(A_N)):
    last = A_N[j][-1]
    for k in range(last, M+1):
      a.append(A_N[j] + [k])
  A_N = a

high_score = 0
for i in range(len(A_N)):
  A = A_N[i]
  score = 0
  for j in range(len(l)):
    aj, bj, cj, dj = l[j]
    if A[bj-1]-A[aj-1] == cj:
      score += dj
  if high_score < score:
    high_score = score 

print(high_score)

Measured memory_bytes: 30544
def main():
    s = input()

    l = 0
    r = len(s) - 1

    ans = 0
    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
            continue

        if s[l] == 'x':
            l += 1
            ans += 1
            continue

        if s[r] == 'x':
            r -= 1
            ans += 1
            continue

        print(-1)
        return

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int oo = 1e9;

#define mp make_pair
#define pb push_back
#define x first
#define y second
const int MAX = 2000001;
const int MOD = 998244353;
int n , aa , b;;

void solve(int a , int b , int v){
  if(a == b){
    if(a!=aa)printf(" ");
    printf("%d", a);
    return;
  }
  int x = (a^b)&(-(a^b));
  v ^= x;
  int y = (v&(-v));
  solve(a,a^y,v);
  solve(a^x^y,b,v);
}
int ccnt(int x){
  int ct = 0;
  while(x){
    ct += (x&1);
    x/= 2;
  }
  return ct;
}
int main() {
  cin >> n >> aa >> b;
  if(ccnt(aa)%2 == ccnt(b)%2){
    puts("NO");
    return 0;
  }
  puts("YES");
  solve(aa,b,(1<<n)-1);
  puts("");
  return 0;
}


Measured memory_bytes: 1024