akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

struct State{
    int lower,size,rest;
    State(int lower,int size,int rest) : lower(lower),size(size),rest(rest) {};
};

int main(){
    vector<int> v;
    vector<int> odd;
    for(int i=1;;i++){
        int c = i*(i+1)*(i+2)/6;
        if(c > 1000000) break;
        v.push_back(c);
        if(c % 2 == 1) odd.push_back(c);
    }
    int M = 1000010;
    vector<int> answer(M,1 << 30);
    vector<int> answer_odd(M,1 << 30);
    answer[0] = 0;
    answer_odd[0] = 0;
    for(int i=0;i<M;i++){
        int nex;
        for(int j=0;j<v.size() && (nex=i+v[j]) < M;j++){
            answer[nex] = min(answer[i] + 1,answer[nex]);
        }
        for(int j=0;j<odd.size() && (nex=i+odd[j]) < M;j++){
            answer_odd[nex] = min(answer_odd[i] + 1,answer_odd[nex]);
        }
    }

    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        cout << answer[n] << " " << answer_odd[n] << endl;
    }
    return 0;
}

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

struct sorter{
	bool operator()(const pair<string, int> & a, const pair<string, int> & b){
		if(a.first == b.first){
			return a.second > b.second;
		}
		else{
			return a.first < b.first;
		}
	}
};
int main(){
	int n, p;
	cin>>n;
	string s;
	vector<pair<string, int> > x;
	map<pair<string, int>, int> m;
	for(int i = 0; i < n; ++i){
		cin>>s>>p;
		x.push_back(make_pair(s, p));
		m[x[i]] = i + 1;
	}
	sort(x.begin(), x.end(), sorter());
	for(auto xp : x){
		cout<<m[xp]<<endl;
	}
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	ll n,p;
	cin >> n >> p;

	map<ll,ll> primes;
	for(ll i = 2LL; i*i <= p; ++i){
		ll cnt = 0LL;
		while(p % i == 0){
			p /=i, cnt++;
		}
		if(cnt != 0) primes[i] = cnt;
	}

	if(p != 1) primes[p] = 1LL;

	ll ans = 1LL;
	for(auto &elem:primes){
		const ll num = elem.second / n;
		rep(loop,num) ans *= elem.first;
	}
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

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

    ll n, resp=(ll)1e18;
    cin >> n;
    
    for (ll i = 1; i*i <= n; i++){
        if (n % i == 0){
            resp = min(resp, i + (n/i) - 2);
        }
    }
    cout << resp << endl;

}

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


int main(){
int n;
cin >> n;
vector<int>a(n);
rep(i,n) cin >> a[i];
  bool isOK = true;
rep(i,n){
    if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0) isOK= false;
}
if(isOK) cout<<"APPROVED"<<endl;
else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define MAX_N 200005

//Union-Findtree
struct UF {
	int par[MAX_N];//親
	int Rank[MAX_N];//木の深さ

	//初期化
	void init(int n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			Rank[i] = 0;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return 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]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
		}
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int n, k, l;
	cin >> n >> k >> l;
	vector<int>p(k), q(k), r(l), s(l);
	UF tree1, tree2;
	tree1.init(n); tree2.init(n);
	int a, b;
	for (int i = 0; i < k; ++i) {
		cin >> a >> b;
		a--; b--;
		p[i] = a; q[i] = b;
	}
	for (int i = 0; i < l; ++i) {
		cin >> a >> b;
		a--; b--;
		r[i] = a; s[i] = b;
	}
	for (int i = 0; i < k; ++i)tree1.unite(p[i], q[i]);
	for (int i = 0; i < l; ++i)tree2.unite(r[i], s[i]);
	map<pair<int, int>, int>count;
	for (int i = 0; i < n; ++i) {
		++count[make_pair(tree1.find(i),tree2.find(i))];
	 }
	vector<int>ans(n);
	for (int i = 0; i < n; ++i) {
		ans[i]= count[make_pair(tree1.find(i), tree2.find(i))];
	}
	for (int i = 0; i < n; ++i) {
		if (i)cout << " ";
		cout << ans[i];
	}cout << endl;
	return 0;
}

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

#define ll long long int
#define ld long double
#define pb push_back
#define pq priority_queue
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vll vector<ll>
#define MODNUM 1000000007
#define lp(i,a,b) for(ll i=a; i<b; i++)

