akhauriyash/Code-Regression huggingface dataset:
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	int d1=n%10,d2=n/10;
	if(9==d1||9==d2)
		cout<<"Yes\n";
	else cout<<"No\n";
}

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

int main(void){
	int a=0,b=0,c=0,t,ah,bh,ch;
	char sa[128],sb[128],sc[128];
	scanf("%s%s%s",sa,sb,sc);
	ah = strlen(sa);
	bh = strlen(sb);
	ch = strlen(sc);
	t = 0;
	while(1){
		if(t == 0){if(ah == a){printf("A\n");break;} t = sa[a]-97;a++;}
		else if(t == 1){if(bh == b){printf("B\n");break;} t = sb[b]-97;b++;}
		else if(t == 2){if(ch == c){printf("C\n");break;} t = sc[c]-97;c++;}
	}
	return 0;
}

Measured memory_bytes: 128
from collections import deque

k = int(input())

ll = [x for x in range(1, 10)]
q = deque(ll)

cnt = 0

while True:
    n = q.popleft()
    mod = n % 10
    if mod == 0:
        q.append(n * 10 + mod)
        q.append(n * 10 + mod + 1)
    elif 1 <= mod <= 8:
        q.append(n * 10 + mod - 1)
        q.append(n * 10 + mod)
        q.append(n * 10 + mod + 1)
    else:  # mod==9
        q.append(n * 10 + mod - 1)
        q.append(n * 10 + mod)

    cnt += 1
    if cnt == k:
        print(n)
        exit(0)


Measured memory_bytes: 11956
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

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

const int MAXN = 1e5+5;

int n;
vi G[MAXN];

int col[MAXN], cnt[2];
void bfs(){
	queue<int> q;
	q.push(0);
	q.push(n-1);
	while(!q.empty()){
		int v=q.front(); q.pop();
		cnt[col[v]]++;
		for(int u : G[v]){
			if(col[u]==-1){
				col[u]=col[v];
				q.push(u);
			}
		}
	}
}

int main(){
	scan(n);
	FOR(i,0,n-1){
		int v,u; scan(v,u); v--; u--;
		G[v].pb(u);
		G[u].pb(v);
	}
	ms(col, -1);
	col[0]=0;
	col[n-1]=1;
	bfs();
	printf(cnt[0]>cnt[1]?"Fennec\n":"Snuke\n");
}

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

using namespace std;

struct Node {
    int x, y, z;
    Node() {}
    Node(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
};

void solve() {
    int n, k;
    cin >> n >> k;
    if (2*(k-1) > n-1) {
        cout << -1; return;
    }

    int x = k + (n-1)/2, y = k + 2*n-1, z = k + 3*n-1;
    while (x >= k) {
        cout << x << ' ' << y << ' ' << z << "\n";
        x--; y--; z-=2;
    }
    x = k + n-1; z = k + 3*n-2;
    while (y >= k+n) {
        cout << x << ' ' << y << ' ' << z << "\n";
        x--; y--; z-=2;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2304
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline int toInt(string s){
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

template<class T> inline string toString(T x){
    ostringstream sout;
    sout << x;
    return sout.str();
}

int main(void){

    int n, l;
    cin >> n >> l;

    ll ans = n*(2*l+n-1) / 2;

    int start = l;
    int end = l+n-1;

    if(l>0)ans -= l;
    else if(l+n-1<0)ans -= l+n-1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())))
eat=sorted(p[:x]+q[:y],reverse=True)
score=sum(eat)
while r:
    be=eat.pop()
    af=r.pop()
    if be<af:
        score+=af-be
    else:
        break
print(score)

Measured memory_bytes: 106980
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int MOD = 100000000 + 7;

bool canDo(vector<int> &a, vector<int> &f, int k, int goal_score)
{
    int n = a.size();
    for (int i = 0; i < n; i++)
    {
        int aa = goal_score / f[i];
        k -= max(0LL, a[i] - aa);
        if (k < 0)
            return false;
    }
    return true;
}

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

    int n, k; // num of member, training times
    cin >> n >> k;
    vector<int> a(n), f(n); // cost, food point
    for (auto &&x : a)
        cin >> x;
    for (auto &&x : f)
        cin >> x;

    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<int>());

    vector<int> af(n);
    for (int i = 0; i < n; i++)
    {
        af[i] = a[i] * f[i];
    }

    int left = 0, right = *max_element(af.begin(), af.end());

