akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N);
  cin>>A;
  for(Int &a:A) a--;
  vector<Int> num(N, 0);
  for(Int i=0;i<N;i++) num[A[i]] = i+1;

  cout<<num<<endl;


  return 0;
}


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

using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    y1--; x1--; y2--; x2--;

    vector<string> C(h);
    for (auto &c: C)
        cin >> c;

    queue<array<int, 3>> Q;
    Q.push({y1, x1, 0});
    const constexpr int INF = 1e9;
    vector<vector<int>> D(h, vector<int>(w, INF));

    vector<int> dy = {0, 1, 0, -1}, dx = {1, 0, -1, 0};
    D[y1][x1] = 0;
    vector<vector<vector<int>>> DD(4, vector<vector<int>>(h, vector<int>(w, INF)));

    while (!Q.empty()){
        auto [y, x, d] = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++){
            for (int j = 1; j <= k; j++){
                int ny = y + dy[i] * j;
                int nx = x + dx[i] * j;
                if (ny < 0 or ny >= h or nx < 0 or nx >= w)
                    break;
                if (DD[i][ny][nx] != INF)
                    break;
                if (D[ny][nx] <= d)
                    break;
                if (C[ny][nx] == '@')
                    break;
                Q.push({ny, nx, d + 1});
                D[ny][nx] = d + 1;
                DD[i][ny][nx] = d + 1;
            }
        }
    }

    if (D[y2][x2] == INF){
        puts("-1");
        return 0;
    }

    cout << D[y2][x2] << endl;
}

Measured memory_bytes: 31596
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Akshay Vashishtha 

//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these differences 
you’ll be able to get past them and grow even closer.
//You can die anytime, but living takes true courage.
//Every journey begins with a single step. We just have to have patience.
//Life is not a game of luck. If you wanna win, work hard.
//It’s more important to master the cards you’re holding 
//than to complain about the ones your opponent was dealt.
//If you just submit yourself to fate, then that’s the end of it.
//Whatever you do, enjoy it to the fullest. That is the secret of life.
//I too will obtain everything that I desire. Not because someone asked me to do it, 
//but because I know in my heart that I have something worth fighting for.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define ps push_back
#define le length
#define in insert
#define vint vector<int>
#define vlld vector<long long int>
#define pii pair<int,int>
#define mk make_pair
#define vst vector<string>
#define lld long long int 
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
 
int main()
{
	int n,m,sm,req,cnt=0,tmp;
  vint v;
  cin>>n>>m;
  sm = 0;
  for(int i = 0 ; i < n ; i++){
    cin>>tmp;
    v.ps(tmp);
    sm += tmp;
  }
  req = sm;
  for(int i= 0 ; i < n ; i++){
    if(req <= (v[i]) * 4 * m)
      cnt++;
  }
  if(cnt >= m)
    cout<<"Yes\n";
  else
  {
    cout<<"No\n";
  }
  
	return 0;
}

Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 300010
#define mdn 1000000007
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int f[N][3][4],n;
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
char ch[N];
int main()
{
	scanf("%s",ch+1); n=strlen(ch+1); f[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int z=0;z<3;z++)	for(int o=0;o<=3;o++)
		{
			int v=f[i-1][z][o];
			if(ch[i]!='0')
			{
				if(z)	upd(f[i][z-1][o],v);
				else	upd(f[i][z][min(o+1,3)],v);
			}
			if(ch[i]!='1')
				upd(f[i][z+1==3?1:z+1][o],v);
		}
	}
	int ans=0;
	for(int z=0;z<3;z++)	for(int o=z+1;o<=3;o++)
		upd(ans,f[n][z][o]);
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    ll total = 0;
    int max_el_so_far = INT_MIN;
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++){
        if(max_el_so_far<a[i]){
            max_el_so_far = a[i];
        }
        total += max_el_so_far - a[i];
    }
    cout << total << '\n';
    return 0;
}

Measured memory_bytes: 4068
n = int(input())
a = list(map(int,input().split()))
ans = "APPROVED"
for i in a:
  if i % 2 != 0:
    continue
  if (i % 3 == 0) or (i % 5 == 0):
    continue
  ans = "DENIED"
  break
print(ans)  


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