using namespace std;

ll mex(ll a, ll b, ll m) {
	if(b==0) return 1;
	if(b%2) return a*mex((a*a)%m,(b-1)/2,m)%m;
	else return mex((a*a)%m,b/2,m);
}

int x,y;
void exteu(ll a, ll m) {
	if(m==0) { x=1;y=0; }
	else {
		exteu(m,a%m);
		ll temp = x;
		x=y;
		y=temp-(a/m)*y;
	}
}

ll fact(ll n) 
{	ll prod=1;
	for(ll i=2; i<=n; i++) {
		prod*=i;
	}
	return prod;
}

ll gcd(ll a, ll b) {
	if(b==0) return a;
	return gcd(b, a%b);
}
// 2 2 2 7
// 2 2 2 3 3
// 3 3 7

// 3
// 2 
// 3 3
bool isprime[200001];
void makesieve() {
	memset(isprime, true, sizeof(isprime));
	for (int i = 2; i <= sqrt(200000); ++i)
	{
		/* code */
		if(isprime[i]) {
			for (int j = i*i; j <= 200000; j+=i)
			{
				/* code */
				isprime[j]=false;
			}
		}
	}
}
// 1001100110011001
void solve() {
	ll n; cin>>n;
	ll nc = n;
	ll ans=0;
	for (ll i = 2; i <= sqrt(nc) && n; ++i)
	{
		ll pn=0;
		while(n%i==0 && n) {pn++;n/=i;}
		ans += (sqrt(1+8*pn)-1)/2;
	}
	if(n && n!=1) ans++;
	cout<<ans;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin >> TESTS;
	// makesieve();
	while(TESTS--) {
		solve();
	}
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A > B) {
    cout << A + max( A-1 , B ) << endl; 
  }
  else {
    cout << B + max( A , B-1 ) << endl; 
  }
}


Measured memory_bytes: 256
n,k,*a=map(int,open(0).read().split());s=t=0;r=range(n)
for i in r:
 for j in r:s+=j>i and a[j]<a[i];t+=a[j]<a[i]