    int mid;
    while (left < right)
    {
        mid = (left + right) / 2;
        bool can = canDo(a, f, k, mid);
        if (can)
            right = mid;
        else
            left = mid + 1;
    }
    mid = (left + right) / 2;
    cout << mid << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
int main(){
	int n,q,ans;
	cin>>n>>q;
	string s;
	cin>>s;
	ans=0;
	vector<int> tn(n+1,0);
	rep(i,n-1){
		if((s.at(i)=='A')&&(s.at(i+1)=='C')){
			tn.at(i+2)=ans+1;
			ans++;
		}else{
			tn.at(i+2)=ans;
		}
	}
	
	vector<int> ln(q,0);
	vector<int> rn(q,0);
	rep(k,q){
		cin>>ln.at(k)>>rn.at(k);
	}
	/*rep(j,n+1){
		cout<<tn.at(j)<<endl;
	}
	cout<<" "<<endl;*/
	rep(l,q){
		cout<<(tn.at(rn.at(l))-tn.at(ln.at(l)))<<endl;
	}
	return 0;
}

Measured memory_bytes: 2176
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const long long MOD = 1000000007;
const int INF{ 2100000000 };	// MAX:2147483647
typedef long long ll;
using namespace std;

// ------------- ここからコード -------------

int main(void) {
	int N;
	cin >> N;
	bool ok = false;
	int cnt = 0;
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		if (a == b) cnt++;
		else cnt = 0;

		if (cnt == 3) ok = true;
	}

	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 21;
const int N0 = 1050010;
const int mod = 1e9 + 7;

int l[N], r[N];
int f[2][N][N0];

void upd(int &a, int b) { a = (a + b) % mod;}

int main()
{
	//freopen("f.in", "r", stdin);
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	Rep(i, k) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if (!c) l[a] |= (1 << (b - 1));
		else r[a] |= (1 << (b - 1));
	}
	
	f[1][1][0] = 1;
	Rep(i, m){
		Rep(j, n) Rep0(s, (1 << n) - 1) f[(i + 1) & 1][j][s] = 0;
		Rep(j, n) Rep0(s, (1 << n) - 1){
			int i0 = (i & 1);
			if (!f[i0][j][s]) continue;
			if (j == n){
				if ((l[i] & s) || (r[i] & s) != r[i]) continue;
				upd(f[(i + 1) & 1][1][s], f[i0][j][s]);
			}
			else {
				upd(f[i0][j + 1][s], f[i0][j][s]);
				if (!(s & (1 << (j - 1)))){
					int tmp = s >> (j - 1), ts = s;
					tmp = (tmp & (-tmp)) << (j - 1);
					ts -= tmp, ts += 1 << (j - 1);
					upd(f[i0][j + 1][ts], f[i0][j][s]);
				}
			}
		}
	}
	
	int ans = 0;
	Rep0(i, (1 << n) - 1) upd(ans, f[(m + 1) & 1][1][i]);
	
	printf("%d\n", ans);
	
	return 0;
}
/*
3 2 1
1 2 0

5 4 2
1 3 1
4 2 0
*/

Measured memory_bytes: 166272
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;


class A
{
    static int[] F=new int[45];
    public static void Main() {
        int n = int.Parse(System.Console.ReadLine());
        F[0] = 1;
        F[1] = 1;
        Console.WriteLine(fibonacchi(n));
    }
    static int fibonacchi(int n) {
        if (n == 0||n==1) {
            return F[n];
        }
        if (F[n] != 0) {
            return F[n];
        }
        F[n] = fibonacchi(n - 1) + fibonacchi(n - 2);
        return F[n];
    }
}


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

using namespace std;
#define rep(i, N) for(int i=0;i<int(N);++i)
#define rep1(i, N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "{" << p.first << ", " << p.second << "}";
    return os;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = (ll) 1e9;
const ll INFLL = (ll) 1e18 + 1;
const ll MOD = (ll) 1e9 + 7;
const double PI = acos(-1.0);