int main(){
    int n;
    cin >>n;
    int h[100000+7];
    int dp[100000+7];
    for(int i=0;i<n+1;i++){
        dp[i]=1000000000;
    }
    dp[0]=0;

    for(int i=0;i<n;i++){
        cin >>h[i];
    
    }
    dp[1]=dp[0]+abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
# 2019/07/23

n,m=map(int,input().split())

if n>=3 and m>=3:
    print((n-2)*(m-2))
elif n==2 or m==2:
    print(0)
else:
    if n==1 and m==1:print(1)
    else:print(max(n,m)-2)

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    double t,x;
    cin>>t>>x;
    printf("%.5f\n", t/x);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, C = LI()
    D = [[] for _ in range(C)]
    for i in range(C):
        D[i] = LI()
    color = [[] for _ in range(N)]
    for i in range(N):
        color[i] = LI()

    # まず各 mod の色の数を調べる。
    counters = [[0 for _ in range(C+1)] for _ in range(3)]
    for i in range(N):
        for j in range(N):
            counters[(i+j)%3][color[i][j]] += 1
    # print(counters)

    sums = [sum(i) for i in counters]

    # 各 mod について、各色を選んだときの違和感を計算する。
    import itertools
    def takemin(variable, val): variable = min(variable, val)
    iwakan = INF
    for selected_cols in itertools.permutations(range(1,C+1), 3):  # 30**3
        sum_ = 0
        for to_, counter  in zip(selected_cols, counters):  # 3
            for from_, num in enumerate(counter):  # 30
                if from_ == 0: continue
                sum_ += D[from_-1][to_-1] * num
        iwakan = min(iwakan, sum_)
    print(iwakan)

main()

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


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

    double a = N/1.08;
    a = ceil(a);
    double b = floor(a*1.08);
    b = ceil(b);

    if (b == N ) {
        cout << a << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	int a;
	scanf("%d %d", &n, &a);
	n = n % 500;
	if(n > a) printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    vector<int> A(200005,0),B(200005,0);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(a==1){
            ++A[b];
        }else if(b==1){
            ++A[a];
        }else if(a==n){
            ++B[b];
        }else if(b==n){
            ++B[a];
        }
    }
    rep(i,200001){
        if(A[i]!=0 && B[i]!=0){
            cout << "POSSIBLE" << "\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << "\n";
    return 0;
}   

Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr long long LINF=334ll<<53; constexpr int INF=15<<26; constexpr long long MOD=1E9+7;
template<typename T, typename S>
struct LazySegmentTree{
    static constexpr T id_val=0;
    static constexpr S id_delay=0;
    inline void composite_delay(S &a, S &b){
        a+=b;
    }
    inline void propagate(int k,int a,int b){
        data[k].val+=data[k].delay*(b-a);
        if(k<n){
            composite_delay(data[2*k].delay, data[k].delay);
            composite_delay(data[2*k+1].delay, data[k].delay);
        }
        data[k].delay=id_delay;
    }
    inline T calc(T a,T b){
        return a+b;
    }

    struct Node{
        T val; S delay;
        Node(){val=id_val;delay=id_delay;}
    };
    int n;
    vector<Node> data;
    explicit LazySegmentTree(int size){
        n=1;
        while(n<size)n*=2;
        data=vector<Node>(2*n,Node());
    }
    inline void update(int l,int r,S v){update(l,r,v,1,0,n);}
    void update(int l, int r, S v, int k, int a, int b){
        if(l<=a && b<=r){
            composite_delay(data[k].delay,v);
            propagate(k,a,b);
            return ;
        }
        propagate(k,a,b);
        if(b<=l || r<=a){return ;}//
        update(l,r,v,2*k,a,(a+b)/2);
        update(l,r,v,2*k+1,(a+b)/2,b);
        data[k].val=calc(data[2*k].val,data[2*k+1].val);
    }
    inline T get(int l,int r){return get(l,r,1,0,n);}
    T get(int l, int r, int k, int a, int b){
        if(b<=l || r<=a){return id_val;}//
        propagate(k,a,b);
        if(l<=a && b<=r){
            return data[k].val;
        }
        T vall=get(l,r,2*k,a,(a+b)/2);
        T valr=get(l,r,2*k+1,(a+b)/2,b);
        return calc(vall,valr);
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<tuple<int,int,int>> s(n);
    for(int i=0; i<n; ++i){
        int l,r;
        cin >> l >> r;
        s[i]=make_tuple(r-l+1,l,r);
    }
    sort(s.begin(),s.end());

    auto it=s.begin();
    LazySegmentTree<LL,LL> seg(m+1);
    for(int i=1; i<=m; ++i){
        int ans=0;
        while(get<0>(*it)<i && it<s.end()){
            seg.update(get<1>(*it),get<2>(*it)+1,1);
            it++;
        }
        ans=s.end()-it;
        for(int j=i; j<=m; j+=i){
            ans+=seg.get(j,j+1);
        }
        cout << ans <<"\n";
    }

    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>

using namespace std;

int main() {
    string S;
    string result;
    cin >> S;
    if(S[2]==S[3]&&S[4]==S[5]){
        result= "Yes";
    }
    else{
        result="No";
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import           Data.List

-- kagamimochi.hs --- Kagamimochi

-- author: Seong Yong-ju <sei40kr@gmail.com>

solve :: [Int] -> Int
solve = length . nub

main :: IO ()
main = do
  n <- readLn
  rs <- replicateM n readLn
  print $ solve rs


Measured memory_bytes: 1020
<?php
function chmin($a, $b) {
    if ($a > $b){
        return $b;  # PHPは値をreturnしてそれを受け取らないと反映されない。https://qiita.com/7968/items/58015344ddab5d5a8b93#第2章-値渡し
    }else{
        return $a;
    };
}

fscanf(STDIN, "%d", $n);
$harray = array();
$harray = explode(' ', trim(fgets(STDIN)));  # explodeで行全部を配列に取り込む。

# dpテーブルを作って、無限を代入する。
# ここでは0から始めたので、dp[$i-1]はiまでたどり着くのに必要な最小コストを表す。
$dp = array();
for($i = 0; $i < $n; $i++){
    $dp[$i] = INF;  # 問題文的にあり得ない大きさの数値にしても良い。実行時間は変わらなかった。
}

# 初期条件。最初の足場へ行くコストはゼロ。一つ目は1通りしかない。
$dp[0] = 0;
$dp[1] = abs($harray[1] - $harray[0]);

for($j=2; $j < $n; $j++){
    $dp[$j] = chmin($dp[$j], ($dp[$j-1] + abs($harray[$j] - $harray[$j-1])));
    # $j-2 の足場から来る場合と比較
    $dp[$j] = chmin($dp[$j], ($dp[$j-2] + abs($harray[$j] - $harray[$j-2])));
}
print $dp[$n - 1];

Measured memory_bytes: 18932
#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
#include <cassert>
#include <algorithm>
using namespace std;

typedef complex<double> point;
typedef vector<point> polygon;

struct line : public vector<point> {
	line(point a, point b) { push_back(a); push_back(b); }
};

namespace std {
	bool operator<(const point& a, const point& b) {
		return a.real()!=b.real() ? a.real()<b.real() : a.imag()<b.imag();
	}
}

const double eps = 1e-10;
bool   equal(const double a, const double b) { return abs(a-b)<eps; }
bool   equal(const point& a, const point& b) { return abs(a-b)<eps; }
double dot  (const point& a, const point& b) { return (a*conj(b)).real(); }
double cross(const point& a, const point& b) { return (conj(a)*b).imag(); }
point  vec  (const line&  l)                 { return l[1]-l[0]; }
point  ortho(const point& v)                 { return v*point(0,1); }

int ccw(const point& a, const point& b, const point& c) {
	point u=b-a, v=c-a;
	if(cross(u,v) > 0 ) return +1; // ccw
	if(cross(u,v) < 0 ) return -1; // cw
	if(  dot(u,v) < 0 ) return +2; // cab
	if(norm(u)<norm(v)) return -2; // abc
	return 0;                      // acb
}

int ccw(const line& s, const point& p) {
	return ccw(s[0], s[1], p);
}

point crosspoint(const line& l, const line& m) {
	double A = cross(vec(l), vec(m));
	double B = cross(vec(l), l[1]-m[0]);
	if(abs(A)<eps) {			// parallel
		assert(abs(B)<eps);
		return m[0];			// sameline
	}
	return m[0] + B/A*vec(m);
}

polygon convex_cut(const polygon& g, const line& l, int f=0) {
	polygon h;
	line m(l[f%2], l[(f+1)%2]);

	for(int i=0; i<g.size(); i++) {
		const point& a = g[i];
		const point& b = g[(i+1)%g.size()];
		if(ccw(m,a) != -1) h.push_back(a);
		if(ccw(m,a)*ccw(m,b) < 0) {
			point p = crosspoint(line(a,b), m);
			if((!equal(a,p)) && (!equal(b,p))) {
				h.push_back(p);
			}
		}
	}
	return h;
}

int main()
{
	int N;
	while(cin>>N, N) {
		polygon g;
		while(N--) {
			double x,y;
			cin>>x>>y;
			g.push_back(point(x,y));
		}

		polygon h;
		h.push_back(point(    0,    0));
		h.push_back(point(10000,    0));
		h.push_back(point(10000,10000));
		h.push_back(point(    0,10000));

		for(int i=0; i<g.size(); i++) {
			h = convex_cut(h, line(g[i], g[(i+1)%g.size()]));
		}
		cout << (h.size()?1:0) << endl;
	}


}

Measured memory_bytes: 0
N, A, B, C, D = map(int, input().split())
S = '#' + input()
for j in range(B, D):
    if S[j] == '#' and S[j + 1] == '#':
        print('No')
        exit()
for j in range(A, C):
    if S[j] == '#' and S[j + 1] == '#':
        print('No')
        exit()
if D > C:
    print('Yes')
    exit()
for j in range(B - 1, D):
    if S[j] == '.' and S[j + 1] == '.' and S[j + 2] == '.':
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	string s;
	cin >> s;
	int n=s.size(),i;
	rep(i,n)
	{
		if(i%2==0)
		{
			cout << s[i];
		}
	}
	return 0;
}


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

int main() {
 int a,b,c;
 cin >> a;
 b = -1;
 c = 7;
 for(int i = 1;i<=a;i++){
   if(c%a==0) {
     b = i;
     break;
   }
   c = c%a*10+7;
 }
  cout << b << endl;
}

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

int main(){
  int N,M,i,ans=0,e,a[51],b[51],c[51],d[51];
  cin>>N>>M;
  for(i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }
  for(i=0;i<M;i++){
    cin>>c[i]>>d[i];
  }
  for(int j=0;j<N;j++){
    e=400000001;
      ans=0;
  for(i=0;i<M;i++){
   if(e>abs(a[j]-c[i])+abs(b[j]-d[i])){
     ans=i+1;
     e=abs(a[j]-c[i])+abs(b[j]-d[i]);
   }
  }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 764
import sys,math,itertools
#n, m = map(int, raw_input().split())
n = input()
S = ["".join(sorted(raw_input())) for i in range(n)]
S.sort(key=lambda x:len(x))
ans = S[0]
def maxBy(f, x, y):
    if f(x) > f(y):
        return x
    else:
        return y

table = { ("","") : "" }
def lcs(xs,ys):
    if (xs,ys) in table:
        return table[(xs,ys)]

    ret = ""
    if xs == "" or ys == "":
        ret = ""
    elif xs[-1] == ys[-1]:
        ret = lcs(xs[:-1],ys[:-1]) + xs[-1]
    else:
        ret = maxBy(len,
                    lcs(xs[:-1],ys),
                    lcs(xs,ys[:-1]))
    table[(xs,ys)] = ret
    return ret
for i in range(1,n):
    ans = lcs(ans,S[i])
print ans

Measured memory_bytes: 12428
url = "https://atcoder.jp//contests/abc095/tasks/arc096_a"

def main():
    A, B, C, X, Y = list(map(int, input().split()))
    piza = [X, Y]
    price = 0
    if A + B > C * 2:
        min_piza = min(X, Y)
        price += min_piza * (C * 2)
        piza = [v - min_piza for v in piza]
    # A
    if A > C * 2:
        price += piza[0] * (C * 2)
        piza[1] -= piza[0]
    else:
        price += piza[0] * A
    # B
    if B > C * 2:
        price += piza[1] * (C * 2)
    else:
        price += piza[1] * B
    print(price)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;

const int N = 300, MOD = 998244353;

int m, n, u;
long long ans = 1;
vector<bitset<N>> eli;

long long pw(int p)
{
    long long ret = 1;
    for (int i = 0; i < p; i++)
        (ret *= 2) %= MOD;
    return ret;
}

int main()
{
    scanf("%d%d", &m, &n);
    for (int i = 0; i < m; i++)
    {
        bitset<N> cur;
        for (int j = 0; j < n; j++)
        {
            scanf("%d", &u);
            cur.set(j, u);
        }
        for (bitset<N> &v : eli)
            if (cur.test(v._Find_first()))
                cur ^= v;
        if (cur._Find_first() < N)
        {
            eli.push_back(cur);
            for (int j = cur.size() - 1; j > 0; j--)
                if (eli[j]._Find_first() < eli[j - 1]._Find_first())
                    swap(eli[j], eli[j - 1]);
                else
                    break;                
        }
    }
    printf("%lld", 1LL * (pw(m) - pw(m - eli.size()) + MOD) * pw(n - 1) % MOD);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;
const i64 mod = 1e9 + 7;

int main()
{
	int n;
	char s[200005];

	scanf("%d%s", &n, s);

	int opened = 0;
	i64 ans = 1;

	for(int pos = 0; pos < 2 * n; pos++) {

		int cur = ((s[pos] == 'B' ? 1 : 0) + opened);

		if(cur % 2 == 1) {
			opened += 1;
		} else {
			ans = ans * opened % mod;
			opened -= 1;
		}

		if(opened < 0) {
			ans = 0;
		}
	}

	if(opened != 0) {
		ans = 0;
	}

	for(int i = 1; i <= n; i++) {
		ans = ans * i % mod;
	}

	printf("%lld\n", ans);

	return 0;
}

/* waffle */


Measured memory_bytes: 384
#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 rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};


int main(){
    while(true){
        int n;
        int c = 0;
        cin >> n;
        if(n == 0) break;
        for(int i=1;i<1000;i++){
            for(int j=i+1;j<1000;j++){
                int total = 0;
                for(int k=i;k<=j;k++){
                    total += k;
                }
                if(total == n) c++;
            }
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, cnt;

int dfs(ll x, bool f3, bool f5, bool f7) {
	if (x > N)return 0;
	if (f3&&f5&&f7)++cnt;
	dfs(x * 10 + 3, true, f5, f7);
	dfs(x * 10 + 5, f3, true, f7);
	dfs(x * 10 + 7, f3, f5, true);
	return 0;
}

int main() {
	cin >> N;
	dfs(0, false, false, false);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine
 
object Main {
  def euclid(m:Int,n:Int):Int = if(n==0) m else euclid(n,m%n)
  def main(args:Array[String]) = {
      val n = readLine.split(" ").map(_.toInt)
      println(euclid(n(0),n(1)))
  }
}

Measured memory_bytes: 43748
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
Ls = nl()

Ls = sorted(Ls, reverse=True)
if Ls[0] < sum(Ls[1:]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
def set_children(inorder_list):
    global p
    rn = preorder[p]
    i = inorder_list.index(rn)
    left_side = inorder_list[:i]
    right_side = inorder_list[i:]
    right_side.remove(rn)
    if left_side:
        p += 1
        set_children(left_side)
    if right_side:
        p += 1
        set_children(right_side)
    postorder.append(rn)

if __name__ == "__main__":
    p = 0
    n = int(input())
    preorder = input().split()
    inorder = input().split()
    postorder = []
    set_children(inorder[:])
    print(" ".join(postorder))



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

int main(void) {
  long long N, x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0, last = -1;
  for (int i = 0; i < N; i++) {
    if (a[i] > x)
      break;
    else {
      x -= a[i];
      ans++;
      last = i;
    }
  }
  if (last == N - 1 && x > 0) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INFTY (1<<30)

int i, H, A[2000000];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int *A, int i){
  int largest, tmp;
  int l = left(i), r = right(i);
  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if (largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}

int extract(){
  int maxv;
  if(H<1)return -INFTY;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(A,1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if(key<A[i])return;
  A[i]=key;
  while(1){
    if(i<=1 || A[i/2]>=A[i])break;
    tmp=A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;
    i=i/2;
  }
}

void insert(int key){
  A[++H]=-INFTY;
  increaseKey(H, key);
}



int main(){
  int key;
  char C[8];
  
  while(1){
    scanf("%s",C);
    if(C[0]=='e'&&C[1]=='n')break;
    if(C[0]=='i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}
 

Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  long long t[105],u=0;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  if(n!=1){
  for(int i=1;i<n;i++){
    if(i==1){
    u=t[i]/__gcd(t[i],t[i-1])*t[i-1];
    }else{
      u=u/__gcd(u,t[i])*t[i];
    }
  }
  if(u<=1000000000000000000){
  cout<<u<<"\n";
  }else{
    cout<<1000000000000000000<<"\n";
  }
  }else{
    cout<<t[0]<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, k;
  int d[15] = {};
  cin >> n >> k;

  REP(i, k) {
    int x;
    cin >> x;
    d[x] = 1;
  }

  ll ans = n;

  while (true) {
    bool flag = true;
    string s = to_string(ans);
    for (auto c : s) {
      if (d[c - '0'] == 1) {
        flag = false;
        break;
      }
    }

    if (flag) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef dsu uf;
typedef fenwick_tree<ll> fw;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n,q;
  cin >> n >> q;
  uf u(n);
  while(q--){
   ll t,w,v;
    cin >> t >> w >> v;
    if(t==0) u.merge(w,v);
    else cout << (u.same(w,v)?1:0) << endl;
    
  }
  

}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 3010;

int n;
ll a[MAX_N];

ll dp[MAX_N][MAX_N];

void init(){
    rep(i,MAX_N) rep(j,MAX_N) dp[i][j] = 0;
}

ll f(int l, int r){
    if(dp[l][r]) return dp[l][r];
    if(l == r){
        dp[l][r] = a[l];
    }else{
        dp[l][r] = max(a[l]-f(l+1,r), a[r]-f(l,r-1));
    }
    return dp[l][r];
}

int main()
{   
    cin >> n;
    rep(i,n) cin >> a[i];

    init();

    f(0,n-1);

    cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 74576
def solve():
    n = int(input())
    s = list(input())
    l = n+0
    while True:
        for i in range(l-1)[::-1]:
            if s[i] == s[i+1]:
                s.pop(i)
                l-=1
        if n == l:
            break
        n = l
    print(l)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 4084
#!/usr/bin/env python3

a, b, c, x, y = map(int, input().split())

ans = 2*5000*100000
for k in range(100001):
    tmp = 2*c*k + max(x-k, 0)*a + max(y-k, 0)*b
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
long long n[50], p;
int main() {
	n[0] = 1; n[1] = 1; n[2] = 2;
	for (int i = 3; i < 40; i++) {
		n[i] = n[i - 1] + n[i - 2] + n[i - 3];
	}
	while (true) {
		cin >> p;
		if (!p) { break; }
		cout << (n[p] + 3649) / 3650 << endl;
	}
}

Measured memory_bytes: 1156
n, m = map(int,input().split())
lst = [-1 for i in range(n + 1)]
lst[0] = 0
def find(x):
    if(lst[x] < 0):
        return(x)
    else:
        return(find(lst[x]))
def unit(x, y):
    xr = find(x)
    yr = find(y)
    if (xr == yr):
        pass
    else:
        if (xr > yr):
            x, y = y, x
            xr, yr = yr, xr
        lst[xr] = lst[xr] + lst[yr]
        lst[yr] = xr

for i in range(m):
    a, b = map(int,input().split())
    unit(a, b)

print(-(min(lst)))
    


Measured memory_bytes: 16760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin>>n;
map<ll, ll> mp;
for (ll i = 0; i < n;i++){
    ll t;
    cin >> t;
    mp[t]++;
}
if (mp.size() == 1 and mp.count(0))
   cout << "Yes" << endl;
else if (mp.size() == 2 and (n % 3) == 0 and mp.count(0)) {
    for(auto i:mp){
        if (i.first == 0) continue;
        if(i.second==2*n/3 and mp.at(0)==n/3){
            cout << "Yes" << endl;
        }
        else
            cout << "No" << endl;
    }
} else if (mp.size() == 3 and (n % 3) == 0) {
    ll a = 0;
    for (auto i : mp) a ^= i.first;
    bool flag = true;
    for(auto i:mp){
        if (i.second != (n / 3)) flag = false;
    }
    if (flag and a==0) cout << "Yes" << endl;
    else
        cout << "No" << endl;
} else
    cout << "No" << endl;
}

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

int main() { 
    string s;
    int a[26] = {0};
    cin >> s;
    int ssize = s.size();
    if(s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << '\n'; 
        return 0;
    }
    if(ssize != 26) {
        for(int i = 0; i < ssize; ++i) {
            a[s[i] - 'a'] = 1;
        }
        for(int i = 0; i < 26; ++i) {
            if(a[i] == 0) {
                s += (char)(i + 'a');
                break;
            }
        }
    } else {
        for(int i = 25; i >= 1; --i) {
            if(s[i-1] < s[i]) {
                for(int j = 0; j < i; ++j) {
                    a[s[j] - 'a'] = 1;
                }
                char ss = s[i-1];
                s = s.substr(0, i-1);
                for(int j = 0; j < 26; ++j) {
                    if(a[j] == 0 && (char)(j + 'a') > ss) {
                        s += (char)(j + 'a');
                        break;
                    }
                }
                break;
            }
        }
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ac=0;
		int wa=0;
		int tle=0;
		int re=0;
		for(int i=0;i<=n;i++) {
			String word = sc.nextLine();
			
			switch(word) {
			case "AC":
				ac++;
				break;
			case "WA":
				wa++;
				break;
			case "TLE":
				tle++;
				break;
			case "RE":
				re++;
				break;
			}
		}
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);
		
		
		
	}
}

Measured memory_bytes: 60204
#include <stdio.h>

int main(void)
{
	int s,a,b,m[5];
	for(s=0;s<4;s++){
	scanf("%d %d",&a,&b);
	if(a==1){
		m[s]=b*6000;
	}else if(a==2){
		m[s]=b*4000;
	}else if(a==3){
		m[s]=b*3000;
	}else if(a==4){
		m[s]=b*2000;
	}
	}
	for(s=0;s<4;s++){
	printf("%d\n",m[s]);
	}
	return 0;
}


Measured memory_bytes: 2124
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> inputs = new ArrayList<Integer>();
		//ArrayList<Integer> results = new ArrayList<Integer>();
		
		setInputs(inputs);
		
		for(int i = 0; i < inputs.size(); i++){
			System.out.println(findCombinationsFaster(inputs.get(i)));
		}
	}
	
	private static void setInputs(ArrayList<Integer> inputs){
		Scanner sc = new Scanner(System.in);
		
		try{
			while(true){
				inputs.add(sc.nextInt());
			}
		}catch(NoSuchElementException e){
			//EOFツ・EOTツつェツ禿シツ療債つウツづェツつスツづァツ篠淞づ個渉按猟敖づーツ行ツつ、
		}
	}
	
	private static int findCombinationsFaster(int sum){
		int numCombinations = 0;
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					for(int l = 9; l > -1; l--){
						if(isBigger(sum, i, j, k, l)){
							break;
						}
						else if(isSame(sum, i, j, k, l)){
							numCombinations++;
						}
					}
				}
			}
		}
		return numCombinations;
	}
	
	private static int findCombinations(int sum){
		int numCombinations = 0;
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					for(int l = 0; l < 10; l++){
						if(isSame(sum, i, j, k, l)){
							numCombinations++;
						}
					}
				}
			}
		}
		return numCombinations;
	}
	
	private static boolean isBigger(int sum, int i, int j, int k, int l){
		if(sum > (i + j + k + l)){
			return true;
		}
		else{
			return false;
		}
	}
	
	private static boolean isSame(int sum, int i, int j, int k, int l){
		if(sum == (i + j + k + l)){
			return true;
		}
		else{
			return false;
		}
	}
}

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

//#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

namespace SA{
    const int MAX=1000000;
    int N,K;
    int tmp[MAX+1],rank[MAX+1];
    bool compare_sa(int i,int j){
        if(rank[i]!=rank[j])return rank[i]<rank[j];
        else{
            int ri=(i+K<=N)?rank[i+K]:-1;
            int rj=(j+K<=N)?rank[j+K]:-1;
            return ri<rj;
        }
    }

    vector<int> construct_sa(string S){
        N=S.size();
        vector<int>sa(N+1);
        for(int i=0;i<=N;i++)sa[i]=i;
        for(int i=0;i<=N;i++){
            rank[i]=i==N?-1:S[i];
        }

        for(K=1;K<=N;K*=2){
            sort(sa.begin(),sa.end(),compare_sa);
            tmp[sa[0]]=0;
            for(int i=1;i<=N;i++){
                tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
            }
            for(int i=0;i<=N;i++)rank[i]=tmp[i];
        }
        return sa;
    }

    int contain(string &S,vector<int>&sa,string &T){
        int a=0,b=S.size();
        while(b-a>1){
            int c=(a+b)/2;
            if(S.compare(sa[c],T.size(),T)<0)a=c;
            else b=c;
        }
        if(S.compare(sa[b],T.size(),T)==0)return b;
        return -1;
    }
}

signed main(){
    string S;
    vint sa;
    int Q;
    cin>>S>>Q;
    sa=SA::construct_sa(S);
    while(Q--){
        string T;cin>>T;
        if(SA::contain(S,sa,T)!=-1)cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 18672
# Aizu Problem NTL_1_D: Euler's Phi Function
#
import itertools
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def get_factors(n):
    f = 2
    increments = itertools.chain([1,2,2], itertools.cycle([4,2,4,2,4,6,2,6]))
    for incr in increments:
        if f*f > n:
            break
        while n % f == 0:
            yield f
            n //= f
        f += incr
    if n > 1:
        yield n

N = int(input())
totient = N
for p in list(set(get_factors(N))):
    totient *= (1 - 1 / p)
print(int(totient))

Measured memory_bytes: 7880
#include <iostream>
#include <stdio.h>
using namespace std;
 
int main(){
  int n,k,d,a;
  cin >> n >> k;
  int array[n];
  for (int i = 0; i < n; ++i) array[i] = 0;
  
  for (int i = 0; i < k; ++i) {
  	cin >> d;
  	for (int j = 0; j < d; ++j) {
      cin >> a;
       array[a-1] += 1;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < n; ++i) {
   	if (array[i] == 0) ans += 1; 
  }
  cout << ans << endl;

  return 0;
}

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

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

const int mod = 1e9 + 7;
const int mN = 1e9;

int n, w;

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

  cin>>n>>w;
  vector<pair<int, int>> arr(n);
  for(int i = 0, x, y; i < n; ++i){
    cin>>x>>y;
    arr[i] = make_pair(x, y);
  }
  vector<vector<ll>> dp(n + 1, vector<ll> (w + 1));

  for(int i = 0; i <= n; ++i){
    for(int j = min(0, arr[i - 1].first - 1); j <= w; ++j){
      if(i == 0 || j == 0) dp[i][j] = 0;
      else if(arr[i - 1].first <= j) dp[i][j] = max(arr[i - 1].second + dp[i - 1][j - arr[i - 1].first], dp[i - 1][j]);
      else dp[i][j] = dp[i - 1][j];
    }
  }
  cout<<dp[n][w]<<"\n";
}


Measured memory_bytes: 83144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
typedef pair<ll,ll>LLP;
const int MAXN=300+20;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double RATE=0.995;
const double eps=1e-15;
std::mt19937 rnd(time(0));
ll qpw(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%MOD; a=(a*a)%MOD; b>>=1; } return ans;}//b>=0
int g[MAXN][MAXN];
int fuel[MAXN][MAXN];
signed main()
{
    int n,m,l;
    scanf("%d%d%d",&n,&m,&l);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            g[i][j]=g[j][i]=fuel[i][j]=fuel[j][i]=INF;
    for(int i=0;i<m;++i)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        g[u][v]=g[v][u]=w;
    }
    for(int k=1;k<=n;++k)
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
                g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
        {
            if(g[i][j]<=l) fuel[i][j]=1;
            else fuel[i][j]=INF;
        }
    for(int k=1;k<=n;++k)
    {
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=n;++j)
            {
                fuel[i][j]=min(fuel[i][j],fuel[i][k]+fuel[k][j]);
            }
        }
    }
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int s,t;
        scanf("%d%d",&s,&t);
        fuel[s][t]==INF?puts("-1"):printf("%d\n",fuel[s][t]-1);
    }
    return 0;
}


Measured memory_bytes: 1280
from collections import deque

N, L = map(int, input().split())
box = list(map(int, input().split()))

que = deque()
ans = []
for i, a in enumerate(box):
    while que and a <= que[-1][1]:
        que.pop()
    que.append((i,a))
    
    ans.append(que[0][1])
    if que and que[0][0] <= i-L+1:
        que.popleft()
        
print(*ans[L-1:])


Measured memory_bytes: 126252
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (L, R) = read!(i64, i64);

    let mut m = 2019;
    if R - L > 3000 {
        m = 0;
    } else {
        for i in L..R + 1 {
            for j in i + 1..R + 1 {
                m = min(m, (i % 2019) * (j % 2019) % 2019);
            }
        }
    }

    println!("{}", m)
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<n; ++i)
#define FOR(i, a, b) for(int i=a; i<b; ++i)
#define FORR(i, a, b) for(int i=b-1; i>=a; --i)

bool f[55556];

void po(){
	FOR(i, 2, 55556){
		if(!f[i]){
			for(int j=i+i; j<=55555; j+=i) f[j]=true;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	po();
	int a[60];
	int cnt=0;
	FOR(i, 2, 55556){
		if(!f[i] && i%5==1){
			a[cnt]=i;
			++cnt;
			if(cnt>=n) break;
		}
	}
	REP(i, n) cout<<a[i]<<' ';
	cout<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=1e5+5;
int x[N],n,m,i,j,b[N],c[N],z[N];
long long k,ans;
void solve(){
	if(k==0)return;
	int y=k&1;k>>=1;solve();
	for(memcpy(z+1,c+1,n-1<<2),i=1;i<n;++i)c[i]=z[c[i]];
	if(y)for(memcpy(z+1,c+1,n-1<<2),i=1;i<n;++i)c[i]=z[b[i]];
}
int main(){
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",x+i),b[i]=c[i]=i;for(i=n;i;--i)x[i]-=x[i-1];
	scanf("%d%lld",&m,&k);for(i=1;i<=m;++i)scanf("%d",&j),std::swap(b[j-1],b[j]);
	solve();printf("%lld\n",ans=x[1]);
	for(i=1;i<n;++i)printf("%lld\n",ans+=x[c[i]+1]);
	return 0;
}

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


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;

  int cnt = 0;

  for(int i = 0; i < 1000; i++){
    string t;
    if(i < 10){t = "00" + to_string(i);}
    else if(i < 100){t = "0" + to_string(i);}
    else{t = to_string(i);}
    int res = 0;
    for(int j = 0; j < s.size(); j++){
      if(s[j] == t[0] && res == 0){res = 1; continue;}
      else if(s[j] == t[1] && res == 1){res = 2; continue;}
      else if(s[j] == t[2] && res == 2){res = 0; cnt++; break;}      
    }

    
  }
  cout << cnt << endl;

}

Measured memory_bytes: 256