print((s*k+k*~-k//2*t)%(10**9+7))

Measured memory_bytes: 3188
str = input().split()
a = int(str[0])
b = int(str[1])
c = int(str[2])
d = int(str[3])
num = 0
while num == 0 :
    c = c - b
    if c <= 0:
        print("Yes")
        break
    a = a - d
    if a <= 0:
        print("No")
        break

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

#define N 3
#define N2 9
#define MAX 500000

typedef struct Puzzle{
  int f[N2];
  int space;
  int path;
} Puzzle ;

int bfs(Puzzle s);
void swap(int x, int y);
void enqueue(Puzzle x);
int sort(Puzzle p);
int isTarget(Puzzle p);

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

int main(){
  Puzzle in;
  int ans;

  for(int i = 0; i < N2; i++){
    scanf("%d",&in.f[i]);
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
	

   ans = bfs(in);
  printf("%d\n",ans);

  return 0;
}

void swap(int x, int y){
  int z;
  z = x;
  x = y;
  y = z;
}


struct Puzzle Q[MAX];
int head = 0, tail = 0;

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

Puzzle dequeue(){
  Puzzle t; 
  t = Q[head];
  head = (head+1)%MAX;
  return t;
}

int sort(Puzzle p){
  int i, j, key, count, n = 0;
  for(i = 0, key = 1; i < N2; key *= ++i){
    for(j = 0, count = 0; j < i; j++){
      if(p.f[j] < p.f[i])count++;
    }
    n += count * key;
  }
  return n;
}

int isTarget(Puzzle p){
  for(int i = 0; i < N2; i++){
  	if(p.f[i] != (i+1)) return 0;
  }
  return 1;
}

int bfs(Puzzle s){
  struct Puzzle u, v;
  s.path = 0;
  enqueue(s);
  V[sort(s)] = 1;
  

  while(head != tail){ 
  int sx, sy, tx, ty, num, r;
    u = dequeue();
    if(isTarget(u) )return u.path;
     sx = u.space / N;
     sy = u.space % N;
    for(int r = 0; r < 4; r++){
       tx = sx + dx[r];
       ty = sy + dy[r];
      if(tx < 0 || ty < 0 || tx >= N || ty >= N)continue;
      v = u;
       num = v.f[u.space];
      v.f[u.space] = v.f[tx * N + ty];
      v.f[tx * N + ty] = num;
      v.space = tx * N + ty;
      if(V[sort(v)] != 1){
	V[sort(v)] = 1;
	v.path++;
	enqueue(v);
      }
    }
  }

  return -1;
}






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

int main()
{
  int i, j, a[4][13], N, x;
  char A;
  cin >> N;

  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      a[i][j] = 0;

  for(i=0;i<N;i++)
    {
      cin >> A >> x;
      if(A=='S') a[0][x-1]=1;
      if(A=='H') a[1][x-1]=1;
      if(A=='C') a[2][x-1]=1;
      if(A=='D') a[3][x-1]=1;
    }

  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      {
	if(a[i][j]==0)
	  {
	    if(i==0) cout << "S " << j+1 << endl;
	    if(i==1) cout << "H " << j+1 << endl;
	    if(i==2) cout << "C " << j+1 << endl;
	    if(i==3) cout << "D " << j+1 << endl;
	  }
      }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int a[100060];
int gcd(int a,int b){
    return a%b==0?b:gcd(b,a%b);
}
int main()
{
    int n,minz=0x3f3f3f3f;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        minz=min(minz,a[i]);
    }
    int ans=a[0];
    for(int i=1;i<n;i++){
        ans=gcd(ans,a[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}

struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

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

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    void dfs(int v, vector<Pii> &P, vector<bool> &checked, Pii p, bool &f, int &x0){
        if(!checked[v]){
            checked[v] = true;
            P[v] = p;

            REP(k, G[v].size()) dfs(G[v][k].to, P, checked, Pii(G[v][k].cost - p.first, -p.second), f, x0);

        }else if(P[v] != p){
            if(f){
                f = false;
                if(P[v].second == p.second || (P[v].first - p.first) % (p.second - P[v].second) != 0){
                    x0 = -INF;
                }else{
                    x0 =  (P[v].first - p.first) / (p.second - P[v].second);
                }
            }else if(x0 != -INF){
                if(p.first + p.second * x0 != P[v].first + P[v].second * x0) x0 = -INF;
            }
        }

    }

};

signed main(){

    int n, m; cin >> n >> m;
    vec u(m), v(m), s(m);
    Graph G(n);
    REP(i, m){
        cin >> u[i] >> v[i] >> s[i];
        u[i]--; v[i]--;
        G.add_edge2(u[i], v[i], s[i]);
    }
    vector<Pii> P(n);
    vector<bool> checked(n, false);
    int x0 = 0;
    bool f = true;
    G.dfs(0, P, checked, Pii(0, 1), f, x0);
    if(f){
        int xmin = -INF, xmax = INF;
        REP(i, n){
            if(P[i].second == 1) xmin = max(xmin, -P[i].first + 1);
            else xmax = min(xmax, P[i].first - 1);
        }

        cout << max(0LL, xmax - xmin + 1);
    }else{
        if(x0 == -INF) cout << 0;
        else{
            f = true;
            REP(i, n) if(P[i].first + P[i].second * x0 <= 0) f = false;
            if(f) cout << 1;
            else cout << 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 15872
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    int n, m;
    while (2 == scanf("%d%d", &n, &m)) {
        printf("%d %d\n", __gcd(n, m), n / __gcd(n, m) * m);
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  
  int count=1;
  int pre = d.at(0);
  for(int i=0; i<d.size(); i++){
    if(pre > d.at(i)){
      count++;
    }
    pre = d.at(i);
  }
  
  cout << count << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int a,b,k;cin>>a>>b>>k;
  int result=0;
  rep(i,b-a+1){
    if(i+a<a+k || i+a>b-k)cout<<i+a<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import itertools
N,D = map(int,input().split())
array = [ list(map(int,input().split())) for x in range(N) ]

if not ( 2 <= N <= 10 and 1 <= D <= 10 ): sys.exit()
for I in array:
    if not ( -20 <= min(I) and max(I) <= 20 ): sys.exit()

count = 0
for I in list(itertools.combinations(array,2)):
    tmp_distance = 0
    for J in range(D):
        tmp_distance += abs(I[0][J] - I[1][J]) ** 2
    distance = tmp_distance ** 0.5 
    if distance.is_integer(): count += 1

print(count)

Measured memory_bytes: 9476
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {    
    int X;
    cin >> X;
    //X = min(X, 180-X);
    
    for (int k=1; true; k++){
        if ((k*X)%360 == 0){
            cout << k << endl;
            return 0;

        }
    }

}


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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector< vector< vector<int> > > a(4,vector< vector<int> >(3,vector<int>(10,0)));
	int b,f,r,v;
	for (int i = 0; i < n; ++i) {
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 10; ++k) {
				cout << " " << a[i][j][k]; 
			}
			cout << endl;
		}
		if (i < 3) {
			cout << "####################" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
 
int main() {
    int H,W ;
    cin >> H >> W;
    char array[H][W];
    char unko = '#';
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> array[i][j];
        }
    }
    for(int i=0;i<H+2;i++){
        if((i==0)||(i==H+1)){
            for(int j=0;j<W+2;j++){
                cout << unko;
            }
            cout << endl;
        }
        else{
            cout << unko;
            for(int j=0;j<W;j++)
                cout << array[i-1][j];
            cout << unko << endl;
        }
    }

}


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

int main(void){
    int n;
    cin >> n;
    bool ok = false;
    for (int i = 1; i < 10; i++) {
        if (n%i==0 && n/i < 10) ok = true;
    }
    cout << ((ok) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
fin = sys.stdin.readline
from heapq import heappop, heappush
from collections import defaultdict


N, K = [int(elem) for elem in fin().split()]
sushi_info = sorted([tuple(int(elem) for elem in fin().split()) for _ in range(N)], key=lambda x: -x[1])


cur_eaten = []
# cur_rest = []
count = defaultdict(int)
for t, d in sushi_info[:K]:
    if count[t] >= 1:
        heappush(cur_eaten, (d, t))
    count[t] += 1


# for t, d in sushi_info[K:]:
#     heappush(cur_rest, (-d, t))

num_distinctive_kinds = sum(v >= 1 for v in count.values())
satisfactions = [sum(d for _, d in sushi_info[:K]) + num_distinctive_kinds**2]

cur_num_kinds = num_distinctive_kinds
for i in range(K, N):
    if count[sushi_info[i][0]] >= 1:
        continue
    if not cur_eaten:
        break
    ditched_d, ditched_t = heappop(cur_eaten)
    added_t, added_d = sushi_info[i]
    # added_d *= -1
    count[ditched_t] -= 1
    count[added_t] += 1
    cur_num_kinds += 1
    satisfactions.append(satisfactions[-1] - ditched_d + added_d + cur_num_kinds * 2 - 1)

print(max(satisfactions))


Measured memory_bytes: 73692
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

ll dp[1000][1001];
ll a[1000];
ll sum[1001];
int main() {
  int n,w;
  while(cin>>n>>w,n||w) {
    sum[0] = 0;
    REP(i,n) {
      cin >> a[i];
      sum[i+1] = sum[i] + a[i];
    }
    REP(i,n)REP(j,n+1)dp[i][j]=INF;
    dp[0][0] = 0;
    for (int i=0; i<n; ++i) {
      for (int j=i; j<n; ++j) {
        // cout << dp[i][j] << " ";
        dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
        // cout << "(" << sum[j]-sum[i] << ")  ";
        dp[j][j+1] = min(dp[j][j+1], dp[i][j]+abs((sum[j]-sum[i])-w));
      }
      // cout << endl;
    }
    ll ans = 1LL<<60;
    for (int i=0;i<n; ++i)
      ans = min(ans, dp[i][n]+max(0LL,(sum[n]-sum[i])-w));
    static int cs = 1;
    printf("Case %d: %lld\n", cs++, ans);
  }
}

Measured memory_bytes: 8992
#include<iostream>

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

int main(){

  string s, t, u; cin>> s>> t>> u;

  cout<< (char)(s[0]-'a'+'A')<< (char)(t[0]-'a'+'A')<< (char)(u[0]-'a'+'A')<< endl;

  return 0;
}


Measured memory_bytes: 256
class BIT(object):
    def __init__(self, size):
        self.size = size
        self.bit = [0] * (self.size + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += i & -i

    def __str__(self):
        return str(self.bit)

n, m = map(int,input().split())
lr = [[] for i in range(m + 1)]
for i in range(n):
    l, r = map(int,input().split())
    lr[r - l + 1].append(l)

bit = BIT(m + 1)
t = 0
for d in range(1, m + 1):
    for l in lr[d]:
        #print(l, l + d)
        bit.add(l, 1)
        #print(bit.bit)
        bit.add(l + d, -1)
        #print(bit.bit)

    t += len(lr[d])
    ans = n - t

    cur = 0
    while cur <= m:
        ans += bit.sum(cur)
        cur += d

    print(ans)

Measured memory_bytes: 81056
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<vector<LL>> VVL;
typedef vector<string> VS;

#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL llRead(){
  LL a;
  cin >> a;
  return a;
};

string stringRead(){
  string a;
  cin >> a;
  return a;
};

vector<LL> vlRead(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> vsRead(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> vvlRead(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, VL& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, VS& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, VVL& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, char* s) {
  cout << line << ":" << name << ":char* " << s << endl;;
}
void debug1(LL line, const char* name, vector<const char*>& v) {
  cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, priority_queue<LL>& p) {
  cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") ";
  priority_queue<LL> copy = p;
  while(!copy.empty()) {
    cout << copy.top() << " ";
    copy.pop();
  }
  cout << endl;
}
void debug1(LL line, const char* name, vector<pair<LL,LL>>& v) {
  cout << line << ":" << name << ":vector<pair<LL,LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i).first << "," << v.at(i).second << " ";
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto n = llRead();
  auto s = stringRead();

  if (n%2 !=0) {
    cout << "No" << endl;
    exit(0);
  }

  auto nh = n/2;
  for (LL i=0;i<nh;i++){
    if (s[i] != s[i+nh]) {
      cout << "No" << endl;
      exit(0);
    }
  }
      cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int d = a - b;
    int rem = c-d;
    if(rem <= 0)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << rem << endl;
    }
    return 0;
}


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

int main() { 
  string n;
  cin >> n;
  string ans = "Yes";
 
for (int i=0; i<n.size(); i++){
  if(i%2 == 0 && n.at(i) == 'L') ans ="No";
  
  if(i%2 == 1 && n.at(i) == 'R') ans = "No";
}


 cout << ans << endl;
  
  return 0;
}

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

string S;

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

	ll ans1 = 0, ans2 = 0, cur = 1;
	cin >> S;
	for (ll i = 0; i < S.length(); i++) {
		ll x = S[i] - '0';
		if (x != cur) ans1++;
		if (x != 1-cur) ans2++;
		cur = 1-cur;
	}
	cout << min(ans1, ans2) << "\n";

}

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

using namespace std;

const int MOD=1e9+7;

int n;
string s;
int dp[3005][3005];

int main()
{
    cin >> n >> s;
    dp[1][1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(s[i-2]=='<')
                dp[i][j]=dp[i-1][j-1];
            else
                dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+MOD)%MOD;
        }
        for(int j=2;j<=i;j++)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=MOD;
        }
    }
    long long ans=0;
    for(int i=1;i<=n;i++) {ans+=dp[n][i]; ans%=MOD;}
    cout << dp[n][n] << endl;
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mx 1000000
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL);

      ll a,b,c=0;
      cin>>a;


      if(a>=400 and a<=599) cout<<8<<endl;
       if(a>=600 and a<=799) cout<<7<<endl;
        if(a>=800 and a<=999) cout<<6<<endl;
         if(a>=1000 and a<=1199) cout<<5<<endl;
          if(a>=1200 and a<=1399) cout<<4<<endl;
           if(a>=1400 and a<=1599) cout<<3<<endl;
            if(a>=1600 and a<=1799) cout<<2<<endl;
             if(a>=1800 and a<=1999) cout<<1<<endl;




  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
using namespace std;
int main(void)
{
  int n,p,t;
  vector<long> v;
  
  cin >> n;
  for(int i = 0;i < n;i++)
  {
    int a;
    cin >> a;
    v.push_back(a);
  }
  v.push_back(1000000001);
  p = 0;
  t=0;
  for(int i = 0;i < n;i++)
  {
    if(v[i] >= v[i+1])
      p++;
    else
    {
      if(t<p)
	  	t = p;
      p=0;
    }
  }
cout << t;
}

Measured memory_bytes: 1400
s = input()
n = len(s)
k = int(input())
dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
for a in range(n):
    for b in range(k + 1):
        for c in range(2):
            nd = int(s[a])
            for d in range(10):
                na, nb, nc = a + 1, b, c
                if 0 != d:
                    nb += 1
                if k < nb:
                    break
                if 0 == nc:
                    if nd > d:
                        nc = 1
                    if nd < d:
                        break
                dp[na][nb][nc] += dp[a][b][c]
print(sum(dp[-1][-1]))


Measured memory_bytes: 3064
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        public static int Solve(int A, int B)
        {
            return new int[] { A * 2 - 1, B * 2 - 1, A + B }.Max();
        }

        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(Solve(ab[0], ab[1]));
        }
    }
}


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

using namespace std;

int main() {
	int k;
	scanf("%d", &k);
	
	long long res = 0;
	
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int ii = 1; ii <= k; ii++) {
				int gcd = __gcd(i, j);
				gcd = __gcd(gcd, ii);
				res += gcd;
			}
		}
	}
	
	printf("%lld\n", res);
}


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

int main(){
  int n, x0, y0, x1, y1, t0, t1;
  int kyori, jikan;
  x1=0; y1=0; t1=0;
  cin >> n;
  int ans=0;
  rep(i,n){
    cin >> t0 >> x0 >> y0;
    kyori = abs(x0 - x1) + abs(y0 - y1);
    jikan = t0 - t1;
    x1=x0; y1=y0; t1=t0;
    if(kyori > jikan || kyori%2 != jikan%2){
      ans = 0;
    }else{
      ans = 1;
    }
  }
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
    char s[20] = "";
    scanf("%s", s);
    int ans = 0, cur = 0;
    int n = strlen(s);
    for (int i = 0; i < n; ++i){
        if (s[i] != '0'){
            ans = max(ans, cur + s[i]-'0'-1 + 9*(n-i-1));
        }
        cur += s[i] - '0';
    }
    ans = max(ans, cur);
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int d = a * c;
    if(d<=b){
        printf("%d", c);
    }else{
        int e = b / a;
        printf("%d\n", e);
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>


int main (void){
        int N;
        long long int A;
        long long int ans=0;
        scanf("%d",&N);
        for (int i = 0; i < N; i++) {
                scanf("%lld",&A);
          while (A%2==0) {
          ans++;
          A/=2;
          }
        }
printf("%lld\n", ans);

        return 0;
}


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


int compare_int(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int main() {

	int n;
	int i;
	int count = 0;

	scanf("%d", &n);

	unsigned int a[n];

	for(i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	qsort(a, n, sizeof(int), compare_int);


	for(i = 0; i < n; i++) {
		if(a[i] == a[i+1]) {
			count++;
			break;
		}
	}
	if(count > 0) {
		printf("NO\n");
	}
	else{
		printf("YES\n");
	}

	return 0;


}


Measured memory_bytes: 1788
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]==','){
            cout<<" ";
        }
        else{
            cout<<s[i];
        }
    }
    cout<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3648
//FA専用
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long LINF=1e18;
int a,b,c,d,e,f,n,m,h,w,ans,cnt;
char C;
string s,t,u;
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
#define L(n) for(int i=0;i<n;i++)
#define V(n) vector<int> v(n)
#define XXX cout<<ans<<endl;
void yy(bool a){
  cout<<(a?"Yes":"No")<<endl;
}
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  for(int i=0;i<n-1;i++)if(v[i]==v[i+1])fin("NO");
  fin("YES");
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }
        private static readonly string _alpha = "abcdefghijklmnopqrstuvwxyz";
        private static object GetResult()
        {
            var N = ReadLong();

            var digit = 1L;
            for (; ; digit++)
            {
                var max = 0L;
                for (int i = 1; i <= digit; i++)
                {
                    max += (long)Math.Pow(26, i);
                }
                if (N <= max)
                {
                    break;
                }
            }

            var r = "";
            for (long i = 0; i < digit; i++)
            {
                var alphabetIndex = N % 26;
                if (alphabetIndex == 0)
                {
                    r += "z";
                    N = (N - 26) / 26;
                }
                else
                {
                    r += _alpha[(int)alphabetIndex - 1];
                    N /= 26;
                }
            }

            return new string(r.Reverse().ToArray());
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

int main(){
  int N;
  cin >> N;
  string Ans="No";
  if(N%10==7 || (N/10)%10==7 || (N/100)%10==7){
    Ans="Yes";
  }
  cout << Ans << endl;
}

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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
ll mod_pow(ll x, ll n, int mod){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}
int main(){ 
  int n, a, b;
  cin >> n >> a >> b;
  mint res = mod_pow(2, n, MOD) - 1;
  mint d1 = 1, c1 = 1, d2 = 1, c2 = 1;
  mint s1 = 1, s2 = 1;
  for (int i = 0; i < a; i++) {
    d1 = (n - i);
    c1 = (i + 1);
    d1 /= c1;
    s1 *= d1;
  }
  for (int i = 0; i < b; i++) {
    d2 = (n - i);
    c2 = (i + 1);
    d2 /= c2;
    s2 *= d2;
  }
  cout <<  res - (s2 + s1) << endl;
  return 0;
} 

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

int n;
int memo[105][112345];
pair<int, int> kp[105];

int knapsack(int i, int w)
{
    if(i == n)
        return 0;
    if(memo[i][w] != -1)
        return memo[i][w];

    int result = knapsack(i+1, w);
    if(w - kp[i].first >= 0)
        result = max(result, kp[i].second + knapsack(i+1, w - kp[i].first));

    memo[i][w] = result;
    return result;
}

signed main()
{
    memset(memo, -1, sizeof(memo));

    int w;
    cin >> n >> w;
    
    for(int i = 0; i < n; ++i)
        cin >> kp[i].first >> kp[i].second;

    cout << knapsack(0, w) << endl;
}


Measured memory_bytes: 92416
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        A.push_back(make_pair(b, a));
    }
    sort(A.begin(), A.end());
    int cnt = 0, last = 0;
    for (auto p : A) {
        int b, a;
        tie(b, a) = p;
        if (a < last && last <= b) continue;
        last = b;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1400
S = input()

a=0
b=0
for i,s in enumerate(S):
    if  i% 2 == 0:
        if s =="0":
            a += 1
        else:
            b += 1
    else:
        if s=="0":
            b+=1
        else:
            a+=1
ans = min(a,b)
print(ans)

Measured memory_bytes: 3188
n,q=map(int,input().split())
s=input()
b=[0]*(n+1)
y=0
for x,i in enumerate(s):
    if i=="A" and x!=n-1 and s[x+1]=="C":
        y+=1
    b[x+1]=y
for i in range(q):
    a0,a1=map(int,input().split())
    print(b[a1-1]-b[a0-1])


Measured memory_bytes: 6164
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    idx = 0
    target = 1
    cnt = 1
    passed = [False]*N
    while True:
        if idx >= N:
            print(-1)
            return
        if A[idx]-1 == target:
            print(cnt)
            return
        if passed[A[idx]-1]:
            print(-1)
            return
        passed[idx] = True
        idx = A[idx]-1
        cnt += 1



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 50008
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = 0;
        for(long i = 2; i * i <= n; i++){
            int count = 0;
            while(n % i == 0){
                count++;
                n/=i;
            }
            for(int j = 1; count - j >= 0; j++){
                ans++;
                count -= j;
            }
        }
        if(n > 1){
            ans++;
        }
        System.out.println(ans);
    }
}


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