/*
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 string dir = "DRUL";
*/

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string S;
    cin >> S;
    cout << (S == "ABC" ? "ARC": "ABC") << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
    int H,W,i,j,cnt;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)break;
        for(i=0;i<H;i++){
            cnt=i;
            for(j=0;j<W;j++){
                if(cnt%2==0){
                    printf("#");
                }
                else{
                    printf(".");
                }
                cnt++;
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<pi,int> P;

int main()
{
    int n,m;
    while(scanf(" %d %d",&n,&m),n)
    {
        vector<P> a(n);
        rep(i,n)
        {
            int d;
            scanf(" %d", &d);

            a[i] = P( pi((m/d)*d,d) , i+1);
        }

        sort(all(a));
        // rep(i,n) printf("%d %d : id=%d\n", a[i].fi.fi, a[i].fi.se,a[i].se);

        int ans=a[0].se;
        if(a[0].fi==a[1].fi) ans=n;
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define MOD 2019

int main(){
	ll L, R;
  	cin >> L >> R;
    int L2 = L%MOD;
    int R2 = R%MOD;
  	if(L2 >= R2 || L+2019 <= R) cout << 0 << endl;
  	else{
      int ans = 2020;
      for(int i = L2; i < R2; i++){
        for(int j = i+1; j <= R2; j++){
          if(i < j){
            int ans_tmp = (i*j)%MOD;
            if(ans > ans_tmp) ans = ans_tmp;
          }
        }
      }
      	cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

int n, r, g, b, ans;
string s[10010];

int main()
{
	cin >> r >> g >> b >> n;
	for (int i = 0; i <= n / r; i++)
	{
		for (int j = 0; j <= n / g; j++)
		{
			if ((i * r + j * g) <= n && (n - i * r - j * g) % b == 0)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int f(int n){
    int sum=0;
    while(n > 0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n, _a, _b; cin >> n;
    int min=1e7;
    int ans=0;
    for(int i=1; i < n; i++){
        int j = n-i;
        _a = f(i);
        _b = f(j);
        if(min > _a+_b) min = _a+_b;
    }
    cout << min << endl;
    return 0;
}


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

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

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

int f(int x){
	int res = 0;
	while(x%2 == 0){
		x /= 2;
		res++;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] /= 2;
	}
	int t = f(a[0]);
	for(int i = 0; i < n; i++){
		if(f(a[i]) != t){
			cout << 0 << endl;
			return 0;
		}
		a[i] >>= t;
	}
	m >>= t;
	long long l = 1;
	for(int i = 0; i < n; i++){
		l = lcm(l, a[i]);
		if(l > m){
			cout << 0 << endl;
			return 0;
		}
	}
	m /= l;
	int ans = (m+1)/2;
	cout << ans << endl;
	return 0;
}

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

long long nPr(long long n, long long r) {
	long long ans = 1;
	for (int i = 0; i < r; i++) {
		ans *= n;
		n--;
		ans %= 1000000007;
	}
	return ans;
}
int main() {
	long long n, m;
	cin >> n >> m;
	if (abs(n - m) == 1) {
		cout << nPr(n, n)*nPr(m, m)% 1000000007 << endl;
	}
	else if (n == m) {
		cout << nPr(n, n)*nPr(m, m) * 2 % 1000000007 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=1
x=1
while n!=0 or x!=0:
  n,x=map(int,input().split())
  if n==0 and x==0:
    break
  ans=0
  for i in range(1,n+1):
    for k in range(i+1,n+1):
      for t in range(k+1,n+1):
        if i+k+t==x:
          ans+=1
  print(ans)          


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  string t = "abcdefghijklmnopqrstuvwxyz";
  int cnt[26] = {0};
  for (int i = 0; i < 26; i++) {
    int c = 999;
    for (int j = 0; j < n; j++) {
      int tmp = 0;
      for (int k = 0; k < s[j].size(); k++) {
        if (t[i] == s[j][k]) {
          tmp++;
        }
      }
      if (tmp < c) {
        c = tmp;
      }
    }
    cnt[i] = c;
  }
  string ans = "";
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      ans += t[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n, k;
    cin>>n>>k;

    double ans = 0;
    rep(i, n) {
        int d = i + 1;
        double cnt = 1;
        while (d < k) {
            cnt *= 0.5;
            d *= 2;
        }
        ans += cnt;
    }
    printf("%.15f\n", ans / n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
#define M 100005 
ll c,v[M],x[M],sum[M],l[M],r[M],res,L[M],R[M];
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n); read(c);
	int i;
	for (i=1;i<=n;i++){
		read(x[i]); read(v[i]);
	}
	x[n+1]=c;
	for (i=1;i<=n;i++){
		sum[i]=sum[i-1]+v[i];
		l[i]=max(l[i-1],sum[i]-x[i]);
		L[i]=max(L[i-1],sum[i]-2*x[i]);
	}
	for (i=n;i>=1;i--){
		r[i]=max(r[i+1],sum[n]-sum[i-1]-(c-x[i]));
		R[i]=max(R[i+1],sum[n]-sum[i-1]-2*(c-x[i]));
	}	
	for (i=1;i<=n;i++){
		Max(res,l[i]+R[i+1]);
		Max(res,L[i]+r[i+1]);	
	}
//	printf("%lld %lld  %lld\n",x[n],c-x[n],sum[n])
	Max(res,sum[n]-x[n]);
	Max(res,sum[n]-c+x[1]);
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++)
		if(s[i]=='x')sum++;
	if(sum<=7)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
 
typedef long long ll;
 
int main(){
  ll n;
  string s;
  cin >> n >> s;
  ll mod=1000000007;
  ll a[26];
  for(int i=0;i<26;i++){
    a[i]=0;
  }
  for(int i=0;i<n;i++){
    ll k=s.at(i)-'a';
    a[k]++;
  }
  ll ans=a[0];
  for(int i=1;i<26;i++){
    ans=(ans*(a[i]+1)+a[i])%mod;
  }
  cout << ans << endl;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 300005;

i64 n;

i64 a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);


    i64 a;
    cin >> a;

    i64 R = inf;

    for (i64 i = 1; i <= sqrt(a) + 2; i++) {
        i64 j = a / i;
        if (i * j != a) {
            continue;
        }

        R = min(R, (i - 1) + (j - 1));
    }


    cout << R << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    ll n, k; cin >> n >> k;
    multiset<ll> st;
    rep(i, n) {
        ll x; cin >> x;
        st.insert(x);
    }
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    auto f = [&](ll score) -> bool {
        multiset<ll> speed = st;
        ll train = k;
        for(const auto& food: a) {  // O(N)
            ll sp = score/food;
            auto it = speed.lower_bound(sp); // O(logN)
            if (it==speed.end()) --it;
            else if (*it>sp) train -= *it-sp;
            speed.erase(it); // O(1)
            if (train<0) return false;
        }
        return true;
    };

    ll left = -1; ll right = (ll)1e12+10ll;
    ll mid;
    while (right-left>1) {
        mid = (left+right)/2ll;
        debug(left, mid, right);
        if (f(mid)) right = mid;
        else left = mid;
    }
    cout << right << endl;
}

Measured memory_bytes: 22656
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cassert>
#include<cmath>
using namespace std;

class Parsing
{
private:
  string parse;
  int pos;
  int size;
  int x;
public:

  Parsing(string parse = "",int x = 0):parse(parse),pos(0),x(x),size(0){}

  int StringToInt(string v)
  {
    int ret = 0;
    for(int i=0;i<v.size();i++)
      ret += (v[i]-'0')*(int)pow(10.0,v.size()-i-1);
    return ret;
  }

  string getCnt()
  {
    assert('0' <= parse[pos] && parse[pos] <= '9');
    string v;
    while('0' <= parse[pos] && parse[pos] <= '9') 
      v += parse[pos++];
    return v;  
  }

  int getCntInt()
  {
    return StringToInt(getCnt());
  }

  string decode()
  {
    assert('0' <= parse[pos] && parse[pos] <= '9');
    int power = getCntInt();
    if(parse[pos] == '(')
      pos++;
    else 
      {
	string mes,ret;
	while('A' <= parse[pos] && parse[pos] <= 'Z')	
	  mes += parse[pos++];
	
	for(int i=0;i<power;i++)
	  {
	    ret += mes;
	    if(ret.size() >= x)
	      break;
	  }
	return ret;	  
      }
    string message;
    while(('0' <= parse[pos] && parse[pos] <= '9') || ('A' <= parse[pos] && parse[pos] <= 'Z') )
      {
	if('0' <= parse[pos] && parse[pos] <= '9')
	  message += decode();
	else if('A' <= parse[pos] && parse[pos] <= 'Z')
	  message += parse[pos++];
      }  
    
    if(parse[pos] == ')')
      pos++;
    
    string ret;
    for(int i=0;i<power;i++)
      {
	ret += message,size += message.size();
	if(ret.size() >= x)
	  break;
      }
    return ret;
  }

  string exp()
  {
    string ret;
    for(;pos<parse.size();)
      {
	if('0' <= parse[pos] && parse[pos] <= '9')
	  ret += decode();
	else
	  ret += parse[pos++],size++;
	if(ret.size() >= x)
	  break;
	//cout << "ret = " << ret << endl;
      }
    return ret;
  }

  int getSize()
  {
    return size;
  }

};

int main()
{
  string Genome;  
  int pos;
  while(cin >> Genome >> pos, Genome != "0" || pos != 0)
    {
      Parsing par = Parsing(Genome,pos+10);
      string message = par.exp();
      //cout << "message = " << message << endl;
      if(message.size() <= pos)
	cout << 0 << endl;
      else
	cout << message[pos] << endl;
    }
  return 0;
}

Measured memory_bytes: 6852
#include<stdio.h>

int main()
{
    int x;
    scanf("%d", &x);
    if(x < 600) {
        printf("8\n");
    }
    else if(x < 800) {
        printf("7\n");
    }
    else if(x < 1000) {
        printf("6\n");
    }
    else if(x < 1200) {
        printf("5\n");
    }
    else if(x < 1400) {
        printf("4\n");
    }
    else if(x < 1600) {
        printf("3\n");
    }
    else if(x < 1800) {
        printf("2\n");
    }
    else {
        printf("1\n");
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
using namespace std;
typedef long long int llf;
vector<int> p;
llf gcd(llf a,llf b){
	while(a!=b){
		if(max(a,b)%min(a,b)==0)
		return min(a,b);
		if(a>b)
		a-=b*(a/b);
		else
		b-=a*(b/a);
	}
	return a;
}
llf gcd(llf c[10],int n){
	llf d[10];
	for(int i=0;i<n;i++)
	d[i]=c[i];
	llf x=d[0];
	for(int i=1;i<n;i++)
	x=gcd(x,d[i]);
	return x;
}
llf lcm(llf c[10],int n){
	int d[10];
	for(int i=0;i<10;i++)
	d[i]=c[i];
	int times[10000]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<p.size();j++){
			int k=0;
			while(d[i]%p[j]==0){
				d[i]/=p[j];
				k++;
			}
			times[p[j]]=max(times[p[j]],k);
		}
	}
	llf ans=1;
	for(int i=0;i<p.size();i++)
		for(int j=0;j<times[p[i]];j++)
			ans*=p[i];
	return ans;
}
int main() {
	// your code goes here
	p.push_back(2);
	for(int i=3;i<=10000;i++){
		for(int j=0;j<p.size();j++){
			if(i%p[j]==0)
			break;
			if(j==p.size()-1)
			p.push_back(i);
		}
	}
	int n;
	while(cin >> n && n!=0){
		llf d[10],v[10];
		for(int i=0;i<n;i++)
		cin >> d[i] >> v[i];
		llf times=lcm(d,n);
		for(int i=0;i<n;i++)
		v[i]*=(times/d[i]);
		llf c=gcd(v,n);
		for(int i=0;i<n;i++)
		cout << v[i]/c << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
n,k = gets.chomp.split.map(&:to_i)
r,s,p = gets.chomp.split.map(&:to_i)
t = gets.chomp

point = {'r' => p, 's' => r, 'p' => s}
flags = Array.new(k,nil)

ans = 0
n.times do |i|
  if flags[i%k] == t[i]
    flags[i%k] = nil
  else
    ans += point[t[i]]
    flags[i%k] = t[i]
  end
end

puts(ans)

Measured memory_bytes: 20308
#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long
using namespace std;
int n,m;
LL ans;
const int N=8010,M=210,mod=998244353,G=3,Ginv=(mod+1)/3;
int r[N<<2];
LL jc[N],inv[N],f[N][M],A[N<<2],B[N<<2];
LL ksm(LL a,LL b,LL mod)
{
	LL res=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)res=res*a%mod;
	return res;
}
namespace Poly
{
	void NTT(LL *A,int lim,int opt)
	{
		for(int i=0;i<lim;++i)r[i]=(r[i>>1]>>1)|(i&1?lim>>1:0);
		for(int i=0;i<lim;++i)
			if(i<r[i])swap(A[i],A[r[i]]);
		for(int mid=1;mid<lim;mid<<=1)
		{
			LL wn=ksm(opt==1?G:Ginv,(mod-1)/(mid<<1),mod);
			for(int j=0;j<lim;j+=(mid<<1))
			{
				LL w=1;
				for(int k=j;k<j+mid;++k,w=w*wn%mod)
				{
					LL x=A[k],y=w*A[k+mid]%mod;
					A[k]=(x+y)%mod;A[k+mid]=(x-y+mod)%mod;
				}
			}
		}
		if(opt==1)return;
		int ni=ksm(lim,mod-2,mod);
		for(int i=0;i<lim;++i)A[i]=A[i]*ni%mod;
	}
	void MUL(LL *A,int n,LL *B,int m)
	{
		int lim=1;
		while(lim<=(n+m))lim<<=1;
		NTT(A,lim,1);NTT(B,lim,1);
		for(int i=0;i<lim;++i)A[i]=A[i]*B[i]%mod;
		NTT(A,lim,-1);
	}
}
void YYCH(int n)
{
	jc[0]=jc[1]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;++i)jc[i]=jc[i-1]*i%mod;
	inv[n]=ksm(jc[n],mod-2,mod);
	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(int n,int m){return jc[n]*inv[m]%mod*inv[n-m]%mod;}
void solve(int j)
{
	memset(A,0,sizeof(A));memset(B,0,sizeof(B));
	for(int i=1;i<=n;++i)A[i]=inv[i+2];
	for(int i=0;i<=n;++i)B[i]=f[i][j-1]*inv[i]%mod;
	Poly::MUL(A,n+1,B,n+1);
	for(int i=0;i<=n;++i)f[i][j]=f[i][j-1]*(1+i+i*(i-1)/2)%mod;
	for(int i=1;i<=n;++i)f[i][j]=(f[i][j]+A[i]*jc[i+2])%mod;
}
int main()
{
	cin>>n>>m;YYCH(n+2);
	f[0][0]=1;
	for(int i=1;i<=m;++i)solve(i);
	for(int i=0;i<=n;++i)(ans+=C(n,i)*f[i][m])%=mod;
	cout<<ans;
	return 0;
}

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

int main(void){
  string c[2]; 

  cin >> c[0] >> c[1];

  if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
    cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n2, m, a, b, ans; 
bool t[9][9];

bool used[8];
int perm[8];
//0からn-1
void permutation1(int pos, int n){
	if(pos == n){
		bool flag = 1;
		for(int i=1;i<n;i++){
			if(!t[perm[i]][perm[i-1]]) flag = 0;
		}
		if(flag) ans++;
		//permに対する操作
		return ;
	}

	//permのpos番目を0からn-1のどれにするか
	for(int i = 1; i < n; i++){
		if(!used[i]){
			perm[pos] = i;
			used[i] = true; //iのフラグをtrueに
			permutation1(pos + 1, n);
			used[i] = false; //フラグを戻す
		}
	}
	return ;
}


int main(){
	cin >> n2 >> m;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		t[a-1][b-1] = 1;
		t[b-1][a-1] = 1;
	}
	permutation1(1, n2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

T = np.array(T).cumsum()
V = np.array(V)

va = []
i = 0
for t in np.arange(0, T[-1], 0.5):  # 0.5 区切りの時間
    if t < T[i]:
        va.append(V[i])
    else:
        i += 1
        va.append(min(V[i], V[i - 1]))
va.append(0)

v = 0
for i in range(len(va)):
    va[i] = min(va[i], v)
    v = va[i] + 0.5
v = 0
for i in reversed(range(len(va))):
    va[i] = min(va[i], v)
    v = va[i] + 0.5

print((np.array(va) / 2).sum())


Measured memory_bytes: 14472
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    s = input()
    print('ABC'+s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>


using namespace std;

int main(void) {
    char c1,c2;
    c2 = '-';
    bool f = false;
    for(int i=0; i<4; i++) {
        cin >> c1;

        if ( f || c1 == c2 ) {
            f = true;
        }
        c2 = c1;
    }

    cout << (f? "Bad" : "Good") << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x;
  cin >> x;
  if(x>=30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll p=1000000007;
ll bin(ll val,ll po)
{
	if(po==0)
		return 1;
	ll ans=1;
	if(po%2==1)
	{
		po-=1;
		ans=ans*val%p;
	}
	ll p1=bin(val,po/2);
	ans=ans*p1%p;
	ans=ans*p1%p;
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	    ll n,m;
	    cin>>n>>m;
	    ll s,t;
	    vector<ll>adj[3*n+1];
	    for(ll i=1;i<=m;i++)
	    {
	    	ll u,v;
	    	cin>>u>>v;
	    	adj[u].push_back(v+n);
	    	adj[u+n].push_back(v+2*n);
	    	adj[u+2*n].push_back(v);
	    }
	    ll dist[3*n+1];
	    memset(dist,-1,sizeof(dist));
	    cin>>s>>t;
	    dist[s]=0;
	    queue<ll>q;
	    q.push(s);
	    ll visited[3*n+1];
	    memset(visited,0,sizeof(visited));
	    visited[s]=1;
	    while(!(q.empty()))
	    {
	    	ll x=q.front();
	    	q.pop();
	    	for(ll j:adj[x])
	    	{
	    		if(visited[j]==0)
	    		{
	    			visited[j]=1;
	    			q.push(j);
	    			dist[j]=dist[x]+1;
	    		}
	    	}
	    }
	    if(dist[t]==-1)
	    	cout<<"-1";
	    else
	    	cout<<dist[t]/3;
}

Measured memory_bytes: 21376
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define adp(a) for(auto ii:a) cout << ii.F << " " << ii.S << endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;
#define N 200003
#define INF INTMAX_MAX

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};


ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

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

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

bool cmp(const pll &a, const pll &b)
{
    if (a.F != b.F) {
        return a.F > b.F;
    }
    else
        return a.S < b.S;
}


// bool check(ll i, ll j)
// {
//     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '#')
//         return true;
//     return false;
// }

int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        ll n, k;
        cin >> n >> k;
        ll a[n];
        REP(i, 0, n) cin >> a[i];
        ll l = 1, h = 1e9, mid, ans = INTMAX_MAX;
        while (l <= h)
        {
            mid = (l + h) / 2;
            ll r = 0;
            REP(i, 0, n)
            {
                r += (a[i] - 1) / mid;
            }
            if (r > k) {
                l = mid + 1;
            }
            else
            {
                ans = min(ans, mid);
                h = mid - 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
int main(){
  set<string> sen;
  string s;
  int n;
  cin>>n;
  for (int i=0;i<n;i++){
    cin>>s;
    sen.insert(s);
  }
  cout<<sen.size()<<endl;
  return 0;
}

Measured memory_bytes: 19124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[3005][3005];
string s;
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++)dp[0][i]=1;
    for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++)dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%M;
		if(s[i-1]=='<'){
			for(int j=0;j<=n-i-1;j++){
				dp[i][j]=(dp[i-1][n]-dp[i-1][j]+M)%M;
			}
		}else{
			for(int j=0;j<=n-i-1;j++){
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	printf("%lld\n",dp[n-1][0]);
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int N,W;
  cin>>N>>W;
  vector<int64_t>w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  vector<vector<int64_t>>dp(N+1,vector<int64_t>(W+1));
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(w[i]+j<=W){
        chmax(dp[i+1][j+w[i]],dp[i][j]+v[i]);
      }
      chmax(dp[i+1][j],dp[i][j]);
    }
  }
  cout<<dp[N][W]<<endl;
  return 0;  
}

Measured memory_bytes: 82968
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
Ws = [0]*(N+1)
Ws[0] = [0]*(W+1)

for i, (v, w) in enumerate(items, 1):
    Ws[i] = [max(Ws[i-1][j], Ws[i-1][j-w]+v) if j-w>=0 else Ws[i-1][j] for j in range(W+1)]
print(Ws[N][-1])


Measured memory_bytes: 25944
from math import sqrt

N, D, *XY = map(int, open(0).read().split())

X = []
Y = []
for i, x in enumerate(XY):
    if i % 2 == 0:
        X.append(x)
    else:
        Y.append(x)

count = 0
for x in range(N):
    if sqrt(X[x] ** 2 + Y[x] ** 2) <= D:
        count += 1

print(count)

Measured memory_bytes: 55104
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

struct Move {
    int x1, y1, x2, y2;

    Move() : Move(0, 0, 0, 0) { }
    Move(int x1, int y1, int x2, int y2) : x1 { x1 }, y1 { y1 }, x2 { x2 }, y2 { y2 } { }
};

const int MAXN = 505;

int n, m, A[MAXN][MAXN];
vector<Move> ans;

int main() {
    scanf("%d%d", &n, &m);

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

    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < m; j++) {
            if (A[i][j] % 2 == 1) {
                ans.push_back({i + 1, j + 1, i, j + 1});
                A[i - 1][j]++;
            }
        }
    }

    for (int i = 0; i < m - 1; i++) {
        if (A[0][i] % 2 == 1) {
            ans.push_back({1, i + 1, 1, i + 2});
            A[0][i + 1]++;
        }
    }

    printf("%d\n", sz(ans));

    for (Move move : ans) {
        printf("%d %d %d %d\n", move.x1, move.y1, move.x2, move.y2);
    }

    return 0;
}

Measured memory_bytes: 5104
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int pos;

int digits(const string& str){
  int scalar = 1;
  string num_str="";
  while(isdigit(str[pos])){
    num_str += str[pos];
    pos++;
  }

  return atoi(num_str.c_str());
}

int equation(const string& str){
  int res = 0;
  vector<int> nums;
  if(pos < str.size() && str[pos] == '['){
    pos++;

    while(str[pos] != ']'){
      int num = equation(str);
      nums.push_back(num);
    }

    pos++;
    sort(nums.begin(),nums.end());
    for(int i=0;i<(nums.size()+1)/2;i++){
      res += nums[i];
    }
    return res;
  }
  else if(pos < str.size() && isdigit(str[pos])){
    int num = digits(str);
    return num / 2 + 1;
  }
  else{
    return res;
  }
}



int main(){
  int N;
  
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    string str;
    cin >> str;
    pos=0;
    printf("%d\n",equation(str));
  }
}

Measured memory_bytes: 1312
N = int(input())
H = list(map(int, input().split()))

next = 10**9
for i in range(N-1,0,-1):
  if H[i] <= next:
    next = H[i]
  elif H[i]-1 <= next:
    next = H[i]-1
  else:
    print("No")
    exit()
  
print("Yes")

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }
    rep(i, n / 2)
    {
        if (s[i] != s[n / 2 + i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
//#include <string>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;



int main(){

	int n,ans[3];
	cin >> n;
	ans[0] = n / 100;
	n %= 100;
	ans[1] = n / 10;
	n %= 10;
	ans[2] = n;
	
	if (ans[0] > ans[1]) cout << ans[0] * 111 << endl;
	else if(ans[0]>=max(ans[1],ans[2]))  cout << ans[0] * 111 << endl;
	else cout << (ans[0] + 1) * 111 <<endl;
	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    double ans = 0;
    cin >> a >> b;
    for (int i = 1; i <= a; ++i) {
        double tmp = 1.0 / a;
        int cur = i;
        while (cur < b) {
            cur *= 2;
            tmp /= 2.0;
        }
        ans += tmp;
    }
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
struct node{int x,note=0x3f;}a[100005];
int main(){int n,ans=1;cin>>n;for(int i=1;i<=n;i++)cin>>a[i].x;a[1].note=2;for(int i=2;i<=n;i++){if(a[i-1].note==0){if(a[i].x>a[i-1].x) a[i].note=2,ans++;else a[i].note=0;}else if(a[i-1].note==1){if(a[i].x>=a[i-1].x) a[i].note=1;else a[i].note=2,ans++;}else if(a[i-1].note==2){if(a[i].x<a[i-1].x) a[i].note=0;else if(a[i].x==a[i-1].x) a[i].note=2;else a[i].note=1;}}cout<<ans<<endl;return 0;}

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

using namespace std;

#define fi(a, b) for(int i=a;i<b;++i)

void solve(){
	int n, t;
	int l = 0;
	int ans = 0;
	scanf("%d%d",&n,&t);
	fi(0, n){
		int ti;
		scanf("%d",&ti);
		ans += min(t, (ti - l));
		l = ti;
	}
	ans += t;
	cout << ans << endl;
}

int main(){
	solve();


	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    val sur = StdIn.readLine.split(" ").toList.map(_.toInt)
    val ops = StdIn.readLine

    val dice = new Dice(sur)
    println(appOp(dice, ops).head)
  }

  def appOp(dice: Dice, ops: String): List[Int] ={
    if(ops == "") dice.index
    else
      ops.head match{
      case 'N' => appOp(new Dice(dice.rotN()), ops.tail)
      case 'S' => appOp(new Dice(dice.rotS()), ops.tail)
      case 'W' => appOp(new Dice(dice.rotW()), ops.tail)
      case 'E' => appOp(new Dice(dice.rotE()), ops.tail)
      case _ => List()
    }
  }
}

class Dice(sur: List[Int]){
  val index: List[Int] = sur

  def rotN(): List[Int] ={
    List[Int](index(1), index(5), index(2), index(3), index(0), index(4))
  }

  def rotS(): List[Int] ={
    List[Int](index(4), index(0), index(2), index(3), index(5), index(1))
  }

  def rotW(): List[Int] ={
    List[Int](index(2), index(1), index(5), index(0), index(4), index(3))
  }

  def rotE(): List[Int] ={
    List[Int](index(3), index(1), index(0), index(5), index(4), index(2))
  }
}

Measured memory_bytes: 43864