using namespace std;

int main(){
  	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<a[n-1]<<endl;
  	
	return 0;
}

Measured memory_bytes: 256
import itertools

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

answers = []
for bit in range(1, 2 ** 10):
    t = [min(1, bit & (1 << i)) for i in range(10)]
    answer = 0
    for i in range(n):
        c = sum(1 for j in range(10) if f[i][j] == 1 and t[j] == 1)
        answer += p[i][c]
    answers.append(answer)

print(max(answers))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;
typedef long long llong;
const int MOD=1000000007;

int main(int argc, char**argv){
    int a, b;
    cin >> a >> b;
    int sum = a + b;
    if (sum % 2 == 0) cout << sum/2 << endl;
    else cout << sum/2 + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())

t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)
t[0] = 0
x[0] = 0
y[0] = 0
result = "Yes"

def is_even(num):
    return num % 2 == 0

for i in range(1, N+1):
    t[i], x[i], y[i] = list(map(int, input().split()))

for i in range(1, N+1):
    time = t[i] - t[i-1]
    xlen = abs(x[i] - x[i-1])
    ylen = abs(y[i] - y[i-1])
    distance = xlen+ylen
    if is_even(time) == is_even(distance) and distance <= time:
        continue
    result = "No"
    break
    
print(result)


Measured memory_bytes: 11764
use proconio::{input,fastout};
#[fastout]
fn main() {
    input!{
        n: u64,
    }
    if n % 2 == 0 || n % 5 == 0 {
        println!("{}", -1);
    } else {
        let mut r = 0;
        for i in 1..=n {
            r = (r * 10 + 7) % n;
            if r == 0 {
                println!("{}", i);
                return;
            }
        }
    }
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=a;i--)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << " "
#define pw(x) (1ll<<(x))
#define pq priority_queue
#define endl "\n"
int main()
{
    ios::sync_with_stdio(false);
    ll h1,h2,m1,m2,k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	if(h2<h1)
		h1+=24;
	if(h1==h2 && m2<m1)
		h1+=24;
	ll ans=60*(h2-h1)+m2-m1-k;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
immutable string YES = "Yes";
immutable string NO = "No";
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    string N;
    N = input.front.to!string;
    input.popFront;

    solve(N);
}

void solve(string N)
{
    long x;
    foreach (c; N)
    {
        x += c - '0';
        x %= 9;
    }
    writeln(x == 0 ? YES : NO);
}


Measured memory_bytes: 4088
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    string s;
    cin>>s;
    int q;
    cin>>q;
    int count = 0;
    vector<char> first;
    vector<char> back;

    for(int i=0;i<q;i++){

        int x;
        cin>>x;
        
        if(x==1){
            count++;
        }else{
            int a;
            char b;
            cin>>a>>b;

            if((count%2==0 && a==1) || (count%2==1 && a==2)){
                first.push_back(b);
                //s = b+s;
            }else{
                back.push_back(b);
                //s = s+b;
            }
        }
        
    }

    if(count%2==0){
        for(int i=first.size()-1;i>=0;i--) cout<<first[i];
        cout<<s;
        for(int i=0;i<back.size();i++) cout<<back[i];

    }else{
        for(int i=back.size()-1;i>=0;i--) cout<<back[i];
        for(int i=s.length()-1;i>=0;i--) cout<<s[i];
        for(int i=0;i<first.size();i++) cout<<first[i];
    }
    cout<<endl;
    return 0;
    

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 666
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int mod=1e9+7;
int go[N],mx[N][N],mn[N][N],s[N],f[N][N],g[N];
int main()
{	int n,k,x,y,ans=0; cin>>n>>k; n*=2;
	for(rint i=1;i<=k;i++) scanf("%d%d",&x,&y),go[x]=y,go[y]=x;
	for(rint i=1;i<=n;i++) s[i]=s[i-1]+(!go[i]);
	for(rint i=1;i<=n;i++)
	{	mx[i][i-1]=0; mn[i][i-1]=1e9;
		for(rint j=i;j<=n;j++)
		{	mx[i][j]=mx[i][j-1]; mn[i][j]=mn[i][j-1];
			if(go[j]) mx[i][j]=max(mx[i][j],go[j]),mn[i][j]=min(mn[i][j],go[j]);
		}
	}
	g[0]=1; for(rint i=2;i<=n;i++) g[i]=(ll)g[i-2]*(i-1)%mod;
	for(rint i=2;i<=n;i+=2)
	{	for(rint l=1;l+i-1<=n;l++)
		{	int r=l+i-1;
			if(mn[l][r]<l||mx[l][r]>r) continue; f[l][r]=g[s[r]-s[l-1]];
			for(rint k=l+1;k<r;k+=2)
			f[l][r]=(f[l][r]-(ll)f[l][k]*g[s[r]-s[k]]%mod+mod)%mod;
			(ans+=(ll)f[l][r]*g[s[l-1]+s[n]-s[r]]%mod)%=mod;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5120
N, C, K, *T = map(int, open(0).read().split())
T = sorted(T)
ans = 0
curr = [T[0]]
for i in range(N - 1):
    if len(curr) < C and T[i + 1] - curr[0] <= K:
        curr.append(T[i + 1])
    else:
        ans += 1
        curr = [T[i + 1]]
print(ans + 1)


Measured memory_bytes: 